MatchList.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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_match'], 'Sports')
  606. ->where($this->source)
  607. ->where($where)
  608. ->count('*');
  609. //获取满足状态的球类/去除冠军类
  610. if($matchNum != 0 and $type['game_code']!='gj'){
  611. $gameData[] = $type;
  612. }
  613. }else{
  614. $matchModel = $this->commonFunction->getModels($type['game_code']);
  615. $matchNum = lm($matchModel['model_odds'], 'Sports')
  616. ->where($this->source)
  617. ->where($where)
  618. ->count('*');
  619. //获取满足状态的球类/去除冠军类
  620. if($matchNum != 0 and $type['game_code']!='gj'){
  621. $gameData[] = $type;
  622. }
  623. }
  624. }
  625. Render($gameData, '1', lang('Tips','Sports')->get('success'));
  626. } catch (\Exception $e) {
  627. echo $e->getMessage();
  628. }
  629. }
  630. /**
  631. * @throws \Exception
  632. * 获取不同状态下 各球类赛事数据
  633. * game_code 球类代码
  634. * type_code 类型代码
  635. */
  636. public function matchState(){
  637. $source = $this->source;//数据源 条件
  638. $ret = $_REQUEST;
  639. try {
  640. if(empty($ret['game_code']) || empty($ret['type_code'])){
  641. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  642. }
  643. $data = $this->getTypeData->typeData($ret,$source);
  644. Render($data, '1', lang('Tips','Sports')->get('success'));
  645. } catch (\Exception $e) {
  646. echo $e->getMessage();
  647. }
  648. }
  649. /**
  650. * 根据赛事状态获取赔率查询条件
  651. */
  652. public function getOddsTypeWhere($model_odds,$oddsType){
  653. //获取赛事不同状态下的赔率
  654. if(!empty($oddsType)){
  655. switch ($oddsType)
  656. {
  657. case 'StRollBall'://滚球
  658. $oddsTypeWhere = [[$model_odds.'.is_rollball','=',1]];
  659. break;
  660. case 'StSoon'://即将
  661. $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
  662. break;
  663. case 'StToday'://今日
  664. $oddsTypeWhere = [[$model_odds.'.is_today','=',1]];
  665. break;
  666. case 'StMorningPlate'://早盘
  667. $oddsTypeWhere = [[$model_odds.'.is_morningplate','=',1]];
  668. break;
  669. case 'StStringScene'://串场
  670. $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
  671. break;
  672. case 'home'://首页
  673. $oddsTypeWhere = [[$model_odds.'.is_stringscene','=',1]];
  674. break;
  675. default:
  676. $oddsTypeWhere = [];
  677. }
  678. }
  679. return $oddsTypeWhere;
  680. }
  681. /**
  682. * 获取赛事所有玩法赔率数据
  683. */
  684. public function matchOdds(){
  685. $game_code = $_REQUEST['game_code'];
  686. $matchID = $_REQUEST['matchID'];
  687. $status = $_REQUEST['status'];
  688. $oddsType = $_REQUEST['oddsType'];
  689. try {
  690. if(empty($game_code) || empty($matchID) || empty($oddsType)){
  691. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  692. }
  693. //根据球类代码 获取相关model
  694. $models = $this->commonFunction->getModels($game_code,0);
  695. $model_match = $models['model_match'];
  696. $model_odds = $models['model_odds'];
  697. $model_league = $models['model_league'];
  698. $model_result = $models['model_result'];
  699. $oddsTypeWhere = $this->getOddsTypeWhere($model_odds,$oddsType);
  700. $oddsData = lm($model_odds, 'Sports')
  701. ->select('sort','p_code','id','odds_only','odds_code',$model_odds.'.status','odds','condition','sort','source','utime')
  702. ->where($this->source)
  703. ->where($oddsTypeWhere)
  704. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  705. ->where([$model_odds.'.match_id'=>$matchID,$model_odds.'.type'=>0])//,$model_odds.'.expire_time'=>$utime
  706. ->orderBy('sort', 'desc')
  707. ->orderBy('p_code','desc')
  708. ->orderBy('odds_code','desc')
  709. //->groupBy('sort','p_code','id','odds_only','odds_code',$model_odds.'.status','odds','condition','sort','source','utime')
  710. ->get()->toArray();
  711. $matchData = lm($model_match, 'Sports')
  712. ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
  713. ->select($model_match.'.lg_id','name_chinese','match_id','home_team','guest_team','match_date','match_time',$model_match.'.status')
  714. ->where($model_match.'.source',$this->source['source'])
  715. ->where(['match_id'=>$matchID])
  716. ->first();
  717. // ->toarray();
  718. if(empty($matchData)) Render(null, '1', lang('Tips','Sports')->get('success'));
  719. $matchData->ptime = '';//赛事进行时间
  720. $matchData->match_score = '';//赛事比分
  721. //如果该赛事正在进行,则获取进行时间
  722. if($matchData->status ==1){
  723. $result = lm($model_result, 'Sports')->select('match_id','match_time','match_score')
  724. ->where($this->source)
  725. ->where(['match_id'=>$matchData->match_id])
  726. ->first();
  727. $matchData->ptime = $result->match_time;
  728. $matchData->match_score = $result->match_score;
  729. }
  730. //查询当前联赛下的赛事
  731. $league = [];
  732. if($status != 1){
  733. $league = lm($model_match,'Sports')
  734. ->select('match_id','home_team','guest_team')
  735. ->where($this->source)
  736. ->where('lg_id',$matchData->lg_id)
  737. ->get()->toarray();
  738. }
  739. $list = array();
  740. foreach ($oddsData as $key=>$item){
  741. $item['team'] = '';
  742. if(strpos($item['odds_code'],'home') !== false) {
  743. $item['team'] = 'home';
  744. }
  745. if(strpos($item['odds_code'],'guest') !== false) {
  746. $item['team'] = 'guest';
  747. }
  748. //匹配语言文件
  749. // $item['p_code'] = lang('OddsTemp','Sports')->get($item['p_code']);
  750. // $item['odds_code'] = lang('OddsTemp','Sports')->get($item['odds_code']);
  751. $list[$key] = $item;
  752. }
  753. //按p_code分组
  754. // $p_code=array();
  755. // foreach($list as $k=>$v){
  756. // $p_code[$v['p_code']][]=$v;
  757. // }
  758. //
  759. // $sd = [];
  760. // foreach ($p_code as $k1=>$v1){
  761. // foreach ($v1 as $k2=>$v2){
  762. // $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  763. // }
  764. // }
  765. $p_code_array = [];
  766. foreach ($oddsData as $key =>$val){
  767. $p_code_array[$val['p_code']] = lang('OddsTemp','Sports')->get($val['p_code']);
  768. }
  769. // $p_code_array = array_keys(array_flip(array_unique($p_code_array)));//p_code 去重排序
  770. $data = [
  771. 'lg_id' =>$matchData->lg_id,
  772. 'leagueName' =>$matchData->name_chinese,
  773. 'match_id'=>$matchData->match_id,
  774. 'home_team'=>$matchData->home_team,
  775. 'guest_team'=>$matchData->guest_team,
  776. 'match_time'=>$matchData->match_date." ".$matchData->match_time,
  777. 'match_ptime'=>$matchData->ptime,
  778. 'match_score'=>$matchData->match_score,
  779. 'p_code_array'=> $p_code_array,
  780. 'oddsData'=>$oddsData, //$sd,
  781. 'league' => $league,
  782. 'lang' => lang('OddsTemp','Sports')->getAll(),
  783. ];
  784. Render($data, '1', lang('Tips','Sports')->get('success'));
  785. } catch (\Exception $e) {
  786. echo $e->getMessage();
  787. }
  788. }
  789. /**
  790. * 手动 更新 赛事状态
  791. */
  792. public function updateMatch () {
  793. $game_code = $_REQUEST['game_code'];
  794. $match_date = $_REQUEST['match_date'];
  795. try {
  796. if(empty($game_code)){
  797. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  798. }
  799. if(empty($match_date)) $match_date = date('Y-m-d');
  800. //根据球类代码 获取相关model
  801. $models = $this->commonFunction->getModels($game_code);
  802. $model_match = $models['model_match'];
  803. $matchData = lm($model_match,'Sports')->select('match_id','status','match_date','match_time')->where(['match_date'=>$match_date])->get();
  804. foreach ($matchData as $key=>$item){
  805. $time = strtotime($item->match_date.$item->match_time);
  806. if(($time+(60*90)) < time()){ //更新为 已结束
  807. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>2]);
  808. }
  809. if(($time+(60*90)) > time() and $time < time()){ //更新为 进行中
  810. lm($model_match,'Sports')->where(['match_id'=>$item->match_id])->update(['status'=>1]);
  811. }
  812. }
  813. Render([], '1', lang('Tips','Sports')->get('success'));
  814. } catch (\Exception $e) {
  815. echo $e->getMessage();
  816. }
  817. }
  818. /**
  819. * 获取即将开赛 所有赛事
  820. * 首页使用
  821. */
  822. public function getSoon(){
  823. $source = $this->source;//数据源 条件
  824. try {
  825. $where = $this->commonFunction->getState('StSoon');
  826. $data = $this->getTypeData->getAllSoon($source,$where);
  827. Render($data, '1', lang('Tips','Sports')->get('success'));
  828. } catch (\Exception $e) {
  829. echo $e->getMessage();
  830. }
  831. }
  832. /**
  833. * 获取球类-玩法-赔率代码
  834. */
  835. public function getOddsCode(){
  836. $p_code = lm('st_odds_code','Sports')
  837. ->select('id','p_id','odds_code','odds_name','type')
  838. ->where('p_id',0)
  839. ->get();
  840. foreach ($p_code as $k=>$v){
  841. $v->below = lm('st_odds_code','Sports')
  842. ->select('id','p_id','odds_code','odds_name','type')
  843. ->where('p_id',$v['id'])
  844. ->get();
  845. }
  846. Render($p_code, '1', lang('Tips','Sports')->get('success'));
  847. }
  848. /**
  849. * 获取 欧洲冠军杯数据
  850. */
  851. public function getUEFAChampions (){
  852. $data = $this->getTypeData->getUEFAChampions($this->source);
  853. Render($data, '1', lang('Tips','Sports')->get('success'));
  854. }
  855. /**
  856. * 更新赔率数据
  857. */
  858. public function updateOdds(){
  859. $data = $_REQUEST;
  860. // $data = ['game_code'=>'zq','match_id'=>3095448];
  861. $getModels = $this->commonFunction->getModels($data['game_code']);
  862. $model_match = $getModels['model_match'];
  863. $model_odds = $getModels['model_odds'];
  864. $where[] = [$model_match.'.match_id','=',$data['match_id']];
  865. $oddsData = lm($model_match,"Sports")
  866. ->join($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  867. ->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')
  868. ->where($model_match.'.source',$this->source)
  869. ->where($where)
  870. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  871. ->get()->toArray();
  872. Render($oddsData, '1', lang('Tips','Sports')->get('success'));
  873. }
  874. }