修复(#81): 修复永久订阅回归促销误判
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -250,12 +251,7 @@ func (s *gormPromoEligibilitySource) UserCreatedAt(ctx context.Context, userID i
|
||||
|
||||
func (s *gormPromoEligibilitySource) LastSubscribeExpireAt(ctx context.Context, userID int64) (time.Time, error) {
|
||||
var item user.Subscribe
|
||||
err := s.db.WithContext(ctx).
|
||||
Model(&user.Subscribe{}).
|
||||
Where("user_id = ?", userID).
|
||||
Where("expire_time != ?", time.UnixMilli(0)).
|
||||
Order("expire_time DESC").
|
||||
Limit(1).
|
||||
err := lastSubscribeExpireQuery(s.db.WithContext(ctx), userID).
|
||||
Take(&item).Error
|
||||
if err != nil {
|
||||
if stderrors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@@ -266,6 +262,17 @@ func (s *gormPromoEligibilitySource) LastSubscribeExpireAt(ctx context.Context,
|
||||
return item.ExpireTime, nil
|
||||
}
|
||||
|
||||
func lastSubscribeExpireQuery(db *gorm.DB, userID int64) *gorm.DB {
|
||||
return db.
|
||||
Model(&user.Subscribe{}).
|
||||
Where("user_id = ?", userID).
|
||||
Order(clause.OrderBy{Expression: clause.Expr{
|
||||
SQL: "CASE WHEN expire_time = ? THEN 0 ELSE 1 END ASC, expire_time DESC",
|
||||
Vars: []interface{}{time.UnixMilli(0)},
|
||||
}}).
|
||||
Limit(1)
|
||||
}
|
||||
|
||||
func loadEnabledPromoRules(ctx context.Context, svcCtx *svc.ServiceContext) ([]promoRule, error) {
|
||||
if cached, ok := getPromoCache[[]promoRule](ctx, svcCtx, promoRulesEnabledCacheKey); ok {
|
||||
return cached, nil
|
||||
|
||||
Reference in New Issue
Block a user