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) =>