Constraint: 切换 main 前必须保存当前七月分支全部项目进展,套餐生效提案仅属于 Iteration/7-11。 Rejected: 将七月套餐修复直接移植到 main | 两个分支的可靠投递架构不同。 Confidence: medium Scope-risk: broad Directive: 不得将本提交整体 cherry-pick 到 main;main 套餐热修必须基于其纯 Asynq 代码独立实施。 Tested: git diff --check;openspec validate fix-package-activation-starvation --strict。 Not-tested: 按用户要求未运行自动化测试;go build ./... 因当前审计改造中的 Enterprise 模型字面量和 role.recordFailure 参数类型错误未通过。
40 lines
1.6 KiB
Go
40 lines
1.6 KiB
Go
package payment
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
agentrecharge "github.com/break/junhong_cmp_fiber/internal/application/agentrecharge"
|
|
"github.com/break/junhong_cmp_fiber/internal/infrastructure/messaging/outbox"
|
|
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
)
|
|
|
|
// AgentRechargePaymentEventWriter 将支付确认事实写入公共 Outbox。
|
|
type AgentRechargePaymentEventWriter struct {
|
|
outbox *outbox.Repository
|
|
}
|
|
|
|
// NewAgentRechargePaymentEventWriter 创建代理充值支付确认事件 Writer。
|
|
func NewAgentRechargePaymentEventWriter(repository *outbox.Repository) *AgentRechargePaymentEventWriter {
|
|
return &AgentRechargePaymentEventWriter{outbox: repository}
|
|
}
|
|
|
|
// Append 在支付确认事务内追加稳定的代理充值入账事件。
|
|
func (w *AgentRechargePaymentEventWriter) Append(ctx context.Context, tx *gorm.DB, event agentrecharge.PaymentConfirmedEvent) error {
|
|
if w == nil || w.outbox == nil {
|
|
return errors.New(errors.CodeInternalError, "代理充值支付确认 Outbox Writer 未配置")
|
|
}
|
|
_, err := w.outbox.Append(ctx, tx, outbox.Envelope{
|
|
EventID: event.EventID, EventType: constants.OutboxEventTypeAgentRechargePaymentConfirmed,
|
|
PayloadVersion: constants.AgentRechargePaymentConfirmedPayloadVersionV1,
|
|
AggregateType: "agent_recharge", AggregateID: strconv.FormatUint(uint64(event.RechargeID), 10),
|
|
ResourceType: "payment", ResourceID: strconv.FormatUint(uint64(event.PaymentID), 10),
|
|
BusinessKey: event.EventID, RequestID: event.RequestID, CorrelationID: event.CorrelationID,
|
|
ParentEventID: event.ParentEventID, Payload: event,
|
|
})
|
|
return err
|
|
}
|