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

namespace app\admin\controller\bbfxshop\cumulative_fanhuan;

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\CumulativeFanhuan;
    }
    
    public function set(){
        $params = $this->param();
        $config = Db::name("bbfx_cumulative_fanhuan")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID,
      	    "status"=>intval($params['status']),
      	    "fanhuan_total"=>intval($params['fanhuan_total']),
      	    "everyday_rate"=>floatval($params['everyday_rate']),
      	    "fanhuan_score_total"=>intval($params['fanhuan_score_total']),
      	    "everyday_score_rate"=>floatval($params['everyday_score_rate']),
      	    "settlement_currency"=>intval($params['settlement_currency']),
      	    "decimal_type"=>intval($params['decimal_type']), 
      	    "release_method"=>intval($params['release_method']),
      	    "settlement_status"=>intval($params['settlement_status']),
      	    "is_accelerate"=>intval($params['is_accelerate']),
      	    "switch_duration"=>intval($params['switch_duration']),
      	    "sign_release"=>intval($params['sign_release']),
      	    "rule_detailed"=>intval($params['rule_detailed']),
            "rule_content"=>iserializer($params['rule_content']),
            "accelerate_rule"=>iserializer($params['accelerate_rule']),
            "share_reward"=>iserializer($params['share_reward'])
        );
        
    	if(!empty($config)){
          	$res = Db::name("bbfx_cumulative_fanhuan")->where(["id"=>$config['id']])->update($data);
        }
      	else{
      	    $data['return_date'] = date("Y-m-d");
        	$res = Db::name("bbfx_cumulative_fanhuan")->insert($data);
        }
        
        if($res){
            if($config['status'] == 0 && $data['status'] == 1){
                Db::name("bbfx_cumulative_fanhuan_user")->where(['uniacid'=>UNIACID])->update(["sdate"=>date("Y-m-d")]);
            }
        }
        
        \app\admin\model\AdminLog::record("","",$data,"bbfx_cumulative_fanhuan");
        
        __success("编辑成功",$data);
    }
}