修改页面
CI / Server (Go) (push) Has been cancelled
CI / Web (Next.js) (push) Has been cancelled
CI / Mobile (React Native) (push) Has been cancelled
CI / Admin (React) (push) Has been cancelled
CI / Docker Build (push) Has been cancelled

This commit is contained in:
zeronline
2026-06-25 16:33:32 +08:00
parent c5cccd346b
commit 545329ac40
63 changed files with 2560 additions and 161 deletions
+40
View File
@@ -85,6 +85,46 @@ func (s *UserService) DeleteAccount(id string) error {
}).Error
}
// LeaderboardEntry 排行榜条目
type LeaderboardEntry struct {
UserID string `json:"userId"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar,omitempty"`
Value int `json:"value"`
}
// GetLeaderboardByPoints 按积分排行
func (s *UserService) GetLeaderboardByPoints(limit int) ([]LeaderboardEntry, error) {
var users []models.User
if err := s.db.Where("points > 0").Order("points desc").Limit(limit).Find(&users).Error; err != nil {
return nil, err
}
entries := make([]LeaderboardEntry, 0, len(users))
for _, u := range users {
nick := ""
if u.Nickname != nil {
nick = *u.Nickname
}
entries = append(entries, LeaderboardEntry{
UserID: u.ID,
Nickname: nick,
Value: u.Points,
})
}
return entries, nil
}
// SearchUsers 搜索用户(按昵称或手机号)
func (s *UserService) SearchUsers(query string, limit int) ([]models.User, error) {
var users []models.User
q := "%" + query + "%"
if err := s.db.Where("nickname LIKE ? OR phone LIKE ?", q, q).
Limit(limit).Find(&users).Error; err != nil {
return nil, err
}
return users, nil
}
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 12)
return string(bytes), err