hi-server/.claude/plan/sync-features.md

242 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 功能同步计划:私有版 → 开源版
源目录:`/Users/Apple/vpn/ppanel-server`(私有版)
目标目录:`/Users/Apple/code_vpn/vpn/ppanel-server`(开源版)
模块名相同:`github.com/perfect-panel/server`
---
## 批次 A新增独立包直接复制
### A1. pkg/iapApple IAP
- 复制 `pkg/iap/` 全目录
### A2. pkg/kutt短链接服务
- 复制 `pkg/kutt/kutt.go`
### A3. pkg/lokiGrafana Loki
- 复制 `pkg/loki/loki.go`
### A4. pkg/openinstall渠道统计
- 复制 `pkg/openinstall/openinstall.go`
### A5. internal/model/iapIAP 数据模型)
- 复制 `internal/model/iap/` 全目录
### A6. internal/model/logmessage错误日志模型
- 复制 `internal/model/logmessage/` 全目录
---
## 批次 B数据库迁移
### B1. 新增迁移文件(仅从私有版复制)
- `02120_log_message.up.sql` / `.down.sql`
- `02121_apple_iap_transactions.up.sql` / `.down.sql`
- `02122_add_user_last_login_time.up.sql` / `.down.sql`
- `02123_update_auth_method_config.up.sql` / `.down.sql`auth_method MEDIUMTEXT
### B2. 修改共有迁移文件
- `00002_init_basic_data.up.sql`VerifyCodeExpireTime 默认值 300→900
- `02118_traffic_log_idx.up.sql`:添加幂等性检查
- `02119_node.up.sql`@sql 变量名修正(已是私有版逻辑,保留)
---
## 批次 C配置与基础设施
### C1. internal/config/config.go
- 添加KuttConfig、LokiConfig、OpenInstallConfig、AppleIAPConfig 结构体
- 添加FixedRate 浮点型汇率配置
### C2. internal/config/cacheKey.go
- 添加:`UserSessionsKeyPrefix = "auth:user_sessions:"`
### C3. pkg/conf/default.go
- 添加reflect.Float64 case 处理
### C4. internal/svc/serviceContext.go
- 添加Kutt、Loki、OpenInstall、IAPModel 字段
### C5. internal/svc/devce.go
- 修复 SQL Bug`create_at``created_at`
### C6. pkg/orm/mysql.go
- 添加SetConnMaxIdleTime(5min) + SetConnMaxLifetime(30min)
### C7. pkg/exchangeRate/exchangeRate.go
- 保持私有版的 exchangerate.host 实现
### C8. initialize/config.go & init.go
- 添加 Loki、OpenInstall 初始化逻辑
---
## 批次 D数据模型
### D1. internal/model/user/user.go
- 添加LastLoginTime 字段
### D2. internal/model/auth/auth.go
- config 字段 MEDIUMTEXTGo 结构体 tag
- 补全 4 种邮件模板初始化
### D3. internal/model/node/model.go
- 添加CountNodesByIdsAndTags 方法(移除 fmt.Println 调试语句)
- 修复ClearServerAllCache 同时清理 ServerConfig + ServerUserList
- 修复cursor append bugOSS版的 append(keys, keys...)
### D4. internal/model/payment/payment.go
- 添加AppleIAPConfig 结构体
### D5. internal/model/user/subscribe.go
- 添加includeExpired 参数支持(":all" cache key suffix
---
## 批次 E认证与登录逻辑
### E1. internal/logic/auth/userLoginLogic.go
- 添加LastLoginTime 更新
- 添加:邮箱登录调试日志清理
### E2. internal/logic/auth/userRegisterLogic.go
- 添加:邮箱小写/trim 处理
- 添加:验证码过期时间使用配置值
### E3. 新增internal/logic/auth/emailLoginLogic.go
- 从私有版复制邮箱直登逻辑
### E4. 新增apis/auth/auth.api 邮箱登录路由
- 添加 emailLogin 接口定义
---
## 批次 F用户功能逻辑
### F1. internal/logic/public/user/queryUserInfoLogic.go
- 添加Kutt 短链接生成 + Redis 永久缓存
- 添加share_link 字段返回
### F2. internal/logic/public/user/queryUserSubscribeLogic.go
- 添加:查询 Order 判断 IsGiftamount==0
### F3. internal/handler/public/user/queryUserSubscribeHandler.go
- 添加includeExpired query param 注入 context
### F4. internal/model/user/model.go
- 添加FindActiveSubscribe / FindActiveSubscribesByUserIds
- 添加BatchClearRelatedCache
- 添加DeleteUserAuthMethodByIdentifier
---
## 批次 G订单与支付
### G1. internal/logic/public/order/preCreateOrderLogic.go
- 修复math.Round 金额计算
### G2. internal/logic/public/order/purchaseLogic.go
- 修复math.Round
### G3. internal/logic/public/order/renewalLogic.go
- 修复math.Round
### G4. internal/logic/public/portal/purchaseCheckoutLogic.go
- 添加Apple IAP checkout case
- 添加currency 从 DB 动态读取 + FixedRate fallback
- 修复math.Round for alipay
### G5. internal/model/payment/model.go
- 添加AppleIAP payment model 支持
### G6. pkg/payment/platform.go
- 添加AppleIAP platform entry
---
## 批次 H订阅与节点
### H1. internal/logic/public/portal/getSubscriptionLogic.go
- 添加CountNodesByIdsAndTags 调用,返回 node_count
### H2. internal/logic/public/portal/purchaseLogic.go
- 添加CloseOrderTimeMinutes 超时配置
### H3. internal/logic/subscribe/subscribeLogic.go
- 保持PanDomain 模式返回当前 Host
---
## 批次 I队列任务
### I1. queue/logic/order/activateOrderLogic.go
- 添加findGiftSubscription 逻辑
- 添加extendGiftSubscription 逻辑
- 添加grantGiftDaysToBothParties双向赠礼
- 添加no-retry for invalid status
### I2. queue/logic/email/sendEmailLogic.go
- 修改:主题中文化
- 修改:动态过期分钟数
- 修改float64→int 类型转换
- 添加Smart Fallback 模板逻辑4种类型
### I3. queue/logic/task/rateLogic.go
- 添加FixedRate config 支持(跳过 API 调用)
---
## 批次 J路由与类型
### J1. internal/handler/routes.go
- 添加IAP Apple 路由
- 添加email login 路由
- 添加error log 路由
- 添加contact 路由
### J2. internal/types/types.go
- 添加Apple IAP 相关 Request/Response 类型
- 添加BindEmailWithVerificationRequest/Response
- 添加BindInviteCodeRequest
- 添加ProductIds in checkout
### J3. internal/types/subscribe.go
- 保持私有版(移除 Type/Params 开源版新增字段——已在批次 A 处理)
---
## 批次 K邮件系统
### K1. pkg/email/template.go
- 添加Maintenance、TrafficExceed、Verify 3 种邮件模板
---
## 批次 L管理后台
### L1. internal/logic/admin/user/getUserListLogic.go
- 添加MemberStatus + LastLoginTime 展示
- 添加:批量获取 active subscriptions
### L2. internal/logic/admin/user/updateUserBasicInfoLogic.go
- 添加Remark + MemberStatus 更新
- 添加:单事务包裹所有修改
---
## 执行顺序
1. A新包 → B迁移 → C配置 → D模型
2. E认证 → F用户 → G订单 → H订阅
3. I队列 → J路由 → K邮件 → L管理后台
---
## 注意事项
- **排除**App版本管理、设备绑定相关逻辑ZSet Session、DeviceId in token
- **调试日志清理**:不带 fmt.Println 调试语句
- **模块名相同**import 路径无需修改
- **开源版新功能保留**:软删除、注册 IP 限流、兑换码系统、GeoIP 等开源版独有功能不回退