fix: add badge update time for honor wall sorting

This commit is contained in:
hy001 2026-05-16 01:40:34 +08:00
parent 463d7374af
commit 6a0ae4793b
2 changed files with 17 additions and 0 deletions

View File

@ -24,6 +24,7 @@ type badgePictureRow struct {
NotSelectURL sql.NullString `gorm:"column:not_select_url"`
AnimationURL sql.NullString `gorm:"column:animation_url"`
ExpireTime time.Time `gorm:"column:expire_time"`
UpdateTime time.Time `gorm:"column:update_time"`
}
// Current returns the current user's badge list split by long and short display type.
@ -109,6 +110,8 @@ func (s *Service) loadLongBadges(ctx context.Context, sysOrigin string, userID i
Use: true,
ExpireTime: formatMillis(state.ExpireAt),
ExpireAt: formatTime(state.ExpireAt),
UpdateTime: formatMillis(firstNonZeroTime(state.UpdateTime, state.StartAt, state.CreateTime)),
UpdatedAt: formatTime(firstNonZeroTime(state.UpdateTime, state.StartAt, state.CreateTime)),
}
item.BadgeName = firstNonEmpty(nullString(row.BadgeName), state.BadgeName, state.DisplayName)
item.Name = item.BadgeName
@ -132,6 +135,7 @@ func (s *Service) loadShortBadges(ctx context.Context, sysOrigin string, userID
Select(`
backpack.badge_id AS badge_id,
backpack.expire_time AS expire_time,
backpack.update_time AS update_time,
config.type AS source_type,
config.badge_level AS badge_level,
config.milestone AS milestone,
@ -174,6 +178,8 @@ func (s *Service) loadShortBadges(ctx context.Context, sysOrigin string, userID
Use: true,
ExpireTime: formatMillis(row.ExpireTime),
ExpireAt: formatTime(row.ExpireTime),
UpdateTime: formatMillis(row.UpdateTime),
UpdatedAt: formatTime(row.UpdateTime),
}
if row.Milestone.Valid && row.Milestone.Int64 > 0 {
item.Milestone = formatID(row.Milestone.Int64)

View File

@ -78,6 +78,8 @@ type CurrentBadgeItem struct {
Use bool `json:"use"`
ExpireTime int64 `json:"expireTime,omitempty"`
ExpireAt string `json:"expireAt,omitempty"`
UpdateTime int64 `json:"updateTime,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
}
func normalizeUser(user AuthUser) (string, error) {
@ -125,6 +127,15 @@ func formatTime(t time.Time) string {
return t.Format("2006-01-02 15:04:05")
}
func firstNonZeroTime(values ...time.Time) time.Time {
for _, value := range values {
if !value.IsZero() {
return value
}
}
return time.Time{}
}
func firstNonEmpty(values ...string) string {
for _, value := range values {
if trimmed := strings.TrimSpace(value); trimmed != "" {