| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Sports\Controller;
- use BaseController\Controller;
- /**
- * Class Register
- * @package App\Sports\Controller
- * User: junghwi
- * Date: 2019/3/21
- */
- class Sports extends Controller{
- /**
- * 首页体育-球类比赛数据方法
- * @param [type] $game_code 球类代码
- * @param [array] $where 球类额外条件
- * @param [int] $limit_mt 赛事显示条数 默认3条
- * @param [int] $limit_lg 联赛显示条数 默认3条
- * @return [array] $data
- */
- private function Sports_info($game_code,$where,$limit_mt = 3,$limit_lg = 3){
- $data=[];
- $data['name'] = lm('GameType','Sports')->where('game_code',$game_code)->value('game_name');
- $data['game_code'] = 'zq';
- //===查询该球类Models===
- $getModels = getModels($game_code);
- $st_league = $getModels['model_league'];
- $st_competition = $getModels['model_match'];
- //查询足球早盘其他球的所有赛事
- if ($data['game_code'] == 'zq'){
- $data['today']['name'] ='今日赛事';
- $data['today']['count'] = lm('st_zq_competition','Sports')
- ->join('st_zq_league','st_zq_league.lg_id','st_zq_competition.lg_id')
- ->where(getState('StToday'))
- ->where('st_zq_competition.source',$this->source['source'])
- ->distinct('st_zq_competition.match_id')
- ->count('*');
- } else {
- $data['all']['name'] = '所有赛事';
- $data['today']['count'] = lm($st_competition,'Sports')
- ->where([[$st_competition.'.status', '<', '2'],
- [$st_competition.'.source',$this->source['source']]])
- ->where('st_zq_competition.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->count('*');
- }
- //查询正在进行的和未开始的球类比赛
- $data['match'] = lm($st_competition,"Sports")
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->select($st_competition.'.match_id',$st_competition.'.home_team',$st_competition.'.guest_team',$st_competition.'.match_date',$st_competition.'.match_time')
- ->where([[$st_competition.'.status','<',2],[$st_competition.'.source',$this->source]])
- ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where($where)
- ->limit($limit_mt)
- ->get();
- if(!empty($data['match'])){
- $data['match'] = $data['match']->toarray();
- }
- //获取正在进行的和未开始联赛
- $data['league'] = lm($st_competition,"Sports")
- ->join($st_league,$st_league.'.lg_id',$st_competition.'.lg_id')
- ->select($st_league.'.lg_id',$st_league.'.name_chinese')
- ->where([[$st_competition.'.status','<',2],[$st_competition.'.source',$this->source]])
- ->where($st_competition.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where($where)
- ->limit($limit_lg)
- ->distinct($st_league.'lg_id')
- ->get();
- if (!empty($data['league'])) {
- $data['league'] = $data['league']->toarray();
- foreach($data['league'] as $k => $v){
- //统计当前联赛下的联赛
- $data['league'][$k]['count'] = lm($st_competition,'Sports')
- ->where([[$st_competition.'.status','<',2],[$st_competition.'.source',$this->source]])
- ->where('lg_id',$v['lg_id'])
- ->where($where)
- ->count('*');
- }
- }
- return $data;
- }
- /*
- * 获取首页体育信息数据接口
- */
- public function data(){
- $where = [];//球类额外条件
- $lq[] = $this->Sports_info('lq',$where);
- $wq[] = $this->Sports_info('wq',$where);
- $bq[] = $this->Sports_info('bq',$where);
- $zq[] = $this->Sports_info('zq',$where);
- $data = array_merge_recursive($zq,$lq,$bq,$wq);
- Render($data,'1', lang('Tips','Sports')->get('success'));
- }
- }
|