Sports.php 4.2 KB

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