双倍时间bug
Build docker and publish / build (20.15.1) (push) Successful in 8m33s

This commit is contained in:
2026-03-07 02:05:48 -08:00
parent 4d913c1728
commit 03573d2e65
4 changed files with 1069 additions and 19 deletions
@@ -241,7 +241,7 @@ func (l *AttachTransactionLogic) Attach(req *types.AttachAppleTransactionRequest
if existTx != nil && existTx.Id > 0 {
if isNewPurchaseOrder {
if syncErr := l.syncOrderStatusAndEnqueue(orderInfo); syncErr != nil {
if syncErr := l.syncOrderStatusAndEnqueue(orderInfo, 0); syncErr != nil {
l.Errorw("事务已处理但同步订单状态失败", logger.Field("orderNo", req.OrderNo), logger.Field("error", syncErr.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "sync order status failed: %v", syncErr.Error())
}
@@ -309,16 +309,10 @@ func (l *AttachTransactionLogic) Attach(req *types.AttachAppleTransactionRequest
if !isNewPurchaseOrder {
merged := false
if orderLinkedSub != nil {
if _, e := l.extendSubscribeForIAP(orderLinkedSub, exp, subscribeId, tx); e != nil {
l.Errorw("更新订单关联订阅失败", logger.Field("error", e.Error()), logger.Field("userSubscribeId", orderLinkedSub.Id))
return e
}
// 不在此处更新 expire_time:由激活队列统一写入,避免双重叠加天数
merged = true
} else if singleModeAnchorSub != nil {
if _, e := l.extendSubscribeForIAP(singleModeAnchorSub, exp, subscribeId, tx); e != nil {
l.Errorw("更新单订阅锚点失败", logger.Field("error", e.Error()), logger.Field("userSubscribeId", singleModeAnchorSub.Id))
return e
}
// 同上
merged = true
}
if !merged {
@@ -343,7 +337,7 @@ func (l *AttachTransactionLogic) Attach(req *types.AttachAppleTransactionRequest
} else {
l.Infow("首购订单跳过 attach 阶段订阅写入", logger.Field("orderNo", orderInfo.OrderNo), logger.Field("orderType", orderInfo.Type))
}
if e := l.syncOrderStatusAndEnqueue(orderInfo, tx); e != nil {
if e := l.syncOrderStatusAndEnqueue(orderInfo, exp.Unix(), tx); e != nil {
l.Errorw("同步订单状态失败", logger.Field("orderNo", req.OrderNo), logger.Field("error", e.Error()))
return e
}
@@ -360,7 +354,7 @@ func (l *AttachTransactionLogic) Attach(req *types.AttachAppleTransactionRequest
}, nil
}
func (l *AttachTransactionLogic) syncOrderStatusAndEnqueue(orderInfo *ordermodel.Order, tx ...*gorm.DB) error {
func (l *AttachTransactionLogic) syncOrderStatusAndEnqueue(orderInfo *ordermodel.Order, iapExpireAt int64, tx ...*gorm.DB) error {
if orderInfo == nil || orderInfo.OrderNo == "" {
return errors.New("order info is nil")
}
@@ -372,7 +366,7 @@ func (l *AttachTransactionLogic) syncOrderStatusAndEnqueue(orderInfo *ordermodel
l.Infow("更新订单状态成功", logger.Field("orderNo", orderInfo.OrderNo), logger.Field("status", orderStatusPaid))
}
// enqueue activation regardless (idempotent handler downstream)
payload := queueType.ForthwithActivateOrderPayload{OrderNo: orderInfo.OrderNo}
payload := queueType.ForthwithActivateOrderPayload{OrderNo: orderInfo.OrderNo, IAPExpireAt: iapExpireAt}
bytes, _ := json.Marshal(payload)
task := asynq.NewTask(queueType.ForthwithActivateOrder, bytes)
if _, err := l.svcCtx.Queue.EnqueueContext(l.ctx, task); err != nil {