<?php
namespace App\Models;
use DB;
class TypeName extends BaseModel {

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

	protected function getList($where='',$limit=20){
        $data=$this->orderBy('sort','desc');
        if(is_array($where)&&count($where)>0){
            $data=$data->where($where);
        }
        $data=$data->paginate($limit);

        return $data->toArray();
    }

    protected function getAllType(){
        $data=$this->orderBy('id','desc')->get();
        if(!$data){
            return array();
        }
        return $data->toArray();
    }

    protected function addGroup($data){
	    // if(($res=$this->checkCode($data['name'],$data['name'])) < 0 ){
     //            return $res;
     //    }
     //    if(!isset($data['create_at'])){
     //        $data['create_at']=date('Y-m-d H:i:s');
     //    }
 
        $resd=$this->insert($data);
        if(!$resd){
            return -240002;
        }
        return 1;
    }
    //检测重复
    protected function checkCode($code,$name){
        $res=$this->where('group_code',$code)->orWhere('group_name',$name)->first();
        if($res){
            return -240001;
        }
        return 1;

    }

    protected function getGroups($ids){
        $data=$this->whereIn('id',$ids)->get();
        if(!$data){
            return -240004;
        }
        return $data->toArray();
    }

    protected function getInfoById($id){
        $data=$this->where('id',$id)->first();
        if(!$data){
            return -240001;
        }
        return $data->toArray();
    }

    

}
