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

namespace app\admin\controller\bbfxshop\repurchase_jiandan;

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\RepurchaseJiandan;
    }
    
    public function set(){
        $params = $this->param();
        
        $config = Db::name("bbfx_repurchase_jiandan")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID,
            "status"=>intval($params['status']),
            "mode"=>intval($params['mode']),
            "slip_method"=>intval($params['slip_method']),
            "layer"=>intval($params['layer']),
            "type"=>intval($params['type']),
            "repurchase_goods"=>trim($params['repurchase_goods']),
        );
        
        if($data['layer'] <= 0){
            $data['layer'] = 12;
        }
        
    	if(!empty($config)){
          	$res = Db::name("bbfx_repurchase_jiandan")->where(["id"=>$config['id']])->update($data);;
        }
      	else{
        	$res = Db::name("bbfx_repurchase_jiandan")->insert($data);
        }
         
        if($res){

            if($data['status'] == 1){
                Db::name("bbfx_pyramid")->where(["uniacid"=>UNIACID])->update(['status'=>0]);
                Db::name("bbfx_fenxiao")->where(["uniacid"=>UNIACID])->update(['transfer_mode'=>0,'yies_mode'=>0]);
                Db::name("bbfx_double_track")->where(["uniacid"=>UNIACID])->update(['status'=>0]);
            }
            
            \app\admin\model\AdminLog::record("","",$data,"bbfx_repurchase_jiandan");
            __success("编辑成功",$data);
        }
      	else{
      	    __success("操作成功",$data);
      	}
    }
}