common.php 961 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // 应用公共文件
  3. function jump($msg = '', $url = null, $wait = 3)
  4. {
  5. if (is_null($url)) {
  6. $url = 'javascript:history.back(-1);';
  7. } else {
  8. $url = "location.href = '" . url($url) . "'";
  9. }
  10. $result = [
  11. 'msg' => $msg,
  12. 'url' => $url,
  13. 'wait' => $wait,
  14. ];
  15. $html = view('/public/jump', $result);
  16. throw new \think\exception\HttpResponseException($html);
  17. }
  18. function ajax_success($data)
  19. {
  20. $res = ['code' => 0, 'msg' => '成功', 'data' => $data];
  21. $response = \think\Response::create($res, 'json');
  22. throw new \think\exception\HttpResponseException($response);
  23. }
  24. function get_user_id()
  25. {
  26. $sessionUserId = session('mobile.user.id');
  27. if (empty($sessionUserId)) {
  28. session('back_url',request()->url());
  29. $response = redirect('/mobile/login/login');
  30. throw new \think\exception\HttpResponseException($response);
  31. }
  32. return $sessionUserId;
  33. }