<?php
namespace App\Sports\Model;

use \System\Model;

/**
 * Class Account
 * @package App\Sports\Model
 * 用户账号
 */
class St_zq_competition extends Model
{

    protected $table = 'st_zq_competition';

    /**
     * @param array $where 条件
     * @param string $select 字段
     * @param string $sort 排序字段
     * @param string $orderby 排序方式
     * @return mixed
     * 获取赛事数据
     */
    public static function getMatchData($where=[],$select='id',$sort='id',$orderby='asc'){
        $matchData = self::select($select)->where($where)->orderBy($sort,$orderby)->get();
        return $matchData;
    }

    //获取各球类 滚球赛事关联赛事结果数据
    public static function getRollMatchDataAll($source,$models,$where,$lg_ids=[]){
        $model_match = $models['model_match'];
        $model_result = $models['model_result'];

        $select = [$model_match.'.lg_id',$model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time as a_time','match_process'];
        if($model_result == 'st_wq_result'){
            $select = [$model_match.'.lg_id',$model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team','home_player_score','guest_player_score',$model_result.'.match_time as a_time','match_process'];
        }
        $data = lm($model_match,"Sports")
            ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
//            ->select($model_match.'.lg_id',$model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time as a_time','match_process')
            ->select($select)
            ->where($model_match.'.source',$source['source'])
            ->whereIn($model_match.'.lg_id',$lg_ids)
            ->where($where)
            ->get()
            ->toarray();

        return $data;
    }

    //获取各球类 非滚球赛事关联赛事结果数据
    public static function getSoonMatchDataAll($source,$models,$where,$lg_ids=[]){
        $model_match = $models['model_match'];

        $data = lm($model_match,"Sports")
            ->select($model_match.'.lg_id',$model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team',$model_match.'.us_time')
            ->where($source)
            ->where($where)
            ->whereIn($model_match.'.lg_id',$lg_ids)
            ->orderBy('match_time','asc')
            ->get()
            ->toarray();

        return $data;
    }


}