GetmatchData.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. <?php
  2. /**
  3. * 根据不同状态获取 赛事数据
  4. * User: Jun.peng
  5. * Date: 2019/4/4
  6. * Time: 10:57
  7. */
  8. namespace Biz\Match;
  9. use Biz\Match\GetOddsData;
  10. use App\Sports\Model\St_zq_league as leagueModel;
  11. use App\Sports\Model\St_zq_competition as matchModel;
  12. use App\Sports\Model\St_zq_odds as ZQoddsModel;
  13. use App\Sports\Model\St_wq_odds as WQoddsModel;
  14. use App\Sports\Model\St_bq_odds as BQoddsModel;
  15. use App\Sports\Model\St_lq_odds as LQoddsModel;
  16. class GetmatchData {
  17. public function __construct() {
  18. $this->getOddsData = new GetOddsData();
  19. $this->commonFunction = C()->get('commonFunction');
  20. }
  21. /**
  22. * @param $ret 提交参数
  23. * @param $source 数据源条件
  24. * @return array
  25. * @throws \Exception
  26. * 获取不同状态下的赛事相关数据
  27. */
  28. public function typeData($ret,$source){
  29. //根据球类代码 获取相关model
  30. $models = $this->commonFunction->getModels($ret['game_code']);
  31. $model_match = $models['model_match'];
  32. //获取 不同状态的查询条件
  33. $where = $this->commonFunction->getState($ret['type_code'],$model_match);
  34. //根据联赛id查询
  35. if(!empty($ret['lg_id'])){
  36. $lg_id = $ret['lg_id'];
  37. }
  38. //根据搜索查询
  39. if(!empty($ret['search'])){
  40. $search = $ret['search'];
  41. }
  42. switch ($ret['type_code']){
  43. case 'StRollBall'://滚球
  44. $data = $this->getRollBall($source,$models,$where,$ret,$search);
  45. break;
  46. case 'StSoon'://即将
  47. $oddsTypeWhere = [
  48. [$models['model_odds'].'.is_morningplate','=',1],
  49. ];
  50. $data = $this->getSoon($source,$models,$where,$lg_id,$ret,$search,$oddsTypeWhere);
  51. break;
  52. case 'StToday'://今日
  53. $oddsTypeWhere = [
  54. [$models['model_odds'].'.is_today','=',1],
  55. ];
  56. $data = $this->getToday($source,$models,$where,$lg_id,$search,$oddsTypeWhere);
  57. break;
  58. case 'StMorningPlate'://早盘
  59. //默认当天
  60. if(empty($ret['match_date'])){
  61. $match_date = date("Y-m-d");
  62. }else{
  63. if($ret['match_date'] != 'other'){
  64. $match_date = $ret['match_date'];
  65. }else{
  66. $match_date = 'other';
  67. }
  68. }
  69. $oddsTypeWhere = [
  70. [$models['model_odds'].'.is_morningplate','=',1],
  71. ];
  72. $data = $this->getMorningPlate($source,$models,$where,$lg_id,$search,$match_date,$oddsTypeWhere);
  73. break;
  74. case 'StStringScene'://串场
  75. $oddsTypeWhere = [
  76. [$models['model_odds'].'.is_stringscene','=',1],
  77. ];
  78. if(empty($ret['str_type']) || $ret['str_type'] ==0){//赛事
  79. $data = $this->getStringScene($source,$models,$where,$lg_id,$search,'',$oddsTypeWhere);
  80. }
  81. if($ret['str_type'] == 1){//参赛表
  82. }
  83. if($ret['str_type'] == 2){//冠军盘口
  84. $where = $this->commonFunction->getState('StChampion',$model_match);
  85. $data = $this->getChampion($source,$models,$where,$lg_id,$search,'StChampion');
  86. }
  87. break;
  88. case 'StChampion'://冠军
  89. $data = $this->getChampion($source,$models,$where,$lg_id,$search,$ret['type_code']);
  90. break;
  91. default:
  92. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  93. }
  94. return $data;
  95. }
  96. /**
  97. * 获取滚球数据
  98. */
  99. public function __getRollBall($source,$models,$where,$ret,$search=''){
  100. $model_match = $models['model_match'];
  101. $model_odds = $models['model_odds'];
  102. $model_league = $models['model_league'];
  103. $model_result = $models['model_result'];
  104. //当前状态下所有联赛
  105. $data = lm($model_league,"Sports")
  106. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  107. ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
  108. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  109. ->distinct($model_league.'.name_chinese')
  110. ->where($model_league.'.source',$source['source'])
  111. ->where($where)
  112. ->where(function($query)use ($model_match,$search){
  113. $query->where($model_match.'.home_team','like','%'.$search.'%')
  114. ->orWhere(function($query)use ($model_match,$search) {
  115. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  116. });
  117. })
  118. ->get()
  119. ->toarray();
  120. if(empty($data)){
  121. $data = [];
  122. return $data;
  123. }
  124. //统计联赛下的赛事及查询赛事
  125. foreach($data as $k => $v){
  126. $data[$k]['matchNum'] = lm($model_match,"Sports")
  127. ->where($source)
  128. ->where('lg_id',$v['lg_id'])
  129. ->where($where)
  130. ->count();
  131. $data[$k]['matchData'] = lm($model_match,"Sports")
  132. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  133. ->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')
  134. ->where($model_match.'.source',$source['source'])
  135. ->where($model_match.'.lg_id',$v['lg_id'])
  136. ->where($where)
  137. ->get()
  138. ->toarray();
  139. }
  140. foreach($data as $k => $v){
  141. foreach($v['matchData'] as $kk => $vv){
  142. $oddsData= lm($model_match,"Sports")
  143. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  144. ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','odds_only','sort')
  145. ->where($model_match.'.source',$source['source'])
  146. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])//查询滚球赔率
  147. //->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  148. ->where(function($query)use ($model_odds){
  149. $query->where($model_odds.'.odds_code','concede_home')
  150. ->orWhere(function($query)use ($model_odds){
  151. $query->where($model_odds.'.odds_code','concede_guest');
  152. })
  153. ->orWhere(function($query)use ($model_odds){
  154. $query->where($model_odds.'.odds_code','size_home');
  155. })
  156. ->orWhere(function($query)use ($model_odds){
  157. $query->where($model_odds.'.odds_code','size_guest');
  158. })
  159. ->orWhere(function($query)use ($model_odds){
  160. $query->where($model_odds.'.odds_code','capot_home');
  161. })
  162. ->orWhere(function($query)use ($model_odds){
  163. $query->where($model_odds.'.odds_code','capot_dogfall');
  164. })
  165. ->orWhere(function($query)use ($model_odds){
  166. $query->where($model_odds.'.odds_code','capot_guest');
  167. });
  168. })
  169. ->get()
  170. ->toarray();
  171. //根据 排序 获取 最新让球/大小玩法赔率
  172. $sortData = array_column($oddsData,'sort');
  173. array_multisort($sortData,SORT_DESC,$oddsData);
  174. $zu = [];
  175. foreach ($oddsData as $key1 =>$item1){
  176. $zu[$item1['p_code']][] = $item1;
  177. }
  178. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  179. $capot = $zu['capot'];//独赢
  180. $capot = [$capot[0],$capot[2],$capot[1]];//排序
  181. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  182. }
  183. }
  184. return $data;
  185. }
  186. public function getRollBall($source,$models,$where,$ret,$search=''){
  187. //获取当前状态下所有联赛
  188. $leagueData = leagueModel::getRollLeagueData($source,$models,$where,$search);
  189. if(empty($leagueData)){
  190. return $leagueData=[];
  191. }
  192. //统计联赛下的赛事及查询赛事
  193. $matchData = matchModel::getRollMatchDataAll($source,$models,$where);
  194. //获取赛事下滚球默认赔率
  195. $oddsData = ZQoddsModel::getMatchOdds($source,$models);
  196. $data = [];
  197. foreach ($leagueData as $k=>$v){
  198. $data[$k] = $v;
  199. foreach ($matchData as $kk=>$vv){
  200. if($v['lg_id'] == $vv['lg_id']){
  201. $data[$k]['matchData'][] = $vv;
  202. }
  203. }
  204. $data[$k]['matchNum'] = count($data[$k]['matchData']);
  205. }
  206. foreach ($data as $k=>$v){
  207. foreach ($v['matchData'] as $kk=>$vv){
  208. //获取赛事下赔率并且分组
  209. $capot = [];
  210. $concede_size = [];
  211. foreach ($oddsData as $kkk=>$vvv) {
  212. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  213. if($vvv['p_code'] == 'concede_size'){
  214. $concede_size[] = $vvv;
  215. }
  216. if($vvv['p_code'] == 'capot'){
  217. $capot[] = $vvv;
  218. }
  219. }
  220. }
  221. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  222. }
  223. }
  224. return $data;
  225. }
  226. /**
  227. * 获取即将数据
  228. */
  229. public function __getSoon($source,$models,$where,$lg_id=0,$ret,$search='',$oddsTypeWhere=''){
  230. $model_match = $models['model_match'];
  231. $model_odds = $models['model_odds'];
  232. $model_league = $models['model_league'];
  233. $model_result = $models['model_result'];
  234. //当前状态下所有联赛
  235. $data = lm($model_league,"Sports")
  236. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  237. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  238. ->distinct($model_league.'.name_chinese')
  239. ->where($model_league.'.source',$source['source'])
  240. ->where($where)
  241. ->where(function($query)use ($model_match,$search){
  242. $query->where($model_match.'.home_team','like','%'.$search.'%')
  243. ->orWhere(function($query)use ($model_match,$search) {
  244. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  245. });
  246. })
  247. ->get()
  248. ->toarray();
  249. if(empty($data)){
  250. $data = [];
  251. return $data;
  252. }
  253. //统计联赛下的赛事及查询赛事
  254. foreach($data as $k => $v){
  255. $data[$k]['matchNum'] = lm($model_match,"Sports")
  256. ->where($source)
  257. ->where('lg_id',$v['lg_id'])
  258. ->where($where)
  259. ->count();
  260. $data[$k]['matchData'] = lm($model_match,"Sports")
  261. ->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')
  262. ->where($source)
  263. ->where($model_match.'.lg_id',$v['lg_id'])
  264. ->where($where)
  265. ->orderBy('match_time','asc')
  266. ->get()
  267. ->toarray();
  268. }
  269. //获取当前美东时间
  270. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  271. //获取足球即将默认玩法赔率
  272. if($ret['game_code'] == 'zq'){
  273. foreach($data as $k => $v){
  274. foreach($v['matchData'] as $kk => $vv){
  275. $wait_time = ceil(((strtotime( $vv['us_time']))-$s_time)/60);
  276. $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
  277. $oddsData= lm($model_match,"Sports")
  278. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  279. ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  280. ->where($model_match.'.source',$source['source'])
  281. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  282. // ->where($oddsTypeWhere)
  283. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  284. ->where(function($query)use ($model_odds){
  285. $query->where($model_odds.'.odds_code','concede_home')
  286. ->orWhere(function($query)use ($model_odds){
  287. $query->where($model_odds.'.odds_code','concede_guest');
  288. })
  289. ->orWhere(function($query)use ($model_odds){
  290. $query->where($model_odds.'.odds_code','size_home');
  291. })
  292. ->orWhere(function($query)use ($model_odds){
  293. $query->where($model_odds.'.odds_code','size_guest');
  294. })
  295. ->orWhere(function($query)use ($model_odds){
  296. $query->where($model_odds.'.odds_code','capot_home');
  297. })
  298. ->orWhere(function($query)use ($model_odds){
  299. $query->where($model_odds.'.odds_code','capot_dogfall');
  300. })
  301. ->orWhere(function($query)use ($model_odds){
  302. $query->where($model_odds.'.odds_code','capot_guest');
  303. });
  304. })
  305. ->get()
  306. ->toarray();
  307. //根据 排序 获取 最新让球/大小玩法赔率
  308. $sortData = array_column($oddsData,'sort');
  309. array_multisort($sortData,SORT_ASC,$oddsData);
  310. $zu = [];
  311. foreach ($oddsData as $key1 =>$item1){
  312. $zu[$item1['p_code']][] = $item1;
  313. }
  314. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  315. $capot = $zu['capot'];//独赢
  316. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  317. }
  318. }
  319. }
  320. //获取网球即将默认玩法赔率
  321. if($ret['game_code'] == 'wq'){
  322. foreach($data as $k => $v){
  323. $matchData = $this->getOddsData->getOddsWQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  324. $data[$k]['matchData'] = $matchData;
  325. }
  326. }
  327. //获取篮球即将默认玩法赔率
  328. if($ret['game_code'] == 'lq'){
  329. foreach($data as $k => $v){
  330. foreach($v['matchData'] as $kk => $vv){
  331. $wait_time = ceil(((strtotime( $vv['match_time']))-time())/60);
  332. $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
  333. $oddsData= lm($model_match,"Sports")
  334. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  335. ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  336. ->where($model_match.'.source',$source['source'])
  337. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  338. // ->where($oddsTypeWhere)
  339. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  340. ->where(function($query)use ($model_odds){
  341. $query->where($model_odds.'.odds_code','concede_home')
  342. ->orWhere(function($query)use ($model_odds){
  343. $query->where($model_odds.'.odds_code','concede_guest');
  344. })
  345. ->orWhere(function($query)use ($model_odds){
  346. $query->where($model_odds.'.odds_code','total_sizes_big');
  347. })
  348. ->orWhere(function($query)use ($model_odds){
  349. $query->where($model_odds.'.odds_code','total_sizes_small');
  350. })
  351. ->orWhere(function($query)use ($model_odds){
  352. $query->where($model_odds.'.odds_code','capot_home');
  353. })
  354. ->orWhere(function($query)use ($model_odds){
  355. $query->where($model_odds.'.odds_code','capot_dogfall');
  356. })
  357. ->orWhere(function($query)use ($model_odds){
  358. $query->where($model_odds.'.odds_code','capot_guest');
  359. });
  360. })
  361. ->get()
  362. ->toarray();
  363. //根据 排序 获取 最新让球/大小玩法赔率
  364. $sortData = array_column($oddsData,'sort');
  365. array_multisort($sortData,SORT_ASC,$oddsData);
  366. $zu = [];
  367. foreach ($oddsData as $key1 =>$item1){
  368. $zu[$item1['p_code']][] = $item1;
  369. }
  370. $c_s['concede'] = array_slice($zu['concede'],0,2);//让球 前四条 放入
  371. $c_s['total_size'] = array_slice($zu['total_size'],0,2);//让球 前四条 放入
  372. $capot = $zu['capot'];//独赢
  373. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  374. }
  375. // $matchData = $this->getOddsData->getOddsLQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  376. // $data[$k]['matchData'] = $matchData;
  377. }
  378. }
  379. //获取棒球即将默认玩法赔率
  380. if($ret['game_code'] == 'bq'){
  381. foreach($data as $k => $v){
  382. $matchData = $this->getOddsData->getOddsBQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  383. $data[$k]['matchData'] = $matchData;
  384. }
  385. }
  386. return $data;
  387. }
  388. public function getSoon($source,$models,$where,$lg_id=0,$ret,$search='',$oddsTypeWhere=''){
  389. //获取当前状态下所有联赛
  390. $leagueData = leagueModel::getSoonLeagueData($source,$models,$where,$search);
  391. if(empty($leagueData)){
  392. return $leagueData=[];
  393. }
  394. //统计联赛下的赛事及查询赛事
  395. $matchData = matchModel::getSoonMatchDataAll($source,$models,$where);
  396. //获取当前美东时间
  397. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  398. $data = [];
  399. foreach ($leagueData as $k=>$v){
  400. $data[$k] = $v;
  401. foreach ($matchData as $kk=>$vv){
  402. if($v['lg_id'] == $vv['lg_id']){
  403. $wait_time = ceil(((strtotime( $vv['us_time']))-$s_time)/60);
  404. $vv['wait_time'] = $wait_time;//追加距离开赛时间
  405. $data[$k]['matchData'][] = $vv;
  406. }
  407. }
  408. $data[$k]['matchNum'] = count($data[$k]['matchData']);
  409. }
  410. if($ret['game_code'] == 'zq') {
  411. //获取赛事下默认赔率
  412. $oddsData = ZQoddsModel::getMatchOdds($source, $models);
  413. foreach ($data as $k=>$v){
  414. foreach ($v['matchData'] as $kk=>$vv){
  415. //获取赛事下赔率并且分组
  416. $capot = [];
  417. $concede_size = [];
  418. foreach ($oddsData as $kkk=>$vvv) {
  419. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  420. if($vvv['p_code'] == 'concede_size'){
  421. $concede_size[] = $vvv;
  422. }
  423. if($vvv['p_code'] == 'capot'){
  424. $capot[] = $vvv;
  425. }
  426. }
  427. }
  428. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  429. }
  430. }
  431. }
  432. if($ret['game_code'] == 'lq') {
  433. $oddsData = LQoddsModel::getMatchOdds($source);
  434. foreach ($data as $k=>$v){
  435. foreach ($v['matchData'] as $kk=>$vv){
  436. //获取赛事下赔率并且分组
  437. $odds = [];
  438. foreach ($oddsData as $kkk=>$vvv) {
  439. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  440. $odds[] = $vvv;
  441. }
  442. }
  443. $data[$k]['matchData'][$kk]['oddsData'] = $odds;
  444. }
  445. }
  446. }
  447. if($ret['game_code'] == 'wq') {
  448. $oddsData = WQoddsModel::getMatchOdds($source);
  449. foreach ($data as $k=>$v){
  450. foreach ($v['matchData'] as $kk=>$vv){
  451. //获取赛事下赔率并且分组
  452. $odds = [];
  453. foreach ($oddsData as $kkk=>$vvv) {
  454. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  455. $odds[] = $vvv;
  456. }
  457. }
  458. $data[$k]['matchData'][$kk]['oddsData'] = $odds;
  459. }
  460. }
  461. }
  462. if($ret['game_code'] == 'bq') {
  463. $oddsData = BQoddsModel::getMatchOdds($source);
  464. foreach ($data as $k=>$v){
  465. foreach ($v['matchData'] as $kk=>$vv){
  466. //获取赛事下赔率并且分组
  467. $odds = [];
  468. foreach ($oddsData as $kkk=>$vvv) {
  469. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  470. $odds[] = $vvv;
  471. }
  472. }
  473. $data[$k]['matchData'][$kk]['oddsData'] = $odds;
  474. }
  475. }
  476. }
  477. return $data;
  478. }
  479. /**
  480. * 获取今日数据
  481. */
  482. public function getToday($source,$models,$where,$lg_id=0,$search='',$oddsTypeWhere=[]){
  483. //获取model
  484. $model_match = $models['model_match'];
  485. $model_odds = $models['model_odds'];
  486. $model_league = $models['model_league'];
  487. $model_result = $models['model_result'];
  488. //根据联赛id 获取联赛下 赛事赔率数据
  489. if($lg_id >0){
  490. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,'',$oddsTypeWhere);
  491. return $leagueData;
  492. }
  493. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where);
  494. return $data;
  495. }
  496. /**
  497. * 获取早盘数据
  498. */
  499. public function getMorningPlate($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  500. //获取model
  501. $model_match = $models['model_match'];
  502. $model_odds = $models['model_odds'];
  503. $model_league = $models['model_league'];
  504. $model_result = $models['model_result'];
  505. //根据联赛id 获取联赛下 赛事赔率数据
  506. if($lg_id >0){
  507. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  508. return $leagueData;
  509. }
  510. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  511. return $data;
  512. }
  513. /**
  514. * 获取串场数据
  515. */
  516. public function getStringScene($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  517. //获取model
  518. $model_match = $models['model_match'];
  519. $model_odds = $models['model_odds'];
  520. $model_league = $models['model_league'];
  521. $model_result = $models['model_result'];
  522. //根据联赛id 获取联赛下 赛事赔率数据
  523. if($lg_id >0){
  524. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  525. return $leagueData;
  526. }
  527. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  528. return $data;
  529. }
  530. /**
  531. * 获取冠军数据
  532. */
  533. public function getChampion($source,$models,$where,$lg_id=0,$search='',$type_code=''){
  534. //获取model
  535. $model_odds = $models['model_odds'];
  536. $model_league = $models['model_league'];
  537. //根据联赛id 获取联赛下 冠军玩法盘口
  538. if($lg_id >0){
  539. $last_time = lm($model_league, 'Sports')
  540. ->select('last_time')
  541. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  542. ->where($source)
  543. ->where('lg_id',$lg_id)
  544. ->first()->last_time;
  545. $championData = lm($model_odds, 'Sports')
  546. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  547. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  548. ->where($source)
  549. ->where('lg_id',$lg_id)
  550. ->where($where)
  551. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  552. ->get()->toArray();
  553. //按p_code分组
  554. $p_code=array();
  555. foreach($championData as $k=>$v){
  556. $p_code[$v['p_code']][]=$v;
  557. }
  558. $sd = [];
  559. foreach ($p_code as $k1=>$v1){
  560. foreach ($v1 as $k2=>$v2){
  561. $sd[$v2['p_code']]['last_time'] =$last_time;
  562. $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  563. }
  564. }
  565. return $sd;
  566. }
  567. //获取国家/洲下所有联赛及数量
  568. $data = $this->getMatch($source,$model_league,'',$model_odds,$search,$where,'',$type_code);
  569. return $data;
  570. }
  571. /**
  572. * 获取国家/洲 下联赛
  573. */
  574. public function getMatch($source,$model_league,$model_match='',$model_odds='',$search,$where,$time='',$type_code=''){
  575. //国家下所有联赛
  576. $country = lm($model_league,"Sports")
  577. ->leftjoin('st_country','st_country.country_id',$model_league.'.country_id')
  578. ->select('st_country.country_id','st_country.name_chinese as region')
  579. // ->select('st_country.country_id as region_id','st_country.name_chinese as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  580. ->distinct('st_country.name_chinese')
  581. ->where([[$model_league.'.name_chinese','!=','']])
  582. ->where($model_league.'.source',$source['source'])
  583. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  584. ->get()
  585. ->toArray();
  586. //洲下所有联赛
  587. $area = lm($model_league,"Sports")
  588. ->leftjoin('st_area','st_area.id',$model_league.'.area_id')
  589. ->select('st_area.id as area_id','st_area.title as region')
  590. // ->select('st_area.id as region_id','st_area.title as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  591. ->distinct('st_area.title')
  592. ->where([[$model_league.'.name_chinese','!=','']])
  593. ->where($model_league.'.source',$source['source'])
  594. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  595. ->get()
  596. ->toArray();
  597. if($type_code != 'StChampion'){//非冠军赛事
  598. $data = $this->getMatchNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  599. }else{//冠军赛事
  600. $data = $this->getMatchStChampionNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  601. }
  602. return $data;
  603. }
  604. /**
  605. * 获取联赛下赛事 数量
  606. * 非冠军盘口
  607. */
  608. public function getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  609. $leagueData = lm($model_league,'Sports')
  610. ->select('id','lg_id','name_chinese as league','country_id','area_id')
  611. ->where($source)
  612. ->where([[$model_league.'.name_chinese','!=','']])
  613. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  614. ->get()
  615. ->toArray();
  616. $timeWhere = [];
  617. if(!empty($time)){
  618. if($time == 'other'){
  619. $timeWhere[] = ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))];
  620. }else{
  621. $timeWhere[] = ['match_date',$time];
  622. }
  623. }
  624. $matchData = lm($model_match,'Sports')
  625. ->select('id','lg_id','match_id')
  626. ->where($where)
  627. ->where($source)
  628. ->where($timeWhere)
  629. ->get()
  630. ->toArray();
  631. //按国家
  632. $countryData = [];
  633. if(!empty($country) and !empty($leagueData) and !empty($matchData)){
  634. foreach ($country as $k=>$v){
  635. if($v['country_id']){
  636. $countryData[$k] = $v;
  637. foreach ($leagueData as $kk=>$vv){
  638. if($v['country_id'] == $vv['country_id']){
  639. $countryData[$k]['league_count'][] = $vv;
  640. }
  641. }
  642. }
  643. }
  644. }
  645. //去除无联赛 国家
  646. foreach ($countryData as $k=>$v){
  647. if(count($v) == 2){
  648. unset($countryData[$k]);
  649. }
  650. }
  651. //按地区
  652. $areaData = [];
  653. if(!empty($area) and !empty($leagueData) and($matchData)){
  654. foreach ($area as $k=>$v){
  655. if($v['area_id']){
  656. $areaData[$k] = $v;
  657. foreach ($leagueData as $kk=>$vv){
  658. if($v['area_id'] == $vv['area_id']){
  659. $areaData[$k]['league_count'][] = $vv;
  660. }
  661. }
  662. }
  663. }
  664. }
  665. //去除无联赛 地区
  666. foreach ($areaData as $k=>$v){
  667. if(count($v) == 2){
  668. unset($areaData[$k]);
  669. }
  670. }
  671. $countryData = $this->commonFunction->array_other_tt($countryData,$matchData);
  672. $areaData = $this->commonFunction->array_other_tt($areaData,$matchData);
  673. $data = array_merge($countryData,$areaData);
  674. return $data;
  675. }
  676. /**
  677. * 弃用 获取联赛下赛事 数量
  678. * 非冠军盘口
  679. */
  680. public function __getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  681. //统计国家下联赛-赛事/盘口数量
  682. if(!empty($country)){
  683. foreach($country as $k => $v) {
  684. $country[$k]['league_count'] = lm($model_league, 'Sports')
  685. ->select('lg_id', 'name_chinese as league')
  686. ->where($source)
  687. ->where('country_id', $v['country_id'])
  688. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  689. ->get()->toarray();
  690. }
  691. foreach ($country as $k => $v) {
  692. foreach($v['league_count'] as $kk => $vv ){
  693. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  694. if(empty($time)){
  695. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  696. ->select("match_id")
  697. ->where($source)
  698. ->where('lg_id',$vv['lg_id'])
  699. ->where($where)
  700. ->count("*");
  701. }else{//早盘 下有时间查询
  702. if($time == 'other'){//早盘 一周后
  703. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  704. ->select("match_id")
  705. ->where($source)
  706. ->where('lg_id',$vv['lg_id'])
  707. ->where($where)
  708. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  709. ->count("*");
  710. }else{
  711. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  712. ->select("match_id")
  713. ->where($source)
  714. ->where('lg_id',$vv['lg_id'])
  715. ->where($where)
  716. ->where('match_date',$time)
  717. ->count("*");
  718. }
  719. }
  720. }
  721. if($country[$k]['league_count'][$kk]['count'] == 0){
  722. unset($country[$k]['league_count'][$kk]);
  723. }
  724. }
  725. }
  726. }
  727. //统计 地区 联赛-赛事/盘口数量
  728. if(!empty($area)){
  729. foreach($area as $k => $v) {
  730. $area[$k]['league_count'] = lm($model_league, 'Sports')
  731. ->select('lg_id', 'name_chinese as league')
  732. ->where($source)
  733. ->where('area_id', $v['area_id'])
  734. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  735. ->get()->toarray();
  736. }
  737. foreach ($area as $k => $v) {
  738. foreach($v['league_count'] as $kk => $vv ){
  739. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  740. if(empty($time)){
  741. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  742. ->select("match_id")
  743. ->where($source)
  744. ->where('lg_id',$vv['lg_id'])
  745. ->where($where)
  746. ->count("*");
  747. }else {
  748. if ($time == 'other') {// 今日 一周后
  749. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  750. ->select("match_id")
  751. ->where($source)
  752. ->where('lg_id', $vv['lg_id'])
  753. ->where($where)
  754. ->where('match_date', '>', date("Y-m-d", strtotime("+1weeks", strtotime(date('Y-m-d', time())))))
  755. ->count("*");
  756. } else {//今日 大于今日
  757. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  758. ->select("match_id")
  759. ->where($source)
  760. ->where('lg_id',$vv['lg_id'])
  761. ->where($where)
  762. ->where('match_date',$time)
  763. ->count("*");
  764. }
  765. }
  766. }
  767. if($area[$k]['league_count'][$kk]['count'] == 0){
  768. unset($area[$k]['league_count'][$kk]);
  769. }
  770. }
  771. }
  772. }
  773. //处理空联赛国家
  774. $countryData = $this->commonFunction->handleArr($country);
  775. $areaData = $this->commonFunction->handleArr($area);
  776. //合并数组
  777. $data = array_merge($countryData,$areaData);
  778. return $data;
  779. }
  780. /**
  781. * 获取联赛下赛事 数量
  782. * 冠军盘口
  783. */
  784. public function getMatchStChampionNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  785. $leagueData = lm($model_league,'Sports')
  786. ->select('id','lg_id','name_chinese as league','country_id','area_id')
  787. ->where($source)
  788. ->where([[$model_league.'.name_chinese','!=','']])
  789. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  790. ->get()
  791. ->toArray();
  792. $oddsData = lm($model_odds,'Sports')
  793. ->select('id','lg_id','p_code')
  794. ->distinct("p_code")//去重
  795. ->where($where)
  796. ->where($source)
  797. ->get()
  798. ->toArray();
  799. //按国家
  800. $countryData = [];
  801. if(!empty($country) and !empty($leagueData) and !empty($oddsData)){
  802. foreach ($country as $k=>$v){
  803. if($v['country_id']){
  804. $countryData[$k] = $v;
  805. foreach ($leagueData as $kk=>$vv){
  806. if($v['country_id'] == $vv['country_id']){
  807. $countryData[$k]['league_count'][] = $vv;
  808. }
  809. }
  810. }
  811. }
  812. }
  813. //去除无联赛 国家
  814. foreach ($countryData as $k=>$v){
  815. if(count($v) == 2){
  816. unset($countryData[$k]);
  817. }
  818. }
  819. //按地区
  820. $areaData = [];
  821. if(!empty($area) and !empty($leagueData) and($oddsData)){
  822. foreach ($area as $k=>$v){
  823. if($v['area_id']){
  824. $areaData[$k] = $v;
  825. foreach ($leagueData as $kk=>$vv){
  826. if($v['area_id'] == $vv['area_id']){
  827. $areaData[$k]['league_count'][] = $vv;
  828. }
  829. }
  830. }
  831. }
  832. }
  833. //去除无联赛 地区
  834. foreach ($areaData as $k=>$v){
  835. if(count($v) == 2){
  836. unset($areaData[$k]);
  837. }
  838. }
  839. $countryData = $this->commonFunction->array_gj_tt($countryData,$oddsData);
  840. $areaData = $this->commonFunction->array_gj_tt($areaData,$oddsData);
  841. $data = array_merge($countryData,$areaData);
  842. return $data;
  843. }
  844. /**
  845. * 获取联赛下 赛事赔率
  846. */
  847. public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time='',$oddsTypeWhere=[]){
  848. $leagueData = lm($model_league,"Sports")
  849. ->select('lg_id','name_chinese as leagueName')
  850. ->where($source)
  851. ->where('lg_id',$lg_id)
  852. ->first();
  853. if(!empty($time)){//早盘 按时间查询
  854. if($time == 'other'){//早盘 一周后
  855. $matchData = lm($model_match,"Sports")
  856. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  857. ->where($source)
  858. ->where($model_match.'.lg_id',$lg_id)
  859. ->where($where)
  860. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  861. ->where(function($query)use ($model_match,$search){
  862. $query->where($model_match.'.home_team','like','%'.$search.'%')
  863. ->orWhere(function($query)use ($model_match,$search) {
  864. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  865. });
  866. })
  867. ->get()
  868. ->toarray();
  869. }else{
  870. if($time == date('Y-m-d')){//早盘今天
  871. $matchData = lm($model_match,"Sports")
  872. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  873. ->where($source)
  874. ->where($model_match.'.lg_id',$lg_id)
  875. ->where('is_morningplate','=',1)
  876. ->where('match_date',$time)
  877. ->where('match_time','>',date("H:i:s", time()))
  878. ->where(function($query)use ($model_match,$search){
  879. $query->where($model_match.'.home_team','like','%'.$search.'%')
  880. ->orWhere(function($query)use ($model_match,$search) {
  881. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  882. });
  883. })
  884. ->get()
  885. ->toarray();
  886. }else{//早盘 今天以后
  887. $matchData = lm($model_match,"Sports")
  888. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  889. ->where($source)
  890. ->where($model_match.'.lg_id',$lg_id)
  891. ->where($where)
  892. ->where('match_date',$time)
  893. ->where(function($query)use ($model_match,$search){
  894. $query->where($model_match.'.home_team','like','%'.$search.'%')
  895. ->orWhere(function($query)use ($model_match,$search) {
  896. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  897. });
  898. })
  899. ->get()
  900. ->toarray();
  901. }
  902. }
  903. }else{
  904. $matchData = lm($model_match,"Sports")
  905. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  906. ->where($source)
  907. ->where($model_match.'.lg_id',$lg_id)
  908. ->where($where)
  909. ->where(function($query)use ($model_match,$search){
  910. $query->where($model_match.'.home_team','like','%'.$search.'%')
  911. ->orWhere(function($query)use ($model_match,$search) {
  912. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  913. });
  914. })
  915. ->get()
  916. ->toarray();
  917. }
  918. //获取各球类默认赔率
  919. $game_code = $_REQUEST['game_code'];
  920. switch ($game_code) {
  921. case 'zq'://足球
  922. $matchData = $this->getOddsData->getOddsZQ($matchData, $model_odds, $source,$oddsTypeWhere);
  923. break;
  924. case 'lq'://篮球
  925. $matchData = $this->getOddsData->getOddsLQ($matchData, $model_odds, $source,$oddsTypeWhere);
  926. break;
  927. case 'wq'://网球
  928. $matchData = $this->getOddsData->getOddsWQ($matchData, $model_odds, $source,$oddsTypeWhere);
  929. break;
  930. case 'bq'://棒球
  931. $matchData = $this->getOddsData->getOddsBQ($matchData, $model_odds, $source,$oddsTypeWhere);
  932. break;
  933. }
  934. $leagueData->matchNum = count($matchData);
  935. $leagueData->matchData = $matchData;
  936. return $leagueData;
  937. }
  938. /**
  939. * @param $source 数据源
  940. * @param $where 该状态 查询条件
  941. * @return array
  942. * @throws \Exception
  943. * 获取所有即将开赛 数据
  944. */
  945. public function getAllSoon($source,$where){
  946. $game = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
  947. //获取当前美东时间
  948. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  949. $data=[];
  950. foreach ($game as $key=>$item){
  951. if($item['game_code'] !='gj'){
  952. $model = $this->commonFunction->getModels($item['game_code']);
  953. $matchData = lm($model['model_match'], 'Sports')
  954. ->select('match_id','home_team','guest_team','match_time','us_time')
  955. ->where($source)
  956. ->where($where)
  957. ->orderBy('match_time','asc')
  958. // ->limit(6)
  959. ->get()->toArray();
  960. $matchNum = count($matchData);
  961. $matchData = array_slice($matchData,0,6);
  962. foreach ($matchData as $key1 => $item1){
  963. //获取等待时间
  964. $wait_time = ceil(((strtotime($item1['us_time']))-$s_time)/60);
  965. $matchData[$key1]['wait_time'] = $wait_time;
  966. }
  967. if($matchNum > 0){
  968. // $matchData = array_multisort(array_column($matchData,'wait_time'),SOTR_ASC,$matchData);
  969. $data[$item['game_code']]['matchData'] = $matchData;
  970. $data[$item['game_code']]['matchNum'] = $matchNum;
  971. $data[$item['game_code']]['gameName'] = $item['game_name'];
  972. $data[$item['game_code']]['gameCode'] = $item['game_code'];
  973. }
  974. }
  975. }
  976. return $data;
  977. }
  978. /**
  979. * 获取欧冠 各状态赛事数据
  980. */
  981. public function getUEFAChampions($source){
  982. //根据搜索查询
  983. if(!empty($_GET['search'])){
  984. $search = $_GET['search'];
  985. }
  986. $model = $this->commonFunction->getModels('gj',1);
  987. $model_league = $model['model_league'];
  988. $leagueData = lm($model_league,'Sports')
  989. ->select('name_chinese','lg_id','last_time')
  990. ->where($model_league.'.source',$source['source'])
  991. ->where($model_league.'.name_chinese','欧洲冠军杯')
  992. ->first();
  993. //获取滚球数据
  994. $StRollBall = $this->getUEFAStRollBall($model,'StRollBall',$source,$leagueData->lg_id,$search);
  995. //获取今日数据
  996. $StToday = $this->getUEFAStToday($model,'StToday',$source,$leagueData->lg_id,$search);
  997. //获取早盘数据
  998. $StMorningPlate = $this->getUEFAStMorningPlate($model,'StMorningPlate',$source,$leagueData->lg_id,$search);
  999. //获取冠军盘口数据
  1000. $StChampion = $this->getUEFAStChampion($model,'StChampion',$source,$leagueData->lg_id,$leagueData->last_time);
  1001. $data = [
  1002. 'lg_id' => $leagueData->lg_id,
  1003. 'leagueName'=> $leagueData->name_chinese,
  1004. 'StRollBall'=>[//滚球数据
  1005. 'typeName'=>'滚球',
  1006. 'matchNum'=>count($StRollBall),
  1007. 'matchData'=>$StRollBall
  1008. ],
  1009. 'StToday'=>[//今日数据
  1010. 'typeName'=>'今日',
  1011. 'matchNum'=>count($StToday),
  1012. 'matchData'=>$StToday
  1013. ],
  1014. 'StMorningPlate'=>[//早盘数据
  1015. 'typeName'=>'早盘',
  1016. 'matchNum'=>count($StMorningPlate),
  1017. 'matchData'=>$StMorningPlate
  1018. ],
  1019. 'StChampion'=>[//冠军盘口
  1020. 'typeName'=>'冠军盘口',
  1021. 'matchNum'=>count($StChampion),
  1022. 'matchData'=>$StChampion
  1023. ]
  1024. ];
  1025. return $data;
  1026. }
  1027. /**
  1028. * 获取欧冠 滚球数据
  1029. */
  1030. public function getUEFAStRollBall($model,$type_code,$source,$lg_id,$search=''){
  1031. $model_match = $model['model_match'];
  1032. $model_odds = $model['model_odds'];
  1033. $model_result = $model['model_result'];
  1034. $where = $this->commonFunction->getState($type_code,$model_match);
  1035. $matchData = lm($model_match,"Sports")
  1036. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  1037. ->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')
  1038. ->where($model_match.'.source',$source['source'])
  1039. ->where($model_match.'.lg_id',$lg_id)
  1040. ->where($where)
  1041. ->where(function($query)use ($model_match,$search){
  1042. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1043. ->orWhere(function($query)use ($model_match,$search) {
  1044. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1045. });
  1046. })
  1047. ->get()
  1048. ->toarray();
  1049. foreach($matchData as $kk => $vv){
  1050. $oddsData= lm($model_match,"Sports")
  1051. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  1052. ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  1053. ->where($model_match.'.source',$source['source'])
  1054. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  1055. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  1056. ->where(function($query)use ($model_odds){
  1057. $query->where($model_odds.'.odds_code','concede_home')
  1058. ->orWhere(function($query)use ($model_odds){
  1059. $query->where($model_odds.'.odds_code','concede_guest');
  1060. })
  1061. ->orWhere(function($query)use ($model_odds){
  1062. $query->where($model_odds.'.odds_code','size_home');
  1063. })
  1064. ->orWhere(function($query)use ($model_odds){
  1065. $query->where($model_odds.'.odds_code','size_guest');
  1066. })
  1067. ->orWhere(function($query)use ($model_odds){
  1068. $query->where($model_odds.'.odds_code','capot_home');
  1069. })
  1070. ->orWhere(function($query)use ($model_odds){
  1071. $query->where($model_odds.'.odds_code','capot_dogfall');
  1072. })
  1073. ->orWhere(function($query)use ($model_odds){
  1074. $query->where($model_odds.'.odds_code','capot_guest');
  1075. });
  1076. })
  1077. ->get()
  1078. ->toarray();
  1079. //根据 排序 获取 最新让球/大小玩法赔率
  1080. $sortData = array_column($oddsData,'sort');
  1081. array_multisort($sortData,SORT_ASC,$oddsData);
  1082. $zu = [];
  1083. foreach ($oddsData as $key1 =>$item1){
  1084. $zu[$item1['p_code']][] = $item1;
  1085. }
  1086. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  1087. $capot = $zu['capot'];//独赢
  1088. $matchData[$kk]['oddsData'] = [$c_s,$capot];
  1089. }
  1090. return $matchData;
  1091. }
  1092. /**
  1093. * 获取欧冠 今日数据
  1094. */
  1095. public function getUEFAStToday($model,$type_code,$source,$lg_id,$search=''){
  1096. $model_match = $model['model_match'];
  1097. $model_odds = $model['model_odds'];
  1098. $where = $this->commonFunction->getState($type_code);
  1099. $matchData = lm($model_match,'Sports')
  1100. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  1101. ->where($model_match.'.source',$source['source'])
  1102. ->where($where)
  1103. ->where('lg_id',$lg_id)
  1104. ->where(function($query)use ($model_match,$search){
  1105. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1106. ->orWhere(function($query)use ($model_match,$search) {
  1107. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1108. });
  1109. })
  1110. ->get()->toArray();
  1111. foreach($matchData as $kk => $vv) {
  1112. $oddsData = lm($model_match, "Sports")
  1113. ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
  1114. ->select($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  1115. ->where($model_match.'.source',$source['source'])
  1116. ->where([$model_odds . '.match_id' => $vv['match_id']])
  1117. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  1118. ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  1119. ->orderBy($model_odds . '.id','desc')
  1120. ->get()
  1121. ->toarray();
  1122. $matchData[$kk]['oddsData'] = $oddsData;
  1123. }
  1124. return $matchData;
  1125. }
  1126. /**
  1127. * 获取欧冠 早盘数据
  1128. */
  1129. public function getUEFAStMorningPlate($model,$type_code,$source,$lg_id,$search=''){
  1130. $model_match = $model['model_match'];
  1131. $model_odds = $model['model_odds'];
  1132. $where = $this->commonFunction->getState($type_code);
  1133. $matchData = lm($model_match,'Sports')
  1134. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  1135. ->where($model_match.'.source',$source['source'])
  1136. ->where($where)
  1137. ->where('lg_id',$lg_id)
  1138. ->where(function($query)use ($model_match,$search){
  1139. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1140. ->orWhere(function($query)use ($model_match,$search) {
  1141. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1142. });
  1143. })
  1144. ->get()->toArray();
  1145. $data = $this->getOddsData->getOddsZQ($matchData,$model_odds,$source,[]);
  1146. return $data;
  1147. }
  1148. /**
  1149. * 获取 欧冠 冠军盘口数据
  1150. */
  1151. public function getUEFAStChampion($model,$type_code,$source,$lg_id,$last_time=''){
  1152. $model_odds = $model['model_odds'];
  1153. $where = $this->commonFunction->getState($type_code);
  1154. $championData = lm($model_odds, 'Sports')
  1155. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  1156. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  1157. ->where($source)
  1158. ->where('lg_id',$lg_id)
  1159. ->where($where)
  1160. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  1161. ->get()->toArray();
  1162. //按p_code分组
  1163. $p_code=array();
  1164. foreach($championData as $k=>$v){
  1165. $p_code[$v['p_code']][]=$v;
  1166. }
  1167. $data = [];
  1168. foreach ($p_code as $k1=>$v1){
  1169. foreach ($v1 as $k2=>$v2){
  1170. $data[$v2['p_code']]['last_time'] =$last_time;
  1171. $data[$v2['p_code']][$v2['odds_code']][] = $v2;
  1172. }
  1173. }
  1174. return $data;
  1175. }
  1176. }