You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.0 KiB

2 years ago
  1. package util
  2. import (
  3. "regexp"
  4. "strings"
  5. "time"
  6. )
  7. func substr2(str string, start int, end int) string {
  8. rs := []rune(str)
  9. return string(rs[start:end])
  10. }
  11. func HideStar(str string) (result string) {
  12. if str == "" {
  13. return ""
  14. }
  15. if strings.Contains(str, "@") {
  16. res := strings.Split(str, "@")
  17. if len(res[0]) < 3 {
  18. resString := "***"
  19. result = resString + "@" + res[1]
  20. } else {
  21. res2 := substr2(str, 0, 3)
  22. resString := res2 + "***"
  23. result = resString + "@" + res[1]
  24. }
  25. return result
  26. } else {
  27. reg := `^1[0-9]\d{9}$`
  28. rgx := regexp.MustCompile(reg)
  29. mobileMatch := rgx.MatchString(str)
  30. if mobileMatch {
  31. result = substr2(str, 0, 3) + "****" + substr2(str, 7, 11)
  32. } else {
  33. nameRune := []rune(str)
  34. lens := len(nameRune)
  35. if lens <= 1 {
  36. result = "***"
  37. } else if lens == 2 {
  38. result = string(nameRune[:1]) + "*"
  39. } else if lens == 3 {
  40. result = string(nameRune[:1]) + "*" + string(nameRune[2:3])
  41. } else if lens == 4 {
  42. result = string(nameRune[:1]) + "**" + string(nameRune[lens-1:lens])
  43. } else if lens > 4 {
  44. result = string(nameRune[:2]) + "***" + string(nameRune[lens-2:lens])
  45. }
  46. }
  47. return
  48. }
  49. }
  50. func FTime(fTime string) (sTime string) {
  51. if len(fTime) == 0 {
  52. return ``
  53. }
  54. t, _ := time.Parse(time.RFC3339, fTime)
  55. sTime = t.Format("2006-01-02 15:04:05")
  56. return
  57. }
  58. func GetStatus(status int) (statusInfo string) {
  59. var data = map[int]string{
  60. 1: "未支付",
  61. 2: "已取消",
  62. 3: "已支付",
  63. 4: "调剂中",
  64. 5: "待收药",
  65. 6: "待自提",
  66. 7: "待配送",
  67. 8: "配送中",
  68. 9: "已通知",
  69. 10: "已完成",
  70. 11: "已删除",
  71. 12: "支付失败",
  72. 13: "有退款",
  73. }
  74. statusInfo = data[status]
  75. return
  76. }
  77. func SexToString(sex int) (s string) {
  78. switch sex {
  79. case 1:
  80. s = "男"
  81. case 2:
  82. s = "女"
  83. default:
  84. s = "未知"
  85. }
  86. return
  87. }
  88. func PayTypeString(p string) (t string) {
  89. switch p {
  90. case "online":
  91. t = "线上收款"
  92. case "offline":
  93. t = "系统外收款"
  94. default:
  95. t = ""
  96. }
  97. return
  98. }