<?php
/*
 本代码由 焕岱科技 创建
 技术支持 WX：15285007200
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace app\admin\controller\bbfxshop\aabonus;

use app\admin\controller\bbfxshop\Base;
use think\Db;


class Config extends Base
{

    public $model = null;
    
    public function set(){
        $params = $this->param();
        
        $config = Db::name("bbfx_aabonus")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID,
      	    "status"=>intval($params['status']),
      	    "reward_rate"=>max(0,floatval($params['reward_rate'])),
      	    "rule"=>iserializer($params['rule']),
      	    "jiesuan_date"=>intval($params['jiesuan_date']),
      	    "jiesuan_confirm"=>intval($params['jiesuan_confirm']),
      	    "jiesuan_confirm_user"=>trim($params['jiesuan_confirm_user']),
        );

        if($data['reward_rate'] > 100){
            __error("奖金比例不得大于100%");
        }
        if($data['jiesuan_confirm'] == 1 && empty($data['jiesuan_confirm_user'])){
            __error("请选择发放确认用户");
        }   
        
    	if(!empty($config)){
    	    $res = Db::name("bbfx_aabonus")->where(["id"=>$config['id']])->update($data);
        }
      	else{
        	$res = Db::name("bbfx_aabonus")->insert($data);
        }
        
        if($res){
            
            \app\admin\model\AdminLog::record("","",$data,"bbfx_aabonus");
            
            __success("编辑成功",$data);
        }
      	else{
      	    __success("操作成功",$data);
      	}
    }
}