<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Config as ConfigModel;

class Config extends Base
{
    public function index()
    {
        // 判断权限
        // if(!checkAuth()){
        //     echo "<script>parent.window.location.href='/admin/index/index';</script>";
        //     exit;
        // }
        $configList = ConfigModel::column('varname,value');
        $this->assign('site',$configList);
        return view();
    }

    public function edit($id = 0, $requireField = '', $requireFieldName = '') {
        if(request()->isPost()){
            // 判断权限
            // if(!checkAuth()){
            //     return error('您没有相应的操作权限!');
            // }
            $config = new ConfigModel;
            if($config->saveConfig(input('post.'))){
                return success('配置更新成功!',url('index',['tab'=>1]));
            }else{
                return error('配置更新失败!');
            }
        }
    }
}
