refactor: 完善日志记录处理
This commit is contained in:
@@ -4,6 +4,8 @@ declare (strict_types = 1);
|
||||
namespace app\admin\middleware\v1;
|
||||
|
||||
use app\admin\model\v1\SysOperateLog;
|
||||
use app\admin\model\v1\SysRestfulApiModel;
|
||||
use think\facade\Cache;
|
||||
|
||||
class OperateLog
|
||||
{
|
||||
@@ -18,9 +20,19 @@ class OperateLog
|
||||
{
|
||||
$response = $next($request);
|
||||
|
||||
$restful_api_name_map = Cache::get('sys_restful_api:map:name');
|
||||
if (empty($restful_api_name_map)) {
|
||||
$restful_api_name_map = [];
|
||||
$restful_api = SysRestfulApiModel::cache('sys_restful_api')->select();
|
||||
foreach ($restful_api as $item) {
|
||||
$restful_api_name_map[$item['method'] . '-' . $item['layer'] . '.' . $item['controller'] . '/' . $item['action']] = $item['name'];
|
||||
}
|
||||
Cache::set('sys_restful_api:map:name', $restful_api_name_map);
|
||||
}
|
||||
|
||||
$log = [
|
||||
'user_id' => $request->uid,
|
||||
'title' => '操作日志',
|
||||
'title' => $restful_api_name_map[$request->method() . '-' . $request->controller() . '/' . $request->action()] ?? '',
|
||||
'version' => $request->layer(),
|
||||
'method' => $request->method(),
|
||||
'controller' => $request->controller(base: true),
|
||||
|
||||
Reference in New Issue
Block a user