common.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ajax_error($msg = '', $data = [])
  25. {
  26. ajax_return(1, $msg, $data);
  27. }
  28. function get_user_id()
  29. {
  30. $sessionUserId = session('mobile.user.id');
  31. if (empty($sessionUserId)) {
  32. session('back_url', request()->url());
  33. $response = redirect('/mobile/login/login');
  34. throw new \think\exception\HttpResponseException($response);
  35. }
  36. return $sessionUserId;
  37. }
  38. function get_soldier()
  39. {
  40. $id = session('mobile.soldier.id');
  41. if (empty($id)) {
  42. $response = redirect('/mobile/soldier/login');
  43. throw new \think\exception\HttpResponseException($response);
  44. }
  45. $soldier = \app\common\model\SoldierModel::find($id);
  46. return $soldier;
  47. }
  48. function get_open_id()
  49. {
  50. $open_id = session('mobile.open_id');
  51. if (empty($open_id)) {
  52. $response = redirect('/mobile/seat/login');
  53. throw new \think\exception\HttpResponseException($response);
  54. }
  55. return $open_id;
  56. }
  57. function tip($title = '', $msg = '')
  58. {
  59. $result = [
  60. 'title' => $title,
  61. 'msg' => $msg,
  62. ];
  63. $html = view('/public/tip', $result);
  64. throw new \think\exception\HttpResponseException($html);
  65. }