1
0

OperateLog.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\listener;
  3. use app\event\SysOperateLog;
  4. use app\model\OperateLog as ModelOperateLog;
  5. class OperateLog
  6. {
  7. public function handle(array $argv)
  8. {
  9. $employee = $argv[0];
  10. if (is_string($argv[1])) {
  11. $content = $argv[1];
  12. } elseif (is_object($argv[1])) {
  13. $content = $this->getContent($argv[1]);
  14. }
  15. if ($content == '') return;
  16. $data = [
  17. 'employee_id' => $employee->id,
  18. 'root_id' => $employee->root_id,
  19. 'ip' => request()->ip(),
  20. 'content' => $content,
  21. 'addtime' => date('Y-m-d H:i:s')
  22. ];
  23. ModelOperateLog::create($data);
  24. }
  25. /**
  26. * 获取登录内容
  27. */
  28. public function getContent($obj)
  29. {
  30. $classNameSpace = get_class($obj);
  31. $path = explode('\\', $classNameSpace);
  32. $type = lcfirst(array_pop($path));
  33. $method = 'get' . ucfirst($type) . 'Content';
  34. if (method_exists($this, $method)) {
  35. return $this->$method();
  36. }
  37. return '';
  38. }
  39. }