收口审计治理与套餐任务进展
Constraint: 在线热修前必须保存当前迭代分支全部有效代码进展 Confidence: medium Scope-risk: broad Directive: 后续修改需保持审计事件与业务事务边界一致 Tested: git diff --cached --check Not-tested: 未运行全量测试,提交用于切换分支前保存既有工作
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/infrastructure/audit"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/service/commission_stats"
|
||||
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
@@ -30,6 +31,7 @@ type Service struct {
|
||||
packageStore *postgres.PackageStore
|
||||
commissionStatsStore *postgres.ShopSeriesCommissionStatsStore
|
||||
commissionStatsService *commission_stats.Service
|
||||
auditWriter *audit.Writer
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
@@ -71,12 +73,19 @@ func New(
|
||||
}
|
||||
}
|
||||
|
||||
// SetAuditWriter 注入佣金计算与入账统一审计 Writer。
|
||||
func (s *Service) SetAuditWriter(writer *audit.Writer) {
|
||||
s.auditWriter = writer
|
||||
}
|
||||
|
||||
func (s *Service) CalculateCommission(ctx context.Context, orderID uint) error {
|
||||
return s.db.Transaction(func(tx *gorm.DB) error {
|
||||
order, err := s.orderStore.GetByID(ctx, orderID)
|
||||
var order *model.Order
|
||||
err := s.db.Transaction(func(tx *gorm.DB) error {
|
||||
loadedOrder, err := s.orderStore.GetByID(ctx, orderID)
|
||||
if err != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "获取订单失败")
|
||||
}
|
||||
order = loadedOrder
|
||||
|
||||
if order.CommissionStatus == model.CommissionStatusCompleted || order.CommissionStatus == model.CommissionStatusPendingReview {
|
||||
s.logger.Warn("订单佣金流程已结束,跳过",
|
||||
@@ -120,8 +129,12 @@ func (s *Service) CalculateCommission(ctx context.Context, orderID uint) error {
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "更新订单佣金结果失败")
|
||||
}
|
||||
|
||||
return nil
|
||||
return s.appendCommissionCalculationAudit(ctx, tx, order, commissionStatus, commissionResult)
|
||||
})
|
||||
if err != nil {
|
||||
s.recordCommissionCalculationFailure(ctx, order, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Service) CalculateCostDiffCommission(ctx context.Context, order *model.Order) ([]*model.CommissionRecord, error) {
|
||||
@@ -702,7 +715,7 @@ func (s *Service) creditCommissionInTx(ctx context.Context, tx *gorm.DB, record
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "创建钱包交易记录失败")
|
||||
}
|
||||
|
||||
return nil
|
||||
return s.appendCommissionCreditAudit(ctx, tx, record, &wallet, transaction, balanceBefore)
|
||||
}
|
||||
|
||||
func (s *Service) persistCommissionRecordsInTx(ctx context.Context, tx *gorm.DB, records []*model.CommissionRecord) error {
|
||||
|
||||
Reference in New Issue
Block a user