Main.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2019/12/5
  6. * Time: 17:44
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\controller\base\Permissions;
  10. use app\admin\model\AdminLog;
  11. use app\admin\model\Urlconfig;
  12. use think\Cache;
  13. use think\Db;
  14. class Main extends Permissions
  15. {
  16. public function index()
  17. {
  18. //tp版本号
  19. $info['tp'] = THINK_VERSION;
  20. //php版本
  21. $info['php'] = PHP_VERSION;
  22. //操作系统
  23. $info['win'] = PHP_OS;
  24. //最大上传限制
  25. $info['upload_max_filesize'] = ini_get('upload_max_filesize');//不能使用ini_set修改
  26. $info['post_max_size'] = ini_get('post_max_size');//不能使用ini_set修改
  27. $info['memory_limit'] = ini_get('memory_limit');
  28. $info['tplay_filesize'] = \app\common\model\Webconfig::getValue('file_size') * 1024;
  29. //脚本执行时间限制
  30. $info['max_execution_time'] = ini_get('max_execution_time') . 'S';
  31. //运行环境
  32. // $sapi = php_sapi_name();
  33. // if ($sapi == 'apache2handler') {
  34. // $info['environment'] = 'apache';
  35. // } elseif ($sapi == 'cgi-fcgi') {
  36. // $info['environment'] = 'cgi';
  37. // } elseif ($sapi == 'cli') {
  38. // $info['environment'] = 'cli';
  39. // } else {
  40. // $info['environment'] = $sapi;
  41. // }
  42. $info['environment'] = $_SERVER['SERVER_SOFTWARE'];
  43. try {
  44. //剩余空间大小,服务器没有权限会报错
  45. $info['disk'] = format_bytes(disk_free_space("/"));
  46. } catch (\Exception $e) {
  47. }
  48. $this->assign('info', $info);
  49. //==============网站数据=============================
  50. //用户
  51. $web['user_num'] = Db::name('user')->where('status', \app\common\model\User::STATUS_PASS)->count();
  52. //预约
  53. $web['application_num'] = Db::name('appointment_application')->count();
  54. //反馈
  55. $web['feedback_num'] = Db::name('feedback')->count();
  56. //公告
  57. $web['announcement_num'] = Db::name('announcement')->count();
  58. //
  59. $web['user_num_today'] = Db::name('user')->where('status', \app\common\model\User::STATUS_PASS)->whereTime('create_time', 'today')->count();
  60. $web['application_num_today'] = Db::name('appointment_application')->whereTime('create_time', 'today')->count();
  61. $web['feedback_num_today'] = Db::name('feedback')->whereTime('create_time', 'today')->count();
  62. $web['announcement_num_today'] = Db::name('announcement')->whereTime('create_time', 'today')->count();
  63. //==============管理员操作记录===========================
  64. $today = date('Y-m-d');
  65. //取当前时间的前十天
  66. $date = [];
  67. $date_string = '';
  68. for ($i = 9; $i > 0; $i--) {
  69. $date[] = date("Y-m-d", strtotime("-{$i} day"));
  70. $date_string .= date("Y-m-d", strtotime("-{$i} day")) . ',';
  71. }
  72. $date[] = $today;
  73. $date_string .= $today;
  74. $web['date_string'] = $date_string;
  75. $login_sum = '';
  76. foreach ($date as $k => $val) {
  77. $min_time = strtotime($val);
  78. $max_time = $min_time + 60 * 60 * 24;
  79. $where['create_time'] = [['>=', $min_time], ['<=', $max_time]];
  80. $login_sum .= Db::name('appointment_application')->where($where)->count() . ',';
  81. }
  82. $web['login_sum'] = $login_sum;
  83. $this->assign('web', $web);
  84. //==============风险提示=============================
  85. $safe = true;
  86. if (file_exists(APP_PATH . 'install')) {
  87. $safe = false;
  88. //提示删除install目录
  89. $this->assign('delete_install', true);
  90. }
  91. //提示改密码
  92. $weekpass = Db::name('admin')->where('id', session(self::ADMIN_ID))->where('password', password('123456'))->count();
  93. if ($weekpass > 0) {
  94. $safe = false;
  95. $this->assign('weekpass', true);
  96. if (!in_array($this->request->ip(), ['0.0.0.0', '127.0.0.1'])) {
  97. $this->assign('waring', ['msg' => "当前密码过于简单,是否立即修改?", "url" => url('admin/admin/editpassword')]);
  98. }
  99. }
  100. //提示设置安全入口
  101. if ((new Urlconfig())->isWeekBackend()) {
  102. $safe = false;
  103. $this->assign('week_backend', true);
  104. }
  105. if (session(self::ADMIN_CATE_ID) == \app\admin\model\Admin::SUPER_ADMIN_ID) {
  106. //登录请求过多,防止被爆破,提示管理员修改后台地址
  107. if ((new AdminLog())->where(['admin_menu_id' => '50', 'params' => ['<>', '']])->whereTime('create_time', 'today')->count() > 100) {
  108. $this->assign('waring', ['msg' => "今日发现多次登录请求,是否立即修改后台地址?", "url" => url('admin/urlsconfig/index')]);
  109. }
  110. }
  111. $this->assign('safe', $safe);
  112. return $this->fetch();
  113. }
  114. /**
  115. * 清除全部缓存
  116. */
  117. public function clear()
  118. {
  119. if (false == Cache::clear()) {
  120. $this->error('清除缓存失败');
  121. } else {
  122. $this->success('清除缓存成功');
  123. }
  124. }
  125. }