<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use Think\Config;
/*
后台操作页面
*/
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021 http://mifenlei.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Admin extends Common
{
    //后台分类首页
    public function cate_index()
    {
        return md5Qm();
    }
    //分类添加编辑
    public function cate_add()
    {
        $c=Db::name('cateAdmin')->where(array('id' => get('id',0)))->find();
        $this->assign('c',$c);
        return view();
    }
	//基本设置
    public function set()
    {
	    if (request()->isPost()) {
			if (socha(user('tid'), 1) != 1) {$this->error('无权限'); }
            $data = $this->request->param();
            $id = $data['id'];
            $config = $data['config'];
            $flag = Db::name('set')->where(array('id'=>$id))->setField('config', json_encode($config));
            if ($flag !== false) {
                return json(array('code' => 1, 'msg' => '保存配置成功'));
            } else {
                return json(array('code' => 0, 'msg' => '保存配置失败'));
            }
		}
        return md5Qm();
    }
    //添加设置项目
    public function set_add()
    {
        return md5Qm();
    }
    // 配置添加修改
    public function set_config()
    {
        $c=Db::name('set_config')->find(get('or',0));
        $this->assign('c',$c);
        return md5Qm();
    }
	//执行数据库
    public function sql()
    {
		if (request()->isPost()) {
			$this->error(config('web.sq')); 
		}
		return md5Qm();
    }
    //其他设置配置
    public function set_s()
    {
	    if (request()->isPost()) {
            $config = $this->request->post();
            $url = 'mifenlei/extra/'.get('model','set').'.txt';
            $str = json_encode($config);
            if (file_put_contents($url, $str)) {
                return json(array('code' => 1, 'msg' => '保存成功'));
            } else {
                return json(array('code' => 0, 'msg' => '请检查/mifenlei/extra/是否有写入权限'));
            }
		}
        return md5Qm();
    }
    public function qiandao()
    {
        if (request()->isPost()) {
            $this->error(config('web.sq')); 
        }
        return md5Qm();
    }
}