<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use Think\Config;
/*
后台操作页面
*/
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://myucms.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Admin extends Common
{
    //后台分类首页
    public function cate_index()
    {
        return md5Qm();
    }
    //分类添加
    public function cate_add()
    {
        return view();
    }
    //分类编辑
    public function cate_edit()
    {
		$c=Db::name('cateAdmin')->find(input('id'));
        $this->assign('c',$c);
        return md5Qm();
    }
	//基本设置
    public function set()
    {
	    if (request()->isPost()) {
			//权限
            if (socha(user('tid'), 12) != 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_pay()
    {
        return md5Qm();
    }
    //其他配置
    public function set_qita()
    {
        return md5Qm();
    }
	//执行数据库
    public function sql()
    {
		if (request()->isPost()) {
			//权限
            if (socha(user('tid'), 13) != 1) {
                $this->error('权限不足');
            }
            $data = $this->request->post();
            $db_config = array();
            $db_config['prefix'] = Config::get('database.prefix');
            $sqldata = preg_replace("/<?php/", '', input('sql'));
            $sql_array = preg_split("/;[\r\n]+/", str_replace('my_',prefix(),$sqldata));
            foreach ($sql_array as $k => $v) {
                if (!empty($v)) {
                    Db::query($v);
                }
            }
            $this->success('执行成功');
		}
		return md5Qm();
    }
}