Sports.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. $data['all']['count'] = lm($st_competition,'Sports')
  36. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  37. ->where(getState('StToday',$st_competition))
  38. ->where([
  39. [$st_competition.'.home_team','<>',null],
  40. [$st_competition.'.guest_team','<>',null],
  41. [$st_league.'.name_chinese','<>',null],
  42. [$st_competition.'.status','<',2],
  43. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  44. ])
  45. ->count('*');
  46. } else {
  47. $data['all']['name'] = '所有赛事';
  48. $data['all']['game_code'] = $game_code;
  49. $data['all']['code'] = 'all';
  50. $data['all']['count'] = lm($st_competition,'Sports')
  51. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  52. ->where([[$st_competition.'.status', '<', '2']])
  53. ->where([
  54. [$st_competition.'.home_team','<>',null],
  55. [$st_competition.'.guest_team','<>',null],
  56. [$st_league.'.name_chinese','<>',null],
  57. [$st_competition.'.status','<',2],
  58. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  59. ])
  60. ->where($st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4))
  61. ->count('*');
  62. }
  63. //查询正在进行的和未开始的球类比赛
  64. $data['match'] = lm($st_competition,"Sports")
  65. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  66. ->select($st_competition.'.id as match_id',$st_competition.'.home_team',$st_competition.'.guest_team',$st_competition.'.match_date',$st_competition.'.match_time')
  67. ->where([[$st_competition.'.status','<',2]])
  68. ->where($st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4))
  69. ->where($where)
  70. ->where([
  71. [$st_competition.'.home_team','<>',null],
  72. [$st_competition.'.guest_team','<>',null],
  73. [$st_league.'.name_chinese','<>',null],
  74. [$st_competition.'.status','<',2],
  75. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  76. ])
  77. ->limit($limit_mt)
  78. ->get();
  79. //===获取当前赛事是否有赔率,如果没有则去除===
  80. $data['match'] = $this->commonFunction->Handle_Odds_Null($data['match'],$getModels);
  81. if(!empty($data['match'])){
  82. $data['match'] = $data['match']->toarray();
  83. }
  84. // 获取正在进行的和未开始联赛
  85. $data['league'] = lm($st_competition,"Sports")
  86. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  87. ->select($st_league.'.id as lg_id',$st_league.'.name_chinese',$st_competition.'.id as match_id')
  88. ->where([[$st_competition.'.status','<',2]])
  89. ->where($st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4))
  90. ->where($where)
  91. ->where([
  92. [$st_competition.'.home_team','<>',null],
  93. [$st_competition.'.guest_team','<>',null],
  94. [$st_league.'.name_chinese','<>',null],
  95. [$st_competition.'.status','<',2],
  96. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  97. ])
  98. ->limit($limit_lg)
  99. ->distinct($st_league.'id')
  100. ->get();
  101. //===获取当前赛事是否有赔率,如果没有则去除===
  102. $data['league'] = $this->commonFunction->Handle_Odds_Null($data['league'],$getModels);
  103. if (!empty($data['league'])) {
  104. $data['league'] = $data['league']->toarray();
  105. foreach($data['league'] as $k => $v){
  106. //统计当前联赛下的联赛
  107. $data['league'][$k]['game_code'] = $game_code;
  108. $data['league'][$k]['code'] = "qt";
  109. $data['league'][$k]['count'] = lm($st_competition,'Sports')
  110. ->where([[$st_competition.'.status','<',2]])
  111. ->where('lg_id',$v['lg_id'])
  112. ->where($where)
  113. ->where([
  114. [$st_competition.'.home_team','<>',null],
  115. [$st_competition.'.guest_team','<>',null],
  116. [$st_competition.'.status','<',2],
  117. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  118. ])
  119. ->count('*');
  120. }
  121. }
  122. return $data;
  123. }
  124. /*
  125. * 获取首页体育信息数据接口
  126. */
  127. public function data(){
  128. $where = [];//球类额外条件
  129. $lq[] = $this->Sports_info('lq',$where);
  130. $wq[] = $this->Sports_info('wq',$where);
  131. $bq[] = $this->Sports_info('bq',$where);
  132. $zq[] = $this->Sports_info('zq',$where);
  133. $data = array_merge_recursive($zq,$lq,$bq,$wq);
  134. Render($data,'1', lang('Tips','Sports')->get('success'));
  135. }
  136. }