<?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 Index extends Common
{
    //后台首页
    public function index()
    {
        return md5Qm();
    }
    //框架结构页
    public function admin()
    {
    	$this->assign('caxun',''.ps('my',g_p()).'caxun.html?alias=mi');
    	$this->assign('shengji',''.ps('my',g_p()).'xz.html?alias=mi&www='.$_SERVER['HTTP_HOST'].'&key='.MIFENLEI.'&bb='.config('web.banben').'');
    	$this->assign('tan',''.ps('my',g_p()).'tan.html?www='.$_SERVER['HTTP_HOST'].'');
        return md5Qm();
    }
    //框架结构页
    public function login()
    {
        return md5Qm();
    }
    //升级
    public function sj()
    { 
        return json(array('code' => 0, 'msg' => config('web.mifenlei')));
    }
    // 导入模板开始
    function daoru($exts = 'zip', $size = 50)
    {
        if (user('userid')!=1) {$this->error('无权限'); }
        $rs=checkHex($_FILES['file']['tmp_name']);
        if ($rs==5) {
            return json(array('code' => 0, 'msg' => "当前文件有问题不能上传"));
        } 
        $md5 = md5_file($_FILES['file']['tmp_name']);
        $ext = preg_replace("/(.*)\\./is", "", $_FILES["file"]["name"]);
        //文件格式
        $name = $_FILES["file"]["name"];
        //源文件文件名
        $type = $_FILES["file"]["type"];
        //文件类型
        $size = formatBytes($_FILES["file"]["size"]);
        //文件大小
        $path = "muban." . $ext;
        //文件上传的路径
        $allowedExts = explode(",", $exts);
        if (!in_array($ext, $allowedExts)) {
            return json(array('code' => 0, 'msg' => "当前文件类型不能上传"));
        }
        if ($_FILES["file"]["size"] > dingyi(set('size'), $size) * 1024 * 1024) {
            return json(array('code' => 0, 'msg' => "上传大小超出限制"));
        }
        if (file_exists($path)) {
            // header('location:/index.php/admin/index/admuban.html');
            return json(array('code' => 1, 'msg' => '导入成功', 'type' => $type));
        } else {
            move_uploaded_file($_FILES["file"]["tmp_name"], $path);
            // header('location:/index.php/admin/index/admuban.html');
            return json(array('code' => 1, 'msg' => '导入成功', 'type' => $type));
        }
    }
    // 解压
    public function admuban()
    {
        if (user('userid')!=1) {$this->error('无权限'); }
        $zip = new \ZipArchive();
        if ($zip->open('muban.zip') === TRUE) {
            $zip->extractTo('./template/');
            $zip->close();
            unlink('muban.zip');
            header("content-type:text/html;charset=utf-8");
            header('location:/index.php/admin/com/muban.html');
        }

    }
}