bindbox-game/internal/service/activity/activities_list.go
邹方成 6ee627139c
Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 40s
feat: 新增支付测试小程序与微信支付集成
feat(pay): 添加支付API基础结构
feat(miniapp): 创建支付测试小程序页面与配置
feat(wechatpay): 配置微信支付参数与证书
fix(guild): 修复成员列表查询条件
docs: 更新代码规范文档与需求文档
style: 统一前后端枚举显示与注释格式
refactor(admin): 重构用户奖励发放接口参数处理
test(title): 添加称号效果参数验证测试
2025-11-17 00:42:08 +08:00

49 lines
1.2 KiB
Go
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 activity
import (
"context"
"bindbox-game/internal/repository/mysql/model"
)
// ListActivities 查询活动列表支持名称、分类、Boss、状态过滤与分页
// 参数: in 列表查询输入
// 返回: 活动集合、总数与错误
func (s *service) ListActivities(ctx context.Context, in ListActivitiesInput) (items []*model.Activities, total int64, err error) {
q := s.readDB.Activities.WithContext(ctx).ReadDB()
if in.Name != "" {
q = q.Where(s.readDB.Activities.Name.Like("%" + in.Name + "%"))
}
if in.CategoryID != 0 {
q = q.Where(s.readDB.Activities.ActivityCategoryID.Eq(in.CategoryID))
}
if in.IsBoss != nil {
q = q.Where(s.readDB.Activities.IsBoss.Eq(*in.IsBoss))
}
if in.Status != nil {
q = q.Where(s.readDB.Activities.Status.Eq(*in.Status))
}
total, err = q.Count()
if err != nil {
return nil, 0, err
}
if in.Page <= 0 {
in.Page = 1
}
if in.PageSize <= 0 {
in.PageSize = 20
}
if in.PageSize > 100 {
in.PageSize = 100
}
items, err = q.Order(s.readDB.Activities.ID.Desc()).Offset((in.Page - 1) * in.PageSize).Limit(in.PageSize).Find()
if err != nil {
return nil, 0, err
}
return items, total, nil
}