MatchList.php 45 KB

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