From 79091a766c4b5e4881227f2f73c53e219491ad19 Mon Sep 17 00:00:00 2001 From: walkor Date: Wed, 7 Dec 2022 19:02:44 +0800 Subject: [PATCH] save --- src/plugin/admin/app/common/Util.php | 14 + .../admin/app/controller/IndexController.php | 54 ++- .../admin/app/middleware/AccessControl.php | 2 +- .../app/view/{ => common}/error/403.html | 0 src/plugin/admin/app/view/error/404.html | 21 - src/plugin/admin/app/view/error/500.html | 21 - .../admin/app/view/index/dashboard.html | 358 ++++++++++++++++++ src/plugin/admin/config/middleware.php | 1 + .../admin/public/config/pear.config.json | 4 +- 9 files changed, 429 insertions(+), 46 deletions(-) rename src/plugin/admin/app/view/{ => common}/error/403.html (100%) delete mode 100644 src/plugin/admin/app/view/error/404.html delete mode 100644 src/plugin/admin/app/view/error/500.html create mode 100644 src/plugin/admin/app/view/index/dashboard.html diff --git a/src/plugin/admin/app/common/Util.php b/src/plugin/admin/app/common/Util.php index e6bdab0..9d77363 100644 --- a/src/plugin/admin/app/common/Util.php +++ b/src/plugin/admin/app/common/Util.php @@ -442,6 +442,20 @@ class Util } + /** + * 获取某个composer包的版本 + * @param string $package + * @return mixed|string + */ + static public function getPackageVersion(string $package) + { + $installed_php = base_path('vendor/composer/installed.php'); + if (is_file($installed_php)) { + $packages = include $installed_php; + } + return substr($packages['versions'][$package]['version'] ?? 'unknown ', 0, -2); + } + /** * reload webman (不支持windows) diff --git a/src/plugin/admin/app/controller/IndexController.php b/src/plugin/admin/app/controller/IndexController.php index fe0eed3..e05f8cd 100644 --- a/src/plugin/admin/app/controller/IndexController.php +++ b/src/plugin/admin/app/controller/IndexController.php @@ -2,18 +2,29 @@ namespace plugin\admin\app\controller; +use plugin\admin\app\common\Util; +use plugin\admin\app\model\User; +use support\Db; use support\Request; use support\Response; +use think\db\Where; +use Workerman\Worker; class IndexController { /** * 无需登录的方法 - * @var array + * @var string[] */ protected $noNeedLogin = ['index']; + /** + * 不需要鉴权的方法 + * @var string[] + */ + protected $noNeedAuth = ['dashboard']; + /** * 后台主页 * @param Request $request @@ -32,4 +43,45 @@ class IndexController return view('index/index'); } + /** + * @param Request $request + * @return Response + */ + public function dashboard(Request $request): Response + { + // 今日新增用户数 + $today_user_count = User::where('created_at', '>', date('Y-m-d') . ' 00:00:00')->count(); + // 7天内新增用户数 + $day7_user_count = User::where('created_at', '>', date('Y-m-d H:i:s', time() - 7 * 24 * 60 * 60))->count(); + // 30天内新增用户数 + $day30_user_count = User::where('created_at', '>', date('Y-m-d H:i:s', time() - 30 * 24 * 60 * 60))->count(); + // 总用户数 + $user_count = User::count(); + // mysql版本 + $version = Db::select('select VERSION() as version'); + $mysql_version = $version[0]->version ?? 'unknown'; + + $day7_detail = []; + $now = time(); + for ($i = 0; $i < 7; $i++) { + $date = date('Y-m-d', $now - 24 * 60 * 60 * $i); + $day7_detail[substr($date, 5)] = User::where('created_at', '>', "$date 00:00:00") + ->where('created_at', '<', "$date 23:59:59")->count(); + } + + return view('index/dashboard', [ + 'today_user_count' => $today_user_count, + 'day7_user_count' => $day7_user_count, + 'day30_user_count' => $day30_user_count, + 'user_count' => $user_count, + 'php_version' => PHP_VERSION, + 'workerman_version' => Worker::VERSION, + 'webman_version' => Util::getPackageVersion('workerman/webman-framework'), + 'admin_version' => config('plugin.admin.app.version'), + 'mysql_version' => $mysql_version, + 'os' => PHP_OS, + 'day7_detail' => array_reverse($day7_detail), + ]); + } + } diff --git a/src/plugin/admin/app/middleware/AccessControl.php b/src/plugin/admin/app/middleware/AccessControl.php index 220b826..854efbf 100644 --- a/src/plugin/admin/app/middleware/AccessControl.php +++ b/src/plugin/admin/app/middleware/AccessControl.php @@ -35,7 +35,7 @@ class AccessControl implements MiddlewareInterface EOF ); } else { - $response = view('error/403'); + $response = view('common/error/403'); } } diff --git a/src/plugin/admin/app/view/error/403.html b/src/plugin/admin/app/view/common/error/403.html similarity index 100% rename from src/plugin/admin/app/view/error/403.html rename to src/plugin/admin/app/view/common/error/403.html diff --git a/src/plugin/admin/app/view/error/404.html b/src/plugin/admin/app/view/error/404.html deleted file mode 100644 index bca39cd..0000000 --- a/src/plugin/admin/app/view/error/404.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - -
- -
-

404

-

抱歉,你访问的页面不存在或仍在开发中

-
-
- - - - - \ No newline at end of file diff --git a/src/plugin/admin/app/view/error/500.html b/src/plugin/admin/app/view/error/500.html deleted file mode 100644 index 90604f6..0000000 --- a/src/plugin/admin/app/view/error/500.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - -
- -
-

500

-

抱歉,服务器出错了

-
-
- - - - - \ No newline at end of file diff --git a/src/plugin/admin/app/view/index/dashboard.html b/src/plugin/admin/app/view/index/dashboard.html new file mode 100644 index 0000000..17e2c27 --- /dev/null +++ b/src/plugin/admin/app/view/index/dashboard.html @@ -0,0 +1,358 @@ + + + + + 控制后台 + + + + + + + +
+
+
+
+
今日注册
+
+
+
+ 0 +
+
+ + + + + + + + + +
+
+
+
+
+
+
+
7日内注册
+
+
+
+ 0 +
+
+ + + + + + + + + + + + + +
+
+
+
+
+
+
+
30日内注册
+
+
+
+ 0 +
+
+ + + + + + + + + + +
+
+
+
+
+
+
+
总注册
+
+
+
+ 0 +
+
+ + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
系统信息
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Workerman版本
Webman版本
WebmanAdmin版本
PHP版本
MYSQL版本
操作系统
+
+
+
+
+
+ + + + + + diff --git a/src/plugin/admin/config/middleware.php b/src/plugin/admin/config/middleware.php index 7be60ac..74b4784 100644 --- a/src/plugin/admin/config/middleware.php +++ b/src/plugin/admin/config/middleware.php @@ -17,5 +17,6 @@ use plugin\admin\app\middleware\AccessControl; return [ '' => [ AccessControl::class, + Webman\Log\Middleware::class, ] ]; \ No newline at end of file diff --git a/src/plugin/admin/public/config/pear.config.json b/src/plugin/admin/public/config/pear.config.json index fd9455a..724df23 100644 --- a/src/plugin/admin/public/config/pear.config.json +++ b/src/plugin/admin/public/config/pear.config.json @@ -20,8 +20,8 @@ "preload": false, "max": "30", "index": { - "id": "1", - "href": "/app/admin/table/index", + "id": "0", + "href": "/app/admin/index/dashboard", "title": "首页" } },