From d6055099c78faccaa119c2690c816a94d2131b0b Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 14 Dec 2025 04:25:31 -0800 Subject: [PATCH] =?UTF-8?q?fix(planting):=20=E6=94=AF=E4=BB=98=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=90=8E=E7=9B=B4=E6=8E=A5=E5=BC=80=E5=90=AF=E6=8C=96?= =?UTF-8?q?=E7=9F=BF=EF=BC=8C=E8=B7=B3=E8=BF=87=E5=BA=95=E6=B1=A0=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - enableMining() 允许从 PAID 状态直接开启 - addPlanting() 树直接进入 effectiveTreeCount - payOrder() 删除底池批次逻辑,直接调用 enableMining() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../services/planting-application.service.ts | 16 +++------------- .../aggregates/planting-order.aggregate.ts | 7 ++++++- .../aggregates/planting-position.aggregate.ts | 10 ++++++++-- 3 files changed, 17 insertions(+), 16 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 73a21c44..86ef36d8 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 @@ -268,7 +268,7 @@ export class PlantingApplicationService { // 保存订单状态 await uow.saveOrder(order); - // 更新用户持仓 + // 更新用户持仓(直接生效) const position = await uow.getOrCreatePosition(userId); position.addPlanting( order.treeCount.value, @@ -277,18 +277,8 @@ export class PlantingApplicationService { ); await uow.savePosition(position); - // 安排底池注入批次 - const batch = await uow.findOrCreateCurrentBatch(); - const poolAmount = this.fundAllocationService.getPoolInjectionAmount( - order.treeCount.value, - ); - batch.addOrder(poolAmount); - await uow.saveBatch(batch); - - // 计算注入时间(批次结束后) - const scheduledTime = new Date(batch.endDate); - scheduledTime.setHours(scheduledTime.getHours() + 1); - order.schedulePoolInjection(batch.id!, scheduledTime); + // 直接开启挖矿(跳过底池注入流程) + order.enableMining(); await uow.saveOrder(order); // 8. 添加 Outbox 事件(在同一事务中保存) 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 ab9edd7b..6e1a003a 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 @@ -296,9 +296,14 @@ export class PlantingOrder { /** * 开启挖矿 + * 支付完成后直接开启,跳过底池注入流程 */ enableMining(): void { - this.ensureStatus(PlantingOrderStatus.POOL_INJECTED); + this.ensureStatus( + PlantingOrderStatus.PAID, + PlantingOrderStatus.POOL_SCHEDULED, + PlantingOrderStatus.POOL_INJECTED, + ); this._miningEnabledAt = new Date(); this._status = PlantingOrderStatus.MINING_ENABLED; diff --git a/backend/services/planting-service/src/domain/aggregates/planting-position.aggregate.ts b/backend/services/planting-service/src/domain/aggregates/planting-position.aggregate.ts index c87908bb..ba5d9a3b 100644 --- a/backend/services/planting-service/src/domain/aggregates/planting-position.aggregate.ts +++ b/backend/services/planting-service/src/domain/aggregates/planting-position.aggregate.ts @@ -125,6 +125,7 @@ export class PlantingPosition { /** * 添加认种 + * 支付完成后直接生效,不再等待底池注入 */ addPlanting( treeCount: number, @@ -135,9 +136,14 @@ export class PlantingPosition { throw new Error('认种数量必须大于0'); } - // 更新总数和待生效数 + // 更新总数和有效数(直接生效) this._totalTreeCount += treeCount; - this._pendingTreeCount += treeCount; + this._effectiveTreeCount += treeCount; + + // 设置首次挖矿开始时间 + if (!this._firstMiningStartAt) { + this._firstMiningStartAt = new Date(); + } // 更新省市分布 let distribution = this._distributions.find((d) =>