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.

46 lines
1.3 KiB

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