feat: 用户中心

This commit is contained in:
Blizzard
2026-02-11 14:33:00 +08:00
parent 4ccab96ca2
commit 112a1f439c
17 changed files with 1571 additions and 138 deletions
+1
View File
@@ -8,4 +8,5 @@ type ServiceGroup struct {
WikiService
OcrService
LevelConfigService
UserProfileService
}
+29
View File
@@ -0,0 +1,29 @@
package plant
import (
"sundynix-go/global"
"sundynix-go/model/plant"
plantReq "sundynix-go/model/plant/request"
)
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
}
// ProfileDetail 获取用户详情
func (s *UserProfileService) ProfileDetail(userId string) (plant.UserProfile, error) {
var res plant.UserProfile
err := global.DB.Where("user_id = ?", userId).Preload("Avatar").Preload("Level").First(&res).Error
if err != nil {
return res, err
}
return res, nil
}
+1
View File
@@ -27,6 +27,7 @@ func (s *MenuService) UpdateMenu(menu *system.Menu) (err error) {
"Name": menu.Name,
"Title": menu.Title,
"Code": menu.Code,
"path": menu.Path,
"Permission": menu.Permission,
"Locale": menu.Locale,
"Icon": menu.Icon,
+13 -13
View File
@@ -12,6 +12,7 @@ import (
"strconv"
"sundynix-go/global"
common "sundynix-go/model/commom/request"
"sundynix-go/model/plant"
"sundynix-go/model/system"
systemReq "sundynix-go/model/system/request"
systemResp "sundynix-go/model/system/response"
@@ -157,19 +158,18 @@ func (userService *UserService) MiniLogin(code string) (result *system.User, err
if err := tx.Create(&newUser).Error; err != nil {
return err
}
//// 归一化到当天的0点(本地时区)
//now := time.Now()
//today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
//personal := plant.Personal{
// UserId: newUser.Id,
// JoinDate: today,
// PlantCount: 0,
// CareCount: 0,
// BadgeCount: 0,
//}
//if err := tx.Create(&personal).Error; err != nil {
// return err
//}
profile := plant.UserProfile{
UserId: newUser.Id,
Nickname: newUser.Name,
CurrentSunlight: 0,
TotalSunlight: 0,
PlantCount: 0,
CareCount: 0,
PostCount: 0,
}
if err := tx.Create(&profile).Error; err != nil {
return err
}
// 赋值给外部变量以便返回
user = newUser
return nil