Index.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\controller\sys;
  4. use think\Exception;
  5. use think\facade\App;
  6. use think\facade\Db;
  7. use think\facade\Config;
  8. use think\facade\View;
  9. use app\model\SysMenu as SysMenuModel;
  10. use app\utils\ReUtils;
  11. class Index extends Base
  12. {
  13. public function index()
  14. {
  15. // 系统信息
  16. $mysqlVersion = Db::query('SELECT VERSION() AS ver');
  17. $config = [
  18. 'url' => $_SERVER['HTTP_HOST'],
  19. 'document_root' => $_SERVER['DOCUMENT_ROOT'],
  20. 'server_os' => PHP_OS,
  21. 'server_port' => $_SERVER['SERVER_PORT'],
  22. 'server_ip' => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '',
  23. 'server_soft' => $_SERVER['SERVER_SOFTWARE'],
  24. 'php_version' => PHP_VERSION,
  25. 'mysql_version' => $mysqlVersion[0]['ver'],
  26. 'max_upload_size' => ini_get('upload_max_filesize'),
  27. 'tp_version' => App::version(),
  28. ];
  29. // 快捷方式
  30. $indexButton = \app\model\SysMenu::getIndexButton();
  31. $menuList = \app\model\SysMenu::getMenuList();
  32. View::assign([
  33. 'config' => $config,
  34. // 'user' => $user,
  35. // 'message' => $message ?? 0,
  36. // 'messageCatUrl' => $messageCatUrl,
  37. 'indexButton' => $indexButton,
  38. 'menuList' => $menuList,
  39. 'indexTips' => $this->getIndexTips(),
  40. ]);
  41. return View::fetch('index');
  42. }
  43. // 检查提示信息
  44. private function getIndexTips()
  45. {
  46. $user = $this->getSysUser();
  47. $defaultPassword = Config::get('app.default_password') ?: 'admin';
  48. if ($user->password == md5($defaultPassword . $user->salt)) {
  49. return '<h6 class="mb-0"><i class="icon fas fa-fw fa-exclamation-triangle"></i> 请尽快修改后台初始密码!</h6>';
  50. }
  51. return '';
  52. }
  53. public function usedspace()
  54. {
  55. if ($this->request->isAjax()) {
  56. $dirname = $this->app->getRootPath();
  57. $dirsize = get_dir_size($dirname);
  58. return ['code' => 0, 'size' => format_bytes($dirsize)];
  59. }
  60. }
  61. public function clearcache()
  62. {
  63. if ($this->request->isAjax()) {
  64. $runtime_path = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR;
  65. try {
  66. $cache_dir = $runtime_path . 'cache' . DIRECTORY_SEPARATOR;
  67. $admin_dir = $runtime_path . 'admin' . DIRECTORY_SEPARATOR;
  68. $index_dir = $runtime_path . 'index' . DIRECTORY_SEPARATOR;
  69. $api_dir = $runtime_path . 'api' . DIRECTORY_SEPARATOR;
  70. deldir($cache_dir);
  71. deldir($admin_dir);
  72. deldir($index_dir);
  73. deldir($api_dir);
  74. } catch (\Exception $e) {
  75. return ['code' => 0, 'msg' => $e->getMessage()];
  76. }
  77. return ['code' => 1, 'msg' => '清除成功'];
  78. }
  79. }
  80. // 刷新栏目页
  81. // public function reClass($classid)
  82. // {
  83. // $classess = Enewsclass::with('module')->field("classid, bclassid,classname,modid,classpath,islast,islist,listtempid,classurl")->order('classid desc')->select();
  84. // $publicpath = app()->getRootPath() . 'public/';
  85. // foreach ($classess as $key => $class) {
  86. // if ($class->islast == 1) { // 列表模板, 其他的再说
  87. // $model = "\app\model\\" . $class->modelName;
  88. // $path = $publicpath . $class->classpath;
  89. // if (!file_exists($path)) {
  90. // mkdir($path, 0755, true);
  91. // }
  92. // $listpage = 25; // 每页25条
  93. // // $total =
  94. // }
  95. // }
  96. // }
  97. public function saveIndexButton()
  98. {
  99. $param = $this->request->param();
  100. $menuids = isset($param['checkbox']) ? $param['checkbox'] : [];
  101. $ids = implode(',', $menuids);
  102. $tablename = SysMenuModel::getTable();
  103. $notinsql = "update " . $tablename . " set index_button=0 where id NOT IN (" . $ids . ");";
  104. $insql = "update " . $tablename . " set index_button=1 where id IN (" . $ids . ");";
  105. try {
  106. Db::execute($notinsql);
  107. Db::execute($insql);
  108. } catch (Exception $e) {
  109. return ReUtils::error();
  110. }
  111. return ReUtils::success();
  112. }
  113. }