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

namespace app\admin\controller\bbfxshop\sverify;

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\Sverify;
    }
    
    public function set(){
        $params = $this->param();
        
        $config = Db::name("bbfx_sverify")->where(["uniacid"=>UNIACID])->find();
        
        $data = array(
            "uniacid"=>UNIACID,
            "status"=>$params['status'],
            "wxapp_qrcode"=>$params['wxapp_qrcode'],
            // "query_success_image"=>replaceSiteroot($params['query_success_image']),
            // "query_fail_image"=>replaceSiteroot($params['query_fail_image'])
        );
        
    	if(!empty($config)){
          	$res = Db::name("bbfx_sverify")->where(["id"=>$config['id']])->update($data);;
        }
      	else{
        	$res = Db::name("bbfx_sverify")->insert($data);
        }
        
        if(!empty($params['sverify_file'])){
            $fileinfo = Db::name("attachment")->where(['url'=>$params['sverify_file']])->find();
            if(!empty($fileinfo)){
                $filepath = ROOT_PATH."public/sverify/".$fileinfo['filename'];
                if (!file_exists($filepath)) {
                    $sverify_file_value = file_get_contents(ROOT_PATH."public".$params['sverify_file']);
                    file_put_contents($filepath,$sverify_file_value);
                }
            }
        }
        
        \app\admin\model\AdminLog::record("","",$data,"bbfx_sverify");
        __success("编辑成功",$data);
    }
    
}