1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace app\listener;
- use app\event\SysOperateLog;
- use app\model\OperateLog as ModelOperateLog;
- class OperateLog
- {
- public function handle(array $argv)
- {
- $employee = $argv[0];
- if (is_string($argv[1])) {
- $content = $argv[1];
- } elseif (is_object($argv[1])) {
- $content = $this->getContent($argv[1]);
- }
- if ($content == '') return;
- $data = [
- 'employee_id' => $employee->id,
- 'root_id' => $employee->root_id,
- 'ip' => request()->ip(),
- 'content' => $content,
- 'addtime' => date('Y-m-d H:i:s')
- ];
- ModelOperateLog::create($data);
- }
- /**
- * 获取登录内容
- */
- public function getContent($obj)
- {
- $classNameSpace = get_class($obj);
- $path = explode('\\', $classNameSpace);
- $type = lcfirst(array_pop($path));
- $method = 'get' . ucfirst($type) . 'Content';
- if (method_exists($this, $method)) {
- return $this->$method();
- }
- return '';
- }
- }
|