Compare commits

..

No commits in common. "98972401c27fe879612c5d2825acd608d27b3ac5" and "fd48afd0abeb54012bb3e42b3fff9d6a8bfe775a" have entirely different histories.

4 changed files with 30 additions and 35 deletions

View File

@ -22,7 +22,7 @@ func findSingleModeMergeTarget(ctx context.Context, svcCtx *svc.ServiceContext,
return nil, err return nil, err
} }
userSubs, queryErr := svcCtx.UserModel.QueryUserSubscribe(ctx, userId, 0, 1, 2, 3, 4, 5) userSubs, queryErr := svcCtx.UserModel.QueryUserSubscribe(ctx, userId, 0, 1, 2, 3, 5)
if queryErr != nil { if queryErr != nil {
return nil, queryErr return nil, queryErr
} }

View File

@ -102,9 +102,6 @@ func (d *Device) GetCacheKeys() []string {
if d.Identifier != "" { if d.Identifier != "" {
keys = append(keys, fmt.Sprintf("%s%s", cacheUserDeviceNumberPrefix, d.Identifier)) keys = append(keys, fmt.Sprintf("%s%s", cacheUserDeviceNumberPrefix, d.Identifier))
} }
if d.UserId != 0 {
keys = append(keys, fmt.Sprintf("%s%d", cacheUserIdPrefix, d.UserId))
}
return keys return keys
} }

View File

@ -67,7 +67,7 @@ func (m *defaultUserModel) FindSingleModeAnchorSubscribe(ctx context.Context, us
var data Subscribe var data Subscribe
err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, _ interface{}) error { err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, _ interface{}) error {
return conn.Model(&Subscribe{}). return conn.Model(&Subscribe{}).
Where("user_id = ? AND token != '' AND (order_id > 0 OR token LIKE 'iap:%') AND `status` IN ?", userId, []int64{0, 1, 2, 3, 4, 5}). Where("user_id = ? AND token != '' AND (order_id > 0 OR token LIKE 'iap:%') AND `status` IN ?", userId, []int64{0, 1, 2, 3, 5}).
Order("expire_time DESC"). Order("expire_time DESC").
Order("updated_at DESC"). Order("updated_at DESC").
Order("id DESC"). Order("id DESC").

View File

@ -234,6 +234,7 @@ func (l *ActivateOrderLogic) NewPurchase(ctx context.Context, orderInfo *order.O
anchorSub, anchorErr := l.svc.UserModel.FindSingleModeAnchorSubscribe(ctx, orderInfo.UserId) anchorSub, anchorErr := l.svc.UserModel.FindSingleModeAnchorSubscribe(ctx, orderInfo.UserId)
switch { switch {
case anchorErr == nil && anchorSub != nil: case anchorErr == nil && anchorSub != nil:
if anchorSub.SubscribeId == orderInfo.SubscribeId {
if orderInfo.ParentId == 0 && anchorSub.OrderId > 0 && anchorSub.OrderId != orderInfo.Id { if orderInfo.ParentId == 0 && anchorSub.OrderId > 0 && anchorSub.OrderId != orderInfo.Id {
if patchErr := l.patchOrderParentID(ctx, orderInfo.Id, anchorSub.OrderId); patchErr != nil { if patchErr := l.patchOrderParentID(ctx, orderInfo.Id, anchorSub.OrderId); patchErr != nil {
logger.WithContext(ctx).Error("Patch order parent_id failed", logger.WithContext(ctx).Error("Patch order parent_id failed",
@ -256,11 +257,17 @@ func (l *ActivateOrderLogic) NewPurchase(ctx context.Context, orderInfo *order.O
logger.WithContext(ctx).Infow("Single mode purchase routed to renewal in activation", logger.WithContext(ctx).Infow("Single mode purchase routed to renewal in activation",
logger.Field("mode", "single"), logger.Field("mode", "single"),
logger.Field("route", "purchase_to_renewal"), logger.Field("route", "purchase_to_renewal"),
logger.Field("plan_changed", anchorSub.SubscribeId != orderInfo.SubscribeId),
logger.Field("anchor_user_subscribe_id", anchorSub.Id), logger.Field("anchor_user_subscribe_id", anchorSub.Id),
logger.Field("order_no", orderInfo.OrderNo), logger.Field("order_no", orderInfo.OrderNo),
) )
} }
} else {
logger.WithContext(ctx).Errorw("Single mode anchor subscribe mismatch in activation",
logger.Field("order_no", orderInfo.OrderNo),
logger.Field("order_subscribe_id", orderInfo.SubscribeId),
logger.Field("anchor_subscribe_id", anchorSub.SubscribeId),
)
}
case errors.Is(anchorErr, gorm.ErrRecordNotFound): case errors.Is(anchorErr, gorm.ErrRecordNotFound):
case anchorErr != nil: case anchorErr != nil:
logger.WithContext(ctx).Error("Find single mode anchor subscribe failed", logger.WithContext(ctx).Error("Find single mode anchor subscribe failed",
@ -919,19 +926,11 @@ func (l *ActivateOrderLogic) updateSubscriptionForRenewal(ctx context.Context, u
today := time.Now().Day() today := time.Now().Day()
resetDay := userSub.ExpireTime.Day() resetDay := userSub.ExpireTime.Day()
// 套餐变更更新套餐ID和流量配额并重置已用流量
if userSub.SubscribeId != orderInfo.SubscribeId {
userSub.SubscribeId = orderInfo.SubscribeId
userSub.Traffic = sub.Traffic
userSub.Download = 0
userSub.Upload = 0
} else {
// Reset traffic if enabled // Reset traffic if enabled
if (sub.RenewalReset != nil && *sub.RenewalReset) || today == resetDay { if (sub.RenewalReset != nil && *sub.RenewalReset) || today == resetDay {
userSub.Download = 0 userSub.Download = 0
userSub.Upload = 0 userSub.Upload = 0
} }
}
if userSub.FinishedAt != nil { if userSub.FinishedAt != nil {
if userSub.FinishedAt.Before(now) && today > resetDay { if userSub.FinishedAt.Before(now) && today > resetDay {
@ -943,7 +942,6 @@ func (l *ActivateOrderLogic) updateSubscriptionForRenewal(ctx context.Context, u
userSub.FinishedAt = nil userSub.FinishedAt = nil
} }
userSub.OrderId = orderInfo.Id
userSub.ExpireTime = tool.AddTime(sub.UnitTime, orderInfo.Quantity, userSub.ExpireTime) userSub.ExpireTime = tool.AddTime(sub.UnitTime, orderInfo.Quantity, userSub.ExpireTime)
userSub.Status = 1 userSub.Status = 1
// 续费时重置过期流量字段 // 续费时重置过期流量字段