<?php
namespace App\Models;
class Egame extends BaseModel {

	protected $table = "game_egame";
	public $timestamps = false;

	//获取场次信息
    protected function getInfoList($where,$list=10){
        $data=$this->orderBy('id','desc');
        if(is_array($where)&&count($where)>0){
            $data=$data->where($where);
        }
        $data=$data->paginate($list);
        return $data->toArray();
    }
    //获取该期详情
    protected function getDetail($info_no){
        $data=$this
            ->join('egame_info','egame_info.info_no',$this->table.'.info_no')
            ->where($this->table.'.info_no',$info_no)
            ->first();
        if(!$data){
            return -9040410022;
        }
        return $data->toArray();
    }
    //加入新的一期
    protected function addNew($data){
        if(!isset($data['identity'])){
            $data['identity']=UUID();
        }
        if(!isset($data['info_identity'])){
            $data['info_identity']=UUID();
        }
        $res=$this->insert($data);
        if(!$res){
            return -9050020022;
        }
        return 1;
    }
    //检测是都重复的期号
    protected function checkNo($info_no){
        $data=$this->where('info_no',$info_no)->first();
        if(!$data){
            return 1;
        }
        return -9020040322;
    }
    //获取最新赛事的id
    protected function getNowMatch($game){
        $data=$this->where('game_name',$game)->orderBy('id','desc')->first();
        if(!$data){
            return -9040450022;//没有
        }
        return $data->toArray();
    }


}
