MatchList.php 36 KB

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