refactor(utils): 修复密码哈希比较逻辑错误 feat(user): 新增按状态筛选优惠券接口 docs: 添加虚拟发货与任务中心相关文档 fix(wechat): 修正Code2Session上下文传递问题 test: 补充订单折扣与积分转换测试用例 build: 更新配置文件与构建脚本 style: 清理多余的空行与注释
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package activity
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
"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))
|
||
}
|
||
|
||
now := time.Now()
|
||
q = q.Where(s.readDB.Activities.EndTime.Gt(now))
|
||
|
||
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
|
||
}
|