From c93f43546e398331de6fd96917ff4e0726042fd3 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 13 Dec 2025 06:13:59 -0800 Subject: [PATCH] =?UTF-8?q?fix(planting-service):=20PlantingOrderPaidEvent?= =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=20accountSequence=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug 3 修复: wallet-service 结算待领取奖励时需要 accountSequence - PlantingOrderPaidEvent 事件 data 添加 accountSequence 字段 - markAsPaid(accountSequence) 方法接收并传递 accountSequence - payOrder 调用 markAsPaid 时传入 accountSequence - 更新相关单元测试 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../services/planting-application.service.ts | 3 ++- .../domain/aggregates/planting-order.aggregate.spec.ts | 10 +++++----- .../src/domain/aggregates/planting-order.aggregate.ts | 4 +++- .../src/domain/events/planting-order-paid.event.ts | 1 + 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/backend/services/planting-service/src/application/services/planting-application.service.ts b/backend/services/planting-service/src/application/services/planting-application.service.ts index c0456894..73a21c44 100644 --- a/backend/services/planting-service/src/application/services/planting-application.service.ts +++ b/backend/services/planting-service/src/application/services/planting-application.service.ts @@ -259,7 +259,8 @@ export class PlantingApplicationService { try { // 6. 标记已支付 (内存操作) // 注意:资金分配已移至 reward-service - order.markAsPaid(); + // accountSequence 用于 wallet-service 结算用户的待领取奖励 + order.markAsPaid(accountSequence || ''); // 7. 使用事务保存本地数据库的所有变更 + Outbox事件 // 这确保了订单状态、用户持仓、批次数据、以及事件发布的原子性 diff --git a/backend/services/planting-service/src/domain/aggregates/planting-order.aggregate.spec.ts b/backend/services/planting-service/src/domain/aggregates/planting-order.aggregate.spec.ts index 7d86c660..5fdecaca 100644 --- a/backend/services/planting-service/src/domain/aggregates/planting-order.aggregate.spec.ts +++ b/backend/services/planting-service/src/domain/aggregates/planting-order.aggregate.spec.ts @@ -90,7 +90,7 @@ describe('PlantingOrder', () => { jest.advanceTimersByTime(5000); order.confirmProvinceCity(); - order.markAsPaid(); + order.markAsPaid('D25121300001'); expect(order.status).toBe(PlantingOrderStatus.PAID); expect(order.paidAt).not.toBeNull(); @@ -101,7 +101,7 @@ describe('PlantingOrder', () => { it('应该拒绝未确认省市的支付', () => { const order = PlantingOrder.create(BigInt(1), 1); - expect(() => order.markAsPaid()).toThrow('订单状态错误'); + expect(() => order.markAsPaid('D25121300001')).toThrow('订单状态错误'); }); }); @@ -113,7 +113,7 @@ describe('PlantingOrder', () => { order.selectProvinceCity('440000', '广东省', '440100', '广州市'); jest.advanceTimersByTime(5000); order.confirmProvinceCity(); - order.markAsPaid(); + order.markAsPaid('D25121300001'); const allocations = [ new FundAllocation(FundAllocationTargetType.COST_ACCOUNT, 400, 'ACC1'), @@ -175,7 +175,7 @@ describe('PlantingOrder', () => { order.selectProvinceCity('440000', '广东省', '440100', '广州市'); jest.advanceTimersByTime(5000); order.confirmProvinceCity(); - order.markAsPaid(); + order.markAsPaid('D25121300001'); const allocations = [ new FundAllocation(FundAllocationTargetType.COST_ACCOUNT, 100, 'ACC1'), @@ -204,7 +204,7 @@ describe('PlantingOrder', () => { order.selectProvinceCity('440000', '广东省', '440100', '广州市'); jest.advanceTimersByTime(5000); order.confirmProvinceCity(); - order.markAsPaid(); + order.markAsPaid('D25121300001'); expect(() => order.cancel()).toThrow('只有未支付的订单才能取消'); diff --git a/backend/services/planting-service/src/domain/aggregates/planting-order.aggregate.ts b/backend/services/planting-service/src/domain/aggregates/planting-order.aggregate.ts index b3868a44..ab9edd7b 100644 --- a/backend/services/planting-service/src/domain/aggregates/planting-order.aggregate.ts +++ b/backend/services/planting-service/src/domain/aggregates/planting-order.aggregate.ts @@ -215,8 +215,9 @@ export class PlantingOrder { /** * 标记为已支付 + * @param accountSequence 用户账户序列号,用于 wallet-service 结算待领取奖励 */ - markAsPaid(): void { + markAsPaid(accountSequence: string): void { this.ensureStatus(PlantingOrderStatus.PROVINCE_CITY_CONFIRMED); this._status = PlantingOrderStatus.PAID; @@ -226,6 +227,7 @@ export class PlantingOrder { new PlantingOrderPaidEvent(this.orderNo, { orderNo: this.orderNo, userId: this.userId.toString(), + accountSequence, treeCount: this.treeCount.value, totalAmount: this.totalAmount, provinceCode: this._provinceCitySelection!.provinceCode, diff --git a/backend/services/planting-service/src/domain/events/planting-order-paid.event.ts b/backend/services/planting-service/src/domain/events/planting-order-paid.event.ts index 1c5421a2..fdc7514d 100644 --- a/backend/services/planting-service/src/domain/events/planting-order-paid.event.ts +++ b/backend/services/planting-service/src/domain/events/planting-order-paid.event.ts @@ -10,6 +10,7 @@ export class PlantingOrderPaidEvent implements DomainEvent { public readonly data: { orderNo: string; userId: string; + accountSequence: string; treeCount: number; totalAmount: number; provinceCode: string;