Commit Graph

649 Commits

Author SHA1 Message Date
hailin 2e44263834 feat(profile): 添加我的伞下功能 - 展示下级用户树形结构
- 后端新增 GET /referral/user/:accountSequence/direct-referrals API
- 前端新增伞下树组件,支持懒加载、缓存、展开/收起
- 使用 CustomPaint 绘制父子节点连接线
- 超出屏幕宽度时显示省略号,点击弹出底部列表

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 10:34:56 -08:00
hailin 2eda3be275 fix(frontend): 修正权益金额显示与后端实际配置一致
- 省团队权益: 10 → 20 USDT
- 市区域权益: 20 → 35 USDT
- 省区域权益: 10 → 15 USDT

权益金额配置参考 reward-service/prisma/seed.ts

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 09:46:30 -08:00
hailin c4be2f59f7 fix(frontend): 修正市团队权益描述金额 30 → 40 USDT
市团队权益每棵树实际是 40 USDT,前端显示文案错误写成 30 USDT

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 09:45:05 -08:00
hailin 0860ff23b8 fix(guide): 修复向导页5导入助记词按钮导航问题
将 Navigator.of(context).pushNamed() 改为 context.push(),
使用 go_router 进行页面导航,与 onboarding_page 保持一致。

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 09:19:25 -08:00
hailin ed47e7ab2d fix(authorization): 修复下级团队认种数重复减去自己认种数的 BUG
问题描述:
- 社区/省公司/市公司的初始考核判断错误
- 原因: referral-service 返回的 totalTeamPlantingCount 已经是"下级团队认种数"(不含自己)
  但 authorization-service 又减了一次 selfPlantingCount,导致结果偏小

示例:
- D25121400003: 自己认种12棵,下级认种14棵
- 修复前: subordinateTeamPlantingCount = 14 - 12 = 2 (错误!)
- 修复后: subordinateTeamPlantingCount = 14 (正确)

影响范围:
- 社区权益初始考核 (10棵门槛)
- 省公司权益初始考核
- 市公司权益初始考核 (100棵门槛)
- 所有使用 subordinateTeamPlantingCount 的业务逻辑

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 09:15:00 -08:00
hailin 13d1bedb73 feat(profile): 添加市团队/省团队/市区域/省区域权益考核显示
在"我的"页面社区权益考核下方,根据用户拥有的角色显示对应的权益考核组件:
- 市团队:每新增认种1棵可获得30 USDT
- 省团队:每新增认种1棵可获得10 USDT
- 市区域:每新增认种1棵可获得20 USDT
- 省区域:每新增认种1棵可获得10 USDT

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 08:40:34 -08:00
hailin 090c8b747e fix(reward): 修复 accountSequence 转 userId 时字母前缀导致的 BigInt 转换失败
问题描述:
- 社区权益激活后,用户收不到奖励
- 错误: SyntaxError: Cannot convert D25121400002 to a BigInt
- 原因: accountSequence 格式为 D25121400002 (D+日期+序号),直接 BigInt() 转换失败

修改方案:
- 新增 parseAccountSequenceToUserId() 辅助方法
- 如果 accountSequence 以字母开头,去掉第一个字符后再转 BigInt
- 影响 5 个方法: calculateProvinceTeamRight, calculateProvinceAreaRight,
  calculateCityTeamRight, calculateCityAreaRight, calculateCommunityRight

技术背景:
- accountSequence 格式: D25121400002 (用户) / S0000000001 (固定系统账户) / 9440000 (省系统)
- 省市系统账户在 authorization-service 动态创建,identity-service 中不存在
- reward-service 的 userId 字段实际业务中不被使用 (查询用 accountSequence)

潜在隐患:
1. userId 字段存储的不是 identity-service 中的真实 userId
   - D25121400002 -> 25121400002 (不是真实的自增 userId)
   - S0000000001 -> 1 (恰好匹配固定系统账户)
   - 9440000 -> 9440000 (省系统账户,本无字母前缀)
2. 如果未来 reward-service 需要与 identity-service 关联查询,可能出现问题
3. 建议后续考虑: 将 userId 改为可选字段,或完全移除该字段依赖

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 08:18:23 -08:00
hailin c7d54da49f fix(reward): 修复调用 authorization-service 时传递 userId 而非 accountSequence 的问题
- IAuthorizationServiceClient 接口参数类型从 userId: bigint 改为 accountSequence: string
- authorization-service.client.ts 调用时使用正确的 accountSequence 格式
- calculateCommunityRight/calculateProvinceTeamRight/calculateCityTeamRight 方法增加 sourceAccountSequence 参数

此修复确保 reward-service 调用 authorization-service 时传递正确的用户标识格式(如 D25121400006),
而不是数字形式的 userId(如 7),使 authorization-service 能正确查找社区授权记录。

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 06:48:58 -08:00
hailin c9f944355c fix(referral): 修复 getReferralChain API 返回 accountSequence 而非 userId
- 修改 getReferralChain 方法返回的 ancestorPath 为 accountSequence 格式
- 修改 getBatchReferralChains 方法同样返回 accountSequence 格式
- 这修复了 authorization-service 查询社区层级时使用错误格式的问题
- 之前返回 userId (如 "25121400000"),现在返回 accountSequence (如 "D25121400000")

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 06:10:41 -08:00
hailin 367e34f3a6 fix(reward): 待领取奖励转可结算使用accountSequence
- 添加 claimPendingRewardsForAccountSequence 方法
- event-consumer 改用 accountSequence 查找待领取奖励
- 修复上家认种后待领取奖励不能转为可结算的问题

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 05:58:19 -08:00
hailin 7d95a35204 fix(referral): 团队统计使用accountSequence替代userId
- UpdateTeamStatisticsCommand 改用 accountSequence
- PlantingCreatedHandler 传递 accountSequence
- TeamStatisticsService 使用 findByAccountSequence 查询
- 修复上家团队认种数不正确的问题

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 05:46:11 -08:00
hailin a7c36b5ee1 fix(referral): 使用JWT中的accountSequence替代userId查询
- JwtAuthGuard解析accountSequence字段放入request.user
- getMyReferralInfo和getMyDirectReferrals改用accountSequence
- 修复referral-service与identity-service用户ID不匹配问题

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 05:27:22 -08:00
hailin 6ef8824ef0 fix(referral): 修复 getMyReferralInfo 使用 userId 而不是 accountSequence 的问题
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 05:05:03 -08:00
hailin 1a97a9df54 fix(reward): add WALLET_SERVICE_URL to reward-service
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 04:52:24 -08:00
hailin d6055099c7 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>
2025-12-14 04:25:31 -08:00
hailin 17c3f61657 fix(identity): 优化默认昵称格式为简洁序号
修改默认昵称生成逻辑:
- 从完整序列号中提取后5位数字
- 去掉前导零后组合
- 示例: D24121400001 -> 榴莲女皇1号

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 03:33:40 -08:00
hailin 7c72be3ba0 fix(docker): 修复 referral-service Dockerfile 健康检查 URL
修复 referral-service 的健康检查端点配置:
- referral-service: /health -> /api/v1/health

注:backup-service 使用 /health,leaderboard-service 使用 /api/health(这是服务本身实现的端点)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 03:05:18 -08:00
hailin 6eea4463f8 feat(profile): 支持显示多笔待领取奖励明细
- 新增 PendingRewardItem 数据模型,对接 GET /rewards/pending 接口
- 修改 ProfilePage 并行加载汇总数据和待领取列表
- 重构收益区域 UI,展示每笔奖励的权益类型、金额和独立倒计时

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 01:33:13 -08:00
hailin cd742856c0 fix(identity): 优化默认昵称生成格式
将新用户默认昵称从「用户D2512140001」改为「用户1」,
使用 accountSequence.dailySequence 提取当日序号并去除前导零。

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 00:59:01 -08:00
hailin 35f5d54a0c fix(planting): 无推荐人时分享权益进入分享权益池
- 将无推荐人时的分享权益目标从 SYSTEM_HEADQUARTERS_COMMUNITY 改为 SYSTEM_SHARE_RIGHT_POOL
- 将 SYSTEM:OPERATION_ACCOUNT 改为 SYSTEM:SHARE_RIGHT_POOL

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 00:18:32 -08:00
hailin 4478351f89 fix(authorization): 修复 grantProvinceCompany 业务验证逻辑
- 添加省区域/市区域互斥检查:同一用户不能同时拥有两种身份
- 添加省区域全局唯一性检查:整个系统只允许一个省区域角色被授权
- 添加 findAnyProvinceCompany 仓储方法用于全局唯一性校验
- 移除错误的 validateAuthorizationRequest 调用(该方法只适用于团队角色)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 00:15:09 -08:00
hailin 298ce52fc7 fix(authorization): 修复 grantCityCompany 业务验证逻辑
- 添加市区域/省区域互斥检查:同一用户不能同时拥有两种身份
- 添加用户市区域唯一性检查:一个用户只能有一个市区域角色
- 添加城市全局唯一性检查:同一城市只允许一个市区域角色
- 移除错误的 validateAuthorizationRequest 调用(该方法只适用于团队角色)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 00:11:13 -08:00
hailin 10ce981111 fix(authorization-service): 社区授权唯一性约束
- 一个用户只能拥有一个社区角色
- 社区名称全局唯一,不允许重复
- 添加 findCommunityByName repository 方法

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-14 00:04:24 -08:00
hailin 95e1cdffba feat(authorization-service): 正式省公司(PROVINCE_COMPANY)阶梯考核及月度考核
- 添加 PROVINCE_COMPANY_LADDER 阶梯目标配置 (150→300→600→1200→2400→4800→9600→19200→11750)
- 修改 getProvinceAreaRewardDistribution 使用阶梯目标判断激活条件
- 添加 processExpiredProvinceCompanyBenefits 月度考核方法
- 添加每月最后一天23:59定时任务执行省公司月度考核
- 添加月度数据存档方法 archiveAndResetProvinceCompanyMonthlyTreeCounts

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 23:43:41 -08:00
hailin 1896dd6b4c feat(authorization-service): 正式市公司(CITY_COMPANY)阶梯考核及月度考核
- 添加 CITY_COMPANY_LADDER 阶梯目标配置 (30→60→120→240→480→960→1920→3840→2350)
- 修改 getCityAreaRewardDistribution 使用阶梯目标激活权益
- 添加 processExpiredCityCompanyBenefits 月度考核处理方法
- 添加月末23:59考核定时任务 (判断是否当月最后一天)
- 添加正式市公司月度数据存档定时任务

业务规则:
- 第一个月达标30棵树即可激活权益
- 每月最后一天23:59执行考核
- 达标续期并递增月份索引
- 不达标停用权益

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 23:34:55 -08:00
hailin 4d58d4be6c feat(authorization-service): 省团队授权级联激活/停用及月度考核
- 添加 cascadeActivateParentAuthProvinces: 当省团队授权激活时级联激活上级省团队
- 添加 cascadeDeactivateAuthProvinceBenefits: 月度考核失败时级联停用上级省团队
- 添加 processExpiredAuthProvinceBenefits: 月度考核处理(500棵树/月)
- 修改 tryActivateBenefit 支持 AUTH_PROVINCE_COMPANY 级联激活
- 定时任务: 每天凌晨5点检查省团队权益过期
- 定时任务: 每月1号存档并重置省团队月度新增树数

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 22:32:39 -08:00
hailin 049a13c97e feat(authorization-service): 市团队授权级联激活/停用及月度考核
- 添加 cascadeActivateParentAuthCities: 当市团队授权激活时级联激活上级市团队
- 添加 cascadeDeactivateAuthCityBenefits: 月度考核失败时级联停用上级市团队
- 添加 processExpiredAuthCityBenefits: 月度考核处理(100棵树/月)
- 添加 findExpiredActiveByRoleType 仓储方法
- 修改 tryActivateBenefit 支持 AUTH_CITY_COMPANY 级联激活
- 定时任务: 每天凌晨4点检查市团队权益过期
- 定时任务: 每月1号存档并重置市团队月度新增树数

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 22:04:59 -08:00
hailin 4a2a1e3855 feat(authorization-service): 为 getProvinceTeamRewardDistribution 添加 addMonthlyTrees 调用
参考 getCommunityRewardDistribution 的实现,在以下三个场景添加月度新增树数累计:
1. benefitActive=true 时:全部 treeCount 给该省团队,累加 treeCount
2. currentTeamCount >= initialTarget 时(兜底处理):累加 treeCount
3. 跨越考核达标点时:只累加归自己的部分 afterTargetCount

这确保了省团队权益与社区权益的月度考核追踪逻辑一致。
- 考核目标:500棵(省团队)
- 奖励:20 USDT
- 无上级时分配到系统省团队账户

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 21:55:28 -08:00
hailin 8f91a5b985 feat(authorization-service): 为 getCityTeamRewardDistribution 添加 addMonthlyTrees 调用
参考 getCommunityRewardDistribution 的实现,在以下三个场景添加月度新增树数累计:
1. benefitActive=true 时:全部 treeCount 给该市团队,累加 treeCount
2. currentTeamCount >= initialTarget 时(兜底处理):累加 treeCount
3. 跨越考核达标点时:只累加归自己的部分 afterTargetCount

这确保了市团队权益与社区权益的月度考核追踪逻辑一致。

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 21:36:37 -08:00
hailin d12bf6df2f fix(authorization-service): 修复权益分配边界逻辑 + 添加 addMonthlyTrees 调用
边界逻辑修复:
- 社区/省/市团队和区域权益分配:第N棵(达标棵)也给上级,第N+1棵起才给自己
- 例如社区:第1-10棵全部给上级的上级/总部,第11棵起才归该社区

addMonthlyTrees 调用:
- 权益已激活时:累加全部树数
- 初始考核达标后:累加归自己的那部分(第11棵起)
- 已达标但未激活时:累加全部树数

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 21:24:16 -08:00
hailin 6bd6c6b5be feat(authorization-service): 实现月度考核数据存档机制(方案B)
- 新增 lastMonthTreesAdded 字段,用于存档上月业绩数据
- 新增 archiveAndResetMonthlyTreeCounts 定时任务:每月1日0:00将当月数据存档后重置
- 新增 getTreesForAssessment() 方法:根据 benefitValidUntil 判断使用当月或上月数据
- 修复月度考核时序问题:数据重置(0:00)在考核(3:00)之前执行

业务规则:
- 严格自然月统计,11月的业绩不计入12月
- 激活当月免考核,考核激活当月的下一个月
- 权益有效期在上月末 → 使用 lastMonthTreesAdded
- 权益有效期在当月末 → 使用 monthlyTreesAdded

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 20:39:16 -08:00
hailin b705c6aa91 feat(wallet-service): 新增分享权益池账户S0000000005
- 新增 S0000000005 分享权益池系统账户 (user_id = -5)
- 修改 reward-service: 无推荐人的分享权益(500 USDT/棵)进入分享权益池
- 与总部社区账户(S0000000001)分离,便于单独追踪无推荐人的分享权益

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 18:53:21 -08:00
hailin 947e81b58d chore(wallet-service): 确保 @nestjs/schedule 依赖正确配置
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 17:13:21 -08:00
hailin 2af44e5854 feat(authorization-service): 实现社区权益月度考核及级联激活/停用功能
- 新增 benefitValidUntil、lastAssessmentMonth、monthlyTreesAdded 字段追踪月度考核
- 实现级联激活:当社区权益激活时,自动激活所有上级社区的权益
- 实现级联停用:当月度考核不达标时,级联停用该社区及所有上级社区
- 新增定时任务:每天凌晨3点检查过期社区权益,每月1号凌晨重置月度树数
- 权益有效期为当前月+下月末

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 07:23:46 -08:00
hailin 846915badc fix(wallet-service): 使用事务确保 settleUserPendingRewards 原子性
- 将 pending_rewards 状态更新和 wallet_accounts 余额更新包装在 Prisma $transaction 中
- 修复 Bug 4: pending_rewards 被标记为 SETTLED 但 settleable_usdt 未更新的问题
- 添加 PrismaService 依赖注入
- 同时减少 pendingUsdt/pendingHashpower,增加 settleableUsdt/settleableHashpower
- 记录 REWARD_TO_SETTLEABLE 类型的流水

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 06:58:07 -08:00
hailin c93f43546e fix(planting-service): PlantingOrderPaidEvent 添加 accountSequence 字段
Bug 3 修复: wallet-service 结算待领取奖励时需要 accountSequence

- PlantingOrderPaidEvent 事件 data 添加 accountSequence 字段
- markAsPaid(accountSequence) 方法接收并传递 accountSequence
- payOrder 调用 markAsPaid 时传入 accountSequence
- 更新相关单元测试

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 06:13:59 -08:00
hailin 28864e6160 fix(wallet-service): 修复待领取奖励显示和结算触发问题
Bug 1: allocateToUserWallet 同步更新 wallet_accounts.pending_usdt
- 写入 pending_rewards 表时同步调用 wallet.addPendingReward()
- 修复前端待领取金额显示为 0 的问题

Bug 2: Kafka 事件类型匹配兼容 planting-service 格式
- 支持 eventName 字段解析 (planting-service 使用)
- 支持 data 字段解析 (planting-service 使用)
- 新增 PlantingOrderPaid 事件类型支持
- 修复用户认种后待领取无法转换为可结算的问题

其他: 定时任务频率改为每分钟一次 (测试用途)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 05:51:28 -08:00
hailin e4389a5733 fix(wallet-service): 优化资金分配逻辑 - 区分直接到账和待领取
- SHARE_RIGHT (分享权益): 写入 pending_rewards 表,24小时待领取
- PROVINCE_TEAM_RIGHT/PROVINCE_AREA_RIGHT/CITY_TEAM_RIGHT/CITY_AREA_RIGHT: 直接到账
- COMMUNITY_RIGHT (社区权益): 进入总部社区账户 S0000000001,直接到账

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 04:51:34 -08:00
hailin 737fc3bb3c fix(wallet-service): allocateToUserWallet 改用 pending_rewards 表
- 移除 wallet.addPendingReward() 调用(旧方案,更新 wallet_accounts.pending_usdt)
- 改用 PendingReward.create() + pendingRewardRepo.save() 写入 pending_rewards 表
- 支持 7+省代码(省团队)和 6+市代码(市团队)账户格式

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 03:53:23 -08:00
hailin 8f81c46d75 feat: 省市团队账户及待领取奖励逐笔追踪
1. authorization-service:
   - 省团队权益分配改用系统省团队账户 (7+provinceCode)
   - 市团队权益分配改用系统市团队账户 (6+cityCode)
   - 无推荐链时不再进总部,而是进对应团队账户

2. wallet-service:
   - 新增 pending_rewards 表支持逐笔追踪待领取奖励
   - ensureRegionAccounts 同时创建区域账户和团队账户
   - 新增 getPendingRewards API 查询待领取列表
   - 新增 settleUserPendingRewards 用户认种后结算
   - 新增 processExpiredRewards 定时处理过期奖励
   - PlantingCreatedHandler 监听认种事件触发结算
   - ExpiredRewardsScheduler 每小时处理过期奖励

账户格式:
- 省区域: 9+provinceCode (如 9440000)
- 市区域: 8+cityCode (如 8440100)
- 省团队: 7+provinceCode (如 7440000)
- 市团队: 6+cityCode (如 6440100)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 03:32:47 -08:00
hailin 4d3290f029 fix(wallet-service): 修复系统账户资金分配功能
问题:
- 认种订单支付后,系统账户(成本费、运营费、总部社区、RWA底池)余额始终为0
- reward-service 正确计算分配,但 wallet-service 未实际执行系统账户的资金转移

根本原因:
1. allocateToSystemAccount() 方法只打印日志,未执行任何数据库操作(遗留的 TODO)
2. UserId 值对象不允许负数,而系统账户 user_id 为负数(-1 到 -4)

修复内容:

1. wallet-application.service.ts - allocateToSystemAccount()
   - 实现完整的系统账户资金分配逻辑
   - 通过 findByAccountSequence() 获取系统账户
   - 调用 addAvailableBalance() 直接增加可用余额
   - 创建 SYSTEM_ALLOCATION 类型的流水记录

2. wallet-account.aggregate.ts
   - 新增 addAvailableBalance(amount: Money) 方法
   - 用于系统账户直接增加余额(无需待领取/过期机制)

3. ledger-entry-type.enum.ts
   - 新增 SYSTEM_ALLOCATION 枚举值,用于系统账户分配流水

4. user-id.vo.ts
   - 移除负数校验,允许系统账户使用负数 user_id
   - 系统账户约定:-1(总部社区)、-2(成本费)、-3(运营费)、-4(RWA底池)

验证结果(认种1棵树=2199 USDT):
- S0000000001 总部社区: 9 USDT ✓
- S0000000002 成本费账户: 400 USDT ✓
- S0000000003 运营费账户: 300 USDT ✓
- S0000000004 RWA底池: 800 USDT ✓

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 02:01:48 -08:00
hailin 98d8bee20d fix: 统一推荐码生成逻辑 - 由 identity-service 单点生成
重要变更:
- identity-service 生成用户推荐码,通过 Kafka 事件传递给 referral-service
- referral-service 不再自己生成推荐码,直接使用事件中的推荐码
- 修复两个服务推荐码不一致的问题

涉及服务:
- identity-service: 事件 payload 添加 referralCode 字段
- referral-service: 接收并存储 identity-service 生成的推荐码
- wallet-service: 添加区域账户动态创建接口
- planting-service: 调用区域账户创建接口

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 01:14:56 -08:00
hailin ebbf2d971a feat: 跨服务使用 accountSequence 查询推荐链 + 系统账户动态创建
1. reward-service 使用 accountSequence 查询推荐链
   - event-consumer.controller.ts: 优先使用 accountSequence 作为用户标识
   - reward-calculation.service.ts: 使用 accountSequence 查询推荐关系
   - referral-service.client.ts: 参数从 userId 改为 accountSequence

2. referral-service 支持 accountSequence 格式的推荐链查询
   - referral.controller.ts: /chain/:identifier 同时支持 userId 和 accountSequence

3. wallet-service 系统账户动态创建
   - wallet-application.service.ts: allocateToUserWallet 使用 getOrCreate
   - 支持省区域(9+code)和市区域(8+code)账户自动创建
   - 新增 migration seed: 4个固定系统账户 (S0000000001-S0000000004)

4. planting-service 事件增强
   - 事件中添加 accountSequence 字段用于跨服务关联

系统账户格式:
- S0000000001: 总部社区 (基础费9U + 兜底权益)
- S0000000002: 成本费账户 (400U)
- S0000000003: 运营费账户 (300U)
- S0000000004: RWAD底池账户 (800U)
- 9+provinceCode: 省区域系统账户 (动态创建)
- 8+cityCode: 市区域系统账户 (动态创建)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 23:22:01 -08:00
hailin d20ff9e9b5 fix: 修复 wallet-service 支持 accountSequence 格式及订单状态机
1. wallet-service/internal-wallet.controller.ts:
   - getBalance: 支持 accountSequence (D开头) 和 userId (纯数字) 两种格式

2. wallet-service/wallet-application.service.ts:
   - freezeForPlanting: 修复 BigInt 转换错误,优先按 accountSequence 查找钱包
   - confirmPlantingDeduction: 同上
   - unfreezeForPlanting: 同上
   - getMyWallet: 支持 userId='0' 的情况(仅通过 accountSequence 查询)

3. planting-service/planting-order.aggregate.ts:
   - schedulePoolInjection: 状态检查从 FUND_ALLOCATED 改为 PAID
   - 原因: 资金分配已移至 reward-service 异步处理

修复问题: "Cannot convert D25121300006 to a BigInt"

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 22:35:18 -08:00
hailin ad82e3ee44 fix(referral-service): 从领域层修复 usedReferralCode 存储错误
问题:
- 创建推荐关系时,used_referral_code 字段错误地存储了用户自己的推荐码
- 而不是用户使用的推荐人的推荐码

根本修复(从领域层):
1. ReferralRelationshipProps: 添加 usedReferralCode 字段
2. ReferralRelationship.create(): 新增 referrerReferralCode 参数
3. ReferralRelationship: 添加 _usedReferralCode 私有属性和 getter
4. toPersistence(): 输出 usedReferralCode
5. reconstitute(): 正确重建 usedReferralCode

调用链路修复:
- referral.service.ts: 在查询推荐人时获取其 referralCode,
  并在调用 ReferralRelationship.create() 时传入
- repository: 直接使用 data.usedReferralCode 而不是额外查询

测试更新:
- 更新单元测试和集成测试以支持新的 create() 签名
- 新增 usedReferralCode 相关测试用例

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 19:49:11 -08:00
hailin e557b00c24 fix(reward-service): 修复 targetType 类型断言 2025-12-12 19:16:15 -08:00
hailin 96f031da35 fix(wallet-service): 修复 allocateToUserWallet 使用 accountSequence 查找钱包
- targetId 现在是 accountSequence (如 D2512120001),不再是 userId
- 移除无效的 BigInt(targetId) 转换
- 从 wallet 对象获取 userId 用于流水记录和缓存失效

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 19:15:47 -08:00
hailin 518667e88e fix(reward-service): 修复与 wallet-service 的接口字段不匹配
修复 allocateFunds 接口:
- targetType: 使用 USER/SYSTEM 而不是 rightType
- targetId: 使用 accountSequence 而不是 userId
- allocationType: 新增字段,存储 rightType
- hashpowerPercent: 新增字段,传递算力百分比

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 19:10:39 -08:00
hailin d94badfa53 fix(wallet-service): 修复 account_sequence 类型从 BIGINT 改为 VARCHAR(20)
与其他服务保持一致,accountSequence 格式为 D + YYMMDD + 5位序号
- wallet_accounts.account_sequence
- wallet_ledger_entries.account_sequence
- deposit_orders.account_sequence
- withdrawal_orders.account_sequence

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 18:46:37 -08:00
hailin 552b15e26b fix(mobile): 修复序列号类型转换错误
accountSequence 格式已从数字改为字符串 (D + YYMMDD + 5位序号)
- profile_page.dart: `as int?` → `as String?`
- mining_page.dart: `as int?` → `as String?`

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 14:22:59 -08:00