feat: 徽章api

This commit is contained in:
Blizzard
2026-02-12 14:34:31 +08:00
parent 01e13e736c
commit 0405968597
22 changed files with 1150 additions and 62 deletions
+24 -6
View File
@@ -4,18 +4,36 @@ import (
"sundynix-go/global"
"sundynix-go/model/plant"
plantReq "sundynix-go/model/plant/request"
"sundynix-go/model/system"
"gorm.io/gorm"
)
type UserProfileService struct{}
// UpdateProfile 修改用户信息
func (s *UserProfileService) UpdateProfile(req plantReq.UpdateProfile, userId string) error {
updateMap := map[string]interface{}{
"nick_name": req.Nickname,
"avatar_id": req.AvatarId,
}
return global.DB.Model(&plant.UserProfile{}).Where("user_id = ?", userId).Updates(updateMap).Error
return global.DB.Transaction(func(tx *gorm.DB) error {
//1.更新profile
updateMap := map[string]interface{}{
"nick_name": req.Nickname,
"avatar_id": req.AvatarId,
}
err := tx.Model(&plant.UserProfile{}).Where("user_id = ?", userId).Updates(updateMap).Error
if err != nil {
return err
}
//2.更新user表
updateMap = map[string]interface{}{
"name": req.Nickname,
"avatar_id": req.AvatarId,
}
err = tx.Model(&system.User{}).Where("id = ?", userId).Updates(updateMap).Error
if err != nil {
return err
}
return nil
})
}
// ProfileDetail 获取用户详情