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

namespace app\admin\controller\bbfxshop\apabonus;

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_apabonus")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID,
      	    "status"=>intval($params['status']),
      	    "show_month_income"=>intval($params['show_month_income']),
      	    "jiesuan_day"=>intval($params['jiesuan_day']),
      	    "achievement_jisuan"=>intval($params['achievement_jisuan']),
      	    "remove_daqu"=>intval($params['remove_daqu']),
      	    "rule"=>iserializer($params['rule']),
        );
        // $rule = [['level'=>[],'user'=>[],'reward_rate'=>'']];
        // level：分红等级；user：分红用户；reward_rate：奖金比例
    	if(!empty($config)){
    	    $res = Db::name("bbfx_apabonus")->where(["id"=>$config['id']])->update($data);
        }
      	else{
        	$res = Db::name("bbfx_apabonus")->insert($data);
        }
        
        if($res){

            if($config['status'] == 0 && $data['status'] == 1){
                $data = array(
                    "uniacid"=>UNIACID,
                    "type"=>55,
                    "status"=>1,
                    "is_daozhang"=>1,
                    'extend'=>'apabonus_'.$data['achievement_jisuan'].'_',
                    "dztime"=>time(),
                    "createtime"=>time()
                );
                Db::name("bbfx_fenxiao_order")->insertGetId($data);
            }
            
            \app\admin\model\AdminLog::record("","",$data,"bbfx_apabonus");
            
            __success("编辑成功",$data);
        }
      	else{
      	    __success("操作成功",$data);
      	}
    }
}