Sports.php 5.0 KB

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