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.

97 lines
3.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Weixin;
  3. use App\Http\Controllers\Controller;
  4. use App\Common\Helper;
  5. class CommonController extends Controller
  6. {
  7. protected $isWechatBrowser;
  8. protected $login_info;
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. $this->isWechatBrowser = Helper::isWechatBrowser();
  13. view()->share('isWechatBrowser', $this->isWechatBrowser);
  14. $this->login_info = array();
  15. if (isset($_SESSION['weixin_user_info'])) {
  16. $this->login_info = $_SESSION['weixin_user_info'];
  17. }
  18. // 添加操作记录
  19. $this->operation_log_add();
  20. }
  21. /**
  22. * 操作错误跳转的快捷方法
  23. * @access protected
  24. * @param string $msg 错误信息
  25. * @param string $url 页面跳转地址
  26. * @param mixed $time 当数字时指定跳转时间
  27. * @return void
  28. */
  29. public function error_jump($msg = '', $url = '', $time = 3)
  30. {
  31. if ($url == '' && isset($_SERVER["HTTP_REFERER"])) {
  32. $url = $_SERVER["HTTP_REFERER"];
  33. }
  34. if (!headers_sent()) {
  35. header("Location:" . route('weixin_jump') . "?error=$msg&url=$url&time=$time");
  36. exit();
  37. } else {
  38. $str = "<meta http-equiv='Refresh' content='URL=" . route('weixin_jump') . "?error=$msg&url=$url&time=$time" . "'>";
  39. exit($str);
  40. }
  41. }
  42. /**
  43. * 操作成功跳转的快捷方法
  44. * @access protected
  45. * @param string $msg 提示信息
  46. * @param string $url 页面跳转地址
  47. * @param mixed $time 当数字时指定跳转时间
  48. * @return void
  49. */
  50. public function success_jump($msg = '', $url = '', $time = 1)
  51. {
  52. if ($url == '' && isset($_SERVER["HTTP_REFERER"])) {
  53. $url = $_SERVER["HTTP_REFERER"];
  54. }
  55. if (!headers_sent()) {
  56. header("Location:" . route('weixin_jump') . "?message=$msg&url=$url&time=$time");
  57. exit();
  58. } else {
  59. $str = "<meta http-equiv='Refresh' content='URL=" . route('weixin_jump') . "?message=$msg&url=$url&time=$time" . "'>";
  60. exit($str);
  61. }
  62. }
  63. // 添加操作记录
  64. public function operation_log_add($login_info = [])
  65. {
  66. $time = time();
  67. // 记录操作
  68. if ($login_info) {
  69. $data['login_id'] = $login_info['id'];
  70. $data['login_name'] = $login_info['user_name'];
  71. }
  72. $data['type'] = 5;
  73. $data['ip'] = request()->ip();
  74. $data['url'] = mb_strcut(request()->url(), 0, 255, 'UTF-8');
  75. $data['http_method'] = request()->method();
  76. $data['domain_name'] = mb_strcut($_SERVER['SERVER_NAME'], 0, 60, 'UTF-8');
  77. if ($data['http_method'] != 'GET') {
  78. $data['content'] = mb_strcut(json_encode(request()->toArray(), JSON_UNESCAPED_SLASHES), 0, 255, 'UTF-8');
  79. }
  80. if (!empty($_SERVER['HTTP_REFERER'])) {
  81. $data['http_referer'] = mb_strcut($_SERVER['HTTP_REFERER'], 0, 255, 'UTF-8');
  82. }
  83. $data['add_time'] = $time;
  84. logic('Log')->add($data);
  85. }
  86. }