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

namespace app\admin\controller\bbfxshop\sabonus;

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\Sabonus;
    }
    
    public function set(){
        $params = $this->param();
        
        $config = Db::name("bbfx_sabonus")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID, 
            "status"=>intval($params['status']),
            "calculate_order_status"=>intval($params['calculate_order_status']),
            "abonus_reward"=>intval($params['abonus_reward']),
            "abonus_day"=>intval($params['abonus_day']),
            "calculate_mode"=>intval($params['calculate_mode']),
            "part_calculate"=>intval($params['part_calculate']),
            "abonus_cycle"=>intval($params['abonus_cycle']),
            "reward_source"=>intval($params['reward_source']),
            "part_source"=>intval($params['part_source']),
            "zhitui_order"=>intval($params['zhitui_order']),
            "abonus_money"=>round($params['abonus_money'],2),
            "abonus_levels"=>iserializer($params['abonus_levels'])
        );
        
    	if(!empty($config)){
          	$res = Db::name("bbfx_sabonus")->where(["id"=>$config['id']])->update($data);
        }
      	else{
        	$res = Db::name("bbfx_sabonus")->insert($data);
        }
        
        if($res){
            \app\admin\model\AdminLog::record("","",$data,"bbfx_sabonus");
            __success("编辑成功",$data);
        }
      	else{
      	    __success("操作成功",$data);
      	}
    }
}