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

    protected $table="egame_type";
    public $timestamps = false;
    //获取游戏列表
    function getGameList(){
        $data=$this->select('id','name','game_name as gameCode')->where('game_name','!=',-1)->orderBy('hot','desc')->get();
        if(!$data){
            return -5040000522;//没有数据
        }
        return $data->toArray();
    }

    //获取游戏玩法列表
    function getDescList($list){
        $data=$this->select('id','name','gaem_name')->where('gaem_name','!=',-1)->paginate($list);
        if(!$data){
            return -5040000622;//没有数据
        }
        return $data->toArray();
    }

    //获取游戏关闭开启状态
    function getGameStatus($list=10,$where=''){
        $data=$this->where('game_name','!=',-1);
        if(!empty($where)&&is_array($where)){
            $data = $data->where($where);
        }
        $data = $data->paginate($list);
        if(!$data){
            return -5040000422;//没有数据
        }
        return $data->toArray();
    }

    //一条关闭信息
    function getCloseOne($game){
        $data=$this->where('id',$game)->first();
        if(!$data){
            return -5040000622;
        }
        return $data->toArray();
    }

    //更新关闭信息
    function updateOne($data,$id){
        $res=$this->where('id',$id)->update($data);
        if(!$res){
            return -5040000122;
        }
        return 1;
    }

    //检测游戏名字
    function checkCopyGame($name,$game_name){
        $data=$this->where('name',$name)->orWhere('game_name',$game_name)->first();
        if(!$data){
            return 1;
        }
        return 5040451122;
    }

    //添加
    function addGame($data){
        $data['identity']=UUID();
        $data['created']=date('Y-m-d');
        $res=$this->insert($data);
        if(!$res){
            return -5040001122;
        }
    }

    //关闭游戏
    function closeGame($data,$game){
        $res=$this->where('game_name',$game)->update($data);
        if(!$res){
            return -5040000122;
        }
        return 1;
    }

}