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

namespace app\admin\controller\bbfxshop\luckywheel;

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\Luckywheel;
    }
    
    public function set(){
        $params = $this->param();
        
        $config = Db::name("bbfx_luckywheel")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID,
            "status"=>intval($params['status']),
            "lottery_obtain"=>trim(implode(',',$params['lottery_obtain'])),
            "lottery_method"=>trim(implode(',',$params['lottery_method'])),
            "lottery_score"=>intval($params['lottery_score']),
            "lottery_obtain_rule"=>iserializer($params['lottery_obtain_rule']),
            "lottery_rule"=>htmlspecialchars_decode($this->param("lottery_rule/h")),
            "bg"=>replaceSiteroot($params['bg']),
            "yp_bg"=>replaceSiteroot($params['yp_bg']),
            "title_image"=>replaceSiteroot($params['title_image']),
            "pointer_image"=>replaceSiteroot($params['pointer_image']),
            "lottery_btn_image"=>replaceSiteroot($params['lottery_btn_image']),
            "record_btn_image"=>replaceSiteroot($params['record_btn_image']),
            "rule_btn_image"=>replaceSiteroot($params['rule_btn_image']),
            "popup_image"=>replaceSiteroot($params['popup_image']),
        );
         
    	if(!empty($config)){
          	$res = Db::name("bbfx_luckywheel")->where(["id"=>$config['id']])->update($data);;
        }
      	else{
        	$res = Db::name("bbfx_luckywheel")->insert($data);
        }
        
        
        if($res){
            \app\admin\model\AdminLog::record("","",$data,"bbfx_luckywheel");
            __success("编辑成功",$data);
        }
      	else{
      	    __success("操作成功",$data);
      	}
    }
}