fix(planting): 支付完成后直接开启挖矿,跳过底池注入流程

- enableMining() 允许从 PAID 状态直接开启
- addPlanting() 树直接进入 effectiveTreeCount
- payOrder() 删除底池批次逻辑,直接调用 enableMining()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-14 04:25:31 -08:00
parent 17c3f61657
commit d6055099c7
3 changed files with 17 additions and 16 deletions

View File

@ -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 事件(在同一事务中保存)

View File

@ -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;

View File

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