Sports.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. /**
  5. * Class Register
  6. * @package App\Sports\Controller
  7. * User: junghwi
  8. * Date: 2019/3/21
  9. */
  10. class Sports extends Controller{
  11. public function init() {
  12. $this->commonFunction = C()->get('commonFunction');
  13. }
  14. /**
  15. * 首页体育-球类比赛数据方法
  16. * @param [type] $game_code 球类代码
  17. * @param [array] $where 球类额外条件
  18. * @param [int] $limit_mt 赛事显示条数 默认3条
  19. * @param [int] $limit_lg 联赛显示条数 默认3条
  20. * @return [array] $data
  21. */
  22. private function Sports_info($game_code,$where,$limit_mt = 3,$limit_lg = 3){
  23. $data=[];
  24. $data['name'] = lm('GameType','Sports')->where('game_code',$game_code)->value('game_name');
  25. $data['game_code'] = $game_code;
  26. //===查询该球类Models===
  27. $getModels = $this->commonFunction->getModels($game_code);
  28. $st_league = $getModels['model_league'];
  29. $st_competition = $getModels['model_match'];
  30. //查询足球早盘其他球的所有赛事
  31. if ($game_code == 'zq'){
  32. $data['all']['name'] ='今日赛事';
  33. $data['all']['game_code'] = $game_code;
  34. $data['all']['code'] = 'today';
  35. $matchData = lm($st_competition,'Sports')
  36. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  37. ->select($st_competition.'.id as match_id')
  38. ->where(getState('StToday',$st_competition))
  39. ->where([
  40. [$st_competition.'.home_team','<>',null],
  41. [$st_competition.'.guest_team','<>',null],
  42. [$st_league.'.name_chinese','<>',null],
  43. [$st_competition.'.status','<',2],
  44. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  45. ])
  46. ->get()
  47. ->toArray();
  48. // ->count('*');
  49. } else {
  50. $data['all']['name'] = '所有赛事';
  51. $data['all']['game_code'] = $game_code;
  52. $data['all']['code'] = 'all';
  53. $matchData = lm($st_competition,'Sports')
  54. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  55. ->select($st_competition.'.id as match_id')
  56. ->where([[$st_competition.'.status', '<', '2']])
  57. ->where([
  58. [$st_competition.'.home_team','<>',null],
  59. [$st_competition.'.guest_team','<>',null],
  60. [$st_league.'.name_chinese','<>',null],
  61. [$st_competition.'.status','<',2],
  62. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  63. ])
  64. ->where($st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4))
  65. ->get()
  66. ->toArray();
  67. // ->count('*');
  68. }
  69. //===获取当前赛事是否有赔率,如果没有则去除===
  70. $matchData = $this->commonFunction->Handle_Odds_Null($matchData,$getModels);
  71. $data['all']['count'] = count($matchData);
  72. //查询正在进行的和未开始的球类比赛
  73. $data['match'] = lm($st_competition,"Sports")
  74. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  75. ->select($st_competition.'.id as match_id',$st_competition.'.home_team',$st_competition.'.guest_team',$st_competition.'.match_date',$st_competition.'.match_time')
  76. ->where([[$st_competition.'.status','<',2]])
  77. ->where($st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4))
  78. ->where($where)
  79. ->where([
  80. [$st_competition.'.home_team','<>',null],
  81. [$st_competition.'.guest_team','<>',null],
  82. [$st_league.'.name_chinese','<>',null],
  83. [$st_competition.'.status','<',2],
  84. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  85. ])
  86. ->limit($limit_mt)
  87. ->get()
  88. ->toarray();
  89. //===获取当前赛事是否有赔率,如果没有则去除===
  90. $data['match'] = $this->commonFunction->Handle_Odds_Null($data['match'],$getModels);
  91. if(!empty($data['match'])){
  92. $data['match'] = $data['match'];
  93. }
  94. // 获取正在进行的和未开始联赛
  95. $data['league'] = lm($st_competition,"Sports")
  96. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  97. ->select($st_league.'.id as lg_id',$st_league.'.name_chinese',$st_competition.'.id as match_id')
  98. ->where([[$st_competition.'.status','<',2]])
  99. ->where($st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4))
  100. ->where($where)
  101. ->where([
  102. [$st_competition.'.home_team','<>',null],
  103. [$st_competition.'.guest_team','<>',null],
  104. [$st_league.'.name_chinese','<>',null],
  105. [$st_competition.'.status','<',2],
  106. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  107. ])
  108. ->limit($limit_lg)
  109. ->distinct($st_league.'id')
  110. ->get()
  111. ->toarray();
  112. //===获取当前赛事是否有赔率,如果没有则去除===
  113. $data['league'] = $this->commonFunction->Handle_Odds_Null($data['league'],$getModels);
  114. if (!empty($data['league'])) {
  115. foreach($data['league'] as $k => $v){
  116. //统计当前联赛下的联赛
  117. $data['league'][$k]['game_code'] = $game_code;
  118. $data['league'][$k]['code'] = "qt";
  119. $matchData = lm($st_competition,'Sports')
  120. ->select($st_competition.'.id as match_id')
  121. ->where([[$st_competition.'.status','<',2]])
  122. ->where('lg_id',$v['lg_id'])
  123. ->where($where)
  124. ->where([
  125. [$st_competition.'.home_team','<>',null],
  126. [$st_competition.'.guest_team','<>',null],
  127. [$st_competition.'.status','<',2],
  128. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  129. ])
  130. ->get()
  131. ->toArray();
  132. //===获取当前赛事是否有赔率,如果没有则去除===
  133. $matchNum = $this->commonFunction->Handle_Odds_Null($matchData,$getModels);
  134. $data['league'][$k]['count'] = count($matchNum);
  135. }
  136. }
  137. return $data;
  138. }
  139. /*
  140. * 获取首页体育信息数据接口
  141. */
  142. public function data(){
  143. $where = [];//球类额外条件
  144. $zq[] = $this->Sports_info('zq',$where);
  145. $lq[] = $this->Sports_info('lq',$where);
  146. $wq[] = $this->Sports_info('wq',$where);
  147. $bq[] = $this->Sports_info('bq',$where);
  148. $data = array_merge_recursive($zq,$lq,$bq,$wq);
  149. Render($data,'1', lang('Tips','Sports')->get('success'));
  150. }
  151. }