fix(contribution-service): 合并完成后写入 synced_adoptions 记录以解除卖出限制

swapContributionForMerge 在事务内新增步骤 9f:
- 写入 synced_adoptions(original_adoption_id = 20B + mergeId)
- 供 SellRestrictionService.isRestricted 的 has_real_tree 判断使用
- upsert 保证幂等,contributionDistributed 由调用方置 true

Bug: 合并已完成(contribution_records 正确),但 isRestricted 始终
返回 true,因为 synced_adoptions 中没有 20B+ 记录(virtualAdoption
仅用于计算,未持久化)。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-04 08:25:15 -08:00
parent 94792f56ea
commit 1f5bb62805
1 changed files with 20 additions and 0 deletions

View File

@ -861,6 +861,26 @@ export class PrePlantingContributionService {
where: { sourceAdoptionId: mergeSourceAdoptionId },
data: { remark: mergeRemark },
});
// 9f: 在 synced_adoptions 中写入合并树记录,供 sell-restriction 检查has_real_tree 判断)
// originalAdoptionId 使用 20B 偏移,与 SellRestrictionService.MERGE_OFFSET 一致
const totalPortionCount = sourceOrders.reduce((sum, o) => sum + o.portionCount, 0);
await tx.syncedAdoption.upsert({
where: { originalAdoptionId: mergeSourceAdoptionId },
create: {
originalAdoptionId: mergeSourceAdoptionId,
accountSequence,
treeCount: 1,
adoptionDate: miningEnabledAt,
status: 'MINING_ENABLED',
selectedProvince: firstOrder.provinceCode ?? '',
selectedCity: firstOrder.cityCode ?? '',
contributionPerTree: contributionPerTree,
sourceSequenceNum: BigInt(0),
distributionSummary: `PRE_PLANTING_MERGE:${mergeNo}:portions=${totalPortionCount}`,
},
update: {}, // 幂等:已存在则不修改
});
});
// Step 10: 插入幂等标记(最终一致性,事务提交后 best-effort 写入)