Skip to content

Commit

Permalink
操作日志调整
Browse files Browse the repository at this point in the history
  • Loading branch information
ichynul committed Sep 18, 2023
1 parent 187082c commit 1a82b8c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions data/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 '主键',
Expand All @@ -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 '主键',
Expand Down
22 changes: 21 additions & 1 deletion src/admin/controller/Operationlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
}
Expand Down Expand Up @@ -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', '时间');
Expand All @@ -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%;');
Expand All @@ -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'];
}
}
}
}
}
7 changes: 6 additions & 1 deletion src/admin/model/AdminOperationLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
2 changes: 1 addition & 1 deletion src/common/event/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 1a82b8c

Please sign in to comment.