Sports.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.'.lg_id',$st_competition.'.lg_id')
  34. ->where(getState('StToday'))
  35. ->where($st_competition.'.source',$this->source['source'])
  36. ->distinct($st_competition.'.match_id')
  37. ->count('*');
  38. } else {
  39. $data['all']['name'] = '所有赛事';
  40. $data['all']['game_code'] = $game_code;
  41. $data['all']['code'] = 'all';
  42. $data['all']['count'] = lm($st_competition,'Sports')
  43. ->where([[$st_competition.'.status', '<', '2'],
  44. [$st_competition.'.source',$this->source['source']]])
  45. ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  46. ->count('*');
  47. }
  48. //查询正在进行的和未开始的球类比赛
  49. $data['match'] = lm($st_competition,"Sports")
  50. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  51. ->select($st_competition.'.match_id',$st_competition.'.home_team',$st_competition.'.guest_team',$st_competition.'.match_date',$st_competition.'.match_time')
  52. ->where([[$st_competition.'.status','<',2],[$st_competition.'.source',$this->source]])
  53. ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  54. ->where($where)
  55. ->limit($limit_mt)
  56. ->get();
  57. if(!empty($data['match'])){
  58. $data['match'] = $data['match']->toarray();
  59. }
  60. // 获取正在进行的和未开始联赛
  61. $data['league'] = lm($st_competition,"Sports")
  62. ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
  63. ->select($st_league.'.lg_id',$st_league.'.name_chinese')
  64. ->where([[$st_competition.'.status','<',2],[$st_competition.'.source',$this->source]])
  65. ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  66. ->where($where)
  67. ->limit($limit_lg)
  68. ->distinct($st_league.'lg_id')
  69. ->get();
  70. if (!empty($data['league'])) {
  71. $data['league'] = $data['league']->toarray();
  72. foreach($data['league'] as $k => $v){
  73. //统计当前联赛下的联赛
  74. $data['league'][$k]['game_code'] = $game_code;
  75. $data['league'][$k]['code'] = "qt";
  76. $data['league'][$k]['count'] = lm($st_competition,'Sports')
  77. ->where([[$st_competition.'.status','<',2],[$st_competition.'.source',$this->source]])
  78. ->where('lg_id',$v['lg_id'])
  79. ->where($where)
  80. ->count('*');
  81. }
  82. }
  83. return $data;
  84. }
  85. /*
  86. * 获取首页体育信息数据接口
  87. */
  88. public function data(){
  89. $where = [];//球类额外条件
  90. $lq[] = $this->Sports_info('lq',$where);
  91. $wq[] = $this->Sports_info('wq',$where);
  92. $bq[] = $this->Sports_info('bq',$where);
  93. $zq[] = $this->Sports_info('zq',$where);
  94. $data = array_merge_recursive($zq,$lq,$bq,$wq);
  95. Render($data,'1', lang('Tips','Sports')->get('success'));
  96. }
  97. }