From 1a82b8c563e9b76851a22514212ef9d60d74b490 Mon Sep 17 00:00:00 2001 From: ichynul Date: Mon, 18 Sep 2023 13:45:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/install.sql | 4 ++-- src/admin/controller/Operationlog.php | 22 +++++++++++++++++++++- src/admin/model/AdminOperationLog.php | 7 ++++++- src/common/event/Log.php | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/data/install.sql b/data/install.sql index a4428a5..f16c1f9 100644 --- a/data/install.sql +++ b/data/install.sql @@ -47,7 +47,7 @@ CREATE TABLE IF NOT EXISTS `__PREFIX__admin_role_permission` ( `update_time` datetime NOT NULL DEFAULT '2020-01-01 00:00:00' COMMENT '更新时间', PRIMARY KEY (`id`), INDEX (`role_id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='操作记录表'; +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='角色权限表'; CREATE TABLE IF NOT EXISTS `__PREFIX__admin_role_menu` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', @@ -58,7 +58,7 @@ CREATE TABLE IF NOT EXISTS `__PREFIX__admin_role_menu` ( PRIMARY KEY (`id`), INDEX (`role_id`), INDEX(`menu_id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='角色权限表'; +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='角色菜单表'; CREATE TABLE IF NOT EXISTS `__PREFIX__admin_group` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', diff --git a/src/admin/controller/Operationlog.php b/src/admin/controller/Operationlog.php index cabd998..18bd3ad 100644 --- a/src/admin/controller/Operationlog.php +++ b/src/admin/controller/Operationlog.php @@ -6,6 +6,7 @@ use tpext\builder\traits\actions; use tpext\myadmin\admin\model\AdminOperationLog; use tpext\myadmin\admin\model\AdminUser; +use tpext\myadmin\admin\model\AdminPermission; /** * Undocumented class @@ -38,7 +39,7 @@ protected function initialize() $this->userModel = new AdminUser; $this->pageTitle = '操作记录'; - $this->indexWith = ['admin']; //列表页关联模型 + $this->indexWith = ['admin', 'action']; //列表页关联模型 $this->indexFieldsOnly = 'id,user_id,path,method,ip,create_time,LEFT(data,256) as data'; } @@ -106,6 +107,7 @@ protected function buildForm($isEdit, &$data = []) $form->show('admin.username', '登录帐号'); $form->show('admin.name', '姓名'); $form->show('path', '路径'); + $form->show('permission', '操作')->to('{controller.controller_name}-{action.action_name}'); $form->show('method', '提交方式'); $form->show('ip', 'IP'); $form->show('create_time', '时间'); @@ -128,6 +130,7 @@ protected function buildTable(&$data = []) $table->show('admin.username', '登录帐号'); $table->show('admin.name', '姓名'); $table->show('path', '路径'); + $table->show('permission', '操作')->to('{controller_name}-{action.action_name}'); $table->show('method', '提交方式'); $table->show('ip', 'IP'); $table->show('data', '数据')->cut(100)->getWrapper()->style('max-width:40%;'); @@ -140,5 +143,22 @@ protected function buildTable(&$data = []) $table->getActionbar() ->btnView() ->btnDelete(); + + $constrollers = []; + foreach ($data as $d) { + if ($d['action'] && $d['action']['controller']) { + $constrollers[$d['action']['controller']] = $d['action']['controller']; + } + } + + $constrollers = AdminPermission::where('controller', 'in', $constrollers)->where('action', '#')->select(); + + foreach ($data as $d) { + foreach ($constrollers as $c) { + if ($d['action'] && $d['action']['controller'] && $d['action']['controller'] == $c['controller']) { + $d['controller_name'] = $c['action_name']; + } + } + } } } diff --git a/src/admin/model/AdminOperationLog.php b/src/admin/model/AdminOperationLog.php index 3866677..e7c0c29 100644 --- a/src/admin/model/AdminOperationLog.php +++ b/src/admin/model/AdminOperationLog.php @@ -10,6 +10,11 @@ class AdminOperationLog extends Model public function admin() { - return $this->hasOne('AdminUser', 'id', 'user_id'); + return $this->belongsTo(AdminUser::class, 'user_id', 'id'); + } + + public function action() + { + return $this->belongsTo(AdminPermission::class, 'path', 'url'); } } diff --git a/src/common/event/Log.php b/src/common/event/Log.php index df95999..b2c6628 100644 --- a/src/common/event/Log.php +++ b/src/common/event/Log.php @@ -95,7 +95,7 @@ public function handle($data) AdminOperationLog::create([ 'user_id' => $admin_id, - 'path' => $path, + 'path' => '/' . $path, 'method' => request()->method(), 'ip' => request()->ip(), 'data' => json_encode($param, JSON_UNESCAPED_UNICODE),