MatchList.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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')
  770. ->where($this->source)
  771. ->where($where)
  772. ->where($matchWhere)
  773. ->distinct($model_match.'.match_id')
  774. ->get()
  775. ->toarray();
  776. }
  777. // dump(lm($model_match,'Sports')->getsql());die;
  778. $list = array();
  779. foreach ($oddsData as $key=>$item){
  780. $item['team'] = '';
  781. if(strpos($item['odds_code'],'home') !== false) {
  782. $item['team'] = 'home';
  783. }
  784. if(strpos($item['odds_code'],'guest') !== false) {
  785. $item['team'] = 'guest';
  786. }
  787. //匹配语言文件
  788. // $item['p_code'] = lang('OddsTemp','Sports')->get($item['p_code']);
  789. // $item['odds_code'] = lang('OddsTemp','Sports')->get($item['odds_code']);
  790. $list[$key] = $item;
  791. }
  792. //按p_code分组
  793. // $p_code=array();
  794. // foreach($list as $k=>$v){
  795. // $p_code[$v['p_code']][]=$v;
  796. // }
  797. //
  798. // $sd = [];
  799. // foreach ($p_code as $k1=>$v1){
  800. // foreach ($v1 as $k2=>$v2){
  801. // $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  802. // }
  803. // }
  804. $p_code_array = [];
  805. foreach ($oddsData as $key =>$val){
  806. $p_code_array[] = $val['p_code'];
  807. // $p_code_array[$val['p_code']] = lang('OddsTemp','Sports')->get($val['p_code']);
  808. }
  809. $p_code_array = array_keys(array_flip(array_unique($p_code_array)));//p_code 去重排序
  810. $data = [
  811. 'lg_id' =>$matchData->lg_id,
  812. 'leagueName' =>$matchData->name_chinese,
  813. 'match_id'=>$matchData->match_id,
  814. 'home_team'=>$matchData->home_team,
  815. 'guest_team'=>$matchData->guest_team,
  816. 'match_time'=>$matchData->match_date." ".$matchData->match_time,
  817. 'match_ptime'=>$matchData->ptime,
  818. 'match_score'=>$matchData->match_score,
  819. 'p_code_array'=> $p_code_array,
  820. 'oddsData'=>$oddsData,
  821. 'league' => $league,
  822. // 'lang' => lang('OddsTemp','Sports')->getAll(),
  823. ];
  824. Render($data, '1', lang('Tips','Sports')->get('success'));
  825. } catch (\Exception $e) {
  826. echo $e->getMessage();
  827. }
  828. }
  829. /**
  830. * 手动 更新 赛事状态
  831. */
  832. public function updateMatch () {
  833. $game_code = $_REQUEST['game_code'];
  834. $match_date = $_REQUEST['match_date'];
  835. try {
  836. if(empty($game_code)){
  837. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  838. }
  839. if(empty($match_date)) $match_date = date('Y-m-d');
  840. //根据球类代码 获取相关model
  841. $models = $this->commonFunction->getModels($game_code);
  842. $model_match = $models['model_match'];
  843. $matchData = lm($model_match,'Sports')->select('match_id','status','match_date','match_time')->where(['match_date'=>$match_date])->get();
  844. foreach ($matchData as $key=>$item){
  845. $time = strtotime($item->match_date.$item->match_time);
  846. if(($time+(60*90)) < time()){ //更新为 已结束
  847. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>2]);
  848. }
  849. if(($time+(60*90)) > time() and $time < time()){ //更新为 进行中
  850. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>1]);
  851. }
  852. }
  853. Render([], '1', lang('Tips','Sports')->get('success'));
  854. } catch (\Exception $e) {
  855. echo $e->getMessage();
  856. }
  857. }
  858. /**
  859. * 获取即将开赛 所有赛事
  860. * 首页使用
  861. */
  862. public function getSoon(){
  863. $source = $this->source;//数据源 条件
  864. try {
  865. $where = $this->commonFunction->getState('StSoon');
  866. $data = $this->getTypeData->getAllSoon($source,$where);
  867. Render($data, '1', lang('Tips','Sports')->get('success'));
  868. } catch (\Exception $e) {
  869. echo $e->getMessage();
  870. }
  871. }
  872. /**
  873. * 获取球类-玩法-赔率代码
  874. */
  875. public function getOddsCode(){
  876. $type = $_REQUEST['type'];
  877. if($type == 'p_code'){
  878. $p_code = lm('st_odds_code','Sports')
  879. ->select('odds_code','odds_name')
  880. ->where('p_id',0)
  881. ->get();
  882. }else{
  883. $p_code = lm('st_odds_code','Sports')
  884. ->select('id','odds_code','odds_name')
  885. ->where('p_id',0)
  886. ->get();
  887. foreach ($p_code as $k=>$v){
  888. $v->below = lm('st_odds_code','Sports')
  889. ->select('odds_code','odds_name')
  890. ->where('p_id',$v['id'])
  891. ->get();
  892. }
  893. }
  894. Render($p_code, '1', lang('Tips','Sports')->get('success'));
  895. }
  896. /**
  897. * 获取 欧洲冠军杯数据
  898. */
  899. public function getUEFAChampions (){
  900. $data = $this->getTypeData->getUEFAChampions($this->source);
  901. Render($data, '1', lang('Tips','Sports')->get('success'));
  902. }
  903. /**
  904. * 更新赔率数据
  905. */
  906. public function updateOdds(){
  907. $data = $_REQUEST;
  908. // $data = ['game_code'=>'zq','match_id'=>3095448];
  909. $getModels = $this->commonFunction->getModels($data['game_code']);
  910. $model_match = $getModels['model_match'];
  911. $model_odds = $getModels['model_odds'];
  912. $where[] = [$model_match.'.match_id','=',$data['match_id']];
  913. $oddsData = lm($model_match,"Sports")
  914. ->join($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  915. ->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')
  916. ->where($model_match.'.source',$this->source)
  917. ->where($model_odds.'.type',0)
  918. ->where($where)
  919. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  920. ->get()->toArray();
  921. $p_code_array = [];
  922. foreach ($oddsData as $key =>$val){
  923. $p_code_array[$val['p_code']] = lang('OddsTemp','Sports')->get($val['p_code']);
  924. }
  925. $data = [
  926. 'oddsData'=>$oddsData,
  927. 'p_code_array'=>$p_code_array
  928. ];
  929. Render($data, '1', lang('Tips','Sports')->get('success'));
  930. }
  931. }