GetmatchData.php 51 KB

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