fix(pricing): 修复 priceSupplement 在 Kafka 事件链中丢失的问题

## 问题描述

认种树动态定价涨价功能 (ed6b48562) 在 planting-service 的资金分配
中正确计算了 HQ_PRICE_SUPPLEMENT,但 priceSupplement 字段未随
Kafka 事件传递到 reward-service,导致 reward-service 的
calculateHqPriceSupplement 永远收到 priceSupplement=0,涨价部分
的总部奖励分配不会执行。

## 事件链路径 (修复前 → 修复后)

  planting-service (contract-signing.service.ts)
    ↓ contract.signed / contract.expired
    ↓ 修复前: 不含 priceSupplement 
    ↓ 修复后: 携带 order.priceSupplement 
  referral-service (contract-signing.handler.ts)
    ↓ planting.order.paid / planting.order.expired
    ↓ 修复前: 不含 priceSupplement 
    ↓ 修复后: 透传 eventData.priceSupplement || 0 
  reward-service (event-consumer.controller.ts)
    ↓ calculateHqPriceSupplement(priceSupplement)
    ↓ 修复前: 始终为 0,不分配 
    ↓ 修复后: 收到实际值,正确分配给 S0000000001 

## 修改文件

1. planting-service/src/infrastructure/kafka/event-publisher.service.ts
   - ContractSigningEventData 接口新增 priceSupplement?: number 字段

2. planting-service/src/application/services/contract-signing.service.ts
   - signContract(): publishContractSigned 时传递 order.priceSupplement
   - handleExpiredTasks(): publishContractExpired 时传递 order.priceSupplement

3. referral-service/src/application/event-handlers/contract-signing.handler.ts
   - ContractSigningEvent 接口新增 priceSupplement?: number 字段
   - publishOrderPaidEvent(): 透传 priceSupplement 到 planting.order.paid
   - publishOrderExpiredEvent(): 透传 priceSupplement 到 planting.order.expired

## 向后兼容

- priceSupplement 为可选字段 (?: number),默认 fallback 为 0
- 已存在的订单 priceSupplement=0,不影响现有分配逻辑
- reward-service event-consumer 已有 || 0 fallback 保护

## 验证方法

1. 设置 supplement > 0 后创建认种订单
2. 签署合同后检查 reward-service 日志是否有 HQ_PRICE_SUPPLEMENT 分配记录
3. 检查总部账户 S0000000001 是否收到 priceSupplement * treeCount 的入账

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-26 07:10:31 -08:00
parent ed6b48562a
commit 5adcd023e6
3 changed files with 8 additions and 0 deletions

View File

@ -329,6 +329,7 @@ export class ContractSigningService {
provinceCode: task.provinceCode, provinceCode: task.provinceCode,
cityCode: task.cityCode, cityCode: task.cityCode,
signedAt: task.signedAt?.toISOString(), signedAt: task.signedAt?.toISOString(),
priceSupplement: order.priceSupplement,
}); });
} }
@ -411,6 +412,7 @@ export class ContractSigningService {
provinceCode: task.provinceCode, provinceCode: task.provinceCode,
cityCode: task.cityCode, cityCode: task.cityCode,
expiredAt: new Date().toISOString(), expiredAt: new Date().toISOString(),
priceSupplement: order.priceSupplement,
}); });
count++; count++;

View File

@ -38,6 +38,8 @@ export interface ContractSigningEventData {
cityCode: string; cityCode: string;
signedAt?: string; // contract.signed signedAt?: string; // contract.signed
expiredAt?: string; // contract.expired expiredAt?: string; // contract.expired
// [2026-02-26] 总部运营成本压力涨价(每棵树加价金额),归总部 (S0000000001)
priceSupplement?: number;
} }
@Injectable() @Injectable()

View File

@ -16,6 +16,8 @@ interface ContractSigningEvent {
cityCode: string; cityCode: string;
signedAt?: string; // contract.signed signedAt?: string; // contract.signed
expiredAt?: string; // contract.expired expiredAt?: string; // contract.expired
// [2026-02-26] 总部运营成本压力涨价(每棵树加价金额),归总部 (S0000000001)
priceSupplement?: number;
}; };
} }
@ -177,6 +179,7 @@ export class ContractSigningHandler implements OnModuleInit {
provinceCode: eventData.provinceCode, provinceCode: eventData.provinceCode,
cityCode: eventData.cityCode, cityCode: eventData.cityCode,
paidAt: eventData.signedAt || new Date().toISOString(), paidAt: eventData.signedAt || new Date().toISOString(),
priceSupplement: eventData.priceSupplement || 0,
}, },
}, },
}); });
@ -245,6 +248,7 @@ export class ContractSigningHandler implements OnModuleInit {
provinceCode: eventData.provinceCode, provinceCode: eventData.provinceCode,
cityCode: eventData.cityCode, cityCode: eventData.cityCode,
expiredAt: eventData.expiredAt || new Date().toISOString(), expiredAt: eventData.expiredAt || new Date().toISOString(),
priceSupplement: eventData.priceSupplement || 0,
}, },
}, },
}); });