| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444 |
- <?php
- /**
- * 根据不同状态获取 赛事数据
- * User: Jun.peng
- * Date: 2019/4/4
- * Time: 10:57
- */
- namespace Biz\Match;
- use Biz\Match\GetOddsData;
- use App\Sports\Model\St_zq_league as leagueModel;
- use App\Sports\Model\St_zq_competition as matchModel;
- use App\Sports\Model\St_zq_odds as ZQoddsModel;
- use App\Sports\Model\St_wq_odds as WQoddsModel;
- use App\Sports\Model\St_bq_odds as BQoddsModel;
- use App\Sports\Model\St_lq_odds as LQoddsModel;
- class GetmatchData {
- public function __construct() {
- $this->getOddsData = new GetOddsData();
- $this->commonFunction = C()->get('commonFunction');
- }
- /**
- * @param $ret 提交参数
- * @param $source 数据源条件
- * @return array
- * @throws \Exception
- * 获取不同状态下的赛事相关数据
- */
- public function typeData($ret,$source){
- //根据球类代码 获取相关model
- $models = $this->commonFunction->getModels($ret['game_code']);
- $model_match = $models['model_match'];
- //获取 不同状态的查询条件
- $where = $this->commonFunction->getState($ret['type_code'],$model_match);
- //根据联赛id查询
- if(!empty($ret['lg_id'])){
- $lg_id = $ret['lg_id'];
- }
- //根据搜索查询
- if(!empty($ret['search'])){
- $search = $ret['search'];
- }
- switch ($ret['type_code']){
- case 'StRollBall'://滚球
- $data = $this->getRollBall($source,$models,$where,$ret,$search);
- break;
- case 'StSoon'://即将
- $oddsTypeWhere = [
- [$models['model_odds'].'.is_morningplate','=',1],
- ];
- $data = $this->getSoon($source,$models,$where,$lg_id,$ret,$search,$oddsTypeWhere);
- break;
- case 'StToday'://今日
- $oddsTypeWhere = [
- [$models['model_odds'].'.is_today','=',1],
- ];
- $data = $this->getToday($source,$models,$where,$lg_id,$search,$oddsTypeWhere);
- break;
- case 'StMorningPlate'://早盘
- //默认当天
- if(empty($ret['match_date'])){
- $match_date = date("Y-m-d");
- }else{
- if($ret['match_date'] != 'other'){
- $match_date = $ret['match_date'];
- }else{
- $match_date = 'other';
- }
- }
- $oddsTypeWhere = [
- [$models['model_odds'].'.is_morningplate','=',1],
- ];
- $data = $this->getMorningPlate($source,$models,$where,$lg_id,$search,$match_date,$oddsTypeWhere);
- break;
- case 'StStringScene'://串场
- $oddsTypeWhere = [
- [$models['model_odds'].'.is_stringscene','=',1],
- ];
- if(empty($ret['str_type']) || $ret['str_type'] ==0){//赛事
- $data = $this->getStringScene($source,$models,$where,$lg_id,$search,'',$oddsTypeWhere);
- }
- if($ret['str_type'] == 1){//参赛表
- }
- if($ret['str_type'] == 2){//冠军盘口
- $where = $this->commonFunction->getState('StChampion',$model_match);
- $data = $this->getChampion($source,$models,$where,$lg_id,$search,'StChampion');
- }
- break;
- case 'StChampion'://冠军
- $data = $this->getChampion($source,$models,$where,$lg_id,$search,$ret['type_code']);
- break;
- default:
- throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- return $data;
- }
- /**
- * 获取滚球数据
- */
- public function __getRollBall($source,$models,$where,$ret,$search=''){
- $model_match = $models['model_match'];
- $model_odds = $models['model_odds'];
- $model_league = $models['model_league'];
- $model_result = $models['model_result'];
- //当前状态下所有联赛
- $data = lm($model_league,"Sports")
- ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
- ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
- ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
- ->distinct($model_league.'.name_chinese')
- ->where($model_league.'.source',$source['source'])
- ->where($where)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()
- ->toarray();
- if(empty($data)){
- $data = [];
- return $data;
- }
- //统计联赛下的赛事及查询赛事
- foreach($data as $k => $v){
- $data[$k]['matchNum'] = lm($model_match,"Sports")
- ->where($source)
- ->where('lg_id',$v['lg_id'])
- ->where($where)
- ->count();
- $data[$k]['matchData'] = lm($model_match,"Sports")
- ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
- ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time as a_time','match_process')
- ->where($model_match.'.source',$source['source'])
- ->where($model_match.'.lg_id',$v['lg_id'])
- ->where($where)
- ->get()
- ->toarray();
- }
- foreach($data as $k => $v){
- foreach($v['matchData'] as $kk => $vv){
- $oddsData= lm($model_match,"Sports")
- ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
- ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','odds_only','sort')
- ->where($model_match.'.source',$source['source'])
- ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])//查询滚球赔率
- //->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->where(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_home')
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','size_home');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','size_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_home');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_dogfall');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_guest');
- });
- })
- ->get()
- ->toarray();
- //根据 排序 获取 最新让球/大小玩法赔率
- $sortData = array_column($oddsData,'sort');
- array_multisort($sortData,SORT_DESC,$oddsData);
- $zu = [];
- foreach ($oddsData as $key1 =>$item1){
- $zu[$item1['p_code']][] = $item1;
- }
- $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
- $capot = $zu['capot'];//独赢
- $capot = [$capot[0],$capot[2],$capot[1]];//排序
- $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
- }
- }
- return $data;
- }
- public function getRollBall($source,$models,$where,$ret,$search=''){
- //获取当前状态下所有联赛
- $leagueData = leagueModel::getRollLeagueData($source,$models,$where,$search);
- if(empty($leagueData)){
- return $leagueData=[];
- }
- //获取联赛id
- $lg_ids = [];
- foreach ($leagueData as $k => $v){
- $lg_ids[] = $v['lg_id'];
- }
- //统计联赛下的赛事及查询赛事
- $matchData = matchModel::getRollMatchDataAll($source,$models,$where,$lg_ids);
- //获取赛事id
- $match_ids = [];
- foreach ($matchData as $k => $v){
- $match_ids[] = $v['match_id'];
- }
- //获取赛事下滚球默认赔率
- $oddsData = ZQoddsModel::getMatchOdds($source,$models,$match_ids);
- $data = [];
- foreach ($leagueData as $k=>$v){
- $data[$k] = $v;
- foreach ($matchData as $kk=>$vv){
- if($v['lg_id'] == $vv['lg_id']){
- $data[$k]['matchData'][] = $vv;
- }
- }
- $data[$k]['matchNum'] = count($data[$k]['matchData']);
- }
- if($ret['game_code'] == 'wq') {
- $oddsData = WQoddsModel::getMatchOdds($source,$match_ids);
- foreach ($data as $k=>$v){
- foreach ($v['matchData'] as $kk=>$vv){
- //获取赛事下赔率并且分组
- $odds = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- $odds[] = $vvv;
- }
- }
- $data[$k]['matchData'][$kk]['oddsData'] = $odds;
- }
- }
- }else{
- foreach ($data as $k=>$v){
- foreach ($v['matchData'] as $kk=>$vv){
- //获取赛事下赔率并且分组
- $capot = [];
- $concede_size = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- if($vvv['odds_code'] == 'concede_guest' || $vvv['odds_code'] == 'concede_home' || $vvv['odds_code'] == 'goal_size_home' || $vvv['odds_code'] == 'goal_size_guest'){
- $concede_size[] = $vvv;
- }
- if($vvv['p_code'] == 'capot'){
- $capot[] = $vvv;
- }
- }
- }
- $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
- }
- }
- }
- return $data;
- }
- /**
- * 获取即将数据
- */
- public function __getSoon($source,$models,$where,$lg_id=0,$ret,$search='',$oddsTypeWhere=''){
- $model_match = $models['model_match'];
- $model_odds = $models['model_odds'];
- $model_league = $models['model_league'];
- $model_result = $models['model_result'];
- //当前状态下所有联赛
- $data = lm($model_league,"Sports")
- ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
- ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
- ->distinct($model_league.'.name_chinese')
- ->where($model_league.'.source',$source['source'])
- ->where($where)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()
- ->toarray();
- if(empty($data)){
- $data = [];
- return $data;
- }
- //统计联赛下的赛事及查询赛事
- foreach($data as $k => $v){
- $data[$k]['matchNum'] = lm($model_match,"Sports")
- ->where($source)
- ->where('lg_id',$v['lg_id'])
- ->where($where)
- ->count();
- $data[$k]['matchData'] = lm($model_match,"Sports")
- ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team',$model_match.'.us_time')
- ->where($source)
- ->where($model_match.'.lg_id',$v['lg_id'])
- ->where($where)
- ->orderBy('match_time','asc')
- ->get()
- ->toarray();
- }
- //获取当前美东时间
- $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
- //获取足球即将默认玩法赔率
- if($ret['game_code'] == 'zq'){
- foreach($data as $k => $v){
- foreach($v['matchData'] as $kk => $vv){
- $wait_time = ceil(((strtotime( $vv['us_time']))-$s_time)/60);
- $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
- $oddsData= lm($model_match,"Sports")
- ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
- ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
- ->where($model_match.'.source',$source['source'])
- ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
- // ->where($oddsTypeWhere)
- // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->where(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_home')
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','size_home');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','size_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_home');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_dogfall');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_guest');
- });
- })
- ->get()
- ->toarray();
- //根据 排序 获取 最新让球/大小玩法赔率
- $sortData = array_column($oddsData,'sort');
- array_multisort($sortData,SORT_ASC,$oddsData);
- $zu = [];
- foreach ($oddsData as $key1 =>$item1){
- $zu[$item1['p_code']][] = $item1;
- }
- $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
- $capot = $zu['capot'];//独赢
- $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
- }
- }
- }
- //获取网球即将默认玩法赔率
- if($ret['game_code'] == 'wq'){
- foreach($data as $k => $v){
- $matchData = $this->getOddsData->getOddsWQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
- $data[$k]['matchData'] = $matchData;
- }
- }
- //获取篮球即将默认玩法赔率
- if($ret['game_code'] == 'lq'){
- foreach($data as $k => $v){
- foreach($v['matchData'] as $kk => $vv){
- $wait_time = ceil(((strtotime( $vv['match_time']))-time())/60);
- $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
- $oddsData= lm($model_match,"Sports")
- ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
- ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
- ->where($model_match.'.source',$source['source'])
- ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
- // ->where($oddsTypeWhere)
- // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->where(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_home')
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','total_sizes_big');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','total_sizes_small');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_home');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_dogfall');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_guest');
- });
- })
- ->get()
- ->toarray();
- //根据 排序 获取 最新让球/大小玩法赔率
- $sortData = array_column($oddsData,'sort');
- array_multisort($sortData,SORT_ASC,$oddsData);
- $zu = [];
- foreach ($oddsData as $key1 =>$item1){
- $zu[$item1['p_code']][] = $item1;
- }
- $c_s['concede'] = array_slice($zu['concede'],0,2);//让球 前四条 放入
- $c_s['total_size'] = array_slice($zu['total_size'],0,2);//让球 前四条 放入
- $capot = $zu['capot'];//独赢
- $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
- }
- // $matchData = $this->getOddsData->getOddsLQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
- // $data[$k]['matchData'] = $matchData;
- }
- }
- //获取棒球即将默认玩法赔率
- if($ret['game_code'] == 'bq'){
- foreach($data as $k => $v){
- $matchData = $this->getOddsData->getOddsBQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
- $data[$k]['matchData'] = $matchData;
- }
- }
- return $data;
- }
- public function getSoon($source,$models,$where,$lg_id=0,$ret,$search='',$oddsTypeWhere=''){
- //获取当前状态下所有联赛
- $leagueData = leagueModel::getSoonLeagueData($source,$models,$where,$search);
- if(empty($leagueData)){
- return $leagueData=[];
- }
- //获取联赛id
- $lg_ids = [];
- foreach ($leagueData as $k => $v){
- $lg_ids[] = $v['lg_id'];
- }
- //统计联赛下的赛事及查询赛事
- $matchData = matchModel::getSoonMatchDataAll($source,$models,$where,$lg_ids);
- //获取赛事id
- $match_ids = [];
- foreach ($matchData as $k => $v){
- $match_ids[] = $v['match_id'];
- }
- //获取当前美东时间
- $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
- $data = [];
- foreach ($leagueData as $k=>$v){
- $data[$k] = $v;
- foreach ($matchData as $kk=>$vv){
- if($v['lg_id'] == $vv['lg_id']){
- $wait_time = ceil(((strtotime( $vv['us_time']))-$s_time)/60);
- $vv['wait_time'] = $wait_time;//追加距离开赛时间
- $data[$k]['matchData'][] = $vv;
- }
- }
- $data[$k]['matchNum'] = count($data[$k]['matchData']);
- }
- if($ret['game_code'] == 'zq') {
- //获取赛事下默认赔率
- $oddsData = ZQoddsModel::getMatchOdds($source, $models,$match_ids);
- foreach ($data as $k=>$v){
- foreach ($v['matchData'] as $kk=>$vv){
- //获取赛事下赔率并且分组
- $capot = [];
- $concede_size = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- if($vvv['odds_code'] == 'concede_guest'){
- $concede_g = $vvv;
- }
- if($vvv['odds_code'] == 'concede_home'){
- $concede_h = $vvv;
- }
- if($vvv['odds_code'] == 'total_size_small'){
- $size_s = $vvv;
- }
- if($vvv['odds_code'] == 'total_size_big'){
- $size_b = $vvv;
- }
- if($vvv['odds_code'] == 'capot_home'){
- $capot_h = $vvv;
- }
- if($vvv['odds_code'] == 'capot_dogfall'){
- $capot_d = $vvv;
- }
- if($vvv['odds_code'] == 'capot_guest'){
- $capot_g = $vvv;
- }
- }
- }
- $concede_size = [$concede_g,$concede_h,$size_s,$size_b];
- $capot = [$capot_h,$capot_d,$capot_g];
- foreach ($concede_size as $key => $vaule){
- if($vaule == null) unset($concede_size[$key]);
- }
- foreach ($capot as $key1 => $vaule1){
- if($vaule1 == null) unset($capot[$key1]);
- }
- $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
- }
- }
- }
- if($ret['game_code'] == 'lq') {
- $oddsData = LQoddsModel::getMatchOdds($source,$match_ids);
- foreach ($data as $k=>$v){
- foreach ($v['matchData'] as $kk=>$vv){
- //获取赛事下赔率并且分组
- $capot = [];
- $total_size = [];
- $concede = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- if($vvv['p_code'] == 'capot'){
- $capot[] = $vvv;
- }else{
- if($vvv['p_code'] == 'total_size'){
- $total_size[] = $vvv;
- }
- if($vvv['p_code'] == 'concede'){
- $concede[] = $vvv;
- }
- }
- }
- }
- $concede_size = [$concede[0],$concede[1],$total_size[0],$total_size[1]];
- $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
- }
- }
- }
- if($ret['game_code'] == 'wq') {
- $oddsData = WQoddsModel::getMatchOdds($source,$match_ids);
- foreach ($data as $k=>$v){
- foreach ($v['matchData'] as $kk=>$vv){
- //获取赛事下赔率并且分组
- $odds = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- $odds[] = $vvv;
- }
- }
- $data[$k]['matchData'][$kk]['oddsData'] = $odds;
- }
- }
- }
- if($ret['game_code'] == 'bq') {
- $oddsData = BQoddsModel::getMatchOdds($source,$match_ids);
- foreach ($data as $k=>$v){
- foreach ($v['matchData'] as $kk=>$vv){
- //获取赛事下赔率并且分组
- $odds = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- if($vvv['odds_code'] == 'concede_guest'){
- $concede_g = $vvv;
- }
- if($vvv['odds_code'] == 'concede_home'){
- $concede_h = $vvv;
- }
- if($vvv['odds_code'] == 'total_size_small'){
- $size_s = $vvv;
- }
- if($vvv['odds_code'] == 'total_size_big'){
- $size_b = $vvv;
- }
- if($vvv['odds_code'] == 'capot_home'){
- $capot_h = $vvv;
- }
- if($vvv['odds_code'] == 'capot_guest'){
- $capot_g = $vvv;
- }
- }
- }
- $concede_size = [$concede_g,$concede_h,$size_s,$size_b];
- $capot = [$capot_h,$capot_g];
- foreach ($concede_size as $key => $vaule){
- if($vaule == null) unset($concede_size[$key]);
- }
- foreach ($capot as $key1 => $vaule1){
- if($vaule1 == null) unset($capot[$key1]);
- }
- $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
- }
- }
- }
- return $data;
- }
- /**
- * 获取今日数据
- */
- public function getToday($source,$models,$where,$lg_id=0,$search='',$oddsTypeWhere=[]){
- //获取model
- $model_match = $models['model_match'];
- $model_odds = $models['model_odds'];
- $model_league = $models['model_league'];
- $model_result = $models['model_result'];
- //根据联赛id 获取联赛下 赛事赔率数据
- if($lg_id >0){
- $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,'',$oddsTypeWhere);
- return $leagueData;
- }
- $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where);
- return $data;
- }
- /**
- * 获取早盘数据
- */
- public function getMorningPlate($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
- //获取model
- $model_match = $models['model_match'];
- $model_odds = $models['model_odds'];
- $model_league = $models['model_league'];
- $model_result = $models['model_result'];
- //根据联赛id 获取联赛下 赛事赔率数据
- if($lg_id >0){
- $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
- return $leagueData;
- }
- $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
- return $data;
- }
- /**
- * 获取串场数据
- */
- public function getStringScene($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
- //获取model
- $model_match = $models['model_match'];
- $model_odds = $models['model_odds'];
- $model_league = $models['model_league'];
- $model_result = $models['model_result'];
- //根据联赛id 获取联赛下 赛事赔率数据
- if($lg_id >0){
- $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
- return $leagueData;
- }
- $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
- return $data;
- }
- /**
- * 获取冠军数据
- */
- public function getChampion($source,$models,$where,$lg_id=0,$search='',$type_code=''){
- //获取model
- $model_odds = $models['model_odds'];
- $model_league = $models['model_league'];
- //根据联赛id 获取联赛下 冠军玩法盘口
- if($lg_id >0){
- $last_time = lm($model_league, 'Sports')
- ->select('last_time')
- // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->where($source)
- ->where('lg_id',$lg_id)
- ->first()->last_time;
- $championData = lm($model_odds, 'Sports')
- ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
- // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->where($source)
- ->where('lg_id',$lg_id)
- ->where($where)
- ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
- ->get()->toArray();
- //按p_code分组
- $p_code=array();
- foreach($championData as $k=>$v){
- $p_code[$v['p_code']][]=$v;
- }
- $sd = [];
- foreach ($p_code as $k1=>$v1){
- foreach ($v1 as $k2=>$v2){
- $sd[$v2['p_code']]['last_time'] =$last_time;
- $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
- }
- }
- return $sd;
- }
- //获取国家/洲下所有联赛及数量
- $data = $this->getMatch($source,$model_league,'',$model_odds,$search,$where,'',$type_code);
- return $data;
- }
- /**
- * 获取国家/洲 下联赛
- */
- public function getMatch($source,$model_league,$model_match='',$model_odds='',$search,$where,$time='',$type_code=''){
- //国家下所有联赛
- $country = lm($model_league,"Sports")
- ->leftjoin('st_country','st_country.country_id',$model_league.'.country_id')
- ->select('st_country.country_id','st_country.name_chinese as region')
- // ->select('st_country.country_id as region_id','st_country.name_chinese as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
- ->distinct('st_country.name_chinese')
- ->where([[$model_league.'.name_chinese','!=','']])
- ->where($model_league.'.source',$source['source'])
- ->where($model_league.'.name_chinese','like','%'.$search.'%')
- ->get()
- ->toArray();
- //洲下所有联赛
- $area = lm($model_league,"Sports")
- ->leftjoin('st_area','st_area.id',$model_league.'.area_id')
- ->select('st_area.id as area_id','st_area.title as region')
- // ->select('st_area.id as region_id','st_area.title as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
- ->distinct('st_area.title')
- ->where([[$model_league.'.name_chinese','!=','']])
- ->where($model_league.'.source',$source['source'])
- ->where($model_league.'.name_chinese','like','%'.$search.'%')
- ->get()
- ->toArray();
- if($type_code != 'StChampion'){//非冠军赛事
- $data = $this->getMatchNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
- }else{//冠军赛事
- $data = $this->getMatchStChampionNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
- }
- return $data;
- }
- /**
- * 获取联赛下赛事 数量
- * 非冠军盘口
- */
- public function getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
- $leagueData = lm($model_league,'Sports')
- ->select('id','lg_id','name_chinese as league','country_id','area_id')
- ->where($source)
- ->where([[$model_league.'.name_chinese','!=','']])
- ->where($model_league.'.name_chinese','like','%'.$search.'%')
- ->get()
- ->toArray();
- $timeWhere = [];
- if(!empty($time)){
- if($time == 'other'){
- $timeWhere[] = ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))];
- }else{
- $timeWhere[] = ['match_date',$time];
- }
- }
- $matchData = lm($model_match,'Sports')
- ->select('id','lg_id','match_id')
- ->where($where)
- ->where($source)
- ->where($timeWhere)
- ->get()
- ->toArray();
- //按国家
- $countryData = [];
- if(!empty($country) and !empty($leagueData) and !empty($matchData)){
- foreach ($country as $k=>$v){
- if($v['country_id']){
- $countryData[$k] = $v;
- foreach ($leagueData as $kk=>$vv){
- if($v['country_id'] == $vv['country_id']){
- $countryData[$k]['league_count'][] = $vv;
- }
- }
- }
- }
- }
- //去除无联赛 国家
- foreach ($countryData as $k=>$v){
- if(count($v) == 2){
- unset($countryData[$k]);
- }
- }
- //按地区
- $areaData = [];
- if(!empty($area) and !empty($leagueData) and($matchData)){
- foreach ($area as $k=>$v){
- if($v['area_id']){
- $areaData[$k] = $v;
- foreach ($leagueData as $kk=>$vv){
- if($v['area_id'] == $vv['area_id']){
- $areaData[$k]['league_count'][] = $vv;
- }
- }
- }
- }
- }
- //去除无联赛 地区
- foreach ($areaData as $k=>$v){
- if(count($v) == 2){
- unset($areaData[$k]);
- }
- }
- $countryData = $this->commonFunction->array_other_tt($countryData,$matchData);
- $areaData = $this->commonFunction->array_other_tt($areaData,$matchData);
- $data = array_merge($countryData,$areaData);
- return $data;
- }
- /**
- * 弃用 获取联赛下赛事 数量
- * 非冠军盘口
- */
- public function __getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
- //统计国家下联赛-赛事/盘口数量
- if(!empty($country)){
- foreach($country as $k => $v) {
- $country[$k]['league_count'] = lm($model_league, 'Sports')
- ->select('lg_id', 'name_chinese as league')
- ->where($source)
- ->where('country_id', $v['country_id'])
- ->where($model_league.'.name_chinese','like','%'.$search.'%')
- ->get()->toarray();
- }
- foreach ($country as $k => $v) {
- foreach($v['league_count'] as $kk => $vv ){
- if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
- if(empty($time)){
- $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
- ->select("match_id")
- ->where($source)
- ->where('lg_id',$vv['lg_id'])
- ->where($where)
- ->count("*");
- }else{//早盘 下有时间查询
- if($time == 'other'){//早盘 一周后
- $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
- ->select("match_id")
- ->where($source)
- ->where('lg_id',$vv['lg_id'])
- ->where($where)
- ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
- ->count("*");
- }else{
- $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
- ->select("match_id")
- ->where($source)
- ->where('lg_id',$vv['lg_id'])
- ->where($where)
- ->where('match_date',$time)
- ->count("*");
- }
- }
- }
- if($country[$k]['league_count'][$kk]['count'] == 0){
- unset($country[$k]['league_count'][$kk]);
- }
- }
- }
- }
- //统计 地区 联赛-赛事/盘口数量
- if(!empty($area)){
- foreach($area as $k => $v) {
- $area[$k]['league_count'] = lm($model_league, 'Sports')
- ->select('lg_id', 'name_chinese as league')
- ->where($source)
- ->where('area_id', $v['area_id'])
- ->where($model_league.'.name_chinese','like','%'.$search.'%')
- ->get()->toarray();
- }
- foreach ($area as $k => $v) {
- foreach($v['league_count'] as $kk => $vv ){
- if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
- if(empty($time)){
- $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
- ->select("match_id")
- ->where($source)
- ->where('lg_id',$vv['lg_id'])
- ->where($where)
- ->count("*");
- }else {
- if ($time == 'other') {// 今日 一周后
- $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
- ->select("match_id")
- ->where($source)
- ->where('lg_id', $vv['lg_id'])
- ->where($where)
- ->where('match_date', '>', date("Y-m-d", strtotime("+1weeks", strtotime(date('Y-m-d', time())))))
- ->count("*");
- } else {//今日 大于今日
- $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
- ->select("match_id")
- ->where($source)
- ->where('lg_id',$vv['lg_id'])
- ->where($where)
- ->where('match_date',$time)
- ->count("*");
- }
- }
- }
- if($area[$k]['league_count'][$kk]['count'] == 0){
- unset($area[$k]['league_count'][$kk]);
- }
- }
- }
- }
- //处理空联赛国家
- $countryData = $this->commonFunction->handleArr($country);
- $areaData = $this->commonFunction->handleArr($area);
- //合并数组
- $data = array_merge($countryData,$areaData);
- return $data;
- }
- /**
- * 获取联赛下赛事 数量
- * 冠军盘口
- */
- public function getMatchStChampionNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
- $leagueData = lm($model_league,'Sports')
- ->select('id','lg_id','name_chinese as league','country_id','area_id')
- ->where($source)
- ->where([[$model_league.'.name_chinese','!=','']])
- ->where($model_league.'.name_chinese','like','%'.$search.'%')
- ->get()
- ->toArray();
- $oddsData = lm($model_odds,'Sports')
- ->select('id','lg_id','p_code')
- ->distinct("p_code")//去重
- ->where($where)
- ->where($source)
- ->get()
- ->toArray();
- //按国家
- $countryData = [];
- if(!empty($country) and !empty($leagueData) and !empty($oddsData)){
- foreach ($country as $k=>$v){
- if($v['country_id']){
- $countryData[$k] = $v;
- foreach ($leagueData as $kk=>$vv){
- if($v['country_id'] == $vv['country_id']){
- $countryData[$k]['league_count'][] = $vv;
- }
- }
- }
- }
- }
- //去除无联赛 国家
- foreach ($countryData as $k=>$v){
- if(count($v) == 2){
- unset($countryData[$k]);
- }
- }
- //按地区
- $areaData = [];
- if(!empty($area) and !empty($leagueData) and($oddsData)){
- foreach ($area as $k=>$v){
- if($v['area_id']){
- $areaData[$k] = $v;
- foreach ($leagueData as $kk=>$vv){
- if($v['area_id'] == $vv['area_id']){
- $areaData[$k]['league_count'][] = $vv;
- }
- }
- }
- }
- }
- //去除无联赛 地区
- foreach ($areaData as $k=>$v){
- if(count($v) == 2){
- unset($areaData[$k]);
- }
- }
- $countryData = $this->commonFunction->array_gj_tt($countryData,$oddsData);
- $areaData = $this->commonFunction->array_gj_tt($areaData,$oddsData);
- $data = array_merge($countryData,$areaData);
- return $data;
- }
- /**
- * 获取联赛下 赛事赔率
- */
- public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time='',$oddsTypeWhere=[]){
- $leagueData = lm($model_league,"Sports")
- ->select('lg_id','name_chinese as leagueName')
- ->where($source)
- ->where('lg_id',$lg_id)
- ->first();
- // dd(1213);
- //根据时间 拼装查询条件
- $whereTime = [];
- if(!empty($time)){
- if($time == 'other'){
- //其他时间(七天后)
- $whereTime = [
- ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))],
- ];
- }elseif($time == date('Y-m-d')){
- //今天
- $whereTime = [
- ['is_morningplate','=',1],
- ['match_date','=',$time],
- ['match_time','>',date("H:i:s", time())]
- ];
- }else{
- //今天以后 七天内
- $whereTime = [
- ['match_date','=',$time]
- ];
- }
- }
- $matchData = lm($model_match,"Sports")
- ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
- ->where($source)
- ->where($model_match.'.lg_id',$lg_id)
- ->where($where)
- ->where($whereTime)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()
- ->toarray();
- //获取各球类默认赔率
- $game_code = $_REQUEST['game_code'];
- switch ($game_code) {
- case 'zq'://足球
- $matchData = $this->getOddsData->getOddsZQ($matchData, $model_odds, $source,$oddsTypeWhere);
- break;
- case 'lq'://篮球
- $matchData = $this->getOddsData->getOddsLQ($matchData, $model_odds, $source,$oddsTypeWhere);
- break;
- case 'wq'://网球
- $matchData = $this->getOddsData->getOddsWQ($matchData, $model_odds, $source,$oddsTypeWhere);
- break;
- case 'bq'://棒球
- $matchData = $this->getOddsData->getOddsBQ($matchData, $model_odds, $source,$oddsTypeWhere);
- break;
- }
- $leagueData->matchNum = count($matchData);
- $leagueData->matchData = $matchData;
- return $leagueData;
- }
- /**
- * @param $source 数据源
- * @param $where 该状态 查询条件
- * @return array
- * @throws \Exception
- * 获取所有即将开赛 数据
- */
- public function getAllSoon($source,$where){
- $game = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
- //获取当前美东时间
- $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
- $data=[];
- foreach ($game as $key=>$item){
- if($item['game_code'] !='gj'){
- $model = $this->commonFunction->getModels($item['game_code']);
- $matchData = lm($model['model_match'], 'Sports')
- ->select('match_id','home_team','guest_team','match_time','us_time')
- ->where($source)
- ->where($where)
- ->orderBy('match_time','asc')
- // ->limit(6)
- ->get()->toArray();
- $matchNum = count($matchData);
- $matchData = array_slice($matchData,0,6);
- foreach ($matchData as $key1 => $item1){
- //获取等待时间
- $wait_time = ceil(((strtotime($item1['us_time']))-$s_time)/60);
- $matchData[$key1]['wait_time'] = $wait_time;
- }
- if($matchNum > 0){
- // $matchData = array_multisort(array_column($matchData,'wait_time'),SOTR_ASC,$matchData);
- $data[$item['game_code']]['matchData'] = $matchData;
- $data[$item['game_code']]['matchNum'] = $matchNum;
- $data[$item['game_code']]['gameName'] = $item['game_name'];
- $data[$item['game_code']]['gameCode'] = $item['game_code'];
- }
- }
- }
- return $data;
- }
- /**
- * 获取欧冠 各状态赛事数据
- */
- public function getUEFAChampions($source){
- //根据搜索查询
- if(!empty($_GET['search'])){
- $search = $_GET['search'];
- }
- $model = $this->commonFunction->getModels('gj',1);
- $model_league = $model['model_league'];
- $leagueData = lm($model_league,'Sports')
- ->select('name_chinese','lg_id','last_time')
- ->where($model_league.'.source',$source['source'])
- ->where($model_league.'.name_chinese','欧洲冠军杯')
- ->first();
- //获取滚球数据
- $StRollBall = $this->getUEFAStRollBall($model,'StRollBall',$source,$leagueData->lg_id,$search);
- //获取今日数据
- $StToday = $this->getUEFAStToday($model,'StToday',$source,$leagueData->lg_id,$search);
- //获取早盘数据
- $StMorningPlate = $this->getUEFAStMorningPlate($model,'StMorningPlate',$source,$leagueData->lg_id,$search);
- //获取冠军盘口数据
- $StChampion = $this->getUEFAStChampion($model,'StChampion',$source,$leagueData->lg_id,$leagueData->last_time);
- $data = [
- 'lg_id' => $leagueData->lg_id,
- 'leagueName'=> $leagueData->name_chinese,
- 'StRollBall'=>[//滚球数据
- 'typeName'=>'滚球',
- 'matchNum'=>count($StRollBall),
- 'matchData'=>$StRollBall
- ],
- 'StToday'=>[//今日数据
- 'typeName'=>'今日',
- 'matchNum'=>count($StToday),
- 'matchData'=>$StToday
- ],
- 'StMorningPlate'=>[//早盘数据
- 'typeName'=>'早盘',
- 'matchNum'=>count($StMorningPlate),
- 'matchData'=>$StMorningPlate
- ],
- 'StChampion'=>[//冠军盘口
- 'typeName'=>'冠军盘口',
- 'matchNum'=>count($StChampion),
- 'matchData'=>$StChampion
- ]
- ];
- return $data;
- }
- /**
- * 获取欧冠 滚球数据
- */
- public function __getUEFAStRollBall($model,$type_code,$source,$lg_id,$search=''){
- $model_match = $model['model_match'];
- $model_odds = $model['model_odds'];
- $model_result = $model['model_result'];
- $where = $this->commonFunction->getState($type_code,$model_match);
- $matchData = lm($model_match,"Sports")
- ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
- ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time as a_time','match_process')
- ->where($model_match.'.source',$source['source'])
- ->where($model_match.'.lg_id',$lg_id)
- ->where($where)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()
- ->toarray();
- foreach($matchData as $kk => $vv){
- $oddsData= lm($model_match,"Sports")
- ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
- ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
- ->where($model_match.'.source',$source['source'])
- ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
- // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->where(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_home')
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','size_home');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','size_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_home');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_dogfall');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_guest');
- });
- })
- ->get()
- ->toarray();
- //根据 排序 获取 最新让球/大小玩法赔率
- $sortData = array_column($oddsData,'sort');
- array_multisort($sortData,SORT_ASC,$oddsData);
- $zu = [];
- foreach ($oddsData as $key1 =>$item1){
- $zu[$item1['p_code']][] = $item1;
- }
- $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
- $capot = $zu['capot'];//独赢
- $matchData[$kk]['oddsData'] = [$c_s,$capot];
- }
- return $matchData;
- }
- public function getUEFAStRollBall($model,$type_code,$source,$lg_id,$search=''){
- $model_match = $model['model_match'];
- $model_odds = $model['model_odds'];
- $model_result = $model['model_result'];
- $where = $this->commonFunction->getState($type_code,$model_match);
- $matchData = lm($model_match,"Sports")
- ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
- ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time as a_time','match_process')
- ->where($model_match.'.source',$source['source'])
- ->where($model_match.'.lg_id',$lg_id)
- ->where($where)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()
- ->toarray();
- //获取赛事id
- $match_ids = [];
- foreach ($matchData as $k => $v){
- $match_ids[] = $v['match_id'];
- }
- //获取赛事下滚球默认赔率
- $oddsData = ZQoddsModel::getMatchOdds($source,$model,$match_ids);
- foreach ($matchData as $k=>$v){
- //获取赛事下赔率并且分组
- $capot = [];
- $concede_size = [];
- foreach ($oddsData as $kk=>$vv){
- if ($vv['match_id'] == $v['match_id'] and $vv['sort']==0) {
- if($vv['p_code'] == 'concede_size'){
- $concede_size[] = $vv;
- }
- if($vv['p_code'] == 'capot'){
- $capot[] = $vv;
- }
- }
- }
- $matchData[$k]['oddsData'] = [$concede_size,$capot];
- }
- return $matchData;
- }
- /**
- * 获取欧冠 今日数据
- */
- public function __getUEFAStToday($model,$type_code,$source,$lg_id,$search=''){
- $model_match = $model['model_match'];
- $model_odds = $model['model_odds'];
- $where = $this->commonFunction->getState($type_code);
- $matchData = lm($model_match,'Sports')
- ->select('match_id','match_date','match_time','tag','home_team','guest_team')
- ->where($model_match.'.source',$source['source'])
- ->where($where)
- ->where('lg_id',$lg_id)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()->toArray();
- foreach($matchData as $kk => $vv) {
- $oddsData = lm($model_match, "Sports")
- ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
- ->select($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
- ->where($model_match.'.source',$source['source'])
- ->where([$model_odds . '.match_id' => $vv['match_id']])
- // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
- ->orderBy($model_odds . '.id','desc')
- ->get()
- ->toarray();
- $matchData[$kk]['oddsData'] = $oddsData;
- }
- return $matchData;
- }
- public function getUEFAStToday($model,$type_code,$source,$lg_id,$search=''){
- $model_match = $model['model_match'];
- $model_odds = $model['model_odds'];
- $where = $this->commonFunction->getState($type_code);
- $matchData = lm($model_match,'Sports')
- ->select('match_id','match_date','match_time','tag','home_team','guest_team')
- ->where($model_match.'.source',$source['source'])
- ->where($where)
- ->where('lg_id',$lg_id)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()->toArray();
- //获取赛事id
- $match_ids = [];
- foreach ($matchData as $k => $v){
- $match_ids[] = $v['match_id'];
- }
- //获取赔率数据
- $oddsData = lm($model_odds, "Sports")
- ->select( 'id','p_code', 'odds_code','odds_only','status', 'odds', 'condition', 'sort','match_id')
- ->where('source',$source['source'])
- ->whereIn('match_id', $match_ids)
- ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort','match_id')
- ->orderBy($model_odds . '.id','desc')
- ->get()
- ->toarray();
- foreach ($matchData as $k=>$v){
- foreach ($oddsData as $kk=>$vv){
- if($v['match_id'] == $vv['match_id']){
- $matchData[$k]['oddsData'][] = $vv;
- }
- }
- }
- return $matchData;
- }
- /**
- * 获取欧冠 早盘数据
- */
- public function getUEFAStMorningPlate($model,$type_code,$source,$lg_id,$search=''){
- $model_match = $model['model_match'];
- $model_odds = $model['model_odds'];
- $where = $this->commonFunction->getState($type_code);
- $matchData = lm($model_match,'Sports')
- ->select('match_id','match_date','match_time','tag','home_team','guest_team')
- ->where($model_match.'.source',$source['source'])
- ->where($where)
- ->where('lg_id',$lg_id)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()->toArray();
- $data = $this->getOddsData->getOddsZQ($matchData,$model_odds,$source,[]);
- return $data;
- }
- /**
- * 获取 欧冠 冠军盘口数据
- */
- public function getUEFAStChampion($model,$type_code,$source,$lg_id,$last_time=''){
- $model_odds = $model['model_odds'];
- $where = $this->commonFunction->getState($type_code);
- $championData = lm($model_odds, 'Sports')
- ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
- // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
- ->where($source)
- ->where('lg_id',$lg_id)
- ->where($where)
- ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
- ->get()->toArray();
- //按p_code分组
- $p_code=array();
- foreach($championData as $k=>$v){
- $p_code[$v['p_code']][]=$v;
- }
- $data = [];
- foreach ($p_code as $k1=>$v1){
- foreach ($v1 as $k2=>$v2){
- $data[$v2['p_code']]['last_time'] =$last_time;
- $data[$v2['p_code']][$v2['odds_code']][] = $v2;
- }
- }
- return $data;
- }
- }
|