MatchList.php 38 KB

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