MatchList.php 44 KB

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