MatchList.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. use Biz\Match\GetmatchData;
  5. use Biz\Match\GetOddsData;
  6. /**
  7. * Class RollingData
  8. * @package App\Sports\Controller
  9. * User: tank
  10. * Date: 2019/3/22
  11. */
  12. class MatchList extends Controller {
  13. private $getTypeData;
  14. public function init() {
  15. $this->getTypeData = new GetmatchData();
  16. $this->getOddsData = new GetOddsData();
  17. $this->commonFunction = C()->get('commonFunction');
  18. }
  19. /*
  20. *首页条件筛选(足球参赛表)
  21. */
  22. private function zq_participate (){
  23. $data['type'] = '足球';
  24. $data['game_code'] = 'zq';
  25. //查询今日赛事
  26. $data['info'][0]['name'] = '今日赛事';
  27. $data['info'][0]['code'] = 'today';
  28. $data['info'][0]['count'] = lm('st_zq_competition','Sports')
  29. ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
  30. ->where($this->commonFunction->getState('StToday'))
  31. ->where('st_zq_competition.source',$this->source['source'])
  32. ->where('st_zq_competition.home_team','<>',null)
  33. ->where('st_zq_competition.guest_team','<>',null)
  34. ->distinct('st_zq_competition.match_id')
  35. ->count('*');
  36. //查询明日赛事
  37. $data['info'][1]['name'] = '明日赛事';
  38. $data['info'][1]['code'] = 'tomorrow';
  39. $data['info'][1]['count'] = lm('st_zq_competition','Sports')
  40. ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
  41. ->where('st_zq_competition.source',$this->source['source'])
  42. ->where('st_zq_competition.match_date','tomorrow')
  43. ->where('st_zq_competition.home_team','<>',null)
  44. ->where('st_zq_competition.guest_team','<>',null)
  45. ->count('*');
  46. //受欢迎的欧洲赛事
  47. $data['info'][2]['name'] = '受欢迎的欧洲赛事';
  48. $data['info'][2]['code'] = 'popular';
  49. $data['info'][2]['count'] = lm('st_zq_competition','Sports')
  50. ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
  51. ->join('st_area','st_area.id','st_zq_league.area_id')
  52. ->where('st_area.code',"Europe")
  53. ->where('st_zq_league.hot',0)
  54. ->where('st_zq_competition.status','<',2)
  55. ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  56. ->where('st_zq_competition.source',$this->source['source'])
  57. ->where('st_zq_competition.home_team','<>',null)
  58. ->where('st_zq_competition.guest_team','<>',null)
  59. ->count('*');
  60. //查询亚洲,澳洲赛事
  61. $data['info'][3]['name'] = '亚洲/澳洲赛事';
  62. $data['info'][3]['code'] = 'asia_aus';
  63. $data['info'][3]['count'] = lm('st_zq_competition','Sports')
  64. ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
  65. ->leftjoin('st_country','st_country.country_id','st_zq_league.country_id')
  66. ->leftjoin('st_area','st_area.id','st_zq_league.area_id')
  67. ->select('match_id')
  68. ->where(function ($query) {
  69. $query->Orwhere('st_area.code','=','Asian')
  70. ->Orwhere('st_country.name_english','=','Australia');
  71. })
  72. ->where('st_zq_competition.status','<',2)
  73. ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  74. ->where('st_zq_competition.source',$this->source['source'])
  75. ->where('st_zq_competition.home_team','<>',null)
  76. ->where('st_zq_competition.guest_team','<>',null)
  77. ->count('*');
  78. //查询北美,南美赛事
  79. $data['info'][4]['name'] = '北美/南美赛事';
  80. $data['info'][4]['code'] = 'south_north';
  81. $data['info'][4]['count'] = lm('st_zq_competition','Sports')
  82. ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
  83. ->join('st_area','st_area.id','st_zq_league.area_id')
  84. ->where(function ($query) {
  85. $query->Orwhere('st_area.code','=', "South_America")
  86. ->Orwhere('st_area.code','=', "North_America");
  87. })
  88. ->where('st_zq_competition.status', '<', '2')
  89. ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  90. ->where('st_area.source',$this->source['source'])
  91. ->where('st_zq_competition.home_team','<>',null)
  92. ->where('st_zq_competition.guest_team','<>',null)
  93. ->count('*');
  94. //国际赛事
  95. $data['info'][5]['name'] = '国际赛事';
  96. $data['info'][5]['code'] = 'intl';
  97. $data['info'][5]['count'] = lm('st_area','Sports')
  98. ->join('st_zq_league','st_zq_league.area_id','st_area.id')
  99. ->join('st_zq_competition','st_zq_competition.lg_id','st_zq_league.id')
  100. ->where('st_area.code',"world")
  101. ->where('st_zq_competition.status', '<', '2')
  102. ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  103. ->where('st_area.source',$this->source['source'])
  104. ->where('st_zq_competition.home_team','<>',null)
  105. ->where('st_zq_competition.guest_team','<>',null)
  106. ->count('*');
  107. return $data;
  108. }
  109. /*
  110. *首页条件筛选(其他球参赛表)
  111. */
  112. private function qt_participate ($typeGame){
  113. //===查询该球类是否存在或启用===
  114. $getModels = $this->commonFunction->getModels($typeGame);
  115. $data['game_code'] = $typeGame;
  116. $data['type'] = lm('GameType','Sports')->where('game_code',$typeGame)->value('game_name');
  117. $st_competition = $getModels['model_match'];
  118. $data['info'][0]['name'] = '所有赛事';
  119. $data['info'][0]['code'] = 'all';
  120. $data['info'][0]['count'] =lm($st_competition,'Sports')
  121. ->where([[$st_competition.'.status', '<', '2'],
  122. [$st_competition.'.source',$this->source['source']]])
  123. ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  124. ->where($st_competition.'.home_team','<>',null)
  125. ->where($st_competition.'.guest_team','<>',null)
  126. ->count('*');
  127. $data['info'][1]['name'] = '今日赛事';
  128. $data['info'][1]['code'] = 'today';
  129. $data['info'][1]['count']=lm($st_competition,'Sports')
  130. ->where($st_competition.'.source',$this->source['source'])
  131. ->where($this->commonFunction->getState('StToday',$st_competition))
  132. ->where($st_competition.'.home_team','<>',null)
  133. ->where($st_competition.'.guest_team','<>',null)
  134. ->count('*');
  135. return $data;
  136. }
  137. public function participate(){
  138. $type = $_REQUEST['typeGame'];
  139. if($type != 'zq'|| empty($type)){
  140. $data = $this->qt_participate($type);
  141. }else{
  142. $data = $this->zq_participate();
  143. }
  144. Render($data, '1', lang('Tips','Sports')->get('success'));
  145. }
  146. /*
  147. * 参赛列表详情
  148. */
  149. public function participate_details()
  150. {
  151. $game_code = $_REQUEST['game_code'];//游戏代码
  152. $code = $_REQUEST['code'];//参赛代码
  153. $search = $_REQUEST['search'];//参赛代码
  154. $lg_id = $_REQUEST['lg_id'];//参赛代码
  155. //===查询该球类是否存在或启用===
  156. $getModels = $this->commonFunction->getModels($game_code);
  157. $st_league = $getModels['model_league'];
  158. $st_competition = $getModels['model_match'];
  159. $where_search = function($query)use ($st_competition,$search){
  160. $query->where($st_competition.'.home_team','like','%'.$search.'%')
  161. ->orWhere(function($query)use ($st_competition,$search) {
  162. $query->where($st_competition . '.guest_team', 'like', '%' . $search . '%');
  163. });
  164. };
  165. $Orwhere = "";
  166. switch ($code)
  167. {
  168. case $code == 'today':
  169. $where = $this->commonFunction->getState('StToday',$st_competition);
  170. //查询今日赛事
  171. $data = lm($st_competition,'Sports')
  172. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  173. ->select($st_league.'.name_chinese',$st_league.'.lg_id')
  174. ->where($where)
  175. ->where($where_search)
  176. ->where($st_competition.'.home_team','<>',null)
  177. ->where($st_competition.'.guest_team','<>',null)
  178. ->where($st_competition.'.source',$this->source['source'])
  179. ->distinct($st_competition.'.match_id')
  180. ->get()
  181. ->toarray();
  182. break;
  183. case $code == 'popular':
  184. $where =[
  185. ['st_area.code','Europe'],[$st_league.'.hot',0],
  186. [$st_competition.'.status', '<', '2'],
  187. [$st_competition.'.source',$this->source['source']],
  188. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
  189. [$st_competition.'.home_team','<>',null],
  190. [$st_competition.'.guest_team','<>',null],
  191. ];
  192. //欧洲最受欢迎的赛事
  193. $data = lm($st_competition,'Sports')
  194. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  195. ->join('st_area','st_area.id','st_zq_league.area_id')
  196. ->select($st_league.'.name_chinese',$st_league.'.lg_id')
  197. ->where($where)
  198. ->where($where_search)
  199. ->distinct($st_competition.'.match_id')
  200. ->get()
  201. ->toarray();
  202. break;
  203. case $code == 'asia_aus':
  204. $where = [
  205. [$st_competition.'.status', '<', '2'],
  206. [$st_competition.'.source',$this->source['source']],
  207. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
  208. [$st_competition.'.home_team','<>',null],
  209. [$st_competition.'.guest_team','<>',null],
  210. ];
  211. $Orwhere = function ($query) {
  212. $query->Orwhere('st_area.code','=','Asian')
  213. ->Orwhere('st_country.name_english','=','Australia');
  214. };
  215. //亚洲/澳洲赛事
  216. $data = lm($st_competition,'Sports')
  217. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  218. ->leftjoin('st_country','st_country.country_id',$st_league.'.country_id')
  219. ->leftjoin('st_area','st_area.id',$st_league.'.area_id')
  220. ->select($st_league.'.name_chinese',$st_league.'.lg_id')
  221. ->where($where)
  222. ->where($Orwhere)
  223. ->where($where_search)
  224. ->distinct($st_competition.'.match_id')
  225. ->get()
  226. ->toarray();
  227. break;
  228. case $code == 'south_north':
  229. $where = [
  230. [$st_competition.'.status', '<', '2'],
  231. [$st_competition.'.source',$this->source['source']],
  232. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
  233. [$st_competition.'.home_team','<>',null],
  234. [$st_competition.'.guest_team','<>',null],
  235. ];
  236. $Orwhere = function ($query) {
  237. $query->Orwhere('st_area.code','=', "South_America")
  238. ->Orwhere('st_area.code','=', "North_America");
  239. };
  240. //南美洲/北美洲赛事
  241. $data = lm($st_competition,'Sports')
  242. ->join($st_league,$st_league.'.lg_id',$st_league.'.lg_id')
  243. ->join('st_area','st_area.id','st_zq_league.area_id')
  244. ->select($st_league.'.name_chinese',$st_league.'.lg_id')
  245. ->where($where)
  246. ->where($Orwhere)
  247. ->where($where_search)
  248. ->distinct($st_competition.'.match_id')
  249. ->get()
  250. ->toarray();
  251. break;
  252. case $code == 'tomorrow':
  253. $where = [
  254. [$st_competition.'.match_date','tomorrow'],
  255. [$st_competition.'.status',0],
  256. [$st_competition.'.source',$this->source['source']],
  257. [$st_competition.'.home_team','<>',null],
  258. [$st_competition.'.guest_team','<>',null],
  259. ];
  260. //明日赛事
  261. $data = lm($st_competition,'Sports')
  262. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  263. ->select($st_league.'.name_chinese',$st_league.'.lg_id')
  264. ->where($where)
  265. ->where($where_search)
  266. ->distinct($st_league.'.lg_id')
  267. ->get()
  268. ->toarray();
  269. break;
  270. case $code == 'intl':
  271. $where = [
  272. ['st_area.code', "world"],
  273. [$st_competition.'.status','<','2'],
  274. [$st_competition.'.source',$this->source['source']],
  275. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
  276. [$st_competition.'.home_team','<>',null],
  277. [$st_competition.'.guest_team','<>',null],
  278. ];
  279. //国际赛事
  280. $data = lm($st_competition,'Sports')
  281. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  282. ->join('st_area','st_area.id',$st_league.'.area_id')
  283. ->select($st_league.'.name_chinese',$st_league.'.lg_id')
  284. ->where($where)
  285. ->where($where_search)
  286. ->distinct($st_competition.'.match_id')
  287. ->get()
  288. ->toarray();
  289. break;
  290. case $code == 'all':
  291. $where = [
  292. [$st_competition.'.status','<', '2'],
  293. [$st_competition.'.source',$this->source['source']],
  294. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
  295. [$st_competition.'.home_team','<>',null],
  296. [$st_competition.'.guest_team','<>',null],
  297. ];
  298. //所有赛事
  299. $data = lm($st_competition,'Sports')
  300. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  301. ->select($st_league.'.name_chinese',$st_league.'.lg_id')
  302. ->where($where)
  303. ->where($where_search)
  304. ->distinct($st_competition.'.match_id')
  305. ->get()
  306. ->toarray();
  307. break;
  308. case $code == 'qt':
  309. $where = [
  310. [$st_competition.'.status','<', '2'],
  311. [$st_competition.'.source',$this->source['source']],
  312. [$st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4)],
  313. [$st_league.'.lg_id',$lg_id],
  314. [$st_competition.'.home_team','<>',null],
  315. [$st_competition.'.guest_team','<>',null],
  316. ];
  317. //指定联赛下的赛事
  318. $data = lm($st_competition,'Sports')
  319. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  320. ->select($st_league.'.name_chinese',$st_league.'.lg_id')
  321. ->where($where)
  322. ->where($where_search)
  323. ->distinct($st_competition.'.match_id')
  324. ->get()
  325. ->toarray();
  326. break;
  327. }
  328. //根据联赛ID赛事信息
  329. $data = $this->Competition_info($data,$getModels,$where,$where_search,$Orwhere);
  330. Render($data, '1', lang('Tips','Sports')->get('success'));
  331. }
  332. /*
  333. * 获取联赛信息
  334. */
  335. private function Competition_info(array $data,$getModels,$where,$where_search,$Orwhere){
  336. $st_competition = $getModels['model_match'];
  337. $st_odds = $getModels['model_odds'];
  338. $st_league = $getModels['model_league'];
  339. if(!$Orwhere){
  340. $Orwhere = [];
  341. }
  342. foreach($data as $k => $v){
  343. //统计赛事
  344. $data[$k]['count'] = lm($st_competition,'Sports')
  345. ->join($st_odds,$st_odds.'.match_id',$st_competition.'.match_id')
  346. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  347. ->leftjoin('st_country','st_country.country_id',$st_league.'.country_id')
  348. ->leftjoin('st_area','st_area.id',$st_league.'.area_id')
  349. ->where($st_competition.'.lg_id',$v['lg_id'])
  350. ->where($where)
  351. ->where($Orwhere)
  352. ->where($where_search)
  353. ->distinct($st_competition.'.match_id')
  354. ->count($st_competition.'.match_id');
  355. //获取赛事信息
  356. $data[$k]['match_info'] = lm($st_competition,'Sports')
  357. ->join($st_odds,$st_odds.'.match_id',$st_competition.'.match_id')
  358. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  359. ->leftjoin('st_country','st_country.country_id',$st_league.'.country_id')
  360. ->leftjoin('st_area','st_area.id',$st_league.'.area_id')
  361. ->select($st_competition.'.match_id',$st_competition.'.home_team',$st_competition.'.guest_team',$st_competition.'.match_date',$st_competition.'.status',$st_competition.'.match_time',$st_competition.'.tag')
  362. ->distinct($st_competition.'.match_id')
  363. ->where($where)
  364. ->where($Orwhere)
  365. ->where($where_search)
  366. ->where($st_competition.'.lg_id',$v['lg_id'])
  367. ->get()
  368. ->toarray();
  369. if(!$data[$k]['match_info']){
  370. unset($data[$k]);
  371. }
  372. //循环获取赛事赔率
  373. foreach ($data[$k]['match_info'] as $key=>$item){
  374. $data[$k]['match_info'][$key]['oddsData'] = lm($st_odds, 'Sports')
  375. ->select('id','p_code','odds_code','status','odds','condition','sort')
  376. ->where($this->source)
  377. ->where(['match_id'=>$item['match_id'],'type'=>0])
  378. ->where(function($query)use ($st_odds){
  379. $query->where($st_odds.'.odds_code','concede_home')
  380. ->orWhere(function($query)use ($st_odds){
  381. $query->where($st_odds.'.odds_code','concede_guest');
  382. })
  383. ->orWhere(function($query)use ($st_odds){
  384. $query->where($st_odds.'.odds_code','size_home');
  385. })
  386. ->orWhere(function($query)use ($st_odds){
  387. $query->where($st_odds.'.odds_code','size_guest');
  388. });
  389. })
  390. ->get()->toArray();
  391. if(!empty($data[$k]['match_info'][$key]['oddsData'])){
  392. //根据 排序 获取 最新让球/大小玩法赔率
  393. $sortData = array_column($data[$k]['match_info'][$key]['oddsData'],'sort');
  394. array_multisort($sortData,SORT_DESC,$data[$k]['match_info'][$key]['oddsData']);
  395. $data[$k]['match_info'][$key]['oddsData'] = array_slice($data[$k]['match_info'][$key]['oddsData'],0,4);//前四条 放入
  396. }else{
  397. $data[$k]['match_info'][$key]['oddsData'] = [];
  398. }
  399. }
  400. }
  401. return $data;
  402. }
  403. /*
  404. *首页条件筛选(冠军赛事)
  405. */
  406. public function first (){
  407. $gameType = $_REQUEST['typeGame'];
  408. $search = $_REQUEST['search'];
  409. //===查询该球类是否存在或启用===
  410. $gameType = empty($gameType)? 'zq':$gameType;
  411. $getModels = $this->commonFunction->getModels($gameType);
  412. $st_league = $getModels['model_league'];
  413. $st_competition = $getModels['model_match'];
  414. $data['type'] = lm('GameType', 'Sports')->where('game_code',$gameType)->value('game_name');
  415. //国家下所有联赛
  416. $country = lm($st_league,"Sports")
  417. ->join($st_competition,$st_competition.'.lg_id',$st_league.'.id')
  418. ->join('st_country','st_country.country_id',$st_league.'.country_id')
  419. ->select('st_country.id as region_id','st_country.name_chinese as region')
  420. ->distinct('st_country.name_chinese')
  421. ->where($st_league.'.name_chinese','like','%'.$search.'%')
  422. ->where($st_league.'.source',$this->source)
  423. ->where([])
  424. ->where($st_competition.'.home_team','<>',null)
  425. ->where($st_competition.'.guest_team','<>',null)
  426. ->get()
  427. ->toArray();
  428. //洲下所有联赛
  429. $area = lm($st_league,"Sports")
  430. ->join($st_competition,$st_competition.'.lg_id',$st_league.'.id')
  431. ->join('st_area','st_area.id',$st_league.'.area_id')
  432. ->select('st_area.id as region_id','st_area.title as region')
  433. ->distinct('st_area.title')
  434. ->where($st_league.'.name_chinese','like','%'.$search.'%')
  435. ->where($st_league.'.source',$this->source)
  436. ->where()
  437. ->where([])
  438. ->where($st_competition.'.home_team','<>',null)
  439. ->where($st_competition.'.guest_team','<>',null)
  440. ->get()
  441. ->toArray();
  442. //统计国家联赛下的赛事.
  443. if(!empty($country)){
  444. foreach($country as $k => $v) {
  445. $country[$k]['league_count'] = lm($st_league, 'Sports')
  446. ->select('lg_id', 'name_chinese as league')
  447. ->where($this->source)
  448. ->where('country_id', $v['region_id'])
  449. ->get()->toarray();
  450. }
  451. foreach ($country as $k => $v) {
  452. foreach($v['league_count'] as $kk => $vv ){
  453. $country[$k]['league_count'][$kk]['count'] = lm($st_competition, 'Sports')
  454. ->where($this->source)
  455. ->where('lg_id',$vv['lg_id'])
  456. ->where($st_competition.'.home_team','<>',null)
  457. ->where($st_competition.'.guest_team','<>',null)
  458. ->count('*');
  459. if($country[$k]['league_count'][$kk]['count'] == 0){
  460. unset($country[$k]['league_count'][$kk]);
  461. }
  462. }
  463. }
  464. }
  465. //统计洲联赛下的赛事
  466. if(!empty($area)){
  467. foreach($area as $k => $v) {
  468. $area[$k]['league_count'] = lm($st_league, 'Sports')
  469. ->select('lg_id ', 'name_chinese as league')
  470. ->where($this->source)
  471. ->where('area_id', $v['region_id'])
  472. ->get()->toarray();
  473. }
  474. foreach ($area as $k => $v) {
  475. foreach($v['league_count'] as $kk => $vv ){
  476. $area[$k]['league_count'][$kk]['count'] = lm($st_competition, 'Sports')
  477. ->where($this->source)
  478. ->where('lg_id',$vv['lg_id'])
  479. ->where($st_competition.'.home_team','<>',null)
  480. ->where($st_competition.'.guest_team','<>',null)
  481. ->count('*');
  482. if($area[$k]['league_count'][$kk]['count'] == 0){
  483. unset($area[$k]['league_count'][$kk]);
  484. }
  485. }
  486. }
  487. }
  488. $data['info'] = array_merge($country,$area);
  489. Render($data, '1', lang('Tips','Sports')->get('success'));
  490. }
  491. /*
  492. *首页条件筛选(所有赛事)
  493. */
  494. public function matchData (){
  495. $gameType = $_REQUEST['gameType'];
  496. $search = $_REQUEST['search'];
  497. $date = $_REQUEST['datetime'];
  498. //===查询该球类是否存在或启用===
  499. $gameType = empty($gameType) ? 'zq':$gameType;
  500. $getModels = $this->commonFunction->getModels($gameType);
  501. $st_league = $getModels['model_league'];
  502. $st_competition = $getModels['model_match'];
  503. //所属球类
  504. $where = [];
  505. if(!empty($date)){
  506. if($date == 'morning'){
  507. $where=[[$st_competition.'.is_morningplate',1],
  508. [$st_competition.'.match_date','>',date("Y-m-d",strtotime("+6 day"))]];
  509. }else if($date == 'today'){
  510. $where = $this->commonFunction->getState('StToday');
  511. }else {
  512. $where[$st_competition.'.match_date'] = $date;
  513. }
  514. }
  515. $data['type'] = lm('GameType', 'Sports')
  516. ->where('game_code',$gameType)
  517. ->value('game_name');
  518. //国家联赛数据
  519. $country = lm($st_league,"Sports")
  520. ->join($st_competition,$st_competition.'.lg_id',$st_league.'.lg_id')
  521. ->join('st_country','st_country.country_id',$st_league.'.country_id')
  522. ->select('st_country.country_id as region_id','st_country.name_chinese as region')
  523. ->distinct($st_league.'.lg_id')
  524. ->where($st_league.'.source',$this->source)
  525. ->where($st_league.'.name_chinese','like','%'.$search.'%')
  526. ->where($where)
  527. ->where($st_competition.'.status', '<', '2')
  528. ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  529. ->get()
  530. ->toArray();
  531. //洲下所有联赛
  532. $area = lm($st_league,"Sports")
  533. ->join($st_competition,$st_competition.'.lg_id',$st_league.'.lg_id')
  534. ->join('st_area','st_area.id',$st_league.'.area_id')
  535. ->select('st_area.id as region_id','st_area.title as region')
  536. ->distinct($st_league.'.lg_id')
  537. ->where($st_league.'.source',$this->source)
  538. ->where($st_league.'.name_chinese','like','%'.$search.'%')
  539. ->where($where)
  540. ->where($st_competition.'.status', '<', '2')
  541. ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  542. ->get()
  543. ->toArray();
  544. //统计国家联赛下的赛事
  545. if(!empty($country)){
  546. foreach($country as $k => $v) {
  547. $country[$k]['league_count'] = lm($st_league, 'Sports')
  548. ->select('lg_id', 'name_chinese as league')
  549. ->where($st_league.'.source',$this->source)
  550. ->where($st_league.'.name_chinese','like','%'.$search.'%')
  551. ->where('country_id', $v['region_id'])
  552. ->get()
  553. ->toarray();
  554. }
  555. foreach ($country as $k => $v) {
  556. foreach($v['league_count'] as $kk => $vv ){
  557. $country[$k]['league_count'][$kk]['count'] = lm($st_competition, 'Sports')
  558. ->where($this->source)
  559. ->where($where)
  560. ->where('lg_id',$vv['lg_id'])
  561. ->where('status', '<', '2')
  562. ->where('us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  563. ->where($st_competition.'.home_team','<>',null)
  564. ->where($st_competition.'.guest_team','<>',null)
  565. ->count('*');
  566. if($country[$k]['league_count'][$kk]['count'] == 0){
  567. unset($country[$k]['league_count'][$kk]);
  568. }
  569. }
  570. }
  571. }
  572. //统计洲联赛下的赛事
  573. if (!empty($area)){
  574. foreach($area as $k => $v) {
  575. $area[$k]['league_count'] = lm($st_league,'Sports')
  576. ->select('lg_id', 'name_chinese as league')
  577. ->where($this->source)
  578. ->where($st_league.'.name_chinese','like','%'.$search.'%')
  579. ->where('area_id', $v['region_id'])
  580. ->get()
  581. ->toarray();
  582. }
  583. foreach ($area as $k => $v) {
  584. foreach($v['league_count'] as $kk => $vv ){
  585. $area[$k]['league_count'][$kk]['count'] = lm($st_competition, 'Sports')
  586. ->where($this->source)
  587. ->where($where)
  588. ->where($st_competition.'.home_team','<>',null)
  589. ->where($st_competition.'.guest_team','<>',null)
  590. ->where('status', '<', '2')
  591. ->where('us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  592. ->where('lg_id',$vv['lg_id'])
  593. ->count('*');
  594. if($area[$k]['league_count'][$kk]['count'] == 0){
  595. unset($area[$k]['league_count'][$kk]);
  596. }
  597. }
  598. }
  599. }
  600. $data['info'] = array_merge($country,$area);
  601. Render($data, '1', lang('Tips','Sports')->get('success'));
  602. }
  603. /**
  604. * 联赛下 赛事及默认赔率数据
  605. *
  606. */
  607. public function matchDetails(){
  608. $data = $_REQUEST;
  609. try {
  610. if(empty($data['game_code']) || empty($data['leagueID']) || empty($data['oddsType'])){
  611. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  612. }
  613. //根据时间获取联赛下赛事数据
  614. $whereDate = [];
  615. if(!empty($data['matchDate']) ){
  616. if($data['matchDate']== "morning"){
  617. $whereDate = [['is_morningplate',1],
  618. ['match_date','>',date("Y-m-d",strtotime("+6 day"))]];
  619. }else{
  620. $whereDate = ['match_date'=>$data['matchDate']];
  621. }
  622. }
  623. $models = $this->commonFunction->getModels($data['game_code'],0);
  624. $model_match = $models['model_match'];
  625. $model_odds = $models['model_odds'];
  626. $model_league = $models['model_league'];
  627. $model_result = $models['model_result'];
  628. $oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$data['oddsType']);
  629. $source = $this->source;//数据源
  630. $data = $this->getOddsData->getOddsData($data,$whereDate,$source,$oddsTypeWhere);
  631. Render($data, '1', lang('Tips','Sports')->get('success'));
  632. } catch (\Exception $e) {
  633. echo $e->getMessage();
  634. }
  635. }
  636. //获取各状态下有哪些球类
  637. public function getGame(){
  638. $type_code = $_REQUEST['type_code'];
  639. try {
  640. if(empty($type_code)){
  641. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  642. }
  643. //==获取当前可用球类==
  644. $game = lm('GameType', 'Sports')->where('status',1)->select('game_code','game_name','game_ico_url')->get()->toArray();
  645. //获取 不同状态的查询条件
  646. $where = $this->commonFunction->getState($type_code);
  647. $gameData = [];
  648. foreach ($game as $key=>$type){
  649. if($type_code != 'StChampion'){
  650. $matchModel = $this->commonFunction->getModels($type['game_code']);
  651. $matchNum = lm($matchModel['model_league'],"Sports")
  652. ->join($matchModel['model_match'],$matchModel['model_match'].'.lg_id',$matchModel['model_league'].'.lg_id')
  653. ->where($matchModel['model_match'].'.source',$this->source['source'])
  654. ->where($where)
  655. ->where([[$matchModel['model_league'].'.name_chinese','!=','']])
  656. ->count("*");
  657. //获取满足状态的球类/去除冠军类
  658. if($matchNum != 0 and $type['game_code']!='gj'){
  659. $gameData[] = $type;
  660. }
  661. }else{
  662. $matchModel = $this->commonFunction->getModels($type['game_code']);
  663. $matchNum = lm($matchModel['model_odds'], 'Sports')
  664. ->where($this->source)
  665. ->where($where)
  666. ->count('*');
  667. //获取满足状态的球类/去除冠军类
  668. if($matchNum != 0 and $type['game_code']!='gj'){
  669. $gameData[] = $type;
  670. }
  671. }
  672. }
  673. Render($gameData, '1', lang('Tips','Sports')->get('success'));
  674. } catch (\Exception $e) {
  675. echo $e->getMessage();
  676. }
  677. }
  678. /**
  679. * @throws \Exception
  680. * 获取不同状态下 各球类赛事数据
  681. * game_code 球类代码
  682. * type_code 类型代码
  683. */
  684. public function matchState(){
  685. $source = $this->source;//数据源 条件
  686. $ret = $_REQUEST;
  687. try {
  688. if(empty($ret['game_code']) || empty($ret['type_code'])){
  689. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  690. }
  691. $data = $this->getTypeData->typeData($ret,$source);
  692. Render($data, '1', lang('Tips','Sports')->get('success'));
  693. } catch (\Exception $e) {
  694. echo $e->getMessage();
  695. }
  696. }
  697. /**
  698. * 根据赛事状态获取赔率查询条件
  699. */
  700. public function getOddsTypeWhere($model_odds,$oddsType){
  701. //获取赛事不同状态下的赔率
  702. if(!empty($oddsType)){
  703. switch ($oddsType)
  704. {
  705. case 'StRollBall'://滚球
  706. $oddsTypeWhere = [[$model_odds.'.is_rollball','=',1]];
  707. break;
  708. case 'StSoon'://即将
  709. $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
  710. break;
  711. case 'StToday'://今日
  712. $oddsTypeWhere = [[$model_odds.'.is_today','=',1]];
  713. break;
  714. case 'StMorningPlate'://早盘
  715. $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
  716. break;
  717. case 'StStringScene'://串场
  718. $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
  719. break;
  720. case 'home'://首页
  721. $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
  722. break;
  723. default:
  724. $oddsTypeWhere = [];
  725. }
  726. }
  727. return $oddsTypeWhere;
  728. }
  729. /**
  730. * 获取赛事所有玩法赔率数据
  731. */
  732. public function matchOdds(){
  733. $game_code = $_REQUEST['game_code'];
  734. $matchID = $_REQUEST['matchID'];
  735. $status = $_REQUEST['status'];
  736. $oddsType = $_REQUEST['oddsType'];
  737. try {
  738. if(empty($game_code) || empty($matchID) || empty($oddsType)){
  739. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  740. }
  741. //根据球类代码 获取相关model
  742. $models = $this->commonFunction->getModels($game_code,0);
  743. $model_match = $models['model_match'];
  744. $model_odds = $models['model_odds'];
  745. $model_league = $models['model_league'];
  746. $model_result = $models['model_result'];
  747. //取消按状态查询赔率数据
  748. //$oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$oddsType);
  749. $oddsData = lm($model_odds, 'Sports')
  750. ->select('sort','p_code','id','odds_only','odds_code',$model_odds.'.status','odds','condition','sort','source','utime')
  751. ->where($this->source)
  752. ->where([$model_odds.'.match_id'=>$matchID,$model_odds.'.type'=>0])//,$model_odds.'.expire_time'=>$utime
  753. ->orderBy('sort', 'desc')
  754. ->orderBy('p_code','desc')
  755. ->orderBy('odds_code','desc')
  756. ->get()->toArray();
  757. $matchData = lm($model_match, 'Sports')
  758. ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
  759. ->select($model_match.'.lg_id','name_chinese','match_id','home_team','guest_team','match_date','match_time',$model_match.'.status')
  760. ->where($model_match.'.source',$this->source['source'])
  761. ->where(['match_id'=>$matchID])
  762. ->first();
  763. if(empty($matchData)) Render(null, '1', lang('Tips','Sports')->get('success'));
  764. $matchData->ptime = '';//赛事进行时间
  765. $matchData->match_score = '';//赛事比分
  766. //如果该赛事正在进行,则获取进行时间
  767. if($matchData->status ==1){
  768. $result = lm($model_result, 'Sports')->select('match_id','match_time','match_score')
  769. ->where($this->source)
  770. ->where(['match_id'=>$matchData->match_id])
  771. ->first();
  772. $matchData->ptime = $result->match_time;
  773. $matchData->match_score = $result->match_score;
  774. }
  775. //赛事已结束
  776. if($matchData->status ==2){
  777. $oddsData = [];
  778. }
  779. //查询当前联赛下的赛事
  780. $league = [];
  781. if($oddsType != 'StRollBall'){
  782. $where = [
  783. ['home_team','<>',null],
  784. ['guest_team','<>',null],
  785. ['status','<',2],
  786. ['lg_id',$matchData->lg_id],
  787. ];
  788. switch ($oddsType)
  789. {
  790. case 'StSoon'://即将
  791. $matchWhere=[['is_morningplate','=',1]];
  792. break;
  793. case 'StToday'://今日
  794. $matchWhere=[['is_today','=',1]];
  795. break;
  796. case 'StMorningPlate'://早盘
  797. $matchWhere=[['is_morningplate','=',1]];
  798. break;
  799. case 'StStringScene'://串场
  800. $matchWhere = [['is_stringscene','=',1]];
  801. break;
  802. case 'home'://首页
  803. $matchWhere = [['is_stringscene','=',1]];
  804. break;
  805. default:
  806. $matchWhere = [];
  807. }
  808. $league = lm($model_match,'Sports')
  809. ->select('match_id','home_team','guest_team','status','match_date','match_time')
  810. ->where($this->source)
  811. ->where($where)
  812. ->where($matchWhere)
  813. ->get()
  814. ->toarray();
  815. }
  816. $list = array();
  817. foreach ($oddsData as $key=>$item){
  818. $item['team'] = '';
  819. if(strpos($item['odds_code'],'home') !== false) {
  820. $item['team'] = 'home';
  821. }
  822. if(strpos($item['odds_code'],'guest') !== false) {
  823. $item['team'] = 'guest';
  824. }
  825. $list[$key] = $item;
  826. }
  827. $p_code_array = [];
  828. foreach ($oddsData as $key =>$val){
  829. $p_code_array[] = $val['p_code'];
  830. }
  831. $p_code_array = array_keys(array_flip(array_unique($p_code_array)));//p_code 去重排序
  832. $data = [
  833. 'lg_id' =>$matchData->lg_id,
  834. 'leagueName' =>$matchData->name_chinese,
  835. 'match_id'=>$matchData->match_id,
  836. 'home_team'=>$matchData->home_team,
  837. 'guest_team'=>$matchData->guest_team,
  838. 'match_time'=>$matchData->match_date." ".$matchData->match_time,
  839. 'match_ptime'=>$matchData->ptime,
  840. 'match_score'=>$matchData->match_score,
  841. 'p_code_array'=> $p_code_array,
  842. 'oddsData'=>$oddsData,
  843. 'league' => $league,
  844. ];
  845. Render($data, '1', lang('Tips','Sports')->get('success'));
  846. } catch (\Exception $e) {
  847. echo $e->getMessage();
  848. }
  849. }
  850. /**
  851. * 手动 更新 赛事状态
  852. */
  853. public function updateMatch () {
  854. $game_code = $_REQUEST['game_code'];
  855. $match_date = $_REQUEST['match_date'];
  856. try {
  857. if(empty($game_code)){
  858. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  859. }
  860. if(empty($match_date)) $match_date = date('Y-m-d');
  861. //根据球类代码 获取相关model
  862. $models = $this->commonFunction->getModels($game_code);
  863. $model_match = $models['model_match'];
  864. $matchData = lm($model_match,'Sports')->select('match_id','status','match_date','match_time')->where(['match_date'=>$match_date])->get();
  865. foreach ($matchData as $key=>$item){
  866. $time = strtotime($item->match_date.$item->match_time);
  867. if(($time+(60*90)) < time()){ //更新为 已结束
  868. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>2]);
  869. }
  870. if(($time+(60*90)) > time() and $time < time()){ //更新为 进行中
  871. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>1]);
  872. }
  873. }
  874. Render([], '1', lang('Tips','Sports')->get('success'));
  875. } catch (\Exception $e) {
  876. echo $e->getMessage();
  877. }
  878. }
  879. /**
  880. * 获取即将开赛 所有赛事
  881. * 首页使用
  882. */
  883. public function getSoon(){
  884. $source = $this->source;//数据源 条件
  885. try {
  886. $where = $this->commonFunction->getState('StSoon');
  887. $data = $this->getTypeData->getAllSoon($source,$where);
  888. Render($data, '1', lang('Tips','Sports')->get('success'));
  889. } catch (\Exception $e) {
  890. echo $e->getMessage();
  891. }
  892. }
  893. /**
  894. * 获取球类-玩法-赔率代码
  895. */
  896. public function getOddsCode(){
  897. $type = $_REQUEST['type'];
  898. if($type == 'p_code'){
  899. $p_code = lm('st_odds_code','Sports')
  900. ->select('odds_code','odds_name')
  901. ->where('p_id',0)
  902. ->get();
  903. }else{
  904. $p_code = lm('st_odds_code','Sports')
  905. ->select('id','odds_code','odds_name')
  906. ->where('p_id',0)
  907. ->get();
  908. foreach ($p_code as $k=>$v){
  909. $v->below = lm('st_odds_code','Sports')
  910. ->select('odds_code','odds_name')
  911. ->where('p_id',$v['id'])
  912. ->get();
  913. }
  914. }
  915. Render($p_code, '1', lang('Tips','Sports')->get('success'));
  916. }
  917. /**
  918. * 获取 欧洲冠军杯数据
  919. */
  920. public function getUEFAChampions (){
  921. $data = $this->getTypeData->getUEFAChampions($this->source);
  922. Render($data, '1', lang('Tips','Sports')->get('success'));
  923. }
  924. /**
  925. * 更新赔率数据
  926. */
  927. public function updateOdds(){
  928. $data = $_REQUEST;
  929. // $data = ['game_code'=>'zq','match_id'=>3095448];
  930. $getModels = $this->commonFunction->getModels($data['game_code']);
  931. $model_match = $getModels['model_match'];
  932. $model_odds = $getModels['model_odds'];
  933. $where[] = [$model_match.'.match_id','=',$data['match_id']];
  934. $oddsData = lm($model_match,"Sports")
  935. ->join($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  936. ->select($model_match.'.match_id',$model_match.'.match_date',$model_match.'.home_team',$model_match.'.guest_team',$model_odds.'.id as odds_id',$model_odds.'.p_code',$model_odds.'.odds_code',$model_odds.'.condition',$model_odds.'.odds',$model_odds.'.odds_only',$model_odds.'.status',$model_odds.'.sort')
  937. ->where($model_match.'.source',$this->source)
  938. ->where($model_odds.'.type',0)
  939. ->where($where)
  940. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  941. ->get()->toArray();
  942. $p_code_array = [];
  943. foreach ($oddsData as $key =>$val){
  944. $p_code_array[$val['p_code']] = lang('OddsTemp','Sports')->get($val['p_code']);
  945. }
  946. $data = [
  947. 'oddsData'=>$oddsData,
  948. 'p_code_array'=>$p_code_array
  949. ];
  950. Render($data, '1', lang('Tips','Sports')->get('success'));
  951. }
  952. }