<?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()
    {
		return json(array('code' => 0, 'msg' => config('web.mifenlei')));
		return md5Qm();
    }
    //其他设置配置
    public function set_qita()
    {
	    if (request()->isPost()) {
	        if (socha(user('tid'), 1) != 1) {$this->error('无权限'); }
            $url = 'mifenlei/extra/'.get('model','qita').'.php';
            $info = (include $url);
            $config = array();
            $config = $this->request->post();
            $config = preg_replace("/\\[|\\]|'|\\<\\?php|\\?\\>|embed|data:|iframe|code/i", '', $config);
            $res = array_merge($info, $config);
            $str = '<?php return [';
            foreach ($res as $key => $value) {
                $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ',';
            }
            $str .= ']; ';
            if (file_put_contents($url, $str)) {
                return json(array('code' => 1, 'msg' => '修改成功'));
            } else {
                return json(array('code' => 0, 'msg' => '修改失败'));
            }
        }
        return view('mifenlei/admin/view/admin/'.get('id','qita').'.html');
    }
    public function qiandao()
    {
        if (request()->isPost()) {
            $_data['days'] = 0;
            if (!Db::name(ps('qiandaos'))->strict(false)->data($_data)->insert()) {
                $this->error('添加失败');
            } else {
                $this->success('添加成功');
            }
        }
        return md5Qm();
    }
}