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

package util
import (
"regexp"
"strings"
"time"
)
func substr2(str string, start int, end int) string {
rs := []rune(str)
return string(rs[start:end])
}
func HideStar(str string) (result string) {
if str == "" {
return ""
}
if strings.Contains(str, "@") {
res := strings.Split(str, "@")
if len(res[0]) < 3 {
resString := "***"
result = resString + "@" + res[1]
} else {
res2 := substr2(str, 0, 3)
resString := res2 + "***"
result = resString + "@" + res[1]
}
return result
} else {
reg := `^1[0-9]\d{9}$`
rgx := regexp.MustCompile(reg)
mobileMatch := rgx.MatchString(str)
if mobileMatch {
result = substr2(str, 0, 3) + "****" + substr2(str, 7, 11)
} else {
nameRune := []rune(str)
lens := len(nameRune)
if lens <= 1 {
result = "***"
} else if lens == 2 {
result = string(nameRune[:1]) + "*"
} else if lens == 3 {
result = string(nameRune[:1]) + "*" + string(nameRune[2:3])
} else if lens == 4 {
result = string(nameRune[:1]) + "**" + string(nameRune[lens-1:lens])
} else if lens > 4 {
result = string(nameRune[:2]) + "***" + string(nameRune[lens-2:lens])
}
}
return
}
}
func FTime(fTime string) (sTime string) {
if len(fTime) == 0 {
return ``
}
t, _ := time.Parse(time.RFC3339, fTime)
sTime = t.Format("2006-01-02 15:04:05")
return
}
func GetStatus(status int) (statusInfo string) {
var data = map[int]string{
1: "未支付",
2: "已取消",
3: "已支付",
4: "调剂中",
5: "待收药",
6: "待自提",
7: "待配送",
8: "配送中",
9: "已通知",
10: "已完成",
11: "已删除",
12: "支付失败",
13: "有退款",
}
statusInfo = data[status]
return
}
func SexToString(sex int) (s string) {
switch sex {
case 1:
s = "男"
case 2:
s = "女"
default:
s = "未知"
}
return
}
func PayTypeString(p string) (t string) {
switch p {
case "online":
t = "线上收款"
case "offline":
t = "系统外收款"
default:
t = ""
}
return
}