MatchList.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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. ->count("*");
  656. // lm($matchModel['model_match'], 'Sports')
  657. // ->where($this->source)
  658. // ->where($where)
  659. // ->count('*');
  660. //获取满足状态的球类/去除冠军类
  661. if($matchNum != 0 and $type['game_code']!='gj'){
  662. $gameData[] = $type;
  663. }
  664. }else{
  665. $matchModel = $this->commonFunction->getModels($type['game_code']);
  666. $matchNum = lm($matchModel['model_odds'], 'Sports')
  667. ->where($this->source)
  668. ->where($where)
  669. ->count('*');
  670. //获取满足状态的球类/去除冠军类
  671. if($matchNum != 0 and $type['game_code']!='gj'){
  672. $gameData[] = $type;
  673. }
  674. }
  675. }
  676. Render($gameData, '1', lang('Tips','Sports')->get('success'));
  677. } catch (\Exception $e) {
  678. echo $e->getMessage();
  679. }
  680. }
  681. /**
  682. * @throws \Exception
  683. * 获取不同状态下 各球类赛事数据
  684. * game_code 球类代码
  685. * type_code 类型代码
  686. */
  687. public function matchState(){
  688. $source = $this->source;//数据源 条件
  689. $ret = $_REQUEST;
  690. try {
  691. if(empty($ret['game_code']) || empty($ret['type_code'])){
  692. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  693. }
  694. $data = $this->getTypeData->typeData($ret,$source);
  695. Render($data, '1', lang('Tips','Sports')->get('success'));
  696. } catch (\Exception $e) {
  697. echo $e->getMessage();
  698. }
  699. }
  700. /**
  701. * 根据赛事状态获取赔率查询条件
  702. */
  703. public function getOddsTypeWhere($model_odds,$oddsType){
  704. //获取赛事不同状态下的赔率
  705. if(!empty($oddsType)){
  706. switch ($oddsType)
  707. {
  708. case 'StRollBall'://滚球
  709. $oddsTypeWhere = [[$model_odds.'.is_rollball','=',1]];
  710. break;
  711. case 'StSoon'://即将
  712. $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
  713. break;
  714. case 'StToday'://今日
  715. $oddsTypeWhere = [[$model_odds.'.is_today','=',1]];
  716. break;
  717. case 'StMorningPlate'://早盘
  718. $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
  719. break;
  720. case 'StStringScene'://串场
  721. $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
  722. break;
  723. case 'home'://首页
  724. $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
  725. break;
  726. default:
  727. $oddsTypeWhere = [];
  728. }
  729. }
  730. return $oddsTypeWhere;
  731. }
  732. /**
  733. * 获取赛事所有玩法赔率数据
  734. */
  735. public function matchOdds(){
  736. $game_code = $_REQUEST['game_code'];
  737. $matchID = $_REQUEST['matchID'];
  738. $status = $_REQUEST['status'];
  739. $oddsType = $_REQUEST['oddsType'];
  740. try {
  741. if(empty($game_code) || empty($matchID) || empty($oddsType)){
  742. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  743. }
  744. //根据球类代码 获取相关model
  745. $models = $this->commonFunction->getModels($game_code,0);
  746. $model_match = $models['model_match'];
  747. $model_odds = $models['model_odds'];
  748. $model_league = $models['model_league'];
  749. $model_result = $models['model_result'];
  750. //取消按状态查询赔率数据
  751. //$oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$oddsType);
  752. $oddsData = lm($model_odds, 'Sports')
  753. ->select('sort','p_code','id','odds_only','odds_code',$model_odds.'.status','odds','condition','sort','source','utime')
  754. ->where($this->source)
  755. ->where([$model_odds.'.match_id'=>$matchID,$model_odds.'.type'=>0])//,$model_odds.'.expire_time'=>$utime
  756. ->orderBy('sort', 'desc')
  757. ->orderBy('p_code','desc')
  758. ->orderBy('odds_code','desc')
  759. ->get()->toArray();
  760. $matchData = lm($model_match, 'Sports')
  761. ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
  762. ->select($model_match.'.lg_id','name_chinese','match_id','home_team','guest_team','match_date','match_time',$model_match.'.status')
  763. ->where($model_match.'.source',$this->source['source'])
  764. ->where(['match_id'=>$matchID])
  765. ->first();
  766. if(empty($matchData)) Render(null, '1', lang('Tips','Sports')->get('success'));
  767. $matchData->ptime = '';//赛事进行时间
  768. $matchData->match_score = '';//赛事比分
  769. //如果该赛事正在进行,则获取进行时间
  770. if($matchData->status ==1){
  771. $result = lm($model_result, 'Sports')->select('match_id','match_time','match_score')
  772. ->where($this->source)
  773. ->where(['match_id'=>$matchData->match_id])
  774. ->first();
  775. $matchData->ptime = $result->match_time;
  776. $matchData->match_score = $result->match_score;
  777. }
  778. //赛事已结束
  779. if($matchData->status ==2){
  780. $oddsData = [];
  781. }
  782. //查询当前联赛下的赛事
  783. $league = [];
  784. if($oddsType != 'StRollBall'){
  785. $where = [
  786. ['home_team','<>',null],
  787. ['guest_team','<>',null],
  788. ['status','<',2],
  789. ['lg_id',$matchData->lg_id],
  790. ];
  791. switch ($oddsType)
  792. {
  793. case 'StSoon'://即将
  794. $matchWhere=[['is_morningplate','=',1]];
  795. break;
  796. case 'StToday'://今日
  797. $matchWhere=[['is_today','=',1]];
  798. break;
  799. case 'StMorningPlate'://早盘
  800. $matchWhere=[['is_morningplate','=',1]];
  801. break;
  802. case 'StStringScene'://串场
  803. $matchWhere = [['is_stringscene','=',1]];
  804. break;
  805. case 'home'://首页
  806. $matchWhere = [['is_stringscene','=',1]];
  807. break;
  808. default:
  809. $matchWhere = [];
  810. }
  811. $league = lm($model_match,'Sports')
  812. ->select('match_id','home_team','guest_team','status','match_date','match_time')
  813. ->where($this->source)
  814. ->where($where)
  815. ->where($matchWhere)
  816. ->get()
  817. ->toarray();
  818. }
  819. $list = array();
  820. foreach ($oddsData as $key=>$item){
  821. $item['team'] = '';
  822. if(strpos($item['odds_code'],'home') !== false) {
  823. $item['team'] = 'home';
  824. }
  825. if(strpos($item['odds_code'],'guest') !== false) {
  826. $item['team'] = 'guest';
  827. }
  828. $list[$key] = $item;
  829. }
  830. $p_code_array = [];
  831. foreach ($oddsData as $key =>$val){
  832. $p_code_array[] = $val['p_code'];
  833. }
  834. $p_code_array = array_keys(array_flip(array_unique($p_code_array)));//p_code 去重排序
  835. $data = [
  836. 'lg_id' =>$matchData->lg_id,
  837. 'leagueName' =>$matchData->name_chinese,
  838. 'match_id'=>$matchData->match_id,
  839. 'home_team'=>$matchData->home_team,
  840. 'guest_team'=>$matchData->guest_team,
  841. 'match_time'=>$matchData->match_date." ".$matchData->match_time,
  842. 'match_ptime'=>$matchData->ptime,
  843. 'match_score'=>$matchData->match_score,
  844. 'p_code_array'=> $p_code_array,
  845. 'oddsData'=>$oddsData,
  846. 'league' => $league,
  847. ];
  848. Render($data, '1', lang('Tips','Sports')->get('success'));
  849. } catch (\Exception $e) {
  850. echo $e->getMessage();
  851. }
  852. }
  853. /**
  854. * 手动 更新 赛事状态
  855. */
  856. public function updateMatch () {
  857. $game_code = $_REQUEST['game_code'];
  858. $match_date = $_REQUEST['match_date'];
  859. try {
  860. if(empty($game_code)){
  861. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  862. }
  863. if(empty($match_date)) $match_date = date('Y-m-d');
  864. //根据球类代码 获取相关model
  865. $models = $this->commonFunction->getModels($game_code);
  866. $model_match = $models['model_match'];
  867. $matchData = lm($model_match,'Sports')->select('match_id','status','match_date','match_time')->where(['match_date'=>$match_date])->get();
  868. foreach ($matchData as $key=>$item){
  869. $time = strtotime($item->match_date.$item->match_time);
  870. if(($time+(60*90)) < time()){ //更新为 已结束
  871. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>2]);
  872. }
  873. if(($time+(60*90)) > time() and $time < time()){ //更新为 进行中
  874. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>1]);
  875. }
  876. }
  877. Render([], '1', lang('Tips','Sports')->get('success'));
  878. } catch (\Exception $e) {
  879. echo $e->getMessage();
  880. }
  881. }
  882. /**
  883. * 获取即将开赛 所有赛事
  884. * 首页使用
  885. */
  886. public function getSoon(){
  887. $source = $this->source;//数据源 条件
  888. try {
  889. $where = $this->commonFunction->getState('StSoon');
  890. $data = $this->getTypeData->getAllSoon($source,$where);
  891. Render($data, '1', lang('Tips','Sports')->get('success'));
  892. } catch (\Exception $e) {
  893. echo $e->getMessage();
  894. }
  895. }
  896. /**
  897. * 获取球类-玩法-赔率代码
  898. */
  899. public function getOddsCode(){
  900. $type = $_REQUEST['type'];
  901. if($type == 'p_code'){
  902. $p_code = lm('st_odds_code','Sports')
  903. ->select('odds_code','odds_name')
  904. ->where('p_id',0)
  905. ->get();
  906. }else{
  907. $p_code = lm('st_odds_code','Sports')
  908. ->select('id','odds_code','odds_name')
  909. ->where('p_id',0)
  910. ->get();
  911. foreach ($p_code as $k=>$v){
  912. $v->below = lm('st_odds_code','Sports')
  913. ->select('odds_code','odds_name')
  914. ->where('p_id',$v['id'])
  915. ->get();
  916. }
  917. }
  918. Render($p_code, '1', lang('Tips','Sports')->get('success'));
  919. }
  920. /**
  921. * 获取 欧洲冠军杯数据
  922. */
  923. public function getUEFAChampions (){
  924. $data = $this->getTypeData->getUEFAChampions($this->source);
  925. Render($data, '1', lang('Tips','Sports')->get('success'));
  926. }
  927. /**
  928. * 更新赔率数据
  929. */
  930. public function updateOdds(){
  931. $data = $_REQUEST;
  932. // $data = ['game_code'=>'zq','match_id'=>3095448];
  933. $getModels = $this->commonFunction->getModels($data['game_code']);
  934. $model_match = $getModels['model_match'];
  935. $model_odds = $getModels['model_odds'];
  936. $where[] = [$model_match.'.match_id','=',$data['match_id']];
  937. $oddsData = lm($model_match,"Sports")
  938. ->join($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  939. ->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')
  940. ->where($model_match.'.source',$this->source)
  941. ->where($model_odds.'.type',0)
  942. ->where($where)
  943. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  944. ->get()->toArray();
  945. $p_code_array = [];
  946. foreach ($oddsData as $key =>$val){
  947. $p_code_array[$val['p_code']] = lang('OddsTemp','Sports')->get($val['p_code']);
  948. }
  949. $data = [
  950. 'oddsData'=>$oddsData,
  951. 'p_code_array'=>$p_code_array
  952. ];
  953. Render($data, '1', lang('Tips','Sports')->get('success'));
  954. }
  955. }