- 支持创建/编辑/删除优惠码,设置赠送金额和使用限制 - 注册页面实时验证优惠码并显示赠送金额 - 支持 URL 参数自动填充 (?promo=CODE) - 添加优惠码验证接口速率限制 - 使用数据库行锁防止并发超限 - 新增后台优惠码管理页面,支持复制注册链接
31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
|
)
|
|
|
|
// PromoCodeRepository 优惠码仓储接口
|
|
type PromoCodeRepository interface {
|
|
// 基础 CRUD
|
|
Create(ctx context.Context, code *PromoCode) error
|
|
GetByID(ctx context.Context, id int64) (*PromoCode, error)
|
|
GetByCode(ctx context.Context, code string) (*PromoCode, error)
|
|
GetByCodeForUpdate(ctx context.Context, code string) (*PromoCode, error) // 带行锁的查询,用于并发控制
|
|
Update(ctx context.Context, code *PromoCode) error
|
|
Delete(ctx context.Context, id int64) error
|
|
|
|
// 列表查询
|
|
List(ctx context.Context, params pagination.PaginationParams) ([]PromoCode, *pagination.PaginationResult, error)
|
|
ListWithFilters(ctx context.Context, params pagination.PaginationParams, status, search string) ([]PromoCode, *pagination.PaginationResult, error)
|
|
|
|
// 使用记录
|
|
CreateUsage(ctx context.Context, usage *PromoCodeUsage) error
|
|
GetUsageByPromoCodeAndUser(ctx context.Context, promoCodeID, userID int64) (*PromoCodeUsage, error)
|
|
ListUsagesByPromoCode(ctx context.Context, promoCodeID int64, params pagination.PaginationParams) ([]PromoCodeUsage, *pagination.PaginationResult, error)
|
|
|
|
// 计数操作
|
|
IncrementUsedCount(ctx context.Context, id int64) error
|
|
}
|