MatchList.php 36 KB

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