Sports.php 4.1 KB

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