helpers.php 1.7 KB

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