helpers.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. use Illuminate\Support\Str;
  3. //判断等级
  4. function judge_level($level){
  5. switch ($level){
  6. case 2:
  7. $level='经销商';
  8. break;
  9. case 3:
  10. $level='批发商';
  11. break;
  12. }
  13. return $level;
  14. }
  15. function judge_level_name($level){
  16. switch ($level){
  17. case '经销商':
  18. $level=2;
  19. break;
  20. case '批发商':
  21. $level=3;
  22. break;
  23. }
  24. return $level;
  25. }
  26. function make_excerpt($value, $length = 200)
  27. {
  28. $excerpt = trim(preg_replace('/\r\n|\r|\n+/', ' ', strip_tags($value)));
  29. return str_limit($excerpt, $length);
  30. }
  31. function str_limit($value, $limit = 100, $end = '...')
  32. {
  33. return Str::limit($value, $limit, $end);
  34. }
  35. function code($phone){
  36. $data=md5(uniqid($phone));
  37. // return $data;
  38. $data=substr($data,1,6);
  39. return $data;
  40. }
  41. function str_random($length = 16)
  42. {
  43. return Str::random($length);
  44. }
  45. function hide_phone($phone){
  46. if (mb_strlen($phone)!=11){
  47. return '';
  48. }
  49. return mb_substr($phone,0,3).'****'.mb_substr($phone,7);
  50. }
  51. function auth_code($phone){
  52. $code_1=str_pad(random_int(1, 999), 3, 0, STR_PAD_LEFT);
  53. $code_2=mb_substr($phone,1,3);
  54. $code_3=str_pad(random_int(100, 99999), 6, 0, STR_PAD_LEFT);
  55. $code_4=mb_substr(time(),8,2);
  56. $code='DWBS00'.$code_1.date('ymd',time()).$code_2.$code_3.$code_4;
  57. return $code;
  58. }
  59. //function public_path($path = '')
  60. //{
  61. // return app()->make('path.public').($path ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : $path);
  62. //}