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

namespace app\admin\controller\bbfxshop\management;

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


class Config extends Base
{

    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\Management;
    }
    
    public function set(){
        $params = $this->param();
        
        $config = Db::name("bbfx_management")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID,
            "status"=>intval($params['status']),
            "is_management_assistant_reward"=>intval($params['is_management_assistant_reward']),
            "management_type"=>intval($params['management_type']),
            "show_month_commission"=>intval($params['show_month_commission']),
            "management_jisuan"=>intval($params['management_jisuan']), 
            "management_remove_daqu"=>intval($params['management_remove_daqu']), 
            "management_jiesuan_day"=>max(1,intval($params['management_jiesuan_day'])), 
            "repurchase_xd_calculate"=>intval($params['repurchase_xd_calculate']), 
            "relationship_type"=>intval($params['relationship_type']), 
            "year_month_jisuan"=>intval($params['year_month_jisuan']), 
      	    "management_reward"=>iserializer($params['management_reward']), 
        );
        
    	if(!empty($config)){
          	$res = Db::name("bbfx_management")->where(["id"=>$config['id']])->update($data);;
        }
      	else{
        	$res = Db::name("bbfx_management")->insert($data);
        }
        
        
        if($res){
            \app\admin\model\AdminLog::record("","",$data,"bbfx_management");
            __success("编辑成功",$data);
        }
      	else{
      	    __success("操作成功",$data);
      	}
    }
}