diff --git a/backend/services/contribution-service/src/pre-planting/application/services/pre-planting-contribution.service.ts b/backend/services/contribution-service/src/pre-planting/application/services/pre-planting-contribution.service.ts index c9b5f83e..cdfac55f 100644 --- a/backend/services/contribution-service/src/pre-planting/application/services/pre-planting-contribution.service.ts +++ b/backend/services/contribution-service/src/pre-planting/application/services/pre-planting-contribution.service.ts @@ -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 写入)