getTypeData = new GetmatchData(); $this->getOddsData = new GetOddsData(); $this->commonFunction = C()->get('commonFunction'); } /* *首页条件筛选(足球参赛表) */ private function zq_participate (){ $data['type'] = '足球'; $data['game_code'] = 'zq'; $where_search = []; //查询今日赛事 $match_model = $this->commonFunction->getModels($data['game_code'],1); $where = $this->commonFunction->getState('StToday',$match_model['model_match'],$data['game_code']); $Orwhere = []; $data['info'][0]['name'] = '今日赛事'; $data['info'][0]['code'] = 'today'; $data['info'][0]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']); //查询明日赛事 $where=[['st_zq_competition.match_date','tomorrow']]; $Orwhere=[]; $data['info'][1]['name'] = '明日赛事'; $data['info'][1]['code'] = 'tomorrow'; $data['info'][1]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']); //受欢迎的欧洲赛事 $where =[['area.name_en','Europe'],['st_zq_league.hot',0]]; $Orwhere=[]; $data['info'][2]['name'] = '受欢迎的欧洲赛事'; $data['info'][2]['code'] = 'popular'; $data['info'][2]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']); //查询亚洲,澳洲赛事 $where =[]; $Orwhere = function ($query) { $query->Orwhere('area.name_en','=','Asia') ->Orwhere('country.name_en','=','Australia'); }; $data['info'][3]['name'] = '亚洲/澳洲赛事'; $data['info'][3]['code'] = 'asia_aus'; $data['info'][3]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']); //查询北美,南美赛事 $where = []; $Orwhere = function ($query) { $query->Orwhere('area.name_en','=', "South America") ->Orwhere('area.name_en','=', "North America"); }; $data['info'][4]['name'] = '北美/南美赛事'; $data['info'][4]['code'] = 'south_north'; $data['info'][4]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']); //国际赛事 $where = [['area.name_en',"world"]]; $Orwhere = []; $data['info'][5]['name'] = '国际赛事'; $data['info'][5]['code'] = 'intl'; $data['info'][5]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']); return $data; } /* *首页条件筛选(其他球参赛表) */ private function qt_participate ($typeGame){ //===查询该球类是否存在或启用=== $getModels = $this->commonFunction->getModels($typeGame); $data['game_code'] = $typeGame; $data['type'] = lm('GameType','Sports')->where('game_code',$typeGame)->value('game_name'); $st_competition = $getModels['model_match']; //所有赛事 $where_search = []; $where = []; $Orwhere = []; $data['info'][0]['name'] = '所有赛事'; $data['info'][0]['code'] = 'all'; $data['info'][0]['count'] = $this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']); //今日赛事 $where = $this->commonFunction->getState('StToday',$st_competition,$typeGame); $Orwhere = []; $data['info'][1]['name'] = '今日赛事'; $data['info'][1]['code'] = 'today'; $data['info'][1]['count']=$this->getMatchCount($where,$Orwhere,$where_search,$data['game_code']); return $data; } /* * 参赛表数据接口 */ public function participate(){ $type = $_REQUEST['typeGame']; if($type != 'zq'|| empty($type)){ $data = $this->qt_participate($type); }else{ $data = $this->zq_participate(); } Render($data, '1', lang('Tips','Sports')->get('success')); } /* * 参赛列表详情 */ public function participate_details() { $game_code = $_REQUEST['game_code'];//游戏代码 $code = $_REQUEST['code'];//参赛代码 $search = $_REQUEST['search'];//参赛代码 $lg_id = $_REQUEST['lg_id'];//参赛代码 //===查询该球类是否存在或启用=== $getModels = $this->commonFunction->getModels($game_code); $st_league = $getModels['model_league']; $st_competition = $getModels['model_match']; $st_odds = $getModels['model_odds']; $where_search = function($query)use ($st_competition,$search){ $query->where($st_competition.'.home_team','like','%'.$search.'%') ->orWhere(function($query)use ($st_competition,$search) { $query->where($st_competition . '.guest_team', 'like', '%' . $search . '%'); }); }; $Orwhere = []; switch ($code) { case $code == 'today': $where =$this->commonFunction->getState('StToday',$st_competition,$game_code); //查询今日赛事 $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code); break; case $code == 'popular': $where =[['area.name_en','Europe'],[$st_league.'.hot',0]]; //欧洲最受欢迎的赛事 $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code); break; case $code == 'asia_aus': $where = []; $Orwhere = function ($query) { $query->Orwhere('area.name_en','=','Asia') ->Orwhere('country.name_en','=','Australia'); }; //亚洲/澳洲赛事 $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code); break; case $code == 'south_north': $where = []; $Orwhere = function ($query) { $query->Orwhere('area.name_en','=', "North America") ->Orwhere('area.name_en','=', "South America"); }; //南美洲/北美洲赛事 $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code); break; case $code == 'tomorrow': $where = [[$st_competition.'.match_date','tomorrow']]; //明日赛事 $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code); break; case $code == 'intl': $where = [['area.name_en', "world"]]; //国际赛事 $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code); break; case $code == 'all': $where = []; //所有赛事 $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code); break; case $code == 'qt': $where = [[$st_league.'.id',$lg_id]]; //指定联赛下的赛事 $data = $this->getMatchInfo($where,$Orwhere,$where_search,$game_code); break; } //根据赛事ID获取赔率数据 $matchData = []; foreach($data as $k => $v){ foreach($v['match_info'] as $kk => $vv){ $matchData[] =$vv; } } $oddsTypeWhere = [[$getModels['model_odds'].'.is_stringscene','=',0]]; if($game_code == 'zq'){ $matchData = $this->getOddsData->getOddsZQ($matchData,$st_odds,$this->source,$oddsTypeWhere); } if($game_code == 'lq'){ $matchData = $this->getOddsData->getOddsLQ($matchData,$st_odds,$this->source,$oddsTypeWhere); } if($game_code == 'bq'){ $matchData = $this->getOddsData->getOddsBQ($matchData,$st_odds,$this->source,$oddsTypeWhere); } if($game_code == 'wq'){ $matchData = $this->getOddsData->getOddsWQ($matchData,$st_odds,$this->source,$oddsTypeWhere); } foreach($data as $k => $v){ $v['match_info'] = []; foreach($matchData as $kk=>$vv){ if($v['lg_id'] == $vv['lg_id']){ $v['match_info'][] = $vv; } } $data[$k] = $v; } $data = array_values($data); Render($data, '1', lang('Tips','Sports')->get('success')); } /* *首页条件筛选(所有赛事) */ public function matchData (){ $gameType = $_REQUEST['gameType']; $search = $_REQUEST['search']; $date = $_REQUEST['datetime']; //获取球类 model $gameType = empty($gameType) ? 'zq':$gameType; $getModels = $this->commonFunction->getModels($gameType); $st_league = $getModels['model_league']; $st_competition = $getModels['model_match']; //所属球类 $where = []; if(!empty($date)){ if($date == 'morning'){ $where=[[$st_competition.'.is_morningplate',1], [$st_competition.'.match_date','>',date("Y-m-d",strtotime("+6 day"))]]; }else if($date == 'today'){ $where = $this->commonFunction->getState('StToday',$st_competition,$gameType); }else { $where[$st_competition.'.match_date'] = $date; } } //查询球类名称 $data['type'] = lm('GameType', 'Sports') ->where('game_code',$gameType) ->value('game_name'); //国家联赛数据 $select=['st_area_country.id as region_id','st_area_country.name as region',$st_league.'.id as lg_id',$st_league.'.name_chinese as league',$st_competition.'.id as match_id']; $country = $this->getRegionInfo($where,$search,$select,'st_area_country','id','country_id',$gameType); //洲下所有联赛 $select=['st_area_country.id as region_id','st_area_country.name as region',$st_league.'.id as lg_id',$st_league.'.country_id',$st_league.'.name_chinese as league',$st_competition.'.id as match_id']; $area = $this->getRegionInfo($where,$search,$select,'st_area_country','id','area_id',$gameType); $data['info'] = array_merge($country,$area); Render($data, '1', lang('Tips','Sports')->get('success')); } /** * 根据地区获取信息 * @param [array] $where 条件 * @param [array] $search 搜索条件 * @param [string] $regionModel 地区model * @param [int] $regionID 地区model * @param [type] $game_code 球类代码 * @return [array] $data */ public function getRegionInfo($where=[],$search,$select,$regionModel,$regionID,$a_c_id,$game_code ='zq'){ $getModels = $this->commonFunction->getModels($game_code); $st_league = $getModels['model_league']; $st_competition = $getModels['model_match']; try{ //地区联赛赛事数据 $regionInfo = lm($st_league,"Sports") ->join($st_competition,$st_competition.'.lg_id',$st_league.'.id') ->join($regionModel,$regionModel.'.'.$regionID,$st_league.'.'.$a_c_id) ->select($select) ->where($st_league.'.name_chinese','like','%'.$search.'%') ->where($where) ->where([ [$st_competition.'.home_team','<>',null], [$st_competition.'.guest_team','<>',null], [$st_league.'.name_chinese','!=',''], [$st_competition.'.status','<',2], [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)] ]) ->get() ->toArray(); //===获取当前赛事是否有赔率,如果没有则去除=== $regionInfo = $this->commonFunction->Handle_Odds_Null($regionInfo,$getModels); //地区分割 $info = []; foreach($regionInfo as $k => $v){ $info[$k]['region'] = $v['region']; $info[$k]['region_id'] = $v['region_id']; } //地区去重 $info = array_unique($info, SORT_REGULAR); //根据地区分类 foreach ($info as $key => $vlue) { foreach ($regionInfo as $k => $v) { if ($vlue['region'] == $v['region'] and $v['country_id'] == 0) { $info[$key]['league_count'][$k]['league'] = $v['league']; $info[$key]['league_count'][$k]['lg_id'] = $v['lg_id']; } } } //去除没有联赛的国家或地区 foreach($info as $k =>$v){ if(empty($v['league_count'])){ unset($info[$k]); } } sort($info); //联赛去重 foreach ($info as $key => $vlue) { $info[$key]['league_count'] = array_unique($vlue['league_count'], SORT_REGULAR); //统计联赛下赛事 foreach ($vlue['league_count'] as $k => $v) { foreach ($regionInfo as $kk => $vv) { if ($v['league'] == $vv['league']) { if(!empty($info[$key]['league_count'][$kk]['league'])){ $info[$key]['league_count'][$kk]['count'] += 1; } } } } sort($info[$key]['league_count']); } return $info; } catch (\Exception $e) { echo $e->getMessage(); } } /** * 联赛下 赛事及默认赔率数据 */ public function matchDetails(){ $data = $_REQUEST; try { if(empty($data['game_code']) || empty($data['leagueID']) || empty($data['oddsType'])){ throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR'))); } //根据时间获取联赛下赛事数据 $whereDate = []; if(!empty($data['matchDate']) ){ if($data['matchDate']== "morning"){ $whereDate = [['is_morningplate',1], ['match_date','>',date("Y-m-d",strtotime("+6 day"))]]; }else{ $whereDate = ['match_date'=>$data['matchDate']]; } } $models = $this->commonFunction->getModels($data['game_code'],0); $model_match = $models['model_match']; $model_odds = $models['model_odds']; $model_league = $models['model_league']; $model_result = $models['model_result']; $oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$data['oddsType']); $source = $this->source;//数据源 $data = $this->getOddsData->getOddsData($data,$whereDate,$source,$oddsTypeWhere); if(!empty($data['matchData'])){ foreach($data['matchData'] as $k=>$v){ if(empty($v['oddsData'])) unset($data['matchData'][$k]); } sort($data['matchData']); $data['matchNum'] = count($data['matchData']); } Render($data, '1', lang('Tips','Sports')->get('success')); } catch (\Exception $e) { echo $e->getMessage(); } } //获取各状态下有哪些球类 public function getGame(){ $type_code = $_REQUEST['type_code']; try { if(empty($type_code)){ throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR'))); } //==获取当前可用球类== $game = lm('GameType', 'Sports')->where('status',1)->select('game_code','game_name','game_ico_url')->get()->toArray(); $gameData = []; foreach ($game as $key=>$type){ $matchModel = $this->commonFunction->getModels($type['game_code']); //获取 不同状态的查询条件 $where = $this->commonFunction->getState($type_code,$matchModel['model_match'],$type['game_code']); if($type_code != 'StChampion'){ $matchNum = lm($matchModel['model_league'],"Sports") ->join($matchModel['model_match'],$matchModel['model_match'].'.lg_id',$matchModel['model_league'].'.id') ->join($matchModel['model_odds'],$matchModel['model_odds'].'.match_id',$matchModel['model_match'].'.id') ->where($where) ->where([[$matchModel['model_league'].'.name_chinese','!=','']]) ->count("*"); //获取满足状态的球类/去除冠军类 if($matchNum != 0 and $type['game_code']!='gj'){ $gameData[] = $type; } }else{ $matchNum = lm($matchModel['model_odds'], 'Sports') ->where($where) ->count('*'); //获取满足状态的球类/去除冠军类 if($matchNum != 0 and $type['game_code']!='gj'){ $gameData[] = $type; } } } Render($gameData, '1', lang('Tips','Sports')->get('success')); } catch (\Exception $e) { echo $e->getMessage(); } } /** * @throws \Exception * 获取不同状态下 各球类赛事数据 * game_code 球类代码 * type_code 类型代码 */ public function matchState(){ $source = $this->source;//数据源 条件 $ret = $_REQUEST; try { if(empty($ret['game_code']) || empty($ret['type_code'])){ throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR'))); } $data = $this->getTypeData->typeData($ret,$source); Render($data, '1', lang('Tips','Sports')->get('success')); } catch (\Exception $e) { echo $e->getMessage(); } } /** * 根据赛事状态获取赔率查询条件 */ public function getOddsTypeWhere($model_odds,$oddsType){ //获取赛事不同状态下的赔率 if(!empty($oddsType)){ switch ($oddsType) { case 'StRollBall'://滚球 $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',0]]; break; case 'StSoon'://即将 $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',0]]; break; case 'StToday'://今日 $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',0]]; break; case 'StMorningPlate'://早盘 $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',0]]; break; case 'StStringScene'://串场 $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]]; break; case 'home'://首页 $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',0]]; break; default: $oddsTypeWhere = []; } } return $oddsTypeWhere; } /** * 获取赛事所有玩法赔率数据 */ public function matchOdds(){ $game_code = $_REQUEST['game_code']; $matchID = $_REQUEST['matchID']; $status = $_REQUEST['status']; $oddsType = $_REQUEST['oddsType']; try { if(empty($game_code) || empty($matchID) || empty($oddsType)){ throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR'))); } //根据球类代码 获取相关model $models = $this->commonFunction->getModels($game_code,1); $model_match = $models['model_match']; $model_odds = $models['model_odds']; $model_league = $models['model_league']; $model_result = $models['model_result']; $where[] = ['status','=',0]; //如果是串场,则获取串场赔率 if($oddsType == 'StStringScene'){ $where[] = ['is_stringscene','=',1]; }else{ $where[] = ['is_stringscene','=',0]; } //根据球类追加获取限定玩法 $p_code = $this->commonFunction->getOddsPcode($game_code); $oddsData = lm($model_odds, 'Sports') ->select('sort','p_code','id','odds_only','odds_code',$model_odds.'.status','odds','condition','sort','source','utime') ->where([$model_odds.'.match_id'=>$matchID,$model_odds.'.type'=>0]) ->where($where) ->whereIn('p_code',$p_code) ->orderBy('sort', 'desc') ->orderBy('p_code','desc') ->orderBy('odds_code','desc') ->get()->toArray(); $matchData = lm($model_match, 'Sports') ->join($model_league,$model_league.'.id',$model_match.'.lg_id') ->select($model_match.'.lg_id','name_chinese',$model_match.'.id as match_id','home_team','guest_team','match_date','match_time',$model_match.'.status') ->where([$model_match.'.id'=>$matchID]) ->first(); if(empty($matchData)) Render(null, '1', lang('Tips','Sports')->get('success')); $matchData->ptime = '';//赛事进行时间 $matchData->match_score = '';//赛事比分 $matchData->result_mark = '';//赛事实时数据json //通过开赛日期和时间判断是否是进行中滚球 if($matchData->status < 2 and $matchData->match_date == date("Y-m-d") and $matchData->match_time > date("H:i:s", time()-(90*60)) and $matchData->match_time < date("H:i:s", time())){ $matchData->status = 1; } //如果该赛事正在进行,则获取进行时间 if($matchData->status ==1){ $result_record = $models['model_result_record']; $match_id = $matchData->match_id; //如果是棒球 if($result_record == 'st_bq_result_record' || $result_record == 'st_lq_result_record'){ $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.result_mark from $result_record a, (select match_id,max(id) id from $result_record where match_id =$match_id group by match_id)b where a.match_id = b.match_id and a.id = b.id "; //查询 赛事结果记录最新的一条 $match_result_record = S ('DB')->select ($sql); $home_score = $match_result_record[0]->home_score?:0; $guest_score = $match_result_record[0]->guest_score?:0; $matchData->match_score = $home_score.'-'.$guest_score; $matchData->result_mark = $match_result_record[0]->result_mark; } //如果是网球 else if($result_record == 'st_wq_result_record'){ $sql = "select a.match_id,a.home_player_score,a.guest_player_score,a.match_time as a_time,a.match_process,a.result_mark from $result_record a, (select match_id,max(id) id from $result_record where match_id =$match_id group by match_id)b where a.match_id = b.match_id and a.id = b.id "; //查询 赛事结果记录最新的一条 $match_result_record = S ('DB')->select ($sql); $home_score = $match_result_record[0]->home_player_score?:0; $guest_score = $match_result_record[0]->guest_player_score?:0; $matchData->match_score = $home_score.'-'.$guest_score; $matchData->result_mark = $match_result_record[0]->result_mark; }else{ //其他球类 $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a, (select match_id,max(id) id from $result_record where match_id = $match_id group by match_id)b where a.match_id = b.match_id and a.id = b.id "; //查询 赛事结果记录最新的一条 $match_result_record = S ('DB')->select ($sql); $home_score = $match_result_record[0]->home_score?:0; $guest_score = $match_result_record[0]->guest_score?:0; $matchData->match_score = $home_score.'-'.$guest_score; $matchData->result_mark = ''; } $matchData->ptime = $match_result_record[0]->a_time?:0; } //赛事已结束 if($matchData->status ==2){ $oddsData = []; } //查询当前联赛下的赛事 $league = []; if($oddsType != 'StRollBall'){ $where = [ [$model_match.'.home_team','<>',null], [$model_match.'.guest_team','<>',null], [$model_match.'.status','<',2], [$model_match.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)], [$model_match.'.lg_id',$matchData->lg_id], [$model_league.'.name_chinese','!=',''], ]; if($oddsType !='home'){ $getState = $this->commonFunction->getState($oddsType,$model_match,$game_code); }else{ $getState = []; } $league = lm($model_match,'Sports') ->join($model_league,$model_league.'.id',$model_match.'.lg_id') ->select($model_match.'.id as match_id',$model_match.'.home_team',$model_match.'.guest_team',$model_match.'.status',$model_match.'.match_date',$model_match.'.match_time') ->where($where) ->where($getState) ->get() ->toArray(); //===获取当前赛事是否有赔率,如果没有则去除=== $league = $this->commonFunction->Handle_Odds_Null($league,$models); } $list = array(); foreach ($oddsData as $key=>$item){ //获取数据源ID $item['sourceID'] = $this->commonFunction->getSourceID($item['source']); unset($item['source']); //追加所属赔率状态 $item['oddsType'] = ''; if($oddsType == 'StRollBall'){ $item['oddsType'] = 'StRollBall'; } $item['team'] = ''; if(strpos($item['odds_code'],'home') !== false) { $item['team'] = 'home'; } if(strpos($item['odds_code'],'guest') !== false) { $item['team'] = 'guest'; } $list[$key] = $item; } $p_code_array = []; foreach ($oddsData as $key =>$val){ $p_code_array[] = $val['p_code']; } $p_code_array = array_keys(array_flip(array_unique($p_code_array)));//p_code 去重排序 $data = [ 'lg_id' =>$matchData->lg_id, 'leagueName' =>$matchData->name_chinese, 'match_id'=>$matchData->match_id, 'home_team'=>$matchData->home_team, 'guest_team'=>$matchData->guest_team, 'match_time'=>$matchData->match_date." ".$matchData->match_time, 'match_ptime'=>$matchData->ptime, 'match_score'=>$matchData->match_score, 'p_code_array'=> $p_code_array, 'result_mark'=>$matchData->result_mark, 'oddsData'=>$list, 'league' => $league, ]; Render($data, '1', lang('Tips','Sports')->get('success')); } catch (\Exception $e) { echo $e->getMessage(); } } /** * 手动 更新 赛事状态 */ public function updateMatch () { $game_code = $_REQUEST['game_code']; $match_date = $_REQUEST['match_date']; try { if(empty($game_code)){ throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR'))); } if(empty($match_date)) $match_date = date('Y-m-d'); //根据球类代码 获取相关model $models = $this->commonFunction->getModels($game_code); $model_match = $models['model_match']; $matchData = lm($model_match,'Sports')->select('id as match_id','status','match_date','match_time')->where(['match_date'=>$match_date])->get(); foreach ($matchData as $key=>$item){ $time = strtotime($item->match_date.$item->match_time); if(($time+(60*90)) < time()){ //更新为 已结束 lm($model_match,'Sports')->where(['id'=>$item->match_id])->update(['status'=>2]); } if(($time+(60*90)) > time() and $time < time()){ //更新为 进行中 lm($model_match,'Sports')->where(['id'=>$item->match_id])->update(['status'=>1]); } } Render([], '1', lang('Tips','Sports')->get('success')); } catch (\Exception $e) { echo $e->getMessage(); } } /** * 获取即将开赛 所有赛事 * 首页使用 */ public function getSoon(){ $source = $this->source;//数据源 条件 try { $where = $this->commonFunction->getState('StSoon'); $data = $this->getTypeData->getAllSoon($source,$where); Render($data, '1', lang('Tips','Sports')->get('success')); } catch (\Exception $e) { echo $e->getMessage(); } } /** * 获取球类-玩法-赔率代码 */ public function getOddsCode(){ $type = $_REQUEST['type']; $game_code = $_REQUEST['game_code']; if($type == 'p_code'){ $p_code = lm('st_odds_code','Sports') ->select('game_code','odds_code','odds_name') ->where(['p_id'=>0]) ->get(); }else{ $p_code = lm('st_odds_code','Sports') ->select('id','game_code','odds_code','odds_name') ->where('p_id',0) ->get()->toarray(); $code = lm('st_odds_code','Sports') ->select('id','p_id','game_code','odds_code','odds_name') ->get()->toArray(); foreach ($p_code as $k=>$v){ foreach ($code as $kk=>$vv){ if($v['id'] == $vv['p_id']){ $p_code[$k]['below'][] = $vv; } } } } Render($p_code, '1', lang('Tips','Sports')->get('success')); } /** * 获取 欧洲冠军杯数据 */ public function getUEFAChampions (){ $data = $this->getTypeData->getUEFAChampions($this->source); Render($data, '1', lang('Tips','Sports')->get('success')); } /** * 更新赔率数据 */ public function updateOdds(){ $data = $_REQUEST; $getModels = $this->commonFunction->getModels($data['game_code']); $model_match = $getModels['model_match']; $model_odds = $getModels['model_odds']; $where[] = [$model_match.'.id','=',$data['match_id']]; $oddsData = lm($model_match,"Sports") ->join($model_odds,$model_odds.'.match_id',$model_match.'.id') ->select($model_match.'.id as match_id',$model_match.'.match_date',$model_match.'.home_team',$model_match.'.guest_team',$model_odds.'.id as odds_id',$model_odds.'.p_code',$model_odds.'.odds_code',$model_odds.'.condition',$model_odds.'.odds',$model_odds.'.odds_only',$model_odds.'.status',$model_odds.'.sort') ->where($model_odds.'.type',0) ->where([$model_odds.'.status'=>0]) ->where($where) ->get()->toArray(); $p_code_array = []; foreach ($oddsData as $key =>$val){ $p_code_array[$val['p_code']] = lang('OddsTemp','Sports')->get($val['p_code']); } $data = [ 'oddsData'=>$oddsData, 'p_code_array'=>$p_code_array ]; Render($data, '1', lang('Tips','Sports')->get('success')); } /** * 获取赛事所有数据 * @param [array] $where 条件 *@param [array] $Orwhere 或者条件 * @param [type] $game_code 球类代码 * @return [array] $data */ public function getMatchInfo($where=[],$Orwhere=[],$where_search=[],$game_code ='zq'){ $getModels = $this->commonFunction->getModels($game_code); $st_league = $getModels['model_league']; $st_competition = $getModels['model_match']; try{ //查询今日赛事 $data = lm($st_competition,'Sports') ->join($st_league,$st_league.'.id',$st_competition.'.lg_id') ->leftjoin('st_area_country as country','country.id',$st_league.'.country_id') ->leftjoin('st_area_country as area','area.id',$st_league.'.area_id') ->select($st_league.'.name_chinese',$st_league.'.id as lg_id',$st_competition.'.id as match_id',$st_competition.'.home_team',$st_competition.'.guest_team',$st_competition.'.match_date',$st_competition.'.status',$st_competition.'.match_time',$st_competition.'.tag','country.name as country_name','area.name as area_name') ->where($where) ->where($Orwhere) ->where($where_search) ->where([ [$st_competition.'.home_team','<>',null], [$st_competition.'.guest_team','<>',null], [$st_league.'.name_chinese','<>',null], [$st_competition.'.status','<',2], [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)] ]) ->distinct($st_competition.'.id') ->get() ->toarray(); //===获取当前赛事是否有赔率,如果没有则去除=== $data = $this->commonFunction->Handle_Odds_Null($data,$getModels); $data = $this->division($data); return $data; } catch (\Exception $e) { echo $e->getMessage(); } } /** * 数据分割器 * @param [array] $matchData 赛事数据 * @param [type] $type 分割类型 1:以联赛分 * @return [array] $league */ public function division(array $matchData) { //联赛分割 $league = []; foreach ($matchData as $k => $v) { $league[$k]['name_chinese'] = $v['name_chinese']; $league[$k]['lg_id'] = $v['lg_id']; } //联赛去重 $league = array_unique($league, SORT_REGULAR); //根据联赛分类 foreach ($league as $key => $vlue) { foreach ($matchData as $k => $v) { if ($vlue['name_chinese'] == $v['name_chinese']) { $league[$key]['match_info'][$k] = $v; } } } //统计联赛下赛事 foreach ($league as $key => $vlue) { $league[$key]['match_info'] = array_sort($league[$key]['match_info']); $league[$key]['count'] = count($vlue['match_info']); } return $league; } /** * 获取赛事总数 * @param [array] $where 条件 *@param [array] $Orwhere 或者条件 * @param [type] $game_code 球类代码 * @return [int] $dataCount */ public function getMatchCount($where=[],$Orwhere=[],$where_search=[],$game_code ='zq'){ $getModels = $this->commonFunction->getModels($game_code); $st_league = $getModels['model_league']; $st_competition = $getModels['model_match']; //查询今日赛事 $dataCount = lm($st_competition,'Sports') ->join($st_league,$st_league.'.id',$st_competition.'.lg_id') ->leftjoin('st_area_country as country','country.id',$st_league.'.country_id') ->leftjoin('st_area_country as area','area.id',$st_league.'.area_id') ->select($st_competition.'.id as match_id') ->where($where) ->where($Orwhere) ->where($where_search) ->where([ [$st_competition.'.home_team','<>',null], [$st_competition.'.guest_team','<>',null], [$st_league.'.name_chinese','<>',null], [$st_competition.'.status','<',2], [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)] ]) ->distinct($st_competition.'.id') ->get()->toArray(); //===获取当前赛事是否有赔率,如果没有则去除=== $dataCount = $this->commonFunction->Handle_Odds_Null($dataCount,$getModels); return count($dataCount); } }