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

namespace app\admin\controller\bbfxshop\fenxiao;

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\Fenxiao;
    }
    
    public function set(){
        $params = $this->param();
        
        $fenxiao = Db::name("bbfx_fenxiao")->where(["uniacid"=>UNIACID])->find();
          
        $data = array(
            "uniacid"=>UNIACID,
      	    "status"=>intval($params['status']),
      	    "up_condition_mode"=>intval($params['up_condition_mode']),
      	    "is_becomedue"=>intval($params['is_becomedue']),
      	    "is_mergelevel"=>intval($params['is_mergelevel']),
      	    "level"=>intval($params['level']),
      	    "level_jicha"=>intval($params['level_jicha']),
      	    "ordinary_user_share"=>intval($params['ordinary_user_share']),
      	    "is_selfbuy"=>intval($params['is_selfbuy']),
      	    "up_method"=>intval($params['up_method']),
      	    "is_rebind"=>intval($params['is_rebind']),
      	    "rebind_day"=>intval($params['rebind_day']),
      	    "fenzhang_status"=>intval($params['fenzhang_status']),
      	    "commission_received_type"=>intval($params['commission_received_type']),
      	    "withdrawal_wxtype"=>intval($params['withdrawal_wxtype']),
      	    "withdrawal_type"=>iserializer($params['withdrawal_type']),
      	    "up_type"=>iserializer($params['up_type']),
      	    "dand_up"=>intval($params['dand_up']),
      	    // "become_agent"=>intval($params['become_agent']),
      	    "become_order_type"=>intval($params['become_order_type']),
      	    // "become_card"=>intval($params['become_card']),
      	    // "become_goods"=>trim($params['become_goods']),
      	    // "become_purchase_money"=>floatval($params['become_purchase_money']),
      	    // "become_cz_balance"=>floatval($params['become_cz_balance']),
      	    // "become_team_achievement"=>intval($params['become_team_achievement']),
      	    "withdrawal_limit"=>floatval($params['withdrawal_limit']),
      	    "max_withdrawal"=>floatval($params['max_withdrawal']),
      	    "withdrawal_balance_check"=>intval($params['withdrawal_balance_check']),
      	    "withdrawal_balance_score_free"=>intval($params['withdrawal_balance_score_free']),
      	    "withdrawal_integer_multiple"=>intval($params['withdrawal_integer_multiple']),
      	    "service_charge"=>floatval($params['service_charge']),
      	    // "texts"=>iserializer($params['texts']),
      	    "calculate_type"=>intval($params['calculate_type']),
      	    "settlement_type"=>intval($params['settlement_type']),
      	    "selfbuy_achievement"=>intval($params['selfbuy_achievement']),
      	    "user_shenhe_apply"=>intval($params['user_shenhe_apply']),
      	    "bank"=>$params['bank'],
      	    "is_withdrawal_limit"=>intval($params['is_withdrawal_limit']),
      	    "withdrawal_limit_amount"=>intval($params['withdrawal_limit_amount']),
      	    "withdrawal_unlimit_order"=>intval($params['withdrawal_unlimit_order']),
      	    "withdrawal_unlimit_buygoods"=>trim($params['withdrawal_unlimit_buygoods']),
      	    "settlement_score"=>intval($params['settlement_score']),
      	    "settlement_score_rate"=>intval($params['settlement_score_rate']),
      	    "sup_user_buyorder"=>intval($params['sup_user_buyorder']),
      	    "score_achievement"=>intval($params['score_achievement']),
      	    "sup_uid_show"=>intval($params['sup_uid_show']),
      	    "team_tongji"=>intval($params['team_tongji']),
      	    "achievement_jisuan"=>intval($params['achievement_jisuan']),
      	    "is_hide_team_mobile"=>intval($params['is_hide_team_mobile']),
        );
        
        if($data['is_rebind'] == 1 && $data['rebind_day'] < 0){
            __error("请输入多少天未消费解除绑定关系");
        }
        
        $fenzhang_rate = intval($params['fenzhang_rate']);
        if($data['fenzhang_status'] == 1){
            if($fenzhang_rate > 30){
                __error("分账比例最大不超过30%");
            }
            if($fenzhang_rate <= 0){
                __error("请输入分账比例");
            }
            $data['fenzhang_rate'] = $fenzhang_rate;
        }
        
    	if(!empty($fenxiao)){
            $res = Db::name("bbfx_fenxiao")->where(["id"=>$fenxiao['id']])->update($data);
        }
      	else{
            $res = Db::name("bbfx_fenxiao")->insert($data);
        }
        
        if($res){
            
            \app\admin\model\AdminLog::record("","",$data,'bbfx_fenxiao');

			if($data['achievement_jisuan'] == 1 && $fenxiao['achievement_jisuan'] == 0){
				\app\common\model\bbfxshop\User::initOriginalSupPath();
			}
            
            __success("编辑成功",$data);
        }  
      	else{ 
      	    __success("操作成功",$data);
      	}
    }
    
	public function withdrawalSet(){
		$params = $this->param();
        
        $fenxiao = Db::name("bbfx_fenxiao")->where(["uniacid"=>UNIACID])->find();

		$data = array(
      	    "withdrawal_wxtype"=>intval($params['withdrawal_wxtype']),
      	    "withdrawal_type"=>iserializer($params['withdrawal_type']),
      	    "withdrawal_limit"=>floatval($params['withdrawal_limit']),
      	    "max_withdrawal"=>floatval($params['max_withdrawal']),
      	    "withdrawal_balance_check"=>intval($params['withdrawal_balance_check']),
      	    "withdrawal_balance_score_free"=>intval($params['withdrawal_balance_score_free']),
      	    "withdrawal_integer_multiple"=>intval($params['withdrawal_integer_multiple']),
      	    "service_charge"=>floatval($params['service_charge']),
      	    "fixed_service_charge"=>floatval($params['fixed_service_charge']),
      	    "bank"=>$params['bank'],
      	    "is_withdrawal_limit"=>intval($params['is_withdrawal_limit']),
      	    "withdrawal_limit_amount"=>intval($params['withdrawal_limit_amount']),
      	    "withdrawal_unlimit_order"=>intval($params['withdrawal_unlimit_order']),
      	    "withdrawal_unlimit_buygoods"=>trim($params['withdrawal_unlimit_buygoods']),
			"wexin_tx_check"=>$params['wexin_tx_check'],
			"wexin_tx_check_max"=>$params['wexin_tx_check_max'],
			"tx_date_limit"=>iserializer($params['tx_date_limit'])
        );

		$data['tx_tip'] = htmlspecialchars_decode($this->param('tx_tip/h'));

		if(!empty($fenxiao)){
            $res = Db::name("bbfx_fenxiao")->where(["id"=>$fenxiao['id']])->update($data);
        }
      	else{
            $res = Db::name("bbfx_fenxiao")->insert($data);
        }

		if($res){
            
            \app\admin\model\AdminLog::record("","",$data,'bbfx_fenxiao');
            
            __success("编辑成功",$data);
        }
      	else{
      	    __success("操作成功",$data);
      	}
	}

	public function setUpconditionmodeSignResult(){
		$status = $this->param("status/d");
		if(!in_array($status,[1,2])){
			__error("请选择同意或者拒绝");
		}
		$data = ['up_condition_mode_sign_result'=>$status];
		if($status == 1){
			$content = "已阅读并同意重要法律风险警示，操作账号：".$this->auth->username;
		}
		else{
			$content = "已阅读并拒绝重要法律风险警示，操作账号：".$this->auth->username;
		}

		Db::name("bbfx_fenxiao")->where(["uniacid"=>UNIACID])->update($data);
		
		\app\admin\model\AdminLog::record("阅读风险警示",$content,$data,'bbfx_fenxiao');

		__success("操作成功");
	}
}