修复个人中心问题
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
)
|
||||
|
||||
// 用户头像统一存在认证中心身份表 yz_auth_identity.avatar:
|
||||
// /auth/userinfo 会返回该字段,前端登录回跳、顶部栏、个人中心都从这里取,
|
||||
// 业务侧(yz_system_tenant_user)不再另存一份,避免两处不一致。
|
||||
|
||||
// UpdateIdentityAvatar 更新身份头像
|
||||
func UpdateIdentityAvatar(identityID uint64, avatarURL string) error {
|
||||
if identityID == 0 {
|
||||
return errors.New("身份ID不能为空")
|
||||
}
|
||||
url := strings.TrimSpace(avatarURL)
|
||||
if url == "" {
|
||||
return errors.New("头像地址不能为空")
|
||||
}
|
||||
_, err := models.Orm.QueryTable(new(models.AuthIdentity)).
|
||||
Filter("id", identityID).
|
||||
Update(map[string]interface{}{
|
||||
"avatar": url,
|
||||
"update_time": time.Now(),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// GetIdentityAvatar 读取身份头像;未设置或身份不存在时返回空字符串
|
||||
func GetIdentityAvatar(identityID uint64) string {
|
||||
if identityID == 0 {
|
||||
return ""
|
||||
}
|
||||
var identity models.AuthIdentity
|
||||
if err := models.Orm.QueryTable(new(models.AuthIdentity)).
|
||||
Filter("id", identityID).
|
||||
One(&identity); err != nil || identity.Avatar == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(*identity.Avatar)
|
||||
}
|
||||
Reference in New Issue
Block a user