util_helper.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2016/12/21
  6. * Time: 下午4:06
  7. */
  8. class util
  9. {
  10. public static function member_avatar($path)
  11. {
  12. if (is_null($path) || empty($path)) {
  13. $img = 'female.png';
  14. return RESOURCE_SITE_URL . '/mobile/defimg/' . $img;
  15. } else {
  16. if (strncasecmp($path, "http://", strlen("http://")) == 0) {
  17. $url = $path;
  18. } else {
  19. $url = UPLOAD_SITE_URL . "/shop/avatar{$path}";
  20. }
  21. return $url;
  22. }
  23. }
  24. public static function goods_thumb_image($path, $store_id)
  25. {
  26. return cthumb($path, 480, $store_id);
  27. }
  28. public static function goods_spec($item)
  29. {
  30. $keyval = unserialize($item);
  31. if($keyval == false) {
  32. return "";
  33. }
  34. foreach ($keyval as $key => $val) {
  35. return $val;
  36. }
  37. return "";
  38. }
  39. public static function nickname($nick, $mobile, $name)
  40. {
  41. if (isset($nick) && !empty($nick)) {
  42. return $nick;
  43. }
  44. if (isset($name) && !empty($name)) {
  45. return $name;
  46. }
  47. if (isset($mobile) && !empty($mobile)) {
  48. if (strlen($mobile) == 11) {
  49. return substr_replace($mobile, '****', 3, 4);
  50. }
  51. }
  52. return '';
  53. }
  54. public static function mem_no()
  55. {
  56. $min_number = 500;
  57. $max_number = 2000;
  58. $number = self::mb_incr('member_no',1,$min_number);
  59. if($number > $max_number) {
  60. self::mb_del_incr('member_no');
  61. $start_number = mt_rand($min_number,2 * $min_number);
  62. $number = self::mb_incr('member_no',1,$start_number);
  63. }
  64. return $number;
  65. }
  66. private static function mb_incr($key,$val,$def_value = 0)
  67. {
  68. return incrcache('global_incr',$key,$val,'mb_',$def_value);
  69. }
  70. private static function mb_del_incr($key)
  71. {
  72. return del_incr('global_incr',$key,'mb_');
  73. }
  74. }