GetmatchData.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. <?php
  2. /**
  3. * 根据不同状态获取 赛事数据
  4. * User: Jun.peng
  5. * Date: 2019/4/4
  6. * Time: 10:57
  7. */
  8. namespace Biz\Match;
  9. class GetmatchData {
  10. /**
  11. * @param $ret 提交参数
  12. * @param $source 数据源条件
  13. * @return array
  14. * @throws \Exception
  15. * 获取不同状态下的赛事相关数据
  16. */
  17. public function typeData($ret,$source){
  18. //根据球类代码 获取相关model
  19. $models = getModels($ret['game_code']);
  20. $model_match = $models['model_match'];
  21. //获取 不同状态的查询条件
  22. $where = getState($ret['type_code'],$model_match);
  23. //根据联赛id查询
  24. if(!empty($ret['lg_id'])){
  25. $lg_id = $ret['lg_id'];
  26. }
  27. //根据搜索查询
  28. if(!empty($ret['search'])){
  29. $search = $ret['search'];
  30. }
  31. switch ($ret['type_code']){
  32. case 'StRollBall'://滚球
  33. $data = $this->getRollBall($source,$models,$where,$ret,$search);
  34. break;
  35. case 'StSoon'://即将
  36. $data = $this->getSoon($source,$models,$where,$lg_id,$search);
  37. break;
  38. case 'StToday'://今日
  39. $data = $this->getToday($source,$models,$where,$lg_id,$search);
  40. break;
  41. case 'StMorningPlate'://早盘
  42. //默认当天
  43. if(empty($ret['match_date'])){
  44. $match_date = date("Y-m-d");
  45. }else{
  46. if($ret['match_date'] == 'other'){
  47. $match_date = $ret['match_date'];
  48. }else{
  49. $match_date = date("Y-m-d");
  50. }
  51. }
  52. $data = $this->getMorningPlate($source,$models,$where,$lg_id,$search,$match_date);
  53. break;
  54. case 'StStringScene'://串场
  55. if(empty($ret['str_type']) || $ret['str_type'] ==0){//赛事
  56. $data = $this->getStringScene($source,$models,$where,$lg_id,$search);
  57. }
  58. if($ret['str_type'] == 1){//参赛表
  59. }
  60. if($ret['str_type'] == 2){//冠军盘口
  61. $where = getState('StChampion',$model_match);
  62. $data = $this->getChampion($source,$models,$where,$lg_id,$search);
  63. }
  64. break;
  65. case 'StChampion'://冠军
  66. $data = $this->getChampion($source,$models,$where,$lg_id,$search);
  67. break;
  68. default:
  69. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  70. }
  71. return $data;
  72. }
  73. /**
  74. * 获取滚球数据
  75. */
  76. public function getRollBall($source,$models,$where,$ret,$search=''){
  77. $model_match = $models['model_match'];
  78. $model_odds = $models['model_odds'];
  79. $model_league = $models['model_league'];
  80. $model_result = $models['model_result'];
  81. //当前状态下所有联赛
  82. $data = lm($model_league,"Sports")
  83. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  84. ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
  85. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  86. ->distinct($model_league.'.name_chinese')
  87. ->where($model_league.'.source',$source['source'])
  88. ->where($where)
  89. ->where(function($query)use ($model_match,$search){
  90. $query->where($model_match.'.home_team','like','%'.$search.'%')
  91. ->orWhere(function($query)use ($model_match,$search) {
  92. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  93. });
  94. })
  95. ->get()
  96. ->toarray();
  97. if(empty($data)){
  98. $data = [];
  99. return $data;
  100. }
  101. //统计联赛下的赛事及查询赛事
  102. foreach($data as $k => $v){
  103. $data[$k]['matchNum'] = lm($model_match,"Sports")
  104. ->where($source)
  105. ->where('lg_id',$v['lg_id'])
  106. ->where($where)
  107. ->count();
  108. $data[$k]['matchData'] = lm($model_match,"Sports")
  109. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  110. ->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')
  111. ->where($model_match.'.source',$source['source'])
  112. ->where($model_match.'.lg_id',$v['lg_id'])
  113. ->where($where)
  114. ->get()
  115. ->toarray();
  116. }
  117. foreach($data as $k => $v){
  118. foreach($v['matchData'] as $kk => $vv){
  119. $oddsData= lm($model_match,"Sports")
  120. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  121. ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  122. ->where($model_match.'.source',$source['source'])
  123. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  124. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  125. ->where(function($query)use ($model_odds){
  126. $query->where($model_odds.'.odds_code','concede_home')
  127. ->orWhere(function($query)use ($model_odds){
  128. $query->where($model_odds.'.odds_code','concede_guest');
  129. })
  130. ->orWhere(function($query)use ($model_odds){
  131. $query->where($model_odds.'.odds_code','size_home');
  132. })
  133. ->orWhere(function($query)use ($model_odds){
  134. $query->where($model_odds.'.odds_code','size_guest');
  135. })
  136. ->orWhere(function($query)use ($model_odds){
  137. $query->where($model_odds.'.odds_code','capot_home');
  138. })
  139. ->orWhere(function($query)use ($model_odds){
  140. $query->where($model_odds.'.odds_code','capot_dogfall');
  141. })
  142. ->orWhere(function($query)use ($model_odds){
  143. $query->where($model_odds.'.odds_code','capot_guest');
  144. });
  145. })
  146. ->get()
  147. ->toarray();
  148. //根据 排序 获取 最新让球/大小玩法赔率
  149. $sortData = array_column($oddsData,'sort');
  150. array_multisort($sortData,SORT_DESC,$oddsData);
  151. $zu = [];
  152. foreach ($oddsData as $key1 =>$item1){
  153. $zu[$item1['p_code']][] = $item1;
  154. }
  155. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  156. $capot = $zu['capot'];//独赢
  157. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  158. }
  159. }
  160. return $data;
  161. }
  162. /**
  163. * 获取即将数据
  164. */
  165. public function getSoon($source,$models,$where,$lg_id=0,$search=''){
  166. $model_match = $models['model_match'];
  167. $model_odds = $models['model_odds'];
  168. $model_league = $models['model_league'];
  169. $model_result = $models['model_result'];
  170. //当前状态下所有联赛
  171. $data = lm($model_league,"Sports")
  172. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  173. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  174. ->distinct($model_league.'.name_chinese')
  175. ->where($model_league.'.source',$source['source'])
  176. ->where($where)
  177. ->where(function($query)use ($model_match,$search){
  178. $query->where($model_match.'.home_team','like','%'.$search.'%')
  179. ->orWhere(function($query)use ($model_match,$search) {
  180. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  181. });
  182. })
  183. ->get()
  184. ->toarray();
  185. if(empty($data)){
  186. $data = [];
  187. return $data;
  188. }
  189. //统计联赛下的赛事及查询赛事
  190. foreach($data as $k => $v){
  191. $data[$k]['matchNum'] = lm($model_match,"Sports")
  192. ->where($source)
  193. ->where('lg_id',$v['lg_id'])
  194. ->where($where)
  195. ->count();
  196. $data[$k]['matchData'] = lm($model_match,"Sports")
  197. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  198. ->where($source)
  199. ->where($model_match.'.lg_id',$v['lg_id'])
  200. ->where($where)
  201. ->get()
  202. ->toarray();
  203. }
  204. foreach($data as $k => $v){
  205. foreach($v['matchData'] as $kk => $vv){
  206. $wait_time = ceil(((strtotime( $vv['match_time']))-time())/60);
  207. $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
  208. $oddsData= lm($model_match,"Sports")
  209. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  210. ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  211. ->where($model_match.'.source',$source['source'])
  212. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  213. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  214. ->where(function($query)use ($model_odds){
  215. $query->where($model_odds.'.odds_code','concede_home')
  216. ->orWhere(function($query)use ($model_odds){
  217. $query->where($model_odds.'.odds_code','concede_guest');
  218. })
  219. ->orWhere(function($query)use ($model_odds){
  220. $query->where($model_odds.'.odds_code','size_home');
  221. })
  222. ->orWhere(function($query)use ($model_odds){
  223. $query->where($model_odds.'.odds_code','size_guest');
  224. })
  225. ->orWhere(function($query)use ($model_odds){
  226. $query->where($model_odds.'.odds_code','capot_home');
  227. })
  228. ->orWhere(function($query)use ($model_odds){
  229. $query->where($model_odds.'.odds_code','capot_dogfall');
  230. })
  231. ->orWhere(function($query)use ($model_odds){
  232. $query->where($model_odds.'.odds_code','capot_guest');
  233. });
  234. })
  235. ->get()
  236. ->toarray();
  237. //根据 排序 获取 最新让球/大小玩法赔率
  238. $sortData = array_column($oddsData,'sort');
  239. array_multisort($sortData,SORT_DESC,$oddsData);
  240. $zu = [];
  241. foreach ($oddsData as $key1 =>$item1){
  242. $zu[$item1['p_code']][] = $item1;
  243. }
  244. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  245. $capot = $zu['capot'];//独赢
  246. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  247. }
  248. }
  249. return $data;
  250. }
  251. /**
  252. * 获取今日数据
  253. */
  254. public function getToday($source,$models,$where,$lg_id=0,$search=''){
  255. //获取model
  256. $model_match = $models['model_match'];
  257. $model_odds = $models['model_odds'];
  258. $model_league = $models['model_league'];
  259. $model_result = $models['model_result'];
  260. //根据联赛id 获取联赛下 赛事赔率数据
  261. if($lg_id >0){
  262. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id);
  263. return $leagueData;
  264. }
  265. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where);
  266. return $data;
  267. }
  268. /**
  269. * 获取早盘数据
  270. */
  271. public function getMorningPlate($source,$models,$where,$lg_id=0,$search='',$time=''){
  272. //获取model
  273. $model_match = $models['model_match'];
  274. $model_odds = $models['model_odds'];
  275. $model_league = $models['model_league'];
  276. $model_result = $models['model_result'];
  277. //根据联赛id 获取联赛下 赛事赔率数据
  278. if($lg_id >0){
  279. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time);
  280. return $leagueData;
  281. }
  282. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  283. return $data;
  284. }
  285. /**
  286. * 获取串场数据
  287. */
  288. public function getStringScene($source,$models,$where,$lg_id=0,$search='',$time){
  289. //获取model
  290. $model_match = $models['model_match'];
  291. $model_odds = $models['model_odds'];
  292. $model_league = $models['model_league'];
  293. $model_result = $models['model_result'];
  294. //根据联赛id 获取联赛下 赛事赔率数据
  295. if($lg_id >0){
  296. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time);
  297. return $leagueData;
  298. }
  299. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  300. return $data;
  301. }
  302. /**
  303. * 获取冠军数据
  304. */
  305. public function getChampion($source,$models,$where,$lg_id=0,$search=''){
  306. //获取model
  307. $model_odds = $models['model_odds'];
  308. $model_league = $models['model_league'];
  309. //根据联赛id 获取联赛下 冠军玩法盘口
  310. if($lg_id >0){
  311. $last_time = lm($model_league, 'Sports')
  312. ->select('last_time')
  313. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  314. ->where($source)
  315. ->where('lg_id',$lg_id)
  316. ->first()->last_time;
  317. $championData = lm($model_odds, 'Sports')
  318. ->select("id","lg_id","p_code","odds_code","team","odds","sort","status","odds_only")
  319. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  320. ->where($source)
  321. ->where('lg_id',$lg_id)
  322. ->where($where)
  323. ->groupBy("id","lg_id","p_code","odds_code","team","odds","sort","status","odds_only")
  324. ->get()->toArray();
  325. //按p_code分组
  326. $p_code=array();
  327. foreach($championData as $k=>$v){
  328. $p_code[$v['p_code']][]=$v;
  329. }
  330. $sd = [];
  331. foreach ($p_code as $k1=>$v1){
  332. foreach ($v1 as $k2=>$v2){
  333. $sd[$v2['p_code']]['last_time'] =$last_time;
  334. $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  335. }
  336. }
  337. return $sd;
  338. }
  339. //获取国家/洲下所有联赛及数量
  340. $data = $this->getMatch($source,$model_league,'',$model_odds,$search,$where,'');
  341. return $data;
  342. }
  343. /**
  344. * 获取国家/洲 下联赛
  345. */
  346. public function getMatch($source,$model_league,$model_match='',$model_odds='',$search,$where,$time=''){
  347. //国家下所有联赛
  348. $country = lm($model_league,"Sports")
  349. ->leftjoin('st_country','st_country.country_id',$model_league.'.country_id')
  350. ->select('st_country.country_id as region_id','st_country.name_chinese as region')
  351. // ->select('st_country.country_id as region_id','st_country.name_chinese as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  352. ->distinct('st_country.name_chinese')
  353. ->where($model_league.'.source',$source['source'])
  354. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  355. ->get()
  356. ->toArray();
  357. //洲下所有联赛
  358. $area = lm($model_league,"Sports")
  359. ->leftjoin('st_area','st_area.id',$model_league.'.area_id')
  360. ->select('st_area.id as region_id','st_area.title as region')
  361. // ->select('st_area.id as region_id','st_area.title as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  362. ->distinct('st_area.title')
  363. ->where($model_league.'.source',$source['source'])
  364. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  365. ->get()
  366. ->toArray();
  367. $data = $this->getMatchNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  368. return $data;
  369. }
  370. /**
  371. * 获取联赛下赛事/盘口 数量
  372. */
  373. public function getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  374. //统计国家下联赛-赛事/盘口数量
  375. if(!empty($country)){
  376. foreach($country as $k => $v) {
  377. $country[$k]['league_count'] = lm($model_league, 'Sports')
  378. ->select('lg_id', 'name_chinese as league')
  379. ->where($source)
  380. ->where('country_id', $v['region_id'])
  381. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  382. ->get()->toarray();
  383. }
  384. foreach ($country as $k => $v) {
  385. foreach($v['league_count'] as $kk => $vv ){
  386. if(!empty($model_odds)){//冠军玩法,获取赔率盘口数量
  387. $where = getState('StChampion');
  388. $country[$k]['league_count'][$kk]['count'] = lm($model_odds, 'Sports')
  389. ->select("p_code")
  390. ->where($source)
  391. ->where('lg_id',$vv['lg_id'])
  392. ->where($where)
  393. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  394. ->distinct("p_code")
  395. ->count("p_code");
  396. }
  397. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  398. if(empty($time)){
  399. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  400. ->select("match_id")
  401. ->where($source)
  402. ->where('lg_id',$vv['lg_id'])
  403. ->where($where)
  404. ->count("*");
  405. }else{
  406. if($time == 'other'){
  407. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  408. ->select("match_id")
  409. ->where($source)
  410. ->where('lg_id',$vv['lg_id'])
  411. ->where($where)
  412. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  413. ->count("*");
  414. }else{
  415. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  416. ->select("match_id")
  417. ->where($source)
  418. ->where('lg_id',$vv['lg_id'])
  419. ->where($where)
  420. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  421. ->count("*");
  422. }
  423. }
  424. }
  425. if($country[$k]['league_count'][$kk]['count'] == 0){
  426. unset($country[$k]['league_count'][$kk]);
  427. }
  428. }
  429. }
  430. }
  431. //统计 地区 联赛-赛事/盘口数量
  432. if(!empty($area)){
  433. foreach($area as $k => $v) {
  434. $area[$k]['league_count'] = lm($model_league, 'Sports')
  435. ->select('lg_id', 'name_chinese as league')
  436. ->where($source)
  437. ->where('area_id', $v['region_id'])
  438. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  439. ->get()->toarray();
  440. }
  441. foreach ($area as $k => $v) {
  442. foreach($v['league_count'] as $kk => $vv ){
  443. if(!empty($model_odds)){//冠军玩法,获取赔率盘口数量
  444. $where = getState('StChampion');
  445. $area[$k]['league_count'][$kk]['count'] = lm($model_odds, 'Sports')
  446. ->select("p_code")
  447. ->where($source)
  448. ->where('lg_id',$vv['lg_id'])
  449. ->where($where)
  450. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  451. ->distinct("p_code")
  452. ->count("p_code");
  453. }
  454. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  455. if(empty($time)){
  456. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  457. ->select("match_id")
  458. ->where($source)
  459. ->where('lg_id',$vv['lg_id'])
  460. ->where($where)
  461. ->count("*");
  462. }else {
  463. if ($time == 'other') {
  464. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  465. ->select("match_id")
  466. ->where($source)
  467. ->where('lg_id', $vv['lg_id'])
  468. ->where($where)
  469. ->where('match_date', '>', date("Y-m-d", strtotime("+1weeks", strtotime(date('Y-m-d', time())))))
  470. ->count("*");
  471. } else {
  472. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  473. ->select("match_id")
  474. ->where($source)
  475. ->where('lg_id', $vv['lg_id'])
  476. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  477. ->where('match_date', $time)
  478. ->count("*");
  479. }
  480. }
  481. }
  482. if($area[$k]['league_count'][$kk]['count'] == 0){
  483. unset($area[$k]['league_count'][$kk]);
  484. }
  485. }
  486. }
  487. }
  488. //处理空联赛国家
  489. $countryData = handleArr($country);
  490. $areaData = handleArr($area);
  491. //合并数组
  492. $data = array_merge($countryData,$areaData);
  493. return $data;
  494. }
  495. /**
  496. * 获取联赛下 赛事赔率
  497. */
  498. public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time=''){
  499. $leagueData = lm($model_league,"Sports")
  500. ->select('lg_id','name_chinese as leagueName')
  501. ->where($source)
  502. ->where('lg_id',$lg_id)
  503. ->first();
  504. if(!empty($time)){
  505. if($time == 'other'){
  506. $matchData = lm($model_match,"Sports")
  507. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  508. ->where($source)
  509. ->where($model_match.'.lg_id',$lg_id)
  510. ->where($where)
  511. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  512. ->where(function($query)use ($model_match,$search){
  513. $query->where($model_match.'.home_team','like','%'.$search.'%')
  514. ->orWhere(function($query)use ($model_match,$search) {
  515. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  516. });
  517. })
  518. ->get()
  519. ->toarray();
  520. }else{
  521. $matchData = lm($model_match,"Sports")
  522. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  523. ->where($source)
  524. ->where($model_match.'.lg_id',$lg_id)
  525. ->where($where)
  526. ->where('match_date',$time)
  527. ->where(function($query)use ($model_match,$search){
  528. $query->where($model_match.'.home_team','like','%'.$search.'%')
  529. ->orWhere(function($query)use ($model_match,$search) {
  530. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  531. });
  532. })
  533. ->get()
  534. ->toarray();
  535. }
  536. }else{
  537. $matchData = lm($model_match,"Sports")
  538. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  539. ->where($source)
  540. ->where($model_match.'.lg_id',$lg_id)
  541. ->where($where)
  542. ->where(function($query)use ($model_match,$search){
  543. $query->where($model_match.'.home_team','like','%'.$search.'%')
  544. ->orWhere(function($query)use ($model_match,$search) {
  545. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  546. });
  547. })
  548. ->get()
  549. ->toarray();
  550. }
  551. foreach($matchData as $kk => $vv) {
  552. $oddsData = lm($model_match, "Sports")
  553. ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
  554. ->select($model_odds . '.id', 'odds_only','p_code', 'odds_code', $model_odds . '.status', 'odds', 'condition', 'sort')
  555. ->where($model_match.'.source',$source['source'])
  556. ->where([$model_odds . '.match_id' => $vv['match_id'], $model_odds . '.type' => 0])
  557. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  558. ->where(function ($query) use ($model_odds) {
  559. $query->where($model_odds . '.odds_code', 'concede_home')
  560. ->orWhere(function ($query) use ($model_odds) {
  561. $query->where($model_odds . '.odds_code', 'concede_guest');
  562. })
  563. ->orWhere(function ($query) use ($model_odds) {
  564. $query->where($model_odds . '.odds_code', 'size_home');
  565. })
  566. ->orWhere(function ($query) use ($model_odds) {
  567. $query->where($model_odds . '.odds_code', 'size_guest');
  568. });
  569. })
  570. ->get()
  571. ->toarray();
  572. //根据 排序 获取 最新让球/大小玩法赔率
  573. $sortData = array_column($oddsData,'sort');
  574. array_multisort($sortData,SORT_DESC,$oddsData);
  575. $zu = [];
  576. foreach ($oddsData as $key1 =>$item1){
  577. $zu[$item1['p_code']][] = $item1;
  578. }
  579. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  580. $matchData[$kk]['oddsData'] = $c_s;
  581. }
  582. $leagueData->matchNum = count($matchData);
  583. $leagueData->matchData = $matchData;
  584. return $leagueData;
  585. }
  586. /**
  587. * @param $source 数据源
  588. * @param $where 该状态 查询条件
  589. * @return array
  590. * @throws \Exception
  591. * 获取所有即将开赛 数据
  592. */
  593. public function getAllSoon($source,$where){
  594. $game = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
  595. $data=[];
  596. foreach ($game as $key=>$item){
  597. if($item['game_code'] !='gj'){
  598. $model = getModels($item['game_code']);
  599. $matchData = lm($model['model_match'], 'Sports')
  600. ->select('match_id','home_team','guest_team','match_time')
  601. ->where($source)
  602. ->where($where)
  603. ->get()->toArray();
  604. foreach ($matchData as $key1 => $item1){
  605. //获取等待时间
  606. $wait_time = ceil(((strtotime($item1['match_time']))-time())/60);
  607. $matchData[$key1]['wait_time'] = $wait_time;
  608. }
  609. $matchNum = count($matchData);
  610. if($matchNum > 0){
  611. $data[$item['game_code']]['matchData'] = $matchData;
  612. $data[$item['game_code']]['matchNum'] = $matchNum;
  613. $data[$item['game_code']]['gameName'] = $item['game_name'];
  614. $data[$item['game_code']]['gameCode'] = $item['game_code'];
  615. }
  616. }
  617. }
  618. return $data;
  619. }
  620. /**
  621. * 获取欧冠 赛事数据
  622. */
  623. public function getUEFAChampions($source){
  624. $model = getModels('gj',1);
  625. //获取滚球数据
  626. $StRollBall = $this->getUEFAMatchData($model,'StRollBall',$source);
  627. //获取滚球数据
  628. $StToday = $this->getUEFAMatchData($model,'StToday',$source);
  629. //获取滚球数据
  630. $StMorningPlate = $this->getUEFAMatchData($model,'StMorningPlate',$source);
  631. //获取滚球数据
  632. $StChampion = $this->getUEFAMatchData($model,'StChampion',$source);
  633. $data = [
  634. 'StRollBall'=>[//滚球数据
  635. 'typeName'=>'滚球',
  636. 'matchNum'=>count($StRollBall),
  637. 'matchData'=>$StRollBall
  638. ],
  639. 'StToday'=>[//今日数据
  640. 'typeName'=>'今日',
  641. 'matchNum'=>count($StToday),
  642. 'matchData'=>$StToday
  643. ],
  644. 'StMorningPlate'=>[//早盘数据
  645. 'typeName'=>'早盘',
  646. 'matchNum'=>count($StMorningPlate),
  647. 'matchData'=>$StMorningPlate
  648. ],
  649. 'StChampion'=>[//冠军盘口
  650. 'typeName'=>'冠军盘口',
  651. 'matchNum'=>count($StChampion),
  652. 'matchData'=>$StChampion
  653. ]
  654. ];
  655. return $data;
  656. }
  657. /**
  658. * 获取欧冠 各状态赛事及赔率数据
  659. */
  660. public function getUEFAMatchData($model,$type_code,$source){
  661. $model_league = $model['model_league'];
  662. $model_match = $model['model_match'];
  663. $model_odds = $model['model_odds'];
  664. $where = getState($type_code,$model_match);
  665. if($type_code != 'StChampion'){
  666. $matchData = lm($model_match,'Sports')
  667. ->leftjoin($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
  668. ->select($model_league.'.name_chinese',$model_match.'.match_id','match_date','match_time','tag','home_team','guest_team')
  669. ->where($model_match.'.source',$source['source'])
  670. ->where($where)
  671. ->where($model_league.'.name_chinese','欧洲冠军杯')
  672. ->get()->toArray();
  673. foreach($matchData as $kk => $vv) {
  674. $oddsData = lm($model_match, "Sports")
  675. ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
  676. ->select($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  677. ->where($model_match.'.source',$source['source'])
  678. ->where([$model_odds . '.match_id' => $vv['match_id']])
  679. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  680. ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  681. ->orderBy($model_odds . '.id','desc')
  682. ->get()
  683. ->toarray();
  684. $matchData[$kk]['oddsData'] = $oddsData;
  685. }
  686. }else{
  687. $matchData = [];
  688. }
  689. return $matchData;
  690. }
  691. }