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

namespace app\admin\controller\bbfxshop\ddashboard;

use app\admin\controller\bbfxshop\Base;
use think\Db;


class Config extends Base
{

    public $model = null;

    
    public function set(){
        $params = $this->param();
        
        $config = Db::name("bbfx_ddashboard")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID,
            "status"=>$params['status'],
            "replace_home"=>$params['replace_home'],
            "title"=>$params['title'],
            "password"=>$params['password'],
            "avatar"=>replaceSiteroot($params['avatar']),
            "background1"=>replaceSiteroot($params['background1']),
            "background2"=>replaceSiteroot($params['background2']),
            "map_show_goods_unit"=>$params['map_show_goods_unit'],
        );
        
        if(!empty($params['password'])){
            // $data['password'] = md5($params['password']);
        }
        else{
            if(empty($config['password'])){
                // __error("请输入访问密码");
            }
        }
        
    	if(!empty($config)){
          	$res = Db::name("bbfx_ddashboard")->where(["id"=>$config['id']])->update($data);;
        }
      	else{
        	$res = Db::name("bbfx_ddashboard")->insert($data);
        }
        
        
        if($res){
            \app\admin\model\AdminLog::record("","",$data,"bbfx_ddashboard");
            __success("编辑成功",$data);
        }
      	else{
      	    __success("操作成功",$data);
      	}
    }
}