Compare commits
No commits in common. "98972401c27fe879612c5d2825acd608d27b3ac5" and "fd48afd0abeb54012bb3e42b3fff9d6a8bfe775a" have entirely different histories.
98972401c2
...
fd48afd0ab
@ -22,7 +22,7 @@ func findSingleModeMergeTarget(ctx context.Context, svcCtx *svc.ServiceContext,
|
||||
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 {
|
||||
return nil, queryErr
|
||||
}
|
||||
|
||||
@ -102,9 +102,6 @@ func (d *Device) GetCacheKeys() []string {
|
||||
if 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
|
||||
}
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ func (m *defaultUserModel) FindSingleModeAnchorSubscribe(ctx context.Context, us
|
||||
var data Subscribe
|
||||
err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, _ interface{}) error {
|
||||
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("updated_at DESC").
|
||||
Order("id DESC").
|
||||
|
||||
@ -234,31 +234,38 @@ func (l *ActivateOrderLogic) NewPurchase(ctx context.Context, orderInfo *order.O
|
||||
anchorSub, anchorErr := l.svc.UserModel.FindSingleModeAnchorSubscribe(ctx, orderInfo.UserId)
|
||||
switch {
|
||||
case anchorErr == nil && anchorSub != nil:
|
||||
if orderInfo.ParentId == 0 && anchorSub.OrderId > 0 && anchorSub.OrderId != orderInfo.Id {
|
||||
if patchErr := l.patchOrderParentID(ctx, orderInfo.Id, anchorSub.OrderId); patchErr != nil {
|
||||
logger.WithContext(ctx).Error("Patch order parent_id failed",
|
||||
logger.Field("error", patchErr.Error()),
|
||||
if anchorSub.SubscribeId == orderInfo.SubscribeId {
|
||||
if orderInfo.ParentId == 0 && anchorSub.OrderId > 0 && anchorSub.OrderId != orderInfo.Id {
|
||||
if patchErr := l.patchOrderParentID(ctx, orderInfo.Id, anchorSub.OrderId); patchErr != nil {
|
||||
logger.WithContext(ctx).Error("Patch order parent_id failed",
|
||||
logger.Field("error", patchErr.Error()),
|
||||
logger.Field("order_no", orderInfo.OrderNo),
|
||||
)
|
||||
} else {
|
||||
orderInfo.ParentId = anchorSub.OrderId
|
||||
}
|
||||
}
|
||||
|
||||
if renewErr := l.updateSubscriptionForRenewal(ctx, anchorSub, sub, orderInfo); renewErr != nil {
|
||||
logger.WithContext(ctx).Error("Single mode renewal fallback failed",
|
||||
logger.Field("error", renewErr.Error()),
|
||||
logger.Field("anchor_user_subscribe_id", anchorSub.Id),
|
||||
logger.Field("order_no", orderInfo.OrderNo),
|
||||
)
|
||||
} else {
|
||||
orderInfo.ParentId = anchorSub.OrderId
|
||||
userSub = anchorSub
|
||||
logger.WithContext(ctx).Infow("Single mode purchase routed to renewal in activation",
|
||||
logger.Field("mode", "single"),
|
||||
logger.Field("route", "purchase_to_renewal"),
|
||||
logger.Field("anchor_user_subscribe_id", anchorSub.Id),
|
||||
logger.Field("order_no", orderInfo.OrderNo),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if renewErr := l.updateSubscriptionForRenewal(ctx, anchorSub, sub, orderInfo); renewErr != nil {
|
||||
logger.WithContext(ctx).Error("Single mode renewal fallback failed",
|
||||
logger.Field("error", renewErr.Error()),
|
||||
logger.Field("anchor_user_subscribe_id", anchorSub.Id),
|
||||
logger.Field("order_no", orderInfo.OrderNo),
|
||||
)
|
||||
} else {
|
||||
userSub = anchorSub
|
||||
logger.WithContext(ctx).Infow("Single mode purchase routed to renewal in activation",
|
||||
logger.Field("mode", "single"),
|
||||
logger.Field("route", "purchase_to_renewal"),
|
||||
logger.Field("plan_changed", anchorSub.SubscribeId != orderInfo.SubscribeId),
|
||||
logger.Field("anchor_user_subscribe_id", anchorSub.Id),
|
||||
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):
|
||||
@ -919,18 +926,10 @@ func (l *ActivateOrderLogic) updateSubscriptionForRenewal(ctx context.Context, u
|
||||
today := time.Now().Day()
|
||||
resetDay := userSub.ExpireTime.Day()
|
||||
|
||||
// 套餐变更:更新套餐ID和流量配额,并重置已用流量
|
||||
if userSub.SubscribeId != orderInfo.SubscribeId {
|
||||
userSub.SubscribeId = orderInfo.SubscribeId
|
||||
userSub.Traffic = sub.Traffic
|
||||
// Reset traffic if enabled
|
||||
if (sub.RenewalReset != nil && *sub.RenewalReset) || today == resetDay {
|
||||
userSub.Download = 0
|
||||
userSub.Upload = 0
|
||||
} else {
|
||||
// Reset traffic if enabled
|
||||
if (sub.RenewalReset != nil && *sub.RenewalReset) || today == resetDay {
|
||||
userSub.Download = 0
|
||||
userSub.Upload = 0
|
||||
}
|
||||
}
|
||||
|
||||
if userSub.FinishedAt != nil {
|
||||
@ -943,7 +942,6 @@ func (l *ActivateOrderLogic) updateSubscriptionForRenewal(ctx context.Context, u
|
||||
userSub.FinishedAt = nil
|
||||
}
|
||||
|
||||
userSub.OrderId = orderInfo.Id
|
||||
userSub.ExpireTime = tool.AddTime(sub.UnitTime, orderInfo.Quantity, userSub.ExpireTime)
|
||||
userSub.Status = 1
|
||||
// 续费时重置过期流量字段
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user