mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 18:12:50 +08:00
实现后台操作日志记录;
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\Admin as AppAdmin;
|
||||
use app\model\AdminLog;
|
||||
use app\UploadFiles as AppUploadFiles;
|
||||
use think\facade\View;
|
||||
|
||||
@@ -86,4 +87,14 @@ class Admin extends Common
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function adminLog()
|
||||
{
|
||||
|
||||
$list = AdminLog::order('id desc')->paginate(10);
|
||||
|
||||
View::assign('list',$list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\AdminPermission as AppAdminPermission;
|
||||
use think\facade\Cache;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
@@ -17,7 +18,7 @@ class AdminPermission extends Common
|
||||
{
|
||||
//
|
||||
|
||||
$list = AppAdminPermission::paginate();
|
||||
$list = AppAdminPermission::order('app,controller,action')->paginate();
|
||||
|
||||
View::assign('list',$list);
|
||||
|
||||
@@ -51,6 +52,8 @@ class AdminPermission extends Common
|
||||
|
||||
$model_permission->save();
|
||||
|
||||
Cache::delete('logged_admin_permission');
|
||||
|
||||
return json_message();
|
||||
}
|
||||
|
||||
@@ -63,5 +66,8 @@ class AdminPermission extends Common
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
AppAdminPermission::destroy($id);
|
||||
Cache::delete('logged_admin_permission');
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'\app\middleware\PermissionRecord'
|
||||
'\app\middleware\PermissionRecord',
|
||||
'\app\middleware\AdminLog',
|
||||
];
|
||||
41
app/middleware/AdminLog.php
Normal file
41
app/middleware/AdminLog.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use app\model\AdminLog as AppAdminLog;
|
||||
use app\model\AdminPermission;
|
||||
use app\Request;
|
||||
use think\Collection;
|
||||
use think\facade\Cache;
|
||||
|
||||
class AdminLog
|
||||
{
|
||||
public function handle(Request $request, \Closure $next)
|
||||
{
|
||||
$logged_admin_permission = Cache::get('logged_admin_permission');
|
||||
|
||||
if(empty($logged_admin_permission)){
|
||||
$logged_admin_permission = new Collection(AdminPermission::where('is_log',1)->select());
|
||||
}
|
||||
|
||||
|
||||
$is_exit = $logged_admin_permission->where('app',$request->app())
|
||||
->where('controller',$request->controller())
|
||||
->where('action',$request->action());
|
||||
|
||||
if(!$is_exit->isEmpty()){
|
||||
AppAdminLog::create([
|
||||
'app'=>$request->app(),
|
||||
'controller'=>$request->controller(),
|
||||
'action'=>$request->action(),
|
||||
'param'=>$request->param(),
|
||||
'create_time'=>time(),
|
||||
'admin_id'=>$request->session('admin_id','0'),
|
||||
'ip'=>$request->ip()
|
||||
]);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
}
|
||||
}
|
||||
40
app/model/AdminLog.php
Normal file
40
app/model/AdminLog.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminLog extends Model
|
||||
{
|
||||
//
|
||||
use SoftDelete;
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->belongsTo('Admin','admin_id');
|
||||
}
|
||||
|
||||
public function getUrlAttr()
|
||||
{
|
||||
return AdminPermission::where([
|
||||
'app'=>$this->getData('app'),
|
||||
'controller'=>$this->getData('controller'),
|
||||
'action'=>$this->getData('action'),
|
||||
])->find();
|
||||
}
|
||||
|
||||
public function setParamAttr($value)
|
||||
{
|
||||
return json_encode($value,JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
public function getParamAttr($value)
|
||||
{
|
||||
return \mb_substr($value,0,30);
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,14 @@ use think\Model;
|
||||
class AdminPermission extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public function getIsLogAttr($value)
|
||||
{
|
||||
$status = [
|
||||
0=>'不记录',
|
||||
1=>'记录',
|
||||
];
|
||||
|
||||
return $status[intval($value)];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user