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

namespace app\admin\controller\bbfxshop\ddashboard;

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


class Ddashboard extends Base
{
    protected $noNeedLogin = ['index','checkPassword'];
    protected $noNeedRight = ['index'];
    protected $ddashboard_xkey = "";

    public function _initialize(){
        parent::_initialize();
        $this->ddashboard_xkey = "ddashboard_check_password_".UNIACID;
    }

    public function index(){

        $check_password = Session::get($this->ddashboard_xkey);
        $password = Db::name("bbfx_ddashboard")->where(["uniacid"=>UNIACID])->value("password");
        if(!empty($password) && $check_password != $password){
            __error(-10,"请先验证访问密码后才能查看");
        }
        
        $result = \app\common\model\bbfxshop\Ddashboard::tongji();
        
        __success('操作成功',$result);
    }

    public function checkPassword(){
        $params = $this->param();
        if(empty($params['password'])){
            __error("请输入访问密码");
        }
        $password = Db::name("bbfx_ddashboard")->where(["uniacid"=>UNIACID])->value("password");
        if($password != $params['password']){
            __error("访问密码错误");
        }
        Session::set($this->ddashboard_xkey,$password);
        __success("操作成功");
    }

}