Sports.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. /*
  96. $data['league'] = lm($st_competition,"Sports")
  97. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  98. ->select($st_league.'.id as lg_id',$st_league.'.name_chinese',$st_competition.'.id as match_id')
  99. // ->where([[$st_competition.'.status','<',2]])
  100. // ->where($st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4))
  101. ->where($where)
  102. ->where([
  103. [$st_competition.'.home_team','<>',null],
  104. [$st_competition.'.guest_team','<>',null],
  105. [$st_league.'.name_chinese','<>',null],
  106. [$st_competition.'.status','<',2],
  107. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  108. ])
  109. ->limit($limit_lg)
  110. ->distinct($st_league.'id')
  111. ->get()
  112. ->toArray();
  113. */
  114. $data['league'] = lm($st_league,"Sports")
  115. ->join($st_competition,$st_competition.'.lg_id',$st_league.'.id')
  116. ->select($st_league.'.id as lg_id',$st_league.'.name_chinese',$st_competition.'.id as match_id')
  117. ->where($where)
  118. ->where([
  119. [$st_competition.'.home_team','<>',null],
  120. [$st_competition.'.guest_team','<>',null],
  121. [$st_league.'.name_chinese','<>',null],
  122. [$st_competition.'.status','<',2],
  123. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  124. ])
  125. ->limit($limit_lg)
  126. ->distinct($st_league.'id')
  127. ->get()
  128. ->toArray();
  129. //去重
  130. $data['league'] = $this->commonFunction->array_unset_tt($data['league'],'lg_id');
  131. //===获取当前赛事是否有赔率,如果没有则去除===
  132. $data['league'] = $this->commonFunction->Handle_Odds_Null($data['league'],$getModels);
  133. if (!empty($data['league'])) {
  134. foreach($data['league'] as $k => $v){
  135. //统计当前联赛下的联赛
  136. $data['league'][$k]['game_code'] = $game_code;
  137. $data['league'][$k]['code'] = "qt";
  138. $matchData = lm($st_competition,'Sports')
  139. ->select($st_competition.'.id as match_id')
  140. // ->where([[$st_competition.'.status','<',2]])
  141. ->where('lg_id',$v['lg_id'])
  142. ->where($where)
  143. ->where([
  144. [$st_competition.'.home_team','<>',null],
  145. [$st_competition.'.guest_team','<>',null],
  146. [$st_competition.'.status','<',2],
  147. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  148. ])
  149. ->get()
  150. ->toArray();
  151. //===获取当前赛事是否有赔率,如果没有则去除===
  152. $matchNum = $this->commonFunction->Handle_Odds_Null($matchData,$getModels);
  153. $data['league'][$k]['count'] = count($matchNum);
  154. }
  155. }
  156. return $data;
  157. }
  158. /*
  159. * 获取首页体育信息数据接口
  160. */
  161. public function data(){
  162. $where = [];//球类额外条件
  163. $zq[] = $this->Sports_info('zq',$where);
  164. $lq[] = $this->Sports_info('lq',$where);
  165. $wq[] = $this->Sports_info('wq',$where);
  166. $bq[] = $this->Sports_info('bq',$where);
  167. $data = array_merge_recursive($zq,$lq,$bq,$wq);
  168. Render($data,'1', lang('Tips','Sports')->get('success'));
  169. }
  170. }