获取app用户数据时,用户姓名新增默认name数据

This commit is contained in:
wucongxing8150 2024-09-09 16:52:12 +08:00
parent 997ca33dc4
commit fc4e40f49b
2 changed files with 21 additions and 6 deletions

View File

@ -377,14 +377,15 @@ func (r *UserService) GetAppUserInfo(tx *gorm.DB, user *model.User, userInfo *mo
}
// 姓名
if appUserInfo.Data.Name != "" {
if user.UserName != "" {
if appUserInfo.Data.Name != user.UserName {
userData["user_name"] = appUserInfo.Data.Name
}
} else {
if appUserInfo.Data.Name == "" {
appUserInfo.Data.Name = "GDXZ_" + utils.GenerateRandomString(4)
}
if user.UserName != "" {
if appUserInfo.Data.Name != user.UserName {
userData["user_name"] = appUserInfo.Data.Name
}
} else {
userData["user_name"] = appUserInfo.Data.Name
}
// 头像

View File

@ -2,7 +2,9 @@ package utils
import (
"hepa-calc-api/config"
"math/rand"
"strings"
"time"
)
// RemoveOssDomain 去除oss地址中的前缀
@ -20,3 +22,15 @@ func AddOssDomain(url string) string {
}
return config.C.Oss.OssCustomDomainName + url
}
// GenerateRandomString 生成随机字母字符串
func GenerateRandomString(n int) string {
letters := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r := rand.New(rand.NewSource(time.Now().UnixNano())) // 设置随机数种子
b := make([]byte, n) // 创建长度为 n 的字节切片
for i := range b {
b[i] = letters[r.Intn(len(letters))] // 从字母列表中随机选择字符
}
return string(b) // 转换为字符串返回
}