common.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * 时间
  4. */
  5. function tranTime($utime)
  6. {
  7. $time = time() - $utime;
  8. if ($time < 60) {
  9. $str = '刚刚';
  10. } elseif ($time < 60 * 60) {
  11. $min = floor($time / 60);
  12. $str = $min . '分钟前';
  13. } elseif ($time < 60 * 60 * 24) {
  14. $h = floor($time / (60 * 60));
  15. $str = $h . '小时前';
  16. } elseif ($time < 60 * 60 * 24 * 3) {
  17. $d = floor($time / (60 * 60 * 24));
  18. if ($d == 1) {
  19. $str = '昨天';
  20. } else {
  21. $str = '前天';
  22. }
  23. } else {
  24. $str = date("m-d", $utime);
  25. }
  26. return $str;
  27. }
  28. function get_user_id()
  29. {
  30. $sessionUserId = session('user.id');
  31. if (empty($sessionUserId)) {
  32. return 0;
  33. }
  34. return $sessionUserId;
  35. }
  36. function get_type()
  37. {
  38. $sessionType = session('user.type');
  39. if (empty($sessionType)) {
  40. return 0;
  41. }
  42. return $sessionType;
  43. }
  44. function my_redirect(string $url = '', int $code = 302)
  45. {
  46. throw new \think\exception\HttpResponseException(redirect($url, $code));
  47. }
  48. function page_result($code = 0, $msg = '', $data = [])
  49. {
  50. $res = ['code' => $code, 'msg' => $msg, 'data' => $data];
  51. $response = \think\Response::create($res, 'json');
  52. throw new \think\exception\HttpResponseException($response);
  53. }
  54. function addPByN($str)
  55. {
  56. $comdetails = '';
  57. $comdetails_arr = explode("\n", $str);
  58. foreach ($comdetails_arr as $v) {
  59. $comdetails .= "<p>{$v}</p>";
  60. }
  61. return $comdetails;
  62. }
  63. function getWorkExperience($type = 'json')
  64. {
  65. $json = '[
  66. {id: 1, text: "无经验"},
  67. {id: 2, text: "一年以下"},
  68. {id: 3, text: "1-3年"},
  69. {id: 4, text: "3-5年"},
  70. {id: 5, text: "5-10年"},
  71. {id: 6, text: "10年以上"}
  72. ]';
  73. return $type == 'json' ? $json : json_decode($json, true);
  74. }
  75. function getEducation($type = 'json')
  76. {
  77. $json = '[
  78. {id: 1, text: "初中"},
  79. {id: 2, text: "高中"},
  80. {id: 3, text: "中技"},
  81. {id: 4, text: "中专"},
  82. {id: 5, text: "大专"},
  83. {id: 6, text: "本科"},
  84. {id: 7, text: "硕士"},
  85. {id: 8, text: "博士"},
  86. ]';
  87. return $type == 'json' ? $json : json_decode($json, true);
  88. }