<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
/*
其他通用
*/
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021 http://mifenlei.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Com extends Common
{
	//前台导航
    public function link_index()
    {
        return md5Qm();
    }
	//友情链接
    public function link_youqing()
    {
        return md5Qm();
    }
	//添加编辑链接
    public function link_add()
    {
        $c=Db::name('link')->where(array('id' => get('id',0)))->find();
        $this->assign('c',$c);
        return md5Qm();
    }
	//会员
    public function member()
    {
    	$ks = input('ks');
    	$html = Db::name('member')->order('userid desc')->where('phone|username|userid', 'like', '%' . $ks . '%')->paginate(15, false, $config = ['query' => array('ks' => $ks)]);
		$this->assign('html', $html);
        return md5Qm();
    }
	//添加编辑会员
    public function member_add()
    {
		$c=Db::name('member')->where(array('userid' => input('id')))->find();
        $this->assign('c',$c);
        return md5Qm();
    }
	//文件管理
    public function file()
    {
		return md5Qm();
    }
    //验证码
    public function yanzhengma()
    {
		return md5Qm();
    }
    //单页管理
    public function dan()
    {
        return md5Qm();
    }
    //单页添加编辑
    public function dan_add()
    {
        $c=Db::name('dan')->where(array('id' => get('id',0)))->find();
        $this->assign('c',$c);
        return md5Qm();
    }
    // 主题模板
    public function muban()
    {
        return md5Qm();
    }
    // 广告管理
    public function ad()
    {
        return md5Qm();
    }
    // 广告编辑
    public function ads()
    {
        $c=Db::name('ad')->where(array('id' => get('id',0)))->find();
        $this->assign('c',$c);
        return md5Qm();
    }

    // 积分记录
    public function jifen()
    {
        return md5Qm();
    }
    // 实名认证
    public function sm()
    {
        $ks = input('ks');
        $html = Db::name('member')->order('sm_time desc')->where('sm_open > 0')->where('phone|username|userid|sm_name', 'like', '%' . $ks . '%')->paginate(15, false, $config = ['query' => array('ks' => $ks)]);
        $this->assign('html', $html);
        return md5Qm();
    }
    // 模板设置
    public function muban_config()
    {
        return view('template/'.input('id').'/admin.html');
    }
    // 消息记录
    public function xiaoxi()
    {
        return md5Qm();
    }
    // 创建模板
    public function muban_add()
    {
        if (socha(user('tid'), 21) != 1) {$this->error('无权限'); }
        if (request()->isPost()) {
            if(strpos(input('template')," ")){
                return json(array('code' => 0, 'msg' => '模板标识不能有空格'));
            }
            if (preg_match("/[\x7f-\xff]/", input('template'))) {
                return json(array('code' => 0, 'msg' => '模板标识不能有中文'));
            }
            $dir = iconv("UTF-8", "GBK", "template/".input('template'));
            if (file_exists($dir)){
                return json(array('code' => 0, 'msg' => '当前模板标识已存在'));
            }
            mkdir ($dir,0777,true);
            // 创建首页文件
            mkdir (iconv("UTF-8", "GBK", "template/".input('template').'/index'),0777,true);
            // 创建商家文件
            mkdir (iconv("UTF-8", "GBK", "template/".input('template').'/user'),0777,true);
            // 创建单页文件
            mkdir (iconv("UTF-8", "GBK", "template/".input('template').'/dan'),0777,true);
            // 创建样式扩展文件
            mkdir (iconv("UTF-8", "GBK", "template/".input('template').'/public'),0777,true);
            mkdir (iconv("UTF-8", "GBK", "template/".input('template').'/public/css'),0777,true);
            mkdir (iconv("UTF-8", "GBK", "template/".input('template').'/public/js'),0777,true);
            mkdir (iconv("UTF-8", "GBK", "template/".input('template').'/public/img'),0777,true);
            // 创建配置文件
            $txt = "<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2021 http://mifenlei.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: @梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
// 模板配置文
// +----------------------------------------------------------------------
return array(
    'title' => '".input('title')."',
    'template' => '".input('template')."',
    'banben' => '1.0',
    'author' => '".input('author')."',
    'pic' => '".dingyi(input('pic'),'/template/'.input('template').'/pic.jpg')."',
    'admin' => '".input('admin')."',
    'description' => '".dingyi(input('description'),'无任何介绍')."',
);";
            fwrite(fopen($dir.'/config.php', "w"), $txt);
            fclose($myfile);
            // 创建模板文件
            fwrite(fopen($dir.'/index/index.html', "w"), '首页页面 请参考默认模板的标签');
            fwrite(fopen($dir.'/index/list.html', "w"), '信息默认列表页面 请参考默认模板的标签');
            fwrite(fopen($dir.'/index/html.html', "w"), '信息默认内容页面 请参考默认模板的标签');
            fwrite(fopen($dir.'/index/info.html', "w"), '文章列表页面 请参考默认模板的标签');
            fwrite(fopen($dir.'/index/detail.html', "w"), '文章内容页面 请参考默认模板的标签');
            fwrite(fopen($dir.'/dan/index.html', "w"), '单页默认模板介绍 请参考默认模板的标签');
            fwrite(fopen($dir.'/index/shangjia.html', "w"), '商家列表 请参考默认模板的标签');
            fwrite(fopen($dir.'/index/business.html', "w"), '商家内容页面 请参考默认模板的标签');
            fwrite(fopen($dir.'/index/business_vip.html', "w"), 'VIP商家内容页面 请参考默认模板的标签');
            fwrite(fopen($dir.'/index/add.html', "w"), '添加发布页面 请参考默认模板的标签');
            if (input('admin')==1) {
                $admin = fopen($dir.'/admin.html', "w");
                fwrite($admin, '{include file="mifenlei/admin/view/header.html"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <!--表单提交-->
            <form class="layui-form" url="{:url("admin/api/muban",array("id"=>input("id")))}" t_url="javascript:;">
                 <div class="layui-form-item">
                    <label class="layui-form-label">示例开关</label>
                    <div class="layui-input-block">
                        <input type="radio" name="open" value="1" title="开" {if mi("reg")==1}checked="选择"{/if}>
                        <input type="radio" name="open" value="0" title="关" {if mi("reg")==0}checked="选择"{/if}>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="cms">立即提交</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{include file="mifenlei/admin/view/footer.html"} ');
                fclose($admin);
            }
            return json(array('code' => 1, 'msg' => '创建成功'));
		}
        return md5Qm();
    }

}
