| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 | <?phpdeclare(strict_types=1);namespace app\controller\sys;use think\Exception;use think\facade\App;use think\facade\Db;use think\facade\Config;use think\facade\View;use app\model\SysMenu as SysMenuModel;use app\utils\ReUtils;class Index  extends Base{    public function index()    {        // 系统信息        $mysqlVersion = Db::query('SELECT VERSION() AS ver');        $config       = [            'url'             => $_SERVER['HTTP_HOST'],            'document_root'   => $_SERVER['DOCUMENT_ROOT'],            'server_os'       => PHP_OS,            'server_port'     => $_SERVER['SERVER_PORT'],            'server_ip'       => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '',            'server_soft'     => $_SERVER['SERVER_SOFTWARE'],            'php_version'     => PHP_VERSION,            'mysql_version'   => $mysqlVersion[0]['ver'],            'max_upload_size' => ini_get('upload_max_filesize'),            'tp_version'         => App::version(),        ];        // 快捷方式        $indexButton =  \app\model\SysMenu::getIndexButton();        $menuList = \app\model\SysMenu::getMenuList();        View::assign([            'config'        => $config,            // 'user'          => $user,            // 'message'       => $message ?? 0,            // 'messageCatUrl' => $messageCatUrl,            'indexButton'   => $indexButton,            'menuList'      => $menuList,            'indexTips'     => $this->getIndexTips(),        ]);        return View::fetch('index');    }    // 检查提示信息    private function getIndexTips()    {        $user = $this->getSysUser();        $defaultPassword = Config::get('app.default_password') ?: 'admin';        if ($user->password == md5($defaultPassword . $user->salt)) {            return '<h6 class="mb-0"><i class="icon fas fa-fw fa-exclamation-triangle"></i> 请尽快修改后台初始密码!</h6>';        }        return '';    }    public function usedspace()    {        if ($this->request->isAjax()) {            $dirname = $this->app->getRootPath();            $dirsize = get_dir_size($dirname);            return ['code' => 0, 'size' => format_bytes($dirsize)];        }    }    public function clearcache()    {        if ($this->request->isAjax()) {            $runtime_path = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR;            try {                $cache_dir = $runtime_path . 'cache' . DIRECTORY_SEPARATOR;                $admin_dir = $runtime_path . 'admin' . DIRECTORY_SEPARATOR;                $index_dir = $runtime_path . 'index' . DIRECTORY_SEPARATOR;                $api_dir = $runtime_path . 'api' . DIRECTORY_SEPARATOR;                deldir($cache_dir);                deldir($admin_dir);                deldir($index_dir);                deldir($api_dir);            } catch (\Exception $e) {                return ['code' => 0, 'msg' => $e->getMessage()];            }            return ['code' => 1, 'msg' => '清除成功'];        }    }    // 刷新栏目页    // public function reClass($classid)    // {    //     $classess = Enewsclass::with('module')->field("classid, bclassid,classname,modid,classpath,islast,islist,listtempid,classurl")->order('classid desc')->select();    //     $publicpath = app()->getRootPath() . 'public/';    //     foreach ($classess as $key => $class) {    //         if ($class->islast == 1) {   // 列表模板, 其他的再说    //             $model = "\app\model\\" . $class->modelName;    //             $path = $publicpath . $class->classpath;    //             if (!file_exists($path)) {    //                 mkdir($path, 0755, true);    //             }    //             $listpage = 25; // 每页25条    //             // $total =     //         }    //     }    // }    public function saveIndexButton()    {        $param = $this->request->param();        $menuids = isset($param['checkbox']) ? $param['checkbox'] : [];        $ids = implode(',', $menuids);        $tablename = SysMenuModel::getTable();        $notinsql = "update " . $tablename . " set index_button=0 where id NOT IN (" . $ids . ");";        $insql = "update " . $tablename . " set index_button=1 where id IN (" . $ids . ");";        try {            Db::execute($notinsql);            Db::execute($insql);        } catch (Exception $e) {            return ReUtils::error();        }        return ReUtils::success();    }}
 |