<?php
namespace App\Models;

class GameCategory extends BaseModel
{
    protected $table="game_category";
    public $timestamps = false;

    function getGameCategoryList($list=10)
    {
        $data = $this->select('id','name','codes','sort','is_show')->orderBy('sort','desc')->paginate($list);
        if(!$data){
            return -5040000522;//没有数据
        }
        $data  = $data->toArray();
        $show = trans ('category.show');
        foreach ($data['data'] as $key => $val)
        {
            $data['data'][$key]['is_show'] =  $show[$val['is_show']];
        }
        return $data;
    }
    function getCateOne($id){
        $data=$this->where('id',$id)->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 checkCopyCate($name)
    {
        $data=$this->where('name',$name)->first();
        if(!$data){
            return 1;
        }
        return -5040451122;
    }
    //检测分类代码是否存在
    function checkCopyCateCode($code)
    {
        $data=$this->where('codes',$code)->first();
        if(!$data){
            return 1;
        }
        return -5040451122;
    }

    function addCate($data)
    {
        $res=$this->insert($data);
        if(!$res){
            return -5040001122;
        }
    }
    function getAll()
    {
        $data = $this->select('id','name')->orderBy('id','asc')->get()->toArray();
        if(!$data){
            return $data = [ '暂无分类' ]; //没有数据
        }
        return $data;
    }
}