package voiceroomrocket import ( "context" "net/http" "time" "chatapp3-golang/internal/model" ) // ListRewardPopups 返回当前用户未读中奖弹窗记录。 func (s *Service) ListRewardPopups(ctx context.Context, user AuthUser, roomID int64) (*RewardPopupResponse, error) { sysOrigin := s.normalizeSysOrigin(user.SysOrigin) query := s.repo.DB.WithContext(ctx). Where("sys_origin = ? AND user_id = ? AND popup_status = ?", sysOrigin, user.UserID, popupStatusUnread). Order("create_time DESC, id DESC"). Limit(100) if roomID > 0 { query = query.Where("room_id = ?", roomID) } var rows []model.VoiceRoomRocketRewardRecord if err := query.Find(&rows).Error; err != nil { return nil, err } records := make([]RewardRecordView, 0, len(rows)) for _, row := range rows { records = append(records, toRewardRecordView(row)) } return &RewardPopupResponse{Records: records}, nil } // AckRewardPopups 标记中奖弹窗为已读。 func (s *Service) AckRewardPopups(ctx context.Context, user AuthUser, req AckRewardPopupsRequest) error { if len(req.RewardRecordIDs) == 0 { return NewAppError(http.StatusBadRequest, "missing_reward_record_ids", "rewardRecordIds is required") } ids := make([]int64, 0, len(req.RewardRecordIDs)) for _, id := range req.RewardRecordIDs { if id.Int64() > 0 { ids = append(ids, id.Int64()) } } if len(ids) == 0 { return NewAppError(http.StatusBadRequest, "missing_reward_record_ids", "rewardRecordIds is required") } return s.repo.DB.WithContext(ctx). Model(&model.VoiceRoomRocketRewardRecord{}). Where("sys_origin = ? AND user_id = ? AND id IN ?", s.normalizeSysOrigin(user.SysOrigin), user.UserID, ids). Updates(map[string]any{ "popup_status": popupStatusRead, "update_time": time.Now(), }).Error } // PageRewardRecords 返回用户最近中奖记录。 func (s *Service) PageRewardRecords(ctx context.Context, user AuthUser, roomID int64, cursor int, limit int) (*RewardRecordPageResponse, error) { cursor, limit = normalizePage(cursor, limit) snapshot, err := s.loadConfig(ctx, user.SysOrigin) if err != nil { return nil, err } keepDays := snapshot.RewardRecordKeepDays if keepDays <= 0 { keepDays = defaultRewardRecordKeepDays } startAt := time.Now().AddDate(0, 0, -keepDays) query := s.repo.DB.WithContext(ctx). Where("sys_origin = ? AND user_id = ? AND create_time >= ?", snapshot.SysOrigin, user.UserID, startAt). Order("create_time DESC, id DESC"). Offset((cursor - 1) * limit). Limit(limit) if roomID > 0 { query = query.Where("room_id = ?", roomID) } var rows []model.VoiceRoomRocketRewardRecord if err := query.Find(&rows).Error; err != nil { return nil, err } records := make([]RewardRecordView, 0, len(rows)) for _, row := range rows { records = append(records, toRewardRecordView(row)) } resp := &RewardRecordPageResponse{ Records: records, Cursor: cursor, Limit: limit, } if len(records) == 0 { resp.EmptyReason = "仅展示最近 35 天的记录" } return resp, nil } // PageAdminLaunchRecords 返回后台发射记录。 func (s *Service) PageAdminLaunchRecords(ctx context.Context, sysOrigin string, roomID int64, cursor int, limit int) (*LaunchRecordPageResponse, error) { cursor, limit = normalizePage(cursor, limit) query := s.repo.DB.WithContext(ctx). Where("sys_origin = ?", s.normalizeSysOrigin(sysOrigin)). Order("launch_time DESC, id DESC"). Offset((cursor - 1) * limit). Limit(limit) if roomID > 0 { query = query.Where("room_id = ?", roomID) } var rows []model.VoiceRoomRocketLaunch if err := query.Find(&rows).Error; err != nil { return nil, err } records := make([]LaunchRecordView, 0, len(rows)) for _, row := range rows { records = append(records, toLaunchRecordView(row)) } return &LaunchRecordPageResponse{Records: records, Cursor: cursor, Limit: limit}, nil } // PageAdminRewardRecords 返回后台奖励记录。 func (s *Service) PageAdminRewardRecords(ctx context.Context, sysOrigin string, roomID int64, userID int64, grantStatus string, cursor int, limit int) (*RewardRecordPageResponse, error) { cursor, limit = normalizePage(cursor, limit) query := s.repo.DB.WithContext(ctx). Where("sys_origin = ?", s.normalizeSysOrigin(sysOrigin)). Order("create_time DESC, id DESC"). Offset((cursor - 1) * limit). Limit(limit) if roomID > 0 { query = query.Where("room_id = ?", roomID) } if userID > 0 { query = query.Where("user_id = ?", userID) } if grantStatus != "" { query = query.Where("grant_status = ?", grantStatus) } var rows []model.VoiceRoomRocketRewardRecord if err := query.Find(&rows).Error; err != nil { return nil, err } records := make([]RewardRecordView, 0, len(rows)) for _, row := range rows { records = append(records, toRewardRecordView(row)) } return &RewardRecordPageResponse{Records: records, Cursor: cursor, Limit: limit}, nil }