common.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }
  34. function get_soldier()
  35. {
  36. $id = session('mobile.soldier.id');
  37. if (empty($id)) {
  38. $response = redirect('/mobile/soldier/login');
  39. throw new \think\exception\HttpResponseException($response);
  40. }
  41. $soldier = \app\common\model\SoldierModel::find($id);
  42. return $soldier;
  43. }