| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | <?phpdeclare (strict_types = 1);namespace app\sys\controller;use think\facade\App;use think\facade\Db;use think\facade\Config;use think\facade\View;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(),        ];        View::assign([            'config'        => $config,            // 'user'          => $user,            // 'message'       => $message ?? 0,            // 'messageCatUrl' => $messageCatUrl,            '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'=>'清除成功'];        }    }}
 |