bindbox-game/internal/service/user/item_card_uses_list.go

47 lines
1.3 KiB
Go
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package user
import (
"context"
"bindbox-game/internal/repository/mysql/model"
)
// ListUserItemCardUses 获取用户道具卡使用记录
// 功能描述:
// - 查询指定用户的道具卡使用记录
// - 支持分页查询默认每页20条最大100条
// - 按创建时间倒序排列
//
// 参数说明:
// - ctx: 上下文
// - userID: 用户ID
// - page: 页码从1开始小于1时自动设为1
// - pageSize: 每页条数小于1时设为20大于100时设为100
//
// 返回说明:
// - items: 道具卡使用记录列表
// - total: 总记录数
// - err: 错误信息
func (s *service) ListUserItemCardUses(ctx context.Context, userID int64, page, pageSize int) (items []*model.ActivityDrawEffects, total int64, err error) {
q := s.readDB.ActivityDrawEffects.WithContext(ctx).ReadDB().Where(s.readDB.ActivityDrawEffects.UserID.Eq(userID))
total, err = q.Count()
if err != nil {
return nil, 0, err
}
if page <= 0 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
if pageSize > 100 {
pageSize = 100
}
items, err = q.Order(s.readDB.ActivityDrawEffects.ID.Desc()).Offset((page-1)*pageSize).Limit(pageSize).Find()
if err != nil {
return nil, 0, err
}
return items, total, nil
}