<?php
/**
 * Created by PhpStorm.
 * User: Jonlin
 * Date: 2019/3/21
 * Time: 14:07
 */
namespace App\Sports\Controller;

use BaseController\Controller;
use \System\Model;

class RollingBall extends Controller{
    public function init() {
        $this->commonFunction =  C()->get('commonFunction');
    }

    /**
     * @throws \Exception
     * 首页足球滚球
     */
    public function zqrollingball(){
        $models = $this->commonFunction->getModels('zq',1);

        $model_result = $models['model_result'];
        $model_match = $models['model_match'];
        $model_league = $models['model_league'];

        //获取 滚球查询条件
        $where = $this->commonFunction->getState('StRollBall',$model_match);

        $result =lm($model_match,"Sports")
            ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
            ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
            ->select($model_match.'.match_id',$model_match.'.tag','match_date as start_date',$model_match.'.match_time as start_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time','match_process')
            ->where($model_match.'.source',$this->source['source'])
            ->where([[$model_league.'.name_chinese','!=','']])
            ->where($where)
            ->get()
            ->toarray();

        $data = [
            'game_code'=>'zq',
            'gameName'=>'足球',
            'matchData'=>$result
        ];

        return $data;
//        Render($data, '1', lang('Tips','Sports')->get('success'));

    }

    /**
     * @throws \Exception
     * 首页篮球滚球
     */
    public function lqrollingball(){
        $models = $this->commonFunction->getModels('lq',1);

        $model_result = $models['model_result'];
        $model_match = $models['model_match'];
        $model_league = $models['model_league'];
        //获取 滚球查询条件
        $where = $this->commonFunction->getState('StRollBall',$model_match);
        $result =lm($model_match,"Sports")
            ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
            ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
            ->select($model_match.'.match_id',$model_match.'.tag','match_date as start_date',$model_match.'.match_time as start_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time','match_process')
            ->where($model_match.'.source',$this->source['source'])
            ->where($where)
            ->where([[$model_league.'.name_chinese','!=','']])
            ->get()
            ->toarray();

        $data = [
            'game_code'=>'lq',
            'gameName'=>'篮球',
            'matchData'=>$result
        ];
        return $data;
//        Render($data, '1', lang('Tips','Sports')->get('success'));
    }

    public function wqrollingball(){
        $models = $this->commonFunction->getModels('wq',1);

        $model_result = $models['model_result'];
        $model_match = $models['model_match'];
        $model_league = $models['model_league'];
        //获取 滚球查询条件
        $where = $this->commonFunction->getState('StRollBall',$model_match);
        $result =lm($model_match,"Sports")
            ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
            ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
            ->select($model_match.'.match_id',$model_match.'.tag','match_date as start_date',$model_match.'.match_time as start_time','home_player_name','guest_player_name','first_inning_score','second_inning_score','third_inning_score',$model_result.'.match_time','match_process')
            ->where($model_match.'.source',$this->source['source'])
            ->where($where)
            ->where([[$model_league.'.name_chinese','!=','']])
            ->get()
            ->toarray();

        $data = [
            'game_code'=>'wq',
            'gameName'=>'网球',
            'matchData'=>$result
        ];
        return $data;
//        Render($data, '1', lang('Tips','Sports')->get('success'));
    }

    public function bqrollingball(){
        $models = $this->commonFunction->getModels('bq',1);

        $model_result = $models['model_result'];
        $model_match = $models['model_match'];
        $model_league = $models['model_league'];
        //获取 滚球查询条件
        $where = $this->commonFunction->getState('StRollBall',$model_match);
        $result =lm($model_match,"Sports")
            ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
            ->join($model_league,$model_league.'.lg_id',$model_match.'.lg_id')
            ->select($model_match.'.match_id',$model_match.'.tag','match_date as start_date',$model_match.'.match_time as start_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time','match_process')
            ->where($model_match.'.source',$this->source['source'])
            ->where($where)
            ->where([[$model_league.'.name_chinese','!=','']])
            ->get()
            ->toarray();

        $data = [
            'game_code'=>'bq',
            'gameName'=>'棒球',
            'matchData'=>$result
        ];
        return $data;
//        Render($data, '1', lang('Tips','Sports')->get('success'));

    }

    /**
     * 获取所有球类滚球
     */
    public function getRollingBall(){
        $zqRollingBall = $this->zqrollingball();
        $lqRollingBall = $this->lqrollingball();
        $wqRollingBall = $this->wqrollingball();
        $bqRollingBall = $this->bqrollingball();

        $data = [
            'zqData' =>$zqRollingBall,
            'lqData' =>$lqRollingBall,
            'wqData' =>$wqRollingBall,
            'bqData' =>$bqRollingBall,
        ];

        Render($data, '1', lang('Tips','Sports')->get('success'));
    }
}