快照订单号以及退款订单号
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m27s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m27s
This commit is contained in:
@@ -714,6 +714,10 @@ func (s *Service) GetPackages(ctx context.Context, assetType string, id uint, pa
|
||||
PackageID: u.PackageID,
|
||||
PackageName: pkgName,
|
||||
PackageType: pkgType,
|
||||
OrderID: u.OrderID,
|
||||
OrderNo: u.OrderNo,
|
||||
RefundID: u.RefundID,
|
||||
RefundNo: u.RefundNo,
|
||||
UsageType: u.UsageType,
|
||||
Status: u.Status,
|
||||
StatusName: packageStatusName(u.Status),
|
||||
@@ -791,6 +795,10 @@ func (s *Service) GetCurrentPackage(ctx context.Context, assetType string, id ui
|
||||
PackageID: usage.PackageID,
|
||||
PackageName: pkgName,
|
||||
PackageType: pkgType,
|
||||
OrderID: usage.OrderID,
|
||||
OrderNo: usage.OrderNo,
|
||||
RefundID: usage.RefundID,
|
||||
RefundNo: usage.RefundNo,
|
||||
UsageType: usage.UsageType,
|
||||
Status: usage.Status,
|
||||
StatusName: packageStatusName(usage.Status),
|
||||
|
||||
@@ -2011,6 +2011,7 @@ func (s *Service) activateMainPackage(ctx context.Context, tx *gorm.DB, order *m
|
||||
Updater: order.Creator,
|
||||
},
|
||||
OrderID: order.ID,
|
||||
OrderNo: order.OrderNo,
|
||||
PackageID: pkg.ID,
|
||||
PackageName: pkg.PackageName,
|
||||
UsageType: order.OrderType,
|
||||
@@ -2095,6 +2096,7 @@ func (s *Service) activateAddonPackage(ctx context.Context, tx *gorm.DB, order *
|
||||
Updater: order.Creator,
|
||||
},
|
||||
OrderID: order.ID,
|
||||
OrderNo: order.OrderNo,
|
||||
PackageID: pkg.ID,
|
||||
PackageName: pkg.PackageName,
|
||||
UsageType: order.OrderType,
|
||||
|
||||
@@ -491,12 +491,12 @@ func (s *ActivationService) syncCarrierStatusActivated(ctx context.Context, tx *
|
||||
}
|
||||
}
|
||||
|
||||
// InvalidatePackagesForRefund 退款精准失效套餐
|
||||
// InvalidatePackagesForRefund 退款精准失效套餐并写入退款快照
|
||||
// 规则:
|
||||
// 1. 优先按 packageUsageID 精准失效单条套餐(且必须属于当前退款订单)
|
||||
// 2. 未传 packageUsageID 时,按 orderID 失效该订单生成的套餐
|
||||
// 3. 若命中主套餐,级联失效其加油包,避免残留挂靠关系
|
||||
func (s *ActivationService) InvalidatePackagesForRefund(ctx context.Context, assetType string, assetID uint, orderID uint, packageUsageID *uint) error {
|
||||
func (s *ActivationService) InvalidatePackagesForRefund(ctx context.Context, assetType string, assetID uint, orderID uint, refundID uint, refundNo string, packageUsageID *uint) error {
|
||||
if orderID == 0 {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的订单ID")
|
||||
}
|
||||
@@ -584,10 +584,20 @@ func (s *ActivationService) InvalidatePackagesForRefund(ctx context.Context, ass
|
||||
return nil
|
||||
}
|
||||
|
||||
updates := map[string]any{
|
||||
"status": constants.PackageUsageStatusInvalidated,
|
||||
}
|
||||
if refundID > 0 {
|
||||
updates["refund_id"] = refundID
|
||||
}
|
||||
if refundNo != "" {
|
||||
updates["refund_no"] = refundNo
|
||||
}
|
||||
|
||||
result := s.db.WithContext(ctx).
|
||||
Model(&model.PackageUsage{}).
|
||||
Where("id IN ?", targetIDs).
|
||||
Update("status", constants.PackageUsageStatusInvalidated)
|
||||
Updates(updates)
|
||||
if result.Error != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, result.Error, "退款失效套餐失败")
|
||||
}
|
||||
@@ -596,6 +606,8 @@ func (s *ActivationService) InvalidatePackagesForRefund(ctx context.Context, ass
|
||||
zap.String("asset_type", assetType),
|
||||
zap.Uint("asset_id", assetID),
|
||||
zap.Uint("order_id", orderID),
|
||||
zap.Uint("refund_id", refundID),
|
||||
zap.String("refund_no", refundNo),
|
||||
zap.Int("target_count", len(targetIDs)),
|
||||
zap.Int64("affected", result.RowsAffected),
|
||||
)
|
||||
|
||||
@@ -516,11 +516,13 @@ func (s *Service) handleAssetReset(ctx context.Context, refundID uint) {
|
||||
|
||||
// 1. 按退款单精准失效套餐(仅处理本次退款订单关联套餐)
|
||||
if s.packageActivationService != nil {
|
||||
if err := s.packageActivationService.InvalidatePackagesForRefund(ctx, assetType, assetID, order.ID, refund.PackageUsageID); err != nil {
|
||||
if err := s.packageActivationService.InvalidatePackagesForRefund(ctx, assetType, assetID, order.ID, refund.ID, refund.RefundNo, refund.PackageUsageID); err != nil {
|
||||
fields := []zap.Field{
|
||||
zap.String("asset_type", assetType),
|
||||
zap.Uint("asset_id", assetID),
|
||||
zap.Uint("order_id", order.ID),
|
||||
zap.Uint("refund_id", refund.ID),
|
||||
zap.String("refund_no", refund.RefundNo),
|
||||
zap.Error(err),
|
||||
}
|
||||
if refund.PackageUsageID != nil {
|
||||
|
||||
Reference in New Issue
Block a user