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;