Commit Graph

30 Commits

Author SHA1 Message Date
hailin ac15d6682a feat(admin): 用户预种数量展示 & 授权申请照片查看
## 功能7:用户管理展示预种数量

### 需求
在用户管理(列表+详情页)展示个人及团队预种份数,
并支持跳转预种管理页查看团队中哪些ID购买了预种。

### 后端变更

referral-service — 新增内部 API:
  - GET  /internal/referral/pre-planting-stats/:accountSequence
  - POST /internal/referral/pre-planting-stats/batch
  从 TeamStatistics 表查询 selfPrePlantingPortions/teamPrePlantingPortions

admin-service:
  - 新建 ReferralProxyService (src/referral/) 代理 referral-service 内部 API
  - UserFullDetailDto 新增 selfPrePlantingPortions, teamPrePlantingPortions
  - user-detail.controller 并行调用获取预种统计
  - user.controller 批量获取用户列表预种统计
  - UserListItemDto 新增 selfPrePlantingPortions, teamPrePlantingPortions
  - pre-planting-config.controller 新增 teamOf 查询参数
    → 先从 referralQueryView 获取团队成员列表
    → 将 accountSequences 传递给 planting-service 过滤

planting-service:
  - internal-pre-planting.controller 的 admin orders/positions 端点
    新增 accountSequences 查询参数,支持按用户列表过滤

### 前端变更

admin-web:
  - 用户列表页表格新增"个人预种(份)"、"团队预种(份)"两列
  - 用户详情页新增预种统计卡片(个人/团队预种份数)
  - 团队预种数字可点击,跳转 /pre-planting?teamOf={accountSequence}
  - 预种管理页支持 teamOf URL 参数,团队过滤模式下显示提示条+返回链接

---

## 功能8:授权管理查看申请照片

### 需求
管理后台无法查看社区/市公司/省公司申请时提供的办公室照片。
原因:authorization-service 收到 officePhotoUrls 后只验证未持久化。
照片文件本身已存储在 MinIO,只需持久化 URL 到数据库。

### 后端变更

authorization-service:
  - schema.prisma: AuthorizationRole 新增 officePhotoUrls String[] 字段
  - authorization-role.aggregate: props/字段/getter/构造/toPersistence/所有工厂方法
  - repository: save() create/update 块 + toDomain() 映射
  - application service: 3个 self-apply 方法传递 officePhotoUrls 到 aggregate
  - admin controller: queryAuthorizations 响应包含 officePhotoUrls

admin-service:
  - schema.prisma: AuthorizationRoleQueryView 新增 officePhotoUrls 字段
  - user-detail-query.repository 接口 + impl: 包含 officePhotoUrls
  - user-detail.dto: AuthorizationRoleDto 新增 officePhotoUrls

### 前端变更

admin-web:
  - 授权管理页表格新增"申请照片"列,点击弹出照片网格 Modal
  - 照片支持点击放大(全屏 lightbox 覆盖层)
  - 用户详情页授权信息 Tab 同样支持查看照片
  - authorization.types.ts / userDetail.types.ts 类型更新

---

## 部署注意事项
1. authorization-service 需运行: npx prisma migrate dev --name add-office-photo-urls
2. admin-service 需运行: npx prisma migrate dev --name add-auth-role-office-photos
3. 需部署: authorization-service, admin-service, referral-service, planting-service, admin-web

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 03:09:17 -08:00
hailin b3984c861c feat(pre-planting): 预种方案调整 — 18870 USDT/棵,10份合1树
=== 方案变更 ===
- 全树基础价: 17830 → 18870 USDT
- 每份价格:   3566 → 1887 USDT
- 合并阈值:   5 份 → 10 份

=== 后端改动 (planting-service) ===
1. pre-planting-right-amounts.ts:
   - PRE_PLANTING_PRICE_PER_PORTION: 3566 → 1887
   - PRE_PLANTING_PORTIONS_PER_TREE: 5 → 10
   - 10类权益金额按 floor(整棵树/10) 重算,余数归 HQ_BASE_FEE(319)
2. pre-planting-merge.aggregate.ts:
   - 合并校验从硬编码 5 改为引用 PRE_PLANTING_PORTIONS_PER_TREE 常量
3. purchase-pre-planting.dto.ts:
   - portionCount @Max(5) → @Max(10)
4. pre-planting-application.service.ts:
   - 加价补贴计算 /5 → /PRE_PLANTING_PORTIONS_PER_TREE
   - 错误文案引用常量,消除硬编码

=== 前端改动 (mobile-app) ===
1. pre_planting_purchase_page.dart: 默认价格、份数、协议文本(1/10、4%)
2. pre_planting_position_page.dart: _portionsPerTree 5→10
3. pre_planting_merge_detail_page.dart: 总价值计算和单份显示金额
4. tree_pricing_service.dart: fallback 默认值
5. pre_planting_service.dart: JSON 解析 fallback 默认值
6. 各文件注释同步更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 18:32:32 -08:00
hailin 722c124cc9 feat(pre-planting): 预种购买后自动触发待领取→可结算转换
购买预种份额后,planting-service 调用 wallet-service 新增的内部 API,
将用户标记为 hasPlanted=true 并结算所有 PENDING 奖励为 SETTLED。
纯新增代码,不修改任何现有方法逻辑,两步均幂等,失败不阻塞购买流程。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 08:51:03 -08:00
hailin 05e590ef04 fix(pre-planting): 修复可结算收益重复计算
pre-planting getMyRewards API 错误地将所有分配记录金额算作
settleableUsdt(包括 PENDING 状态的待领取奖励)。
预种奖励的 PENDING/SETTLEABLE 状态由 wallet-service 管理,
reward-service 的 getMyRewardSummary 已包含预种可结算部分,
不应重复累加。

修复:
- 后端 getMyRewards 返回 settleableUsdt: 0
- 前端"我"页面和"兑换"页面不再额外加预种 settleableUsdt

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 03:34:22 -08:00
hailin 1157760d4d fix(pre-planting): 补充社区/省团队/市团队 API 缺失的 treeCount 参数
三个接口调用时未传 treeCount,导致 authorization-service 收到
Number(undefined)=NaN,addMonthlyTrees(NaN) 使字段变为 NaN,
Prisma upsert 报 PrismaClientValidationError。

修复:全部传 treeCount=0(预种不计入月度考核),
省团队补充 provinceCode,市团队补充 cityCode,
同时修正社区/团队接口返回格式为 distributions 数组。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 02:30:35 -08:00
hailin e32658fc5e fix(pre-planting): 修复 authorization-service 响应包装格式解析
authorization-service 全局 TransformInterceptor 将响应包装为
{ success, data: T, timestamp },预种客户端需读取 response.data.data
而非 response.data。此前因解析失败静默 fallback 到系统账户。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 02:22:01 -08:00
hailin d880242807 fix(pre-planting): 修复 authorization-service API 路径错误
预种 client 使用 /internal/authorization/... 但 authorization-service
全局前缀为 api/v1,实际路由是 /api/v1/authorization/...。
路径不对导致所有请求 404 → catch → fallback → 全部进系统账户。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 02:04:09 -08:00
hailin b9ddda2532 fix(pre-planting): 修复省市代码格式不一致导致授权分配失败
预种DTO接收2位省代码(如"44")和4位市代码(如"4401"),
但authorization-service需要6位标准格式(如"440000"/"440100")。
- resolveAllocations中新增padEnd(6,'0')标准化转换
- fallback系统账户生成从padStart改为padEnd(右补零)
- 正常认种不受影响(SelectProvinceCityDto直接接收6位格式)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 01:23:55 -08:00
hailin 3be7b47678 feat(pre-planting+mobile): 预种奖励在"我"页面展示
## 问题
预种奖励直接走 planting-service → wallet-service,绕过 reward-service,
导致前端"我"页面读 reward-service 的 summary/settleable 数据时看不到预种奖励。

## 方案
前端同时读 reward-service(正常认种)和 planting-service(预种),合并展示。

## 后端(planting-service)
- PrePlantingRewardEntryRepository: 新增 findByRecipientAccountSequence() 方法,
  按收款方账户查询预种奖励记录(注入 PrismaService 替代事务 client)
- PrePlantingController: 新增 GET /pre-planting/my-rewards 端点,
  返回当前用户作为收款方收到的预种奖励汇总+明细列表
  格式与 reward-service 的 settleable 对齐(id, rightType, usdtAmount, sourceOrderNo 等)

## 前端(Flutter mobile-app)
- PrePlantingService: 新增 getMyRewards() 方法 + PrePlantingMyRewards/PrePlantingRewardItem 数据类
- profile_page.dart: 并行调用 prePlantingService.getMyRewards(),
  将预种奖励转为 SettleableRewardItem 合并到可结算列表,
  summary.settleableUsdt 也加上预种金额

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 22:03:53 -08:00
hailin f32748c1d5 fix(pre-planting): 修复推荐链 API 调用的 URL 路径和返回格式解析
1. URL: /referrals/:id/chain → /referral/chain/:id(与正常认种对齐)
2. 返回格式: 正确解析 { ancestors: [{accountSequence, hasPlanted}] }
   之前错误期望 { directReferrer: {...} },导致有推荐人也被当成无推荐人

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 21:39:07 -08:00
hailin 545e897c1f fix(pre-planting): 预种省/市区域 API 传 treeCount=0,不计入考核
预种 1 份 = 1/5 棵树,如果将 portionCount 作为 treeCount 传给
authorization-service,会导致省/市公司月度考核进度被多算 5 倍。

修正:传 treeCount=0,预种阶段不累计考核棵数。
等 5 份合成 1 棵完整树后,由合成流程负责累计 1 棵的考核进度。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 20:57:27 -08:00
hailin 1c71cda2ec fix(pre-planting): 修复省/市区域权益分配的三个 bug
问题:
1. 省/市区域 API 调用缺少必需的 treeCount 参数,导致 authorization-service
   报错,每次都走 fallback 路径
2. fallback 路径没有对省/市代码做 padStart(6,'0') 补位,
   生成了错误的账户ID(如 944 而非 9440000,84401 而非 8440100)
3. API 返回格式解析错误:authorization-service 返回
   { distributions: [{accountSequence, ...}] },但预种客户端错误地期望
   { accountSequence: string },导致取到 undefined

修复:
- getProvinceAreaDistribution / getCityAreaDistribution 新增 portionCount 参数
- 正确解析 distributions 数组,优先取非系统账户(省/市公司)
- fallback 中使用 padStart(6,'0') 确保 7 位标准账户 ID 格式
- resolveAllocations 调用时传入 portionCount

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 20:53:12 -08:00
hailin 19fca05a81 fix(pre-planting): 预种权益分配metadata与正常认种对齐 + 删除retry-rewards
1. executeAllocations() metadata 修复:
   - 原:仅传 { source: 'PRE_PLANTING' },wallet流水缺失所有业务信息
   - 现:传完整 metadata(rightType, sourceOrderNo, sourceAccountSequence,
     treeCount, provinceCode, cityCode, memo),与正常认种 reward-service 一致
   - wallet-service 的 prePlantingPrefix() 通过 metadata.source 添加[预种]前缀

2. SHARE_RIGHT PENDING 机制说明(无代码变更):
   - 预种侧只确定收款人,全部标记 SETTLED 发给 wallet-service
   - wallet-service.allocateToUserWallet() 内部根据收款方 hasPlanted 判断:
     已种→SETTLEABLE / 未种→PENDING(24h过期归总部)
   - 与正常认种走同一套 wallet-service 代码

3. 删除无用的 retry-rewards 端点及其 WalletServiceClient 依赖

不涉及历史数据修改,不影响正常认种流程。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 19:27:16 -08:00
hailin d9c238702e feat(pre-planting): 预种权益流水备注添加[预种]前缀
wallet-service 新增 prePlantingPrefix 私有方法,
当 FundAllocationItem.metadata.source === 'PRE_PLANTING' 时,
在流水 memo 中添加 "[预种] " 前缀,使用户可区分预种与普通认种权益。

仅影响 pre-planting 新增的分配流水,不修改任何普通认种 memo。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 12:34:01 -08:00
hailin 1d0e4352df fix(pre-planting): 修复预种权益资金分配字段名错误(allocationType 丢失)
原 executeAllocations 使用了错误的 FundAllocationItem 字段名:
- targetAccountId → 应为 targetId
- 缺少 allocationType 字段
- targetType 错误地使用了 rightType 值而非 'USER'|'SYSTEM'

导致所有预种订单的 SHARE_RIGHT/COMMUNITY_RIGHT 等权益分配静默失败,
资金未能分配到推荐人/社区/省市账户,同时流水明细中也不显示预种记录。

修复内容:
1. WalletServiceClient 新增 allocatePrePlantingFunds 方法(使用正确格式)
2. executeAllocations 改用新方法,正确设置 targetType/targetId/allocationType
3. InternalPrePlantingController 新增 POST /admin/retry-rewards 历史数据修复端点

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 12:29:03 -08:00
hailin 1431c89684 fix(pre-planting): Decimal -> Number in totalAmount reduce 2026-02-28 11:01:37 -08:00
hailin cd73b2dec4 fix(pre-planting): 签署合同前检查实名认证 + 修正合同金额
- getMergeContractPdf: KYC 为 null 时返回 400,不允许查看合同
- getMergeContractPdf: 从源订单汇总实际绿积分金额,CNY = 绿积分 × 1.1
- Flutter: KYC 错误时显示专用提示 + "去完成实名认证" 按钮

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 10:59:26 -08:00
hailin b1e5e6b29f feat(pre-planting): 合并合同走完整签署流程(PDF展示+手写签名)
- planting-service: 新增 GET /merges/:mergeNo/contract-pdf 接口,复用现有 PDF 模板
- planting-service: PrePlantingApplicationService 注入 PdfGeneratorService/IdentityServiceClient
- pre_planting_service.dart: 新增 downloadMergeContractPdf,signMergeContract 简化返回值
- 新建 PrePlantingMergeSigningPage:PDF展示→滚动到底→确认法律效力→手写签名→提交
- pending_contracts_page: 合并卡片点击跳签名页(prePlantingMergeSigning)
- pre_planting_merge_detail_page: 签署按钮跳签名页,移除直接调用逻辑
- 新增路由 /pre-planting/merge-signing/:mergeNo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 10:35:22 -08:00
hailin b17bf82443 feat(pre-planting): 新增 GET /merges/:mergeNo 合并详情接口
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 10:07:53 -08:00
hailin 26dcd1d2de fix(pre-planting): 修复购买省市名称存储及多项购买失败问题
== 问题修复 ==

1. 购买失败:NestJS 返回数组 message 导致 Flutter 类型转换错误
   - 症状:List<dynamic> is not a subtype of String
   - 原因:ValidationPipe 校验失败时 message 字段为 List<String>(每条字段错误一条),
     Flutter _handleDioError 直接用 data['message'] 作为 String 参数导致运行时崩溃
   - 修复:api_client.dart 中对 rawMsg 判断是否 List,若是则 join(', ')

2. 续购省市为空导致 400 校验失败
   - 症状:续购时后端返回 "provinceCode should not be empty"
   - 原因:购买页面续购分支未传入省市,导致 provinceCode/cityCode 为 null
   - 修复:pre_planting_purchase_page.dart 中续购时使用 _position?.provinceCode

3. 购买请求携带 provinceName/cityName 被后端 forbidNonWhitelisted 拒绝
   - 症状:400 "property provinceName should not exist"
   - 原因:前端发送名称字段,但 PurchasePrePlantingDto 未声明这些字段
   - 修复:在 DTO 中添加 @IsOptional() 的 provinceName / cityName 字段

== 功能新增 ==

4. 预种持仓表新增省市名称存储(参照正式认种的处理方式)
   - 迁移:20260228000000_add_province_city_name_to_position
   - Prisma schema:PrePlantingPosition 新增 provinceName / cityName 可空字段
   - 聚合根:addPortions() 接受可选 provinceName/cityName,首购时写入,续购忽略
   - Repository:save/toDomain 同步处理名称字段
   - Application Service:purchasePortion 透传名称,getPosition 返回名称
   - Controller:purchase 端点透传 dto.provinceName / dto.cityName

5. 预种合并时算力精确回滚(contribution-service)
   - 新增 9a-team 步骤:事务内查询即将作废的 TEAM_LEVEL/TEAM_BONUS 算力记录
   - 新增 9c-team 步骤:按账户聚合后精确 decrement 上游推荐人的各档位 pending 和 effective
   - 目的:确保旧份额算力精确回滚,避免新树算力 9d 叠加后造成双倍计入

== UI 优化 ==
   - 购买页面将 "USDT" 改为 "绿积分"(单价、总价、成功提示)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 08:02:14 -08:00
hailin 20b8d41212 feat(pre-planting): 支持省市名称存储,参照正常认种处理方式
- PurchasePrePlantingDto 添加可选字段 provinceName/cityName,
  与 SelectProvinceCityDto 保持一致,解决 NestJS forbidNonWhitelisted 400 错误
- pre_planting_positions 表新增 province_name/city_name 列(迁移)
- PrePlantingPosition aggregate 增加 provinceName/cityName 字段
- addPortions() 接受并存储省市名称
- getPosition() 返回 provinceName/cityName 供续购时显示

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 07:48:47 -08:00
hailin 560674f2e9 fix(pre-planting): 无推荐关系用户购买预种时 404 导致整笔交易失败
问题:PrePlantingReferralClient.getReferralChain() 生产环境遇到 404
(用户无推荐人)时直接 throw error,导致整个购买事务回滚,
无推荐关系的用户(测试账号、直接注册用户)完全无法购买预种份额。

修复:AxiosError status === 404 时返回 { directReferrer: null },
与"直接注册、无推荐人"的正常业务场景对齐,不阻断购买流程。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 02:13:29 -08:00
hailin 2684a81383 fix(pre-planting): getEligibility 返回 canPurchase 字段修复"待开启"问题
后端 getEligibility() 原先只返回 hasPrePlanting/canTrade 等内部字段,
缺少前端购买页期望的 canPurchase/maxAdditional/message 字段。
由于 json['canPurchase'] ?? false 默认为 false,导致购买页始终显示"待开启"。

修复:getEligibility() 现在先查询 admin config 的 isActive 状态,
结合用户持仓计算出 canPurchase/maxAdditional/message,同时保留原有字段。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 23:36:08 -08:00
hailin e328c75fc1 fix(pre-planting): 修复前后端 API 路径不匹配导致预种页面打不开
后端 PrePlantingController 缺少 eligibility 端点,前端请求 404 导致
Future.wait 整体失败,页面显示"加载数据失败"。

修复:
1. 后端: 在 PrePlantingController 添加 GET eligibility 端点
2. 前端: createOrder 路径从 /orders 改为 /purchase(匹配后端)
3. 前端: signMergeContract 路径从 /merges/:no/sign 改为 /sign-contract

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 23:07:47 -08:00
hailin c0ac63d40a feat(pre-planting): 重命名预种持仓→预种明细 + 购买协议弹窗
- mobile-app: "预种持仓"按钮和页面标题改为"预种明细"
- admin-service: 新增预种协议文本 API (GET/PUT agreement),存储于 system_configs 表
- admin-service: 公开 config API 响应增加 agreementText 字段
- planting-service: 新建 PrePlantingPublicController (无需 JWT),暴露 GET /pre-planting/config
- admin-web: 预种管理页面新增协议文本编辑器(textarea + 保存按钮)
- mobile-app: 购买流程增加协议弹窗,用户需勾选同意后才能继续
- mobile-app: 协议文本优先使用后台配置,未配置时使用默认文本

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 21:14:24 -08:00
hailin 37a5610d74 feat(admin): 实现预种管理页面完整API端点
planting-service: InternalPrePlantingController 新增4个管理员查询端点
- GET /internal/pre-planting/admin/orders (分页订单列表)
- GET /internal/pre-planting/admin/positions (分页持仓列表)
- GET /internal/pre-planting/admin/merges (分页合并记录)
- GET /internal/pre-planting/admin/stats (统计汇总)

admin-service: HTTP代理层新增5个端点
- PUT config/toggle (开关切换)
- GET orders/positions/merges/stats (代理转发到planting-service)
- 新建 PrePlantingProxyService (复用ContractService的axios代理模式)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 20:21:31 -08:00
hailin acf55b26a7 feat(pricing): 预种每份价格从 3171 调整为 3566 绿积分
分配规则:按 reward-service RIGHT_AMOUNTS(15831 整棵树)各项 /5 取整,
余额全归总部社区(HQ_BASE_FEE)。5 份合成一棵树 = 17830。

10 类分配金额变更:
- COST_FEE:       576 (不变, floor(2880/5))
- OPERATION_FEE:  420 (不变, floor(2100/5))
- HQ_BASE_FEE:    29.4 → 427 (3566 - 3139, 吸收全部余额)
- RWAD_POOL:      1152 (不变, floor(5760/5))
- SHARE_RIGHT:    720 (不变, floor(3600/5))
- PROVINCE_AREA:  21.6 → 21 (floor(108/5))
- PROVINCE_TEAM:  28.8 → 28 (floor(144/5))
- CITY_AREA:      50.4 → 50 (floor(252/5))
- CITY_TEAM:      57.6 → 57 (floor(288/5))
- COMMUNITY:      115.2 → 115 (floor(576/5))
- 合计: 3171 → 3566 ✓

涉及服务:planting-service, admin-service, contribution-service
涉及前端:admin-web, mobile-app (Flutter)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 08:02:17 -08:00
hailin ed6b48562a feat(pricing): 认种树动态定价涨价系统(总部运营成本压力涨价)
基础价 15831 USDT/棵不变,新增 HQ_PRICE_SUPPLEMENT 加价项全额归总部(S0000000001)。
支持手动调价+自动周期涨价,所有变更可审计,移动端动态展示价格及涨价预告。

- admin-service: TreePricingConfig/ChangeLog 表 + Service + Controller + 定时任务
- planting-service: 正式认种和预种订单快照 priceSupplement,动态价格校验
- reward-service: HQ_PRICE_SUPPLEMENT 分配类型,涨价金额直接入总部账户
- admin-web: Settings 页面新增定价配置区间(手动调价/自动涨价/变更历史)
- mobile-app: TreePricingService + 动态价格加载 + 涨价预告展示

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 03:02:56 -08:00
hailin a11e4d0261 fix(pre-planting): 修复 5 个预种模块 Bug + 补全 3 服务 migration
Bug #1 (HIGH): allocateFunds 从 Prisma 事务内移到事务外
  - pre-planting-reward.service.ts: distributeRewards 拆为
    prepareAndPersistRewards(事务内持久化)+ executeAllocations(事务后转账)
  - pre-planting-application.service.ts: 事务后调用 executeAllocations

Bug #2 (HIGH): signContract 后触发 hasPlanted
  - 签约事务成功后发布 PlantingOrderPaid 到 planting-events topic
  - wallet-service 消费后执行 markUserAsPlanted + settleUserPendingRewards
  - event-publisher.service.ts: 新增 publishRawToPlantingEvents 方法

Bug #3 (MEDIUM): PENDING 推荐奖励改为全部 SETTLED
  - 与现有认种行为对齐,推荐奖励立即发放

Bug #4 (HIGH): 补全 3 个服务的数据库迁移文件
  - planting-service: 4 张预种表(orders/positions/merges/reward_entries)
  - admin-service: 1 张配置表(pre_planting_configs)+ 默认数据
  - contribution-service: 4 张 CDC 追踪表(synced_orders/positions/freeze_states/processed_cdc_events)

Bug #5 (LOW): 合并循环 if→while,支持一次购买多份触发多次合并

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:09:14 -08:00
hailin 010b0392fd feat(pre-planting): 3171 预种计划 1.0 全量实现(纯新增,零侵入)
预种计划(拼种团购):用户以 3171 USDT/份参与认种(1棵树的1/5价格),
累计5份自动合成1棵树,触发合同签署并解除交易/提现限制。

涉及服务(现有代码仅 app.module.ts 加 1 行 import,其余全部为新增文件):
- planting-service: PrePlantingModule(独立聚合根、购买/合并/签约/分配)
- admin-service: 预种开关管理(PrePlantingConfig 表 + API)
- referral-service: PrePlantingStatsModule(消费预种事件更新团队统计)
- authorization-service: PrePlantingGuardModule(未合并不可申请授权)
- wallet-service: PrePlantingGuardModule(未合并不可提现)

新增数据表:pre_planting_orders, pre_planting_positions,
pre_planting_merges, pre_planting_reward_entries, pre_planting_configs

新增 Kafka Topics:pre-planting.portion.purchased, pre-planting.merged,
pre-planting.contract.signed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 05:06:03 -08:00