6.8 KiB
6.8 KiB
功能同步计划:私有版 → 开源版
源目录:/Users/Apple/vpn/ppanel-server(私有版)
目标目录:/Users/Apple/code_vpn/vpn/ppanel-server(开源版)
模块名相同:github.com/perfect-panel/server
批次 A:新增独立包(直接复制)
A1. pkg/iap(Apple IAP)
- 复制
pkg/iap/全目录
A2. pkg/kutt(短链接服务)
- 复制
pkg/kutt/kutt.go
A3. pkg/loki(Grafana Loki)
- 复制
pkg/loki/loki.go
A4. pkg/openinstall(渠道统计)
- 复制
pkg/openinstall/openinstall.go
A5. internal/model/iap(IAP 数据模型)
- 复制
internal/model/iap/全目录
A6. internal/model/logmessage(错误日志模型)
- 复制
internal/model/logmessage/全目录
批次 B:数据库迁移
B1. 新增迁移文件(仅从私有版复制)
02120_log_message.up.sql/.down.sql02121_apple_iap_transactions.up.sql/.down.sql02122_add_user_last_login_time.up.sql/.down.sql02123_update_auth_method_config.up.sql/.down.sql(auth_method MEDIUMTEXT)
B2. 修改共有迁移文件
00002_init_basic_data.up.sql:VerifyCodeExpireTime 默认值 300→90002118_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 字段 MEDIUMTEXT(Go 结构体 tag)
- 补全 4 种邮件模板初始化
D3. internal/model/node/model.go
- 添加:CountNodesByIdsAndTags 方法(移除 fmt.Println 调试语句)
- 修复:ClearServerAllCache 同时清理 ServerConfig + ServerUserList
- 修复:cursor append bug(OSS版的 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 判断 IsGift(amount==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 更新
- 添加:单事务包裹所有修改
执行顺序
- A(新包) → B(迁移) → C(配置) → D(模型)
- E(认证) → F(用户) → G(订单) → H(订阅)
- I(队列) → J(路由) → K(邮件) → L(管理后台)
注意事项
- 排除:App版本管理、设备绑定相关逻辑(ZSet Session、DeviceId in token)
- 调试日志清理:不带 fmt.Println 调试语句
- 模块名相同:import 路径无需修改
- 开源版新功能保留:软删除、注册 IP 限流、兑换码系统、GeoIP 等开源版独有功能不回退