You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

8 years ago
8 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. class CommonController extends Controller
  5. {
  6. /**
  7. * 初始化
  8. * @param void
  9. * @return void
  10. */
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. // 添加操作记录
  15. $this->operation_log_add();
  16. }
  17. // 添加操作记录
  18. public function operation_log_add($login_info = [])
  19. {
  20. $time = time();
  21. // 记录操作
  22. if ($login_info) {
  23. $data['login_id'] = $login_info['id'];
  24. $data['login_name'] = $login_info['user_name'];
  25. }
  26. $data['type'] = 3;
  27. $data['ip'] = request()->ip();
  28. $data['url'] = mb_strcut(request()->url(), 0, 255, 'UTF-8');
  29. $data['http_method'] = request()->method();
  30. $data['domain_name'] = mb_strcut($_SERVER['SERVER_NAME'], 0, 60, 'UTF-8');
  31. if ($data['http_method'] != 'GET') {
  32. $data['content'] = mb_strcut(json_encode(request()->toArray(), JSON_UNESCAPED_SLASHES), 0, 255, 'UTF-8');
  33. }
  34. if (!empty($_SERVER['HTTP_REFERER'])) {
  35. $data['http_referer'] = mb_strcut($_SERVER['HTTP_REFERER'], 0, 255, 'UTF-8');
  36. }
  37. $data['add_time'] = $time;
  38. logic('Log')->add($data);
  39. }
  40. }