OperateLogEvent.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace catchAdmin\permissions\event;
  3. use catchAdmin\permissions\model\Permissions;
  4. use catchAdmin\system\model\OperateLog;
  5. use catcher\CatchAdmin;
  6. use think\facade\Db;
  7. class OperateLogEvent
  8. {
  9. public function handle($params)
  10. {
  11. $permission = $params['permission'];
  12. $parentPermission = Permissions::where('id', $permission->parent_id)->value('permission_name');
  13. $requestParams = request()->param();
  14. // 如果参数过长则不记录
  15. if (!empty($requestParams)) {
  16. if (strlen(\json_encode($requestParams)) > 1000) {
  17. $requestParams = [];
  18. }
  19. }
  20. app(OperateLog::class)->storeBy([
  21. 'creator_id' => $params['creator_id'],
  22. 'module' => $parentPermission ? : '',
  23. 'method' => request()->method(),
  24. 'operate' => $permission->permission_name,
  25. 'route' => $permission->permission_mark,
  26. 'params' => !empty($requestParams) ? json_encode($requestParams, JSON_UNESCAPED_UNICODE) : '',
  27. 'created_at' => time(),
  28. 'ip' => request()->ip(),
  29. ]);
  30. }
  31. }