MatchList.php 43 KB

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