操作日志调整
This commit is contained in:
parent
bd9cbaa6e9
commit
6dd1f5b9bf
|
@ -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 '主键',
|
||||
|
|
|
@ -6,6 +6,7 @@ use think\Controller;
|
|||
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 @@ class Operationlog extends Controller
|
|||
$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 @@ class Operationlog extends Controller
|
|||
$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 @@ class Operationlog extends Controller
|
|||
$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 @@ class Operationlog extends Controller
|
|||
$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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class Log
|
|||
|
||||
AdminOperationLog::create([
|
||||
'user_id' => $admin_id,
|
||||
'path' => $path,
|
||||
'path' => '/' . $path,
|
||||
'method' => request()->method(),
|
||||
'ip' => request()->ip(),
|
||||
'data' => json_encode($param, JSON_UNESCAPED_UNICODE),
|
||||
|
|
Loading…
Reference in New Issue