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. const min_memno = 500;
  11. const max_memno = 2000;
  12. public static function member_avatar($path)
  13. {
  14. if (is_null($path) || empty($path)) {
  15. $img = 'female.png';
  16. return RESOURCE_SITE_URL . '/mobile/defimg/' . $img;
  17. } else {
  18. if (strncasecmp($path, "http://", strlen("http://")) == 0) {
  19. $url = $path;
  20. } else {
  21. $url = UPLOAD_SITE_URL . "/shop/avatar{$path}";
  22. }
  23. return $url;
  24. }
  25. }
  26. public static function goods_thumb_image($path, $store_id)
  27. {
  28. return cthumb($path, 480, $store_id);
  29. }
  30. public static function goods_spec($item)
  31. {
  32. $keyval = unserialize($item);
  33. if($keyval == false) {
  34. return "";
  35. }
  36. foreach ($keyval as $key => $val) {
  37. return $val;
  38. }
  39. return "";
  40. }
  41. public static function nickname($nick, $mobile, $name)
  42. {
  43. if (isset($nick) && !empty($nick)) {
  44. return $nick;
  45. }
  46. if (isset($name) && !empty($name)) {
  47. return $name;
  48. }
  49. if (isset($mobile) && !empty($mobile)) {
  50. if (strlen($mobile) == 11) {
  51. return substr_replace($mobile, '****', 3, 4);
  52. }
  53. }
  54. return '';
  55. }
  56. public static function mem_no()
  57. {
  58. $number = self::mb_incr('member_no',1,self::min_memno);
  59. if($number > self::max_memno) {
  60. self::mb_del_incr('member_no');
  61. $start_number = mt_rand(self::min_memno,2 * self::min_memno);
  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. }