Sports.php 6.3 KB

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