40 lines
843 B
Go
40 lines
843 B
Go
package services
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
|
|
"server/models"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
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)
|
|
}
|