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

	protected $table = "settlement_ratio";
	public $timestamps = false;
	//获取代理金额设置
    function getRatio(){
        $data=$this->get();
        if(!$data){
            return -8005144322;
        }
        return $data->toArray();
    }
    //更新比例
    function updateRatio($ratio,$grade){
        $res=$this->where('grade',$grade)->update(['ratio'=>$ratio]);
        if(!$res){
            return -8005344322;
        }
        return 1;
    }

    function getRatioArray(){
        $data=$this->getRatio();
        if($data<0){
            return $data;
        }
        foreach ($data as $v){
            $arr[$v['grade']]=$v['ratio'];
        }
        return $arr;
    }
    //获取对应等级的提成比例
    function getGradeRatio($grade){
        $data=$this->where('grade',$grade)->first();
        if(!$data){
            return -8050466322;
        }
        return $data->toArray();

    }
}
