GetmatchData.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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,$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.'.is_rollball'=>1,$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. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  175. }
  176. }
  177. return $data;
  178. }
  179. /**
  180. * 获取即将数据
  181. */
  182. public function getSoon($source,$models,$where,$lg_id=0,$search='',$oddsTypeWhere=''){
  183. $model_match = $models['model_match'];
  184. $model_odds = $models['model_odds'];
  185. $model_league = $models['model_league'];
  186. $model_result = $models['model_result'];
  187. //当前状态下所有联赛
  188. $data = lm($model_league,"Sports")
  189. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  190. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  191. ->distinct($model_league.'.name_chinese')
  192. ->where($model_league.'.source',$source['source'])
  193. ->where($where)
  194. ->where(function($query)use ($model_match,$search){
  195. $query->where($model_match.'.home_team','like','%'.$search.'%')
  196. ->orWhere(function($query)use ($model_match,$search) {
  197. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  198. });
  199. })
  200. ->get()
  201. ->toarray();
  202. if(empty($data)){
  203. $data = [];
  204. return $data;
  205. }
  206. //统计联赛下的赛事及查询赛事
  207. foreach($data as $k => $v){
  208. $data[$k]['matchNum'] = lm($model_match,"Sports")
  209. ->where($source)
  210. ->where('lg_id',$v['lg_id'])
  211. ->where($where)
  212. ->count();
  213. $data[$k]['matchData'] = lm($model_match,"Sports")
  214. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  215. ->where($source)
  216. ->where($model_match.'.lg_id',$v['lg_id'])
  217. ->where($where)
  218. ->get()
  219. ->toarray();
  220. }
  221. foreach($data as $k => $v){
  222. foreach($v['matchData'] as $kk => $vv){
  223. $wait_time = ceil(((strtotime( $vv['match_time']))-time())/60);
  224. $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
  225. $oddsData= lm($model_match,"Sports")
  226. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  227. ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  228. ->where($model_match.'.source',$source['source'])
  229. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  230. ->where($oddsTypeWhere)
  231. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  232. ->where(function($query)use ($model_odds){
  233. $query->where($model_odds.'.odds_code','concede_home')
  234. ->orWhere(function($query)use ($model_odds){
  235. $query->where($model_odds.'.odds_code','concede_guest');
  236. })
  237. ->orWhere(function($query)use ($model_odds){
  238. $query->where($model_odds.'.odds_code','size_home');
  239. })
  240. ->orWhere(function($query)use ($model_odds){
  241. $query->where($model_odds.'.odds_code','size_guest');
  242. })
  243. ->orWhere(function($query)use ($model_odds){
  244. $query->where($model_odds.'.odds_code','capot_home');
  245. })
  246. ->orWhere(function($query)use ($model_odds){
  247. $query->where($model_odds.'.odds_code','capot_dogfall');
  248. })
  249. ->orWhere(function($query)use ($model_odds){
  250. $query->where($model_odds.'.odds_code','capot_guest');
  251. });
  252. })
  253. ->get()
  254. ->toarray();
  255. //根据 排序 获取 最新让球/大小玩法赔率
  256. $sortData = array_column($oddsData,'sort');
  257. array_multisort($sortData,SORT_DESC,$oddsData);
  258. $zu = [];
  259. foreach ($oddsData as $key1 =>$item1){
  260. $zu[$item1['p_code']][] = $item1;
  261. }
  262. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  263. $capot = $zu['capot'];//独赢
  264. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  265. }
  266. }
  267. return $data;
  268. }
  269. /**
  270. * 获取今日数据
  271. */
  272. public function getToday($source,$models,$where,$lg_id=0,$search='',$oddsTypeWhere=[]){
  273. //获取model
  274. $model_match = $models['model_match'];
  275. $model_odds = $models['model_odds'];
  276. $model_league = $models['model_league'];
  277. $model_result = $models['model_result'];
  278. //根据联赛id 获取联赛下 赛事赔率数据
  279. if($lg_id >0){
  280. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,'',$oddsTypeWhere);
  281. return $leagueData;
  282. }
  283. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where);
  284. return $data;
  285. }
  286. /**
  287. * 获取早盘数据
  288. */
  289. public function getMorningPlate($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  290. //获取model
  291. $model_match = $models['model_match'];
  292. $model_odds = $models['model_odds'];
  293. $model_league = $models['model_league'];
  294. $model_result = $models['model_result'];
  295. //根据联赛id 获取联赛下 赛事赔率数据
  296. if($lg_id >0){
  297. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  298. return $leagueData;
  299. }
  300. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  301. return $data;
  302. }
  303. /**
  304. * 获取串场数据
  305. */
  306. public function getStringScene($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  307. //获取model
  308. $model_match = $models['model_match'];
  309. $model_odds = $models['model_odds'];
  310. $model_league = $models['model_league'];
  311. $model_result = $models['model_result'];
  312. //根据联赛id 获取联赛下 赛事赔率数据
  313. if($lg_id >0){
  314. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  315. return $leagueData;
  316. }
  317. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  318. return $data;
  319. }
  320. /**
  321. * 获取冠军数据
  322. */
  323. public function getChampion($source,$models,$where,$lg_id=0,$search='',$type_code=''){
  324. //获取model
  325. $model_odds = $models['model_odds'];
  326. $model_league = $models['model_league'];
  327. //根据联赛id 获取联赛下 冠军玩法盘口
  328. if($lg_id >0){
  329. $last_time = lm($model_league, 'Sports')
  330. ->select('last_time')
  331. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  332. ->where($source)
  333. ->where('lg_id',$lg_id)
  334. ->first()->last_time;
  335. $championData = lm($model_odds, 'Sports')
  336. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  337. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  338. ->where($source)
  339. ->where('lg_id',$lg_id)
  340. ->where($where)
  341. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  342. ->get()->toArray();
  343. //按p_code分组
  344. $p_code=array();
  345. foreach($championData as $k=>$v){
  346. $p_code[$v['p_code']][]=$v;
  347. }
  348. $sd = [];
  349. foreach ($p_code as $k1=>$v1){
  350. foreach ($v1 as $k2=>$v2){
  351. $sd[$v2['p_code']]['last_time'] =$last_time;
  352. $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  353. }
  354. }
  355. return $sd;
  356. }
  357. //获取国家/洲下所有联赛及数量
  358. $data = $this->getMatch($source,$model_league,'',$model_odds,$search,$where,'',$type_code);
  359. return $data;
  360. }
  361. /**
  362. * 获取国家/洲 下联赛
  363. */
  364. public function getMatch($source,$model_league,$model_match='',$model_odds='',$search,$where,$time='',$type_code=''){
  365. //国家下所有联赛
  366. $country = lm($model_league,"Sports")
  367. ->leftjoin('st_country','st_country.country_id',$model_league.'.country_id')
  368. ->select('st_country.country_id','st_country.name_chinese as region')
  369. // ->select('st_country.country_id as region_id','st_country.name_chinese as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  370. ->distinct('st_country.name_chinese')
  371. ->where($model_league.'.source',$source['source'])
  372. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  373. ->get()
  374. ->toArray();
  375. //洲下所有联赛
  376. $area = lm($model_league,"Sports")
  377. ->leftjoin('st_area','st_area.id',$model_league.'.area_id')
  378. ->select('st_area.id as area_id','st_area.title as region')
  379. // ->select('st_area.id as region_id','st_area.title as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  380. ->distinct('st_area.title')
  381. ->where($model_league.'.source',$source['source'])
  382. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  383. ->get()
  384. ->toArray();
  385. if($type_code != 'StChampion'){//非冠军赛事
  386. $data = $this->getMatchNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  387. }else{//冠军赛事
  388. $data = $this->getMatchStChampionNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  389. }
  390. return $data;
  391. }
  392. /**
  393. * 获取联赛下赛事 数量
  394. * 非冠军盘口
  395. */
  396. public function getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  397. //统计国家下联赛-赛事/盘口数量
  398. if(!empty($country)){
  399. foreach($country as $k => $v) {
  400. $country[$k]['league_count'] = lm($model_league, 'Sports')
  401. ->select('lg_id', 'name_chinese as league')
  402. ->where($source)
  403. ->where('country_id', $v['country_id'])
  404. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  405. ->get()->toarray();
  406. }
  407. foreach ($country as $k => $v) {
  408. foreach($v['league_count'] as $kk => $vv ){
  409. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  410. if(empty($time)){
  411. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  412. ->select("match_id")
  413. ->where($source)
  414. ->where('lg_id',$vv['lg_id'])
  415. ->where($where)
  416. ->count("*");
  417. }else{//早盘 下有时间查询
  418. if($time == 'other'){//早盘 一周后
  419. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  420. ->select("match_id")
  421. ->where($source)
  422. ->where('lg_id',$vv['lg_id'])
  423. ->where($where)
  424. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  425. ->count("*");
  426. }else{
  427. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  428. ->select("match_id")
  429. ->where($source)
  430. ->where('lg_id',$vv['lg_id'])
  431. ->where($where)
  432. ->where('match_date',$time)
  433. ->count("*");
  434. }
  435. }
  436. }
  437. if($country[$k]['league_count'][$kk]['count'] == 0){
  438. unset($country[$k]['league_count'][$kk]);
  439. }
  440. }
  441. }
  442. }
  443. //统计 地区 联赛-赛事/盘口数量
  444. if(!empty($area)){
  445. foreach($area as $k => $v) {
  446. $area[$k]['league_count'] = lm($model_league, 'Sports')
  447. ->select('lg_id', 'name_chinese as league')
  448. ->where($source)
  449. ->where('area_id', $v['area_id'])
  450. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  451. ->get()->toarray();
  452. }
  453. foreach ($area as $k => $v) {
  454. foreach($v['league_count'] as $kk => $vv ){
  455. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  456. if(empty($time)){
  457. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  458. ->select("match_id")
  459. ->where($source)
  460. ->where('lg_id',$vv['lg_id'])
  461. ->where($where)
  462. ->count("*");
  463. }else {
  464. if ($time == 'other') {// 今日 一周后
  465. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  466. ->select("match_id")
  467. ->where($source)
  468. ->where('lg_id', $vv['lg_id'])
  469. ->where($where)
  470. ->where('match_date', '>', date("Y-m-d", strtotime("+1weeks", strtotime(date('Y-m-d', time())))))
  471. ->count("*");
  472. } else {//今日 大于今日
  473. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  474. ->select("match_id")
  475. ->where($source)
  476. ->where('lg_id',$vv['lg_id'])
  477. ->where($where)
  478. ->where('match_date',$time)
  479. ->count("*");
  480. }
  481. }
  482. }
  483. if($area[$k]['league_count'][$kk]['count'] == 0){
  484. unset($area[$k]['league_count'][$kk]);
  485. }
  486. }
  487. }
  488. }
  489. //处理空联赛国家
  490. $countryData = $this->commonFunction->handleArr($country);
  491. $areaData = $this->commonFunction->handleArr($area);
  492. //合并数组
  493. $data = array_merge($countryData,$areaData);
  494. return $data;
  495. }
  496. /**
  497. * 获取联赛下赛事 数量
  498. * 冠军盘口
  499. */
  500. public function getMatchStChampionNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  501. $leagueData = lm($model_league,'Sports')
  502. ->select('id','lg_id','name_chinese as league','country_id','area_id')
  503. ->where($source)
  504. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  505. ->get()
  506. ->toArray();
  507. $oddsData = lm($model_odds,'Sports')
  508. ->select('id','lg_id','p_code')
  509. ->distinct("p_code")//去重
  510. ->where($where)
  511. ->where($source)
  512. ->get()
  513. ->toArray();
  514. //按国家
  515. $countryData = [];
  516. if(!empty($country) and !empty($leagueData) and($oddsData)){
  517. foreach ($country as $k=>$v){
  518. if($v['country_id']){
  519. $countryData[$k] = $v;
  520. foreach ($leagueData as $kk=>$vv){
  521. if($v['country_id'] == $vv['country_id']){
  522. $countryData[$k]['league_count'][] = $vv;
  523. }
  524. }
  525. }
  526. }
  527. }
  528. //去除无联赛 国家
  529. foreach ($countryData as $k=>$v){
  530. if(count($v) == 2){
  531. unset($countryData[$k]);
  532. }
  533. }
  534. //按地区
  535. $areaData = [];
  536. if(!empty($area) and !empty($leagueData) and($oddsData)){
  537. foreach ($area as $k=>$v){
  538. if($v['area_id']){
  539. $areaData[$k] = $v;
  540. foreach ($leagueData as $kk=>$vv){
  541. if($v['area_id'] == $vv['area_id']){
  542. $areaData[$k]['league_count'][] = $vv;
  543. }
  544. }
  545. }
  546. }
  547. }
  548. //去除无联赛 地区
  549. foreach ($areaData as $k=>$v){
  550. if(count($v) == 2){
  551. unset($areaData[$k]);
  552. }
  553. }
  554. $countryData = $this->commonFunction->array_gj_tt($countryData,$oddsData);
  555. $areaData = $this->commonFunction->array_gj_tt($areaData,$oddsData);
  556. $data = array_merge($countryData,$areaData);
  557. return $data;
  558. }
  559. /**
  560. * 获取联赛下 赛事赔率
  561. */
  562. public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time='',$oddsTypeWhere=[]){
  563. $leagueData = lm($model_league,"Sports")
  564. ->select('lg_id','name_chinese as leagueName')
  565. ->where($source)
  566. ->where('lg_id',$lg_id)
  567. ->first();
  568. if(!empty($time)){//早盘 按时间查询
  569. if($time == 'other'){//早盘 一周后
  570. $matchData = lm($model_match,"Sports")
  571. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  572. ->where($source)
  573. ->where($model_match.'.lg_id',$lg_id)
  574. ->where($where)
  575. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  576. ->where(function($query)use ($model_match,$search){
  577. $query->where($model_match.'.home_team','like','%'.$search.'%')
  578. ->orWhere(function($query)use ($model_match,$search) {
  579. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  580. });
  581. })
  582. ->get()
  583. ->toarray();
  584. }else{
  585. if($time == date('Y-m-d')){//早盘今天
  586. $matchData = lm($model_match,"Sports")
  587. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  588. ->where($source)
  589. ->where($model_match.'.lg_id',$lg_id)
  590. ->where('is_morningplate','=',1)
  591. ->where('match_date',$time)
  592. ->where('match_time','>',date("H:i:s", time()))
  593. ->where(function($query)use ($model_match,$search){
  594. $query->where($model_match.'.home_team','like','%'.$search.'%')
  595. ->orWhere(function($query)use ($model_match,$search) {
  596. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  597. });
  598. })
  599. ->get()
  600. ->toarray();
  601. }else{//早盘 今天以后
  602. $matchData = lm($model_match,"Sports")
  603. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  604. ->where($source)
  605. ->where($model_match.'.lg_id',$lg_id)
  606. ->where($where)
  607. ->where('match_date',$time)
  608. ->where(function($query)use ($model_match,$search){
  609. $query->where($model_match.'.home_team','like','%'.$search.'%')
  610. ->orWhere(function($query)use ($model_match,$search) {
  611. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  612. });
  613. })
  614. ->get()
  615. ->toarray();
  616. }
  617. }
  618. }else{
  619. $matchData = lm($model_match,"Sports")
  620. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  621. ->where($source)
  622. ->where($model_match.'.lg_id',$lg_id)
  623. ->where($where)
  624. ->where(function($query)use ($model_match,$search){
  625. $query->where($model_match.'.home_team','like','%'.$search.'%')
  626. ->orWhere(function($query)use ($model_match,$search) {
  627. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  628. });
  629. })
  630. ->get()
  631. ->toarray();
  632. }
  633. // foreach($matchData as $kk => $vv) {
  634. // $oddsData = lm($model_match, "Sports")
  635. // ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
  636. // ->select($model_odds . '.id', 'odds_only','p_code', 'odds_code', $model_odds . '.status', 'odds', 'condition', 'sort')
  637. // ->where($model_match.'.source',$source['source'])
  638. // ->where([$model_odds . '.match_id' => $vv['match_id'], $model_odds . '.type' => 0])
  639. // ->where($oddsTypeWhere)//追加查询各状态不同的赔率
  640. //// ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  641. // ->where(function ($query) use ($model_odds) {
  642. // $query->where($model_odds . '.odds_code', 'concede_home')
  643. // ->orWhere(function ($query) use ($model_odds) {
  644. // $query->where($model_odds . '.odds_code', 'concede_guest');
  645. // })
  646. // ->orWhere(function ($query) use ($model_odds) {
  647. // $query->where($model_odds . '.odds_code', 'size_home');
  648. // })
  649. // ->orWhere(function ($query) use ($model_odds) {
  650. // $query->where($model_odds . '.odds_code', 'size_guest');
  651. // });
  652. // })
  653. // ->get()
  654. // ->toarray();
  655. // //根据 排序 获取 最新让球/大小玩法赔率
  656. // $sortData = array_column($oddsData,'sort');
  657. // array_multisort($sortData,SORT_DESC,$oddsData);
  658. //
  659. // $zu = [];
  660. // foreach ($oddsData as $key1 =>$item1){
  661. // $zu[$item1['p_code']][] = $item1;
  662. // }
  663. // $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  664. //
  665. // $matchData[$kk]['oddsData'] = $c_s;
  666. // }
  667. //获取各球类默认赔率
  668. $game_code = $_REQUEST['game_code'];
  669. switch ($game_code) {
  670. case 'zq'://足球
  671. $matchData = $this->getOddsData->getOddsZQ($matchData, $model_odds, $source,$oddsTypeWhere);
  672. break;
  673. case 'lq'://篮球
  674. $matchData = $this->getOddsData->getOddsLQ($matchData, $model_odds, $source,$oddsTypeWhere);
  675. break;
  676. case 'wq'://网球
  677. $matchData = $this->getOddsData->getOddsWQ($matchData, $model_odds, $source,$oddsTypeWhere);
  678. break;
  679. case 'bq'://棒球
  680. $matchData = $this->getOddsData->getOddsBQ($matchData, $model_odds, $source,$oddsTypeWhere);
  681. break;
  682. }
  683. $leagueData->matchNum = count($matchData);
  684. $leagueData->matchData = $matchData;
  685. return $leagueData;
  686. }
  687. /**
  688. * @param $source 数据源
  689. * @param $where 该状态 查询条件
  690. * @return array
  691. * @throws \Exception
  692. * 获取所有即将开赛 数据
  693. */
  694. public function getAllSoon($source,$where){
  695. $game = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
  696. $data=[];
  697. foreach ($game as $key=>$item){
  698. if($item['game_code'] !='gj'){
  699. $model = $this->commonFunction->getModels($item['game_code']);
  700. $matchData = lm($model['model_match'], 'Sports')
  701. ->select('match_id','home_team','guest_team','match_time')
  702. ->where($source)
  703. ->where($where)
  704. // ->limit(6)
  705. ->get()->toArray();
  706. $matchNum = count($matchData);
  707. $matchData = array_slice($matchData,0,6);
  708. foreach ($matchData as $key1 => $item1){
  709. //获取等待时间
  710. $wait_time = ceil(((strtotime($item1['match_time']))-time())/60);
  711. $matchData[$key1]['wait_time'] = $wait_time;
  712. }
  713. if($matchNum > 0){
  714. $data[$item['game_code']]['matchData'] = $matchData;
  715. $data[$item['game_code']]['matchNum'] = $matchNum;
  716. $data[$item['game_code']]['gameName'] = $item['game_name'];
  717. $data[$item['game_code']]['gameCode'] = $item['game_code'];
  718. }
  719. }
  720. }
  721. return $data;
  722. }
  723. /**
  724. * 获取欧冠 各状态赛事数据
  725. */
  726. public function getUEFAChampions($source){
  727. //根据搜索查询
  728. if(!empty($_GET['search'])){
  729. $search = $_GET['search'];
  730. }
  731. $model = $this->commonFunction->getModels('gj',1);
  732. $model_league = $model['model_league'];
  733. $leagueData = lm($model_league,'Sports')
  734. ->select('name_chinese','lg_id','last_time')
  735. ->where($model_league.'.source',$source['source'])
  736. ->where($model_league.'.name_chinese','欧洲冠军杯')
  737. ->first();
  738. //获取滚球数据
  739. $StRollBall = $this->getUEFAStRollBall($model,'StRollBall',$source,$leagueData->lg_id,$search);
  740. //获取今日数据
  741. $StToday = $this->getUEFAStToday($model,'StToday',$source,$leagueData->lg_id,$search);
  742. //获取早盘数据
  743. $StMorningPlate = $this->getUEFAStMorningPlate($model,'StMorningPlate',$source,$leagueData->lg_id,$search);
  744. //获取冠军盘口数据
  745. $StChampion = $this->getUEFAStChampion($model,'StChampion',$source,$leagueData->lg_id,$leagueData->last_time);
  746. $data = [
  747. 'lg_id' => $leagueData->lg_id,
  748. 'leagueName'=> $leagueData->name_chinese,
  749. 'StRollBall'=>[//滚球数据
  750. 'typeName'=>'滚球',
  751. 'matchNum'=>count($StRollBall),
  752. 'matchData'=>$StRollBall
  753. ],
  754. 'StToday'=>[//今日数据
  755. 'typeName'=>'今日',
  756. 'matchNum'=>count($StToday),
  757. 'matchData'=>$StToday
  758. ],
  759. 'StMorningPlate'=>[//早盘数据
  760. 'typeName'=>'早盘',
  761. 'matchNum'=>count($StMorningPlate),
  762. 'matchData'=>$StMorningPlate
  763. ],
  764. 'StChampion'=>[//冠军盘口
  765. 'typeName'=>'冠军盘口',
  766. 'matchNum'=>count($StChampion),
  767. 'matchData'=>$StChampion
  768. ]
  769. ];
  770. return $data;
  771. }
  772. /**
  773. * 获取欧冠 滚球数据
  774. */
  775. public function getUEFAStRollBall($model,$type_code,$source,$lg_id,$search=''){
  776. $model_match = $model['model_match'];
  777. $model_odds = $model['model_odds'];
  778. $model_result = $model['model_result'];
  779. $where = $this->commonFunction->getState($type_code,$model_match);
  780. $matchData = lm($model_match,"Sports")
  781. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  782. ->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')
  783. ->where($model_match.'.source',$source['source'])
  784. ->where($model_match.'.lg_id',$lg_id)
  785. ->where($where)
  786. ->where(function($query)use ($model_match,$search){
  787. $query->where($model_match.'.home_team','like','%'.$search.'%')
  788. ->orWhere(function($query)use ($model_match,$search) {
  789. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  790. });
  791. })
  792. ->get()
  793. ->toarray();
  794. foreach($matchData as $kk => $vv){
  795. $oddsData= lm($model_match,"Sports")
  796. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  797. ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  798. ->where($model_match.'.source',$source['source'])
  799. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  800. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  801. ->where(function($query)use ($model_odds){
  802. $query->where($model_odds.'.odds_code','concede_home')
  803. ->orWhere(function($query)use ($model_odds){
  804. $query->where($model_odds.'.odds_code','concede_guest');
  805. })
  806. ->orWhere(function($query)use ($model_odds){
  807. $query->where($model_odds.'.odds_code','size_home');
  808. })
  809. ->orWhere(function($query)use ($model_odds){
  810. $query->where($model_odds.'.odds_code','size_guest');
  811. })
  812. ->orWhere(function($query)use ($model_odds){
  813. $query->where($model_odds.'.odds_code','capot_home');
  814. })
  815. ->orWhere(function($query)use ($model_odds){
  816. $query->where($model_odds.'.odds_code','capot_dogfall');
  817. })
  818. ->orWhere(function($query)use ($model_odds){
  819. $query->where($model_odds.'.odds_code','capot_guest');
  820. });
  821. })
  822. ->get()
  823. ->toarray();
  824. //根据 排序 获取 最新让球/大小玩法赔率
  825. $sortData = array_column($oddsData,'sort');
  826. array_multisort($sortData,SORT_DESC,$oddsData);
  827. $zu = [];
  828. foreach ($oddsData as $key1 =>$item1){
  829. $zu[$item1['p_code']][] = $item1;
  830. }
  831. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  832. $capot = $zu['capot'];//独赢
  833. $matchData[$kk]['oddsData'] = [$c_s,$capot];
  834. }
  835. return $matchData;
  836. }
  837. /**
  838. * 获取欧冠 今日数据
  839. */
  840. public function getUEFAStToday($model,$type_code,$source,$lg_id,$search=''){
  841. $model_match = $model['model_match'];
  842. $model_odds = $model['model_odds'];
  843. $where = $this->commonFunction->getState($type_code);
  844. $matchData = lm($model_match,'Sports')
  845. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  846. ->where($model_match.'.source',$source['source'])
  847. ->where($where)
  848. ->where('lg_id',$lg_id)
  849. ->where(function($query)use ($model_match,$search){
  850. $query->where($model_match.'.home_team','like','%'.$search.'%')
  851. ->orWhere(function($query)use ($model_match,$search) {
  852. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  853. });
  854. })
  855. ->get()->toArray();
  856. foreach($matchData as $kk => $vv) {
  857. $oddsData = lm($model_match, "Sports")
  858. ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
  859. ->select($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  860. ->where($model_match.'.source',$source['source'])
  861. ->where([$model_odds . '.match_id' => $vv['match_id']])
  862. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  863. ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  864. ->orderBy($model_odds . '.id','desc')
  865. ->get()
  866. ->toarray();
  867. $matchData[$kk]['oddsData'] = $oddsData;
  868. }
  869. return $matchData;
  870. }
  871. /**
  872. * 获取欧冠 早盘数据
  873. */
  874. public function getUEFAStMorningPlate($model,$type_code,$source,$lg_id,$search=''){
  875. $model_match = $model['model_match'];
  876. $model_odds = $model['model_odds'];
  877. $where = $this->commonFunction->getState($type_code);
  878. $matchData = lm($model_match,'Sports')
  879. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  880. ->where($model_match.'.source',$source['source'])
  881. ->where($where)
  882. ->where('lg_id',$lg_id)
  883. ->where(function($query)use ($model_match,$search){
  884. $query->where($model_match.'.home_team','like','%'.$search.'%')
  885. ->orWhere(function($query)use ($model_match,$search) {
  886. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  887. });
  888. })
  889. ->get()->toArray();
  890. $data = $this->getOddsData->getOddsZQ($matchData,$model_odds,$source,[]);
  891. return $data;
  892. }
  893. /**
  894. * 获取 欧冠 冠军盘口数据
  895. */
  896. public function getUEFAStChampion($model,$type_code,$source,$lg_id,$last_time=''){
  897. $model_odds = $model['model_odds'];
  898. $where = $this->commonFunction->getState($type_code);
  899. $championData = lm($model_odds, 'Sports')
  900. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  901. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  902. ->where($source)
  903. ->where('lg_id',$lg_id)
  904. ->where($where)
  905. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  906. ->get()->toArray();
  907. //按p_code分组
  908. $p_code=array();
  909. foreach($championData as $k=>$v){
  910. $p_code[$v['p_code']][]=$v;
  911. }
  912. $data = [];
  913. foreach ($p_code as $k1=>$v1){
  914. foreach ($v1 as $k2=>$v2){
  915. $data[$v2['p_code']]['last_time'] =$last_time;
  916. $data[$v2['p_code']][$v2['odds_code']][] = $v2;
  917. }
  918. }
  919. return $data;
  920. }
  921. }