Commit Graph

472 Commits

Author SHA1 Message Date
hailin 92c305c749 fix(mobile-app): 待签署合同页文案改为"10份预种份额已合并为1棵树"
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 03:40:49 -08:00
hailin 2f78899ceb fix(mobile-app): 修复待签署合同页和持仓页硬编码"5份"的问题
预种方案已从5份/棵调整为10份/棵,但以下两处文案仍硬编码为5:

1. 待签署合同页 (pending_contracts_page.dart)
   - 原: "5 份预种份额已合并,请签署合同以开启挖矿"
   - 改: "{订单数} 笔预种订单已合并为 {树数} 棵树,请签署合同以开启挖矿"
   - 使用 merge.sourceOrderNos.length 和 merge.treeCount 动态显示

2. 持仓页空状态 (pre_planting_position_page.dart)
   - 原: "累计 5 份后将自动合成 1 棵树"
   - 改: "累计 $_portionsPerTree 份后将自动合成 1 棵树"
   - 使用已有常量 _portionsPerTree=10

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 03:30:42 -08:00
hailin 55f81ff329 fix(mobile-app): 修复多个页面时间显示为UTC而非北京时间的问题
后端数据库统一存储UTC时间,前端展示时需调用 .toLocal() 转换为
设备本地时区(中国地区即 UTC+8 北京时间)。

以下5个页面的 _formatDateTime() 方法缺少 .toLocal() 转换,
导致页面显示的时间比北京时间慢8小时:

- 预种合并详情页 (pre_planting_merge_detail_page.dart)
  → 合并时间、签署时间、挖矿开启时间
- 预种持仓页 (pre_planting_position_page.dart)
  → 购买时间、合并时间
- 合同签署页 (contract_signing_page.dart)
  → 合同签署时间
- 转让列表页 (transfer_list_page.dart)
  → 转让创建时间
- 转让详情页 (transfer_detail_page.dart)
  → 转让各状态时间

修复方式:在格式化前统一调用 dt.toLocal() 将UTC转为本地时区。
后端和数据库保持UTC不变,仅前端展示层做时区转换。

注:ledger_detail_page.dart 已使用 DateTimeUtils.formatDateTime()
(内含 .toLocal()),无需修改。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 03:11:48 -08:00
hailin 532be9a561 fix(pre-planting): 合并详情显示实际份数和金额,不再硬编码
问题:合并详情页"合并份数"显示订单条数(7)而非实际份数(10),
"总价值"硬编码 订单数×1887,每笔订单金额也硬编码 1,887。

修复:
后端 getMergeDetail:
  - 新增 sourceOrders[] 含每笔订单的 portionCount + totalAmount
  - 新增 totalPortions(总份数)和 totalAmount(总金额)

前端 PrePlantingMerge model:
  - 新增 MergeSourceOrder 类
  - 新增 sourceOrders/totalPortions/totalAmount 字段

前端合并详情页:
  - "合并份数"用 totalPortions 替代 sourceOrderNos.length
  - "总价值"用 totalAmount 替代硬编码计算
  - 来源订单列表显示每笔实际金额和份数(多份时显示"N份"前缀)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 02:58:34 -08:00
hailin d7f7d7082d fix(pricing): 预种定价API常量同步 — 3566→1887, /5→/10, 正式认种15831不变
admin-service tree-pricing.service.ts:
  - BASE_PORTION_PRICE: 3566 → 1887
  - supplement 除数: /5 → /PORTIONS_PER_TREE(10)
  - BASE_PRICE 保持 15831(正式认种价格不变)
  - 移除 updateSupplement 中重复声明的 BASE_PRICE 局部变量

planting-service tree-pricing-admin.client.ts:
  - fallback basePortionPrice/totalPortionPrice: 3566 → 1887

mobile-app tree_pricing_service.dart:
  - 修正上次commit误改的 basePrice/totalPrice fallback: 18870 → 15831
  - basePortionPrice/totalPortionPrice 保持 1887

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 01:56:21 -08:00
hailin a55201b3b3 feat(referral+mobile): 功能6 — App 团队预种数量展示
纯新增实现,不修改任何现有业务逻辑,对现有系统零风险。

## 后端 — referral-service

新建 TeamPrePlantingController(JWT 认证),2 个公开端点:

1. GET /referral/me/team-pre-planting
   - 返回当前用户的个人预种份数、团队预种总量
   - 返回直推成员列表及每人的预种份数
   - 从 TeamStatistics 表读取(CDC 事件维护的数据)

2. GET /referral/me/team-pre-planting/members?limit=20&offset=0
   - 分页返回全部团队成员的预种明细(仅有预种份数 > 0 的成员)
   - 使用 ancestor_path 数组查询所有下级用户
   - JOIN team_statistics 获取每人的 selfPrePlantingPortions

Kong 网关无需修改(/api/v1/referral/* 已覆盖)。

## 前端 — Flutter mobile-app

新建 TeamPrePlantingPage 页面:
- 顶部统计卡片:个人预种 + 团队预种总量
- 直推预种明细列表(所有用户可见)
- 全部团队成员预种明细(仅市/省公司管理者可见,分页加载更多)
- 普通用户看到锁定提示"仅市公司/省公司管理者可查看"

入口:个人中心页预种按钮行新增绿色「团队预种」按钮。

## 文件清单

新建文件:
- backend/.../controllers/team-pre-planting.controller.ts(核心后端控制器)
- frontend/.../pages/team_pre_planting_page.dart(Flutter 团队预种页面)

微量修改(仅追加新行):
- controllers/index.ts: +1 行 export
- api.module.ts: +2 行 import/注册
- api_endpoints.dart: +2 行端点常量
- referral_service.dart: +4 模型类 +2 API 方法
- route_paths.dart, route_names.dart: +1 行路由定义
- app_router.dart: +1 import +1 GoRoute
- profile_page.dart: 预种按钮行追加第三个按钮

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 07:15:17 -08:00
hailin d5d61f4f68 fix(transfer): 修复转让记录 API 路径与参数不匹配
- API 路径: /transfers/my → /transfers(后端无 /my 子路由)
- 分页参数: page/pageSize → limit/offset(匹配后端 DTO)
- 转让记录页显示具体错误信息便于调试

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 23:35:09 -08:00
hailin 6efa74aded refactor(transfer): 移除发起转让页的售价字段 — 线下柜台签合同交易
APP 端树转让仅完成系统层面的所有权变更 + 算力调整(撤回旧用户算力、
新增至新用户及其团队),价格由用户线下到柜台签署合同确定。

变更详情:
- transfer_initiate_page.dart:
  · 移除 _priceController、_feeRate、费用相关 getter
  · 移除"每棵售价"输入框和费用计算卡片 UI
  · 移除 _feeRow 辅助方法
  · 更新说明文案:强调线下柜台签合同
  · 更新确认弹窗:仅显示买方账号和转让棵数
  · API 调用改用 treeCount 替代 pricePerTree
- transfer_service.dart:
  · createTransfer() 参数从 pricePerTree(double) 改为 treeCount(int)
  · 请求体字段同步调整

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 20:06:31 -08:00
hailin 0e34896d0b refactor(mobile-app): 树转让入口从"我"页面迁移至"实名认证"页面
将"发起转让"和"转让记录"按钮从 ProfilePage 顶部移除,
归类为"树服务"放入 KycEntryPage(实名认证入口页),
位于"其他操作 > 验证/更换手机号"的下方。

变更详情:
- profile_page.dart:
  · 移除 _buildTransferButtons() 方法及其调用
  · 移除 _goToTransferInitiate() / _goToTransferList() 导航方法
- kyc_entry_page.dart:
  · 在"验证/更换手机号"下方新增"树服务"分类标题
  · 新增"发起转让"操作卡片 → /transfer/initiate
  · 新增"转让记录"操作卡片 → /transfer/list
  · 复用页面已有的 _buildActionCard 样式,保持 UI 一致

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 19:47:39 -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 fda79304c6 Revert "fix(ledger): 分享收益筛选支持多类型(REWARD_TO_SETTLEABLE + REWARD_PENDING)"
This reverts commit d223671db7.
2026-03-01 11:07:19 -08:00
hailin d223671db7 fix(ledger): 分享收益筛选支持多类型(REWARD_TO_SETTLEABLE + REWARD_PENDING)
后端 entryType 筛选支持逗号分隔多值,前端"分享收益"同时查询两种类型,
解决未认种时收到的 REWARD_PENDING 分享权益在筛选中丢失的问题。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 11:02:08 -08:00
hailin e4a2a0e37a feat(ledger): 流水明细显示来源用户ID + 统计兼容历史批量转换数据
- wallet_service.dart: LedgerEntry 新增 sourceAccountFromMemo 从 memo 提取来源用户
- ledger_detail_page.dart: 流水列表项显示"来自 Dxxx"金色文字
- ledger_detail_page.dart: 权益详情弹窗添加来源用户行和备注行
- wallet-application.service.ts: 统计/趋势保留 memo 兼容历史批量转换记录

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 10:41:11 -08:00
hailin d876dd1591 fix(wallet): 区分直接入账和批量转换的 REWARD_TO_SETTLEABLE
新增 REWARD_PENDING_CONVERTED 类型用于批量转换(待领取→可结算),
REWARD_TO_SETTLEABLE 保留给直接入账(hasPlanted=true时的新收入)。

统计排除:REWARD_PENDING_CONVERTED + REWARD_SETTLED(状态转换)
统计计入:REWARD_PENDING + REWARD_TO_SETTLEABLE(首次入账)

已迁移7条历史数据的 entry_type。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 10:30:47 -08:00
hailin 31e6f9e15a fix(mobile): 预种可结算列表以wallet实际金额为准,避免已结算条目残留
planting-service 的分配记录不跟踪 wallet 端的结算状态,
原来的反向排除法(排除PENDING+EXPIRED)无法处理:
1. 已结算到余额(SETTLED→余额)的条目
2. hasPlanted=true 后直接进可结算、不经 pending_rewards 的条目

改为以 walletInfo.rewards.settleableUsdt 为权威来源:
- settleableUsdt=0 时直接跳过(已全部结算到余额)
- settleableUsdt>0 时按金额截断,确保展示总额不超过实际可结算

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 10:19:31 -08:00
hailin 8e52535dd9 feat(mobile): 预种明细显示来源用户ID + 修复空待领取倒计时
1. 预种待领取/可结算明细的 memo 中追加来源用户(如"来自D26022600016的预种")
2. 修复 pendingUsdt=0 时倒计时仍然显示的问题(pending_expire_at 未清除时兜底)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 09:48:34 -08:00
hailin b13d873f64 feat(mobile): 流水明细中 REWARD_PENDING 标注"已转可结算"
用户购买预种后 hasPlanted=true,所有 PENDING 奖励转为 SETTLED,
此时流水中历史的 REWARD_PENDING 条目追加"(已转可结算)"标注,
避免用户误以为还有未领取的奖励。仅在 pendingUsdt=0 时显示。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 09:15:18 -08:00
hailin e9b9896317 fix(mobile): 修复预种可结算列表与金额不一致
问题:pre-planting/my-rewards 返回所有分配记录不区分状态,
导致 PENDING 状态的预种奖励也被错误地显示在可结算列表中,
而可结算金额(从 wallet-service 取值)正确为 0,造成列表和金额不一致。

修复:在合并预种可结算列表时,排除正在 PENDING 和 EXPIRED 状态的条目。
通过 wallet/pending-rewards 和 wallet/expired-rewards 获取实际状态,
用 sourceOrderId 交叉比对,只保留真正可结算的预种条目。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 08:24:03 -08:00
hailin 4996c1d110 feat(mobile): profile页待领取/可结算/已过期列表统一显示预种数据
变更概要:
- wallet_service.dart: 新增 WalletPendingRewardItem 模型和 getWalletPendingRewards() 方法
  调用 GET /wallet/pending-rewards 获取 wallet-service 的待领取奖励列表
- profile_page.dart: 合并预种待领取奖励到列表中
  从 wallet-service 待领取列表中筛选 PPL 前缀的预种条目,转换为 PendingRewardItem
  与 reward-service 的正常认种待领取统一展示
- profile_page.dart: 已过期列表标记预种条目
  wallet-service GET /wallet/expired-rewards 已包含预种过期记录,
  渲染时通过 sourceOrderId.startsWith('PPL') 动态添加 [预种] 前缀
- profile_page.dart: 所有汇总金额统一从 wallet-service 取值
  _pendingUsdt / _expiredUsdt / _remainingSeconds 改为从 walletInfo.rewards 读取,
  wallet_accounts 包含正常认种 + 预种,是唯一的 source of truth

技术说明:
- 后端零改动,仅前端变更(零风险)
- 预种条目通过订单号 PPL 前缀与正常认种区分,避免重复显示
- 所有预种条目在卡片上显示 [预种] 前缀,方便用户区分来源

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 07:52:02 -08:00
hailin 27cd72fe01 feat(pre-planting): 预种可结算收益结算 + 前端可结算金额修正
背景:
  预种奖励通过 planting-service → wallet-service allocateFunds 链路
  直接写入 wallet_accounts.settleable_usdt,不经过 reward-service。
  因此 reward-service 的一键结算(settleToBalance)无法覆盖预种部分,
  且 reward-service 的 summary.settleableUsdt 不包含预种金额。

改动:
1. wallet-service 新增 POST /wallet/settle-pre-planting 端点
   - 将 wallet 中剩余的 settleable_usdt 转入 available 余额
   - settleable_usdt=0 时幂等跳过,不创建空流水
   - 流水备注标注 [预种],payloadJson.source='pre-planting'

2. mobile-app 兑换页(trading_page):
   - 可结算金额改为从 wallet-service 的 wallet.rewards.settleableUsdt 取值
     (包含正常认种 + 预种的可结算部分,是唯一的 source of truth)
   - 一键结算流程改为两步串行:
     先调 reward-service settleToBalance(正常认种,不动现有逻辑),
     再调 wallet-service settle-pre-planting(预种部分,纯增量)

3. mobile-app 我的页(profile_page):
   - 并行加载新增 walletService.getMyWallet() 调用
   - _settleableUsdt 改为从 wallet.rewards.settleableUsdt 取值

不涉及的系统:
  - reward-service:零改动
  - planting-service:零改动
  - wallet-service 现有结算逻辑:零改动
  - admin-web:零改动

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 07:33:53 -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 cf07712a8c fix(mobile): 兑换页可结算收益聚合正常认种+预种金额
之前只显示正常认种的 settleableUsdt,未包含预种收益,
导致有预种收益但显示"暂无可结算收益"。
现在并行获取两者并累加,与"我"页面保持一致。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 03:11:13 -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 62bbbca609 Revert "fix(ledger): REWARD_EXPIRED条目显示权益类型+已过期标签"
This reverts commit 4bd40970d0.
2026-02-28 12:04:07 -08:00
hailin 4bd40970d0 fix(ledger): REWARD_EXPIRED条目显示权益类型+已过期标签
- 奖励过期条目显示具体权益名(分享权益/省团队权益等)+ 红色"已过期"标签
- 图标改为灰色 timer_off,金额文字改为灰色,背景微灰
- 与正常权益收入条目有明显视觉区分

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 12:01:36 -08:00
hailin a904c8bd42 feat(ledger): 预种份额在流水明细中显示合并合同下载按钮
- 移除硬编码"预种无合同"逻辑
- PPL 份额点击详情时,查找是否有对应的已签署合并记录
- 有签署合同则显示查看/下载按钮,调用预种合并合同 PDF 接口
- 同时新增 _viewMergeContractPdf / _downloadMergeContractPdf 方法

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 11:19:27 -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 2ad1936126 fix(pre-planting): 合并详情页 USDT 改为绿积分
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 10:17:12 -08:00
hailin 7bad0a8935 fix(pre-planting): 修复编译错误(getMerges→getMyMerges、RoutePaths 缺失导入、Future.wait 类型)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 10:00:17 -08:00
hailin b9b23c36d7 feat(pre-planting): 合并后走正常签合同流程,购买第5份直接跳合并详情页
- pre_planting_service: CreatePrePlantingOrderResponse 增加 merged/mergeNo 字段
- pre_planting_purchase_page: 购买成功若触发合并,直接跳转合并详情签合同
- contract_check_service: 注入 PrePlantingService,checkAll 增加预种待签合并检查
- pending_contracts_page: 同时展示普通合同和预种合并待签卡片,复用现有签合同弹窗流程
- injection_container: contractCheckServiceProvider 注入 prePlantingService

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 09:51:21 -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 eea38b2b86 fix(pre-planting): 购买页面和弹窗中 USDT 改为绿积分
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 07:20:51 -08:00
hailin 9b6effe63d debug(pre-planting): 添加购买流程详细日志以排查 List cast 错误
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 07:19:35 -08:00
hailin 606d3c0b22 fix(pre-planting): 修复购买失败时 List<dynamic> 类型转换错误和续购省市缺失
1. api_client.dart: NestJS validation error 返回 message 为数组时,
   用 join(', ') 转为字符串,避免直接传给 ApiException(String) 崩溃
2. pre_planting_purchase_page.dart: 续购时传 _position 中已保存的
   provinceCode/cityCode,满足后端 DTO 必填校验

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 06:56:49 -08:00
hailin 2d7b02aa96 fix(pre-planting): 修复预种页面 5 个 UI 问题(纯前端,零后端改动)
=== 问题 1:流水明细合同按钮 500 错误 ===
文件: ledger_detail_page.dart
原因: 预种订单(PPL 前缀)无合同,但流水详情弹窗显示「查看合同/下载合同」按钮
修复: _showTransactionDetail 检测 refOrderId.startsWith('PPL'),
      预种订单传 showContractButtons: false,弹窗不渲染合同按钮区

=== 问题 2:流水备注显示英文 ===
文件: ledger_detail_page.dart
原因: 备注字段存储的是 'Plant payment (from frozen)'(后端写入,不改后端)
修复: _TransactionDetailSheet 展示备注时,若订单号以 PPL 开头则显示「预种」

=== 问题 3:预种明细订单金额单位错误 ===
文件: pre_planting_position_page.dart
修复: '${order.totalAmount.toInt()} USDT' → '${order.totalAmount.toInt()} 绿积分'

=== 问题 4:省市显示数字代码(如 44 · 4401)===
文件: pre_planting_position_page.dart / pre_planting_purchase_page.dart
原因: provinceName/cityName 为 null 时回退显示 provinceCode/cityCode
修复:
  - position 页:条件改为 provinceName != null && cityName != null,无中文名则不显示省市行
  - purchase 页:加载时不再 fallback 到代码;锁定显示无名称时显示「已锁定」;
    购买确认弹窗省市行无名称时显示「-」

=== 问题 5:「合并进度」改为「合成进度」===
文件: pre_planting_position_page.dart / pre_planting_purchase_page.dart
修复: 两处 Text('合并进度') → Text('合成进度')

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 06:25:38 -08:00
hailin 1d1c60e2a2 feat(notification): 新增强制阅读弹窗功能(管理员可配置 requiresForceRead)
## 功能概述

在不影响任何现有业务的前提下,新增"强制阅读弹窗"功能:
- 管理员创建通知时可勾选「需要强制弹窗阅读」
- App 冷启动进入主页 或 从后台切回前台时自动触发检查
- 存在未读且标记 requiresForceRead=true 的通知时,依次逐条弹窗
- 用户无法通过点击背景或返回键关闭弹窗(强制阅读)
- 最后一条通知弹窗底部显示 checkbox「我已经阅读并知晓」
  - 未勾选时"确定"按钮置灰禁用
  - 勾选后"确定"变为金色可点击,点击后所有弹窗消失
- 全部看完后仅对已展示的强制阅读通知按 ID 逐一标记已读
  (不影响普通未读通知的 badge 计数)

## 涉及改动

### 后端 admin-service

- `prisma/schema.prisma`
  - Notification 模型新增字段 `requiresForceRead Boolean @default(false)`

- `prisma/migrations/20260227100000_add_requires_force_read_to_notifications/migration.sql`
  - 手动创建 SQL migration(本地无 DATABASE_URL 环境)
  - 部署时需在服务器执行 `npx prisma migrate deploy`

- `src/domain/entities/notification.entity.ts`
  - 实体类构造器新增 `requiresForceRead`
  - create() / update() 方法均支持该字段,默认值 false

- `src/infrastructure/persistence/mappers/notification.mapper.ts`
  - toDomain() 从 Prisma 记录读取 requiresForceRead
  - toPersistence() 写入 requiresForceRead

- `src/api/dto/request/notification.dto.ts`
  - CreateNotificationDto / UpdateNotificationDto 各新增可选字段 requiresForceRead

- `src/api/dto/response/notification.dto.ts`
  - NotificationResponseDto(管理端)新增 requiresForceRead
  - UserNotificationResponseDto(移动端)新增 requiresForceRead

- `src/api/controllers/notification.controller.ts`
  - create() / update() 透传 requiresForceRead 到 entity

### 前端 admin-web

- `src/services/notificationService.ts`
  - NotificationItem / CreateNotificationRequest / UpdateNotificationRequest 新增 requiresForceRead

- `src/app/(dashboard)/notifications/page.tsx`
  - 通知列表:requiresForceRead=true 时显示红色「强制阅读」标签
  - 创建/编辑表单:新增 checkbox「需要强制弹窗阅读」及说明文字
  - form state / submit payload / edit 初始化均包含 requiresForceRead

### 移动端 mobile-app

- `lib/core/services/notification_service.dart`
  - NotificationItem 新增字段 requiresForceRead(默认 false,fromJson 安全读取)

- `lib/features/notification/presentation/pages/notification_inbox_page.dart`
  - markAsRead / markAllAsRead 重建 NotificationItem 时保留 requiresForceRead

- `lib/features/notification/presentation/widgets/force_read_notification_dialog.dart`(新建)
  - 单条强制阅读弹窗组件
  - 顶部显示通知类型图标 + 进度「1/3」
  - 可滚动内容区展示完整通知
  - 非最后条:「下一条 ▶」按钮(始终可点)
  - 最后一条:checkbox + 「确定」(勾选后才可点)
  - barrierDismissible: false + PopScope(canPop: false),无法逃出

- `lib/features/home/presentation/pages/home_shell_page.dart`
  - 新增状态:_isShowingForceReadDialog(实例,防重入)
                _lastForceReadDialogShownAt(静态,60秒冷却)
  - 新增方法 _checkAndShowForceReadDialog():
      Guard 1: 防重入锁
      Guard 2: 60秒冷却(防回前台闪弹)
      Guard 3: 检查用户已登录
      Guard 4: 检查无其他弹窗在显示
    弹窗期间同时设置 _isShowingDialog=true,阻止后台合同/KYC检查并发
    全部看完后仅标记 forceReadList 中的通知为已读,再 refresh() 刷新 badge
  - initState addPostFrameCallback 中新增调用
  - didChangeAppLifecycleState resumed 分支中新增调用
  - resetContractCheckState() 中重置 _lastForceReadDialogShownAt(账号切换隔离)

## 安全与兼容性

- API 调用失败时静默返回,不阻断用户进入 App
- 仅对 requiresForceRead=true 的通知弹窗,普通通知完全不受影响
- 与现有合同弹窗、KYC弹窗、维护弹窗、更新弹窗无冲突
- 静态冷却变量在账号切换时重置,避免新账号被旧账号冷却影响
- badge 准确:仅标记已展示的强制通知,不动其他未读通知计数

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 19:33:51 -08:00
hailin ef68b7b9c0 fix(pre-planting): 预种开关关闭时隐藏"我的"页面预种按钮
- profile_page: 加载预种配置,根据 isActive 控制预种按钮显隐
- 开关关闭时不显示「预种购买」「预种明细」按钮
- 默认不显示(_isPrePlantingActive = false),加载成功后更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 23:11:53 -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 8bafb0a8d4 fix(mobile-app): 增加切换账号全局防护,彻底解决切换期间自动退出登录
根因:切换账号时 saveCurrentAccountData() 耗时 ~7 秒,期间定时器仍在发 API 请求,
clear 阶段 token 被删除后 in-flight 请求收到 401 → 触发 tokenExpired →
logoutCurrentAccount() 把刚恢复的新账号数据全部擦除。

修复(两层防护):
1. 全局锁 isSwitchingAccount:MultiAccountService 在 switchToAccount 整个过程中
   设为 true,app.dart _handleTokenExpired 检测到该标志直接 return,不执行 logout
2. 定时器提前停止:将定时器停止从 onBeforeRestore(save 之后)移到 switchToAccount
   调用之前,确保 save 期间无新 API 请求
3. try/finally 保证标志位必定清除,异常情况不会锁死后续 tokenExpired 事件

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 12:41:45 -08:00
hailin a5cc3fdc5b fix(mobile-app): 修复切换账号时 token 过期导致自动退出登录
根因:switchToAccount() 流程中,定时器在 _clearCurrentAccountData()
之后才停止。clear 阶段会删除 token,但此时定时器仍在运行,
in-flight 的 API 请求收到 401 → 触发 _handleTokenExpired()
→ 调用 logoutCurrentAccount() 把正在恢复的新账号数据全部清掉
→ 用户被自动踢到登录页面。

修复:将 onBeforeRestore 回调(停止定时器)移到 _clearCurrentAccountData()
之前执行,确保所有 API 请求停止后再清除 token。

修改前: save → clear(删token) → 停定时器 → restore
修改后: save → 停定时器 → clear(删token) → restore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 12:21:57 -08:00
hailin 12004d1c2e fix(mobile-app): 修复账号切换后自动退出登录的问题
根因:ref.invalidate(authProvider) 销毁旧 AuthNotifier 后,新实例的构造函数
仅设置 AuthState(status: AuthStatus.initial),从不自动调用 checkAuthStatus()
从 SecureStorage 重新加载认证数据。导致 auth 状态停留在 initial(未认证),
依赖 auth 状态的组件误判为"未登录",触发页面跳转到登录页。

修复:
- account_switch_page: invalidate 后立即调用 loadAuthState() 从 storage
  读取新账号数据,确保 auth 状态为 authenticated 后再导航
- account_switch_page: 切换后重置 ApiClient 的 tokenExpired 标记,防止
  旧会话的 401 状态阻塞新账号的请求
- app.dart: _handleTokenExpired() 增加醒目日志和调用栈打印,便于排查
  切换期间是否有 token 过期事件被误触发

切换流程更新为 6 步:
[1/6] switchToAccount() - 保存旧账号、清空、恢复新账号 storage
[2/6] onBeforeRestore - 停止所有定时器
[3/6] invalidate Provider - 销毁旧 Provider 实例
[4/6] loadAuthState() - 从 storage 加载新账号 auth 状态 ← 新增关键步骤
[5/6] 恢复遥测上传
[6/6] 导航到 ranking 页面

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 11:39:31 -08:00
hailin 3a307b5db7 fix(planting): 修复认种页面动态定价不生效 + 添加涨价倒计时
- 修复 admin-service PublicTreePricingController 路由双重前缀问题
  (@Controller('api/v1/tree-pricing') → @Controller('tree-pricing'))
- Kong 网关新增 /api/v1/tree-pricing 路由到 admin-service
- mobile-app 认种页面添加涨价倒计时功能:
  显示"距下次涨价还有 X天 X小时 X分钟"及涨价后价格

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 10:22:27 -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 577979bc83 chore: 同步线上构建版本号,避免服务器编译时版本号回退
- mining-app: 1.0.0+1 → 1.0.0+58(与线上已发布版本对齐)
- mobile-app: 2.0.0+1 → 2.0.0+357(与线上已发布版本对齐)

构建脚本会在此基础上自动递增,下次构建将从 59/358 开始。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 00:29:29 -08:00
hailin eda39b982d fix(mobile-app): 修复切换窗口期 NotificationBadge 混账号请求问题
问题(通过日志发现):
账号切换时存在一个 storage 空窗期(旧数据已清除、新数据尚未恢复完成)。
在此期间,NotificationBadgeNotifier 的 30s 定时器恰好触发,导致:
- _loadUnreadCount() 从 authProvider 内存读到旧账号 userSerialNum
- HTTP interceptor 从 storage 读到已恢复的新账号 accessToken
- 发出混账号请求:?userSerialNum=旧账号 + Authorization: Bearer 新账号token
日志证据:
  _restoreAccountData() 执行期间出现
  GET /notifications/unread-count?userSerialNum=D26022600000
  Authorization: Bearer [D26022600001的token]

修复:

1. notification_badge_provider.dart
   新增 stopAutoRefresh() 公开方法,取消 30s 定时器而不 dispose,
   Provider invalidate 重建后会自动重启定时器。

2. account_switch_page.dart - _switchToAccount
   在 onBeforeRestore 中补加:
     ref.read(notificationBadgeProvider.notifier).stopAutoRefresh()
   确保切换空窗期内 notificationBadge 定时器不触发。

   同时移除 UI 层冗余的 saveCurrentAccountData() 调用——
   switchToAccount() 内部已有此步骤,无需重复。

   日志步骤从 [1/6]...[6/6] 更新为 [1/5]...[5/5],
   并在 onBeforeRestore 注释中说明停止各定时器的原因。

切换空窗期现在所有定时器均已停止:
  ✓ walletStatusProvider (60s)
  ✓ pendingActionPollingService (4s)
  ✓ notificationBadgeProvider (30s)  ← 本次新增
  ✓ TelemetryUploader (30s)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 09:09:37 -08:00
hailin 825c8a32e4 chore(mobile-app): 补全多账号切换流程的关键日志,便于验证与排查
切换流程中的每一步现在都有清晰的日志输出,方便通过 adb logcat
或 flutter logs 验证切换行为是否符合预期。

account_switch_page.dart - 三条路径全部覆盖:

_switchToAccount(切换账号):
  [1/6] 保存当前账号数据
  [2/6] 调用 switchToAccount()
  [3/6] onBeforeRestore - 停止 walletStatus/pendingAction 轮询、暂停遥测
  [4/6] invalidate authProvider / walletStatusProvider / notificationBadgeProvider
  [5/6] 恢复遥测上传
  [6/6] 导航到 ranking 页面

_addNewAccount(添加新账号):
  [1/5] 保存当前账号数据
  [2/5] 停止定时器
  [3/5] 调用 logoutCurrentAccount()
  [4/5] invalidate 三个 Provider
  [5/5] 导航到 guide 页面

_deleteAccount(删除账号):
  删除前打印目标账号,删除后打印剩余账号数

profile_page.dart - _performLogout(退出登录):
  [1/4] 停止 walletStatus/pendingAction 轮询
  [2/4] 调用 logoutCurrentAccount()
  [3/4] invalidate 三个 Provider
  [4/4] 导航到 guide 页面

每条关键操作完成后打印 ✓ 确认符号,便于逐步验证。
每条路径用 ========== 分隔符标识开始/完成,日志易于 grep 过滤。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 09:04:14 -08:00
hailin e02bcf418c fix(mobile-app): 升级弹窗禁止点击外部或返回键关闭,必须通过按钮操作
问题:
检测到新版本弹出升级对话框时,用户点击弹窗外部区域或按系统返回键
即可直接关闭弹窗,绕过升级提示,导致用户可能永远不会注意到更新。

修复:
对所有 3 个升级弹窗统一加两层防护:
- barrierDismissible: false — 禁止点击弹窗外部区域关闭
- PopScope(canPop: false) — 禁止系统返回键关闭

涉及弹窗:
1. self_hosted_updater.dart - _showSelfHostedUpdateDialog(自建APK更新)
2. self_hosted_updater.dart - _showMarketUpdateDialog(应用市场引导更新)
3. update_service.dart - _checkGooglePlayUpdate(Google Play 更新)

用户必须通过弹窗内按钮操作:
- 非强制更新:点击「稍后」/「暂时不更新」关闭,或点击「立即更新」开始更新
- 强制更新:只有「立即更新」按钮,无法跳过

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 08:01:52 -08:00