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

	protected $table = "game_playtype_money";
	public $timestamps = false;
	
    //获取游戏限额信息
    protected function getList($list=20,$fild='id',$order='desc',$where=''){
        $data=$this->orderBy($fild,$order);
        if(!empty($where)&&is_array($where)){
            $data = $data->where($where);
        }
        $data = $data->paginate($list);
        if(!$data){
            return -50610000102;//没有相关数据
        }
        return $data->toArray();
    }
	
	//添加六合彩投注限额信息
	protected function addInfo($data,$where) {
        //DB::connection()->enableQueryLog();
        //验证记录是否已存在
        $hasinfo = $this->where($where)->first();
        //$queries = DB::getQueryLog();
        //print_r($queries);
        if(!$hasinfo||empty($hasinfo)){//添加
            $this->identity = UUID();
            $this->game_type = $data['game_type'];
            $this->big_money = $data['big_money'];
            $this->small_money = $data['small_money'];
            $this->grade = $data['grade'];
            $this->oneoption_bigmoney = $data['oneoption_bigmoney'];
            $this->play_type = $data['play_type'];
            $res = $this->save();
            if (!$res) {
                return -50610000602; //添加失败
            }
        }else{//修改
            return -50610001202;
            /*$res = $this->updateInfo($data,$hasinfo['identity']);
            if($res<0){
                return -50610000802; //添加失败
            }*/
        }
		
		return 1;
	}

    //修改投注限额信息
    protected function updateInfo($data,$identity){
        $data=$this->where('identity',$identity)->update($data);
        if(!$data){
            return -50610000702;//更新失败
        }
        return 1;
    }

	
    //获取一条数据
    protected function getOne($identity){
        $data=$this->select('game_playtype_money.id', 'game_playtype_money.grade', 'dc_user_grade.name', 'game_type', 'big_money', 'small_money', 'identity', 'commission_money', 'commission_rate', 'oneoption_bigmoney', 'play_type', 'user_identity','username')->join('dc_user_grade', 'game_playtype_money.grade', '=', 'dc_user_grade.grade')->where('identity',$identity)->first();
        if(!$data){
             $data=$this->where('identity',$identity)->first();
             if(!$data){
                return -50610001002;//没有相关数据
             }
            
        }
        return $data->toArray();
    }
	
    //删除一条投注限额
    protected function deletePlaymoney($identity){
        $data=$this->where('identity',$identity)->delete();
        if(!$data){
            return -50610001102;//删除失败
        }
        return 1;
    }
}
