fix(order): restore expired subscribe for invite gifts
Some checks failed
Build docker and publish / build (20.15.1) (push) Has been cancelled
Some checks failed
Build docker and publish / build (20.15.1) (push) Has been cancelled
This commit is contained in:
parent
280437be91
commit
cf70838142
@ -1193,7 +1193,7 @@ func (l *ActivateOrderLogic) grantGiftDays(ctx context.Context, u *user.User, da
|
||||
return nil
|
||||
}
|
||||
|
||||
activeSubscribe, err := l.svc.UserModel.FindActiveSubscribe(ctx, u.Id)
|
||||
activeSubscribe, err := l.findGiftDaysSubscription(ctx, u.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
giftLog := &log.Gift{
|
||||
@ -1215,9 +1215,18 @@ func (l *ActivateOrderLogic) grantGiftDays(ctx context.Context, u *user.User, da
|
||||
}
|
||||
return err
|
||||
}
|
||||
now := time.Now()
|
||||
if !activeSubscribe.ExpireTime.Equal(time.UnixMilli(0)) {
|
||||
activeSubscribe.ExpireTime = activeSubscribe.ExpireTime.Add(time.Duration(days) * 24 * time.Hour)
|
||||
if activeSubscribe.ExpireTime.Before(now) {
|
||||
activeSubscribe.ExpireTime = now.Add(time.Duration(days) * 24 * time.Hour)
|
||||
} else {
|
||||
activeSubscribe.ExpireTime = activeSubscribe.ExpireTime.Add(time.Duration(days) * 24 * time.Hour)
|
||||
}
|
||||
}
|
||||
activeSubscribe.Status = 1
|
||||
activeSubscribe.FinishedAt = nil
|
||||
activeSubscribe.ExpiredDownload = 0
|
||||
activeSubscribe.ExpiredUpload = 0
|
||||
err = l.svc.UserModel.UpdateSubscribe(ctx, activeSubscribe)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -1242,6 +1251,30 @@ func (l *ActivateOrderLogic) grantGiftDays(ctx context.Context, u *user.User, da
|
||||
})
|
||||
}
|
||||
|
||||
func (l *ActivateOrderLogic) findGiftDaysSubscription(ctx context.Context, userID int64) (*user.Subscribe, error) {
|
||||
activeSubscribe, err := l.svc.UserModel.FindActiveSubscribe(ctx, userID)
|
||||
if err == nil {
|
||||
return activeSubscribe, nil
|
||||
}
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var fallback user.Subscribe
|
||||
err = l.svc.DB.WithContext(ctx).
|
||||
Model(&user.Subscribe{}).
|
||||
Where("user_id = ? AND token != ''", userID).
|
||||
Where("status IN ?", []int64{0, 1, 2, 3}).
|
||||
Order("expire_time DESC").
|
||||
Order("updated_at DESC").
|
||||
Order("id DESC").
|
||||
First(&fallback).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fallback, nil
|
||||
}
|
||||
|
||||
// shouldProcessCommission determines if commission should be processed based on
|
||||
// referrer existence, commission settings, and order type
|
||||
func (l *ActivateOrderLogic) shouldProcessCommission(userInfo *user.User, isFirstPurchase bool) bool {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user