Sports.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. ->toarray();
  80. //===获取当前赛事是否有赔率,如果没有则去除===
  81. $data['match'] = $this->commonFunction->Handle_Odds_Null($data['match'],$getModels);
  82. if(!empty($data['match'])){
  83. $data['match'] = $data['match']->toarray();
  84. }
  85. // 获取正在进行的和未开始联赛
  86. $data['league'] = lm($st_competition,"Sports")
  87. ->join($st_league,$st_league.'.id',$st_competition.'.lg_id')
  88. ->select($st_league.'.id as lg_id',$st_league.'.name_chinese',$st_competition.'.id as match_id')
  89. ->where([[$st_competition.'.status','<',2]])
  90. ->where($st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4))
  91. ->where($where)
  92. ->where([
  93. [$st_competition.'.home_team','<>',null],
  94. [$st_competition.'.guest_team','<>',null],
  95. [$st_league.'.name_chinese','<>',null],
  96. [$st_competition.'.status','<',2],
  97. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  98. ])
  99. ->limit($limit_lg)
  100. ->distinct($st_league.'id')
  101. ->get()
  102. ->toarray();
  103. //===获取当前赛事是否有赔率,如果没有则去除===
  104. $data['league'] = $this->commonFunction->Handle_Odds_Null($data['league'],$getModels);
  105. if (!empty($data['league'])) {
  106. foreach($data['league'] as $k => $v){
  107. //统计当前联赛下的联赛
  108. $data['league'][$k]['game_code'] = $game_code;
  109. $data['league'][$k]['code'] = "qt";
  110. $data['league'][$k]['count'] = lm($st_competition,'Sports')
  111. ->where([[$st_competition.'.status','<',2]])
  112. ->where('lg_id',$v['lg_id'])
  113. ->where($where)
  114. ->where([
  115. [$st_competition.'.home_team','<>',null],
  116. [$st_competition.'.guest_team','<>',null],
  117. [$st_competition.'.status','<',2],
  118. [$st_competition.'.us_time','>',$this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4)]
  119. ])
  120. ->count('*');
  121. }
  122. }
  123. return $data;
  124. }
  125. /*
  126. * 获取首页体育信息数据接口
  127. */
  128. public function data(){
  129. $where = [];//球类额外条件
  130. $lq[] = $this->Sports_info('lq',$where);
  131. $wq[] = $this->Sports_info('wq',$where);
  132. $bq[] = $this->Sports_info('bq',$where);
  133. $zq[] = $this->Sports_info('zq',$where);
  134. $data = array_merge_recursive($zq,$lq,$bq,$wq);
  135. Render($data,'1', lang('Tips','Sports')->get('success'));
  136. }
  137. }