feat(points): 对齐后端积分/订阅 API 最终契约(types + API 层改造) #1956
Reference in New Issue
Block a user
Delete Branch "fix/points-api-contract-v2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 改造概述
对齐灵应 09:16 确认的 staging 实测最终契约,完成积分/订阅系统的类型层 + API 层改造。保持
POINTS_API_MOCK=true,等后端 P0(支付通道接入)完成后切 false 联调。✅ 完成项
类型层(api/points/types.ts + api/subscription/types.ts)
scene_name→name、points_per_use→base_points、包id→code、units→quantityprice_cents(分),前端÷100展示PointsTxType = "add" | "deduct"(refund 通过source=refund:<origin>前缀标识)free_clips_used/limit/remaining,免费额度改由DailyUsage提供discounted_price_for_*,前端按price_cents * (user_discount ?? 1) / 100算折后{items,total,page,page_size};source_name移除,前端按source映射中文名;ref_id是""非 null;移除signed_amount,前端按 type 算正负DailyUsage(GET /usage/daily)、MembershipResponse(GET /points/subscription/membership,含max_resolution)、SubscriptionPlan(GET /subscription/plans,4 档 free/monthly/quarterly/yearly)、BillingRecord(GET /subscription/billing-records)、CreateRechargeOrderResponse.pay_params/points_amount/expire_atMemberType(free/monthly/quarterly/yearly)+billing_cycle(monthly/yearly)双维度 → 新PlanId(free/monthly/quarterly/yearly)+BillingCycle,旧PlanType保留别名兼容;端点POST /subscription/subscribe→POST /subscription/change-plan {target_plan_id,billing_cycle};取消续费拆为/subscription/cancel+/subscription/toggle-auto-renew {enabled}{error:{code,message,valid_scenes?}}API 层(api/points/index.ts + api/subscription/subscription.ts)
apiClient(baseURL=/api/v1 + token 拦截器),不再用裸 requestgetDailyUsage()、getMembership()、getSubscriptionPlans()getPointsPackages/getPointsRules/getPointsTransactions/checkPoints/createPointsOrder字段对齐api/subscription/(changePlan/cancelSubscription/toggleAutoRenew/getSubscriptionPlans/getBillingRecords)pay_params: {}、points_amount字段已补消费端最小适配
dailyUsage/membership状态;optimisticAdd/Deduct同步更新 membership.points_balancemembership.member_type,降级取subscription.plan_id;tooltip 展示 max_resolutionsource + quantity + durationMinutes,units保留兼容;非会员免费额度从dailyUsage.free_clips_remaining取;支持 compact 模式dailyUsage驱动;会员标签+倍率提示从 store 取;reset_at展示重置时间pkg.code/pkg.price_cents,getDiscountPriceCents算折后;createPointsOrder 提示支付通道待接入SOURCE_LABEL前端映射 source→中文名(含refund:前缀);分页走 Tabs 本地过滤(服务端分页预留)getSubscriptionPlans()动态渲染 4 档,changePlan({target_plan_id,billing_cycle});移除旧 SUBSCRIPTION_PLANS 硬编码hasEnoughPoints签名更新(接收 dailyUsage/plans/currentPlanId/freeMultiplier),非会员ceil(base × 1.15)、会员floor(base × points_discount);PointsBadge 路径保留 points_balance 冗余🔴 等后端 P0(不阻塞本次合入)
🧪 验证
🚀 预览环境已部署
CI全绿,自动审批通过。
CI全绿,自动审批通过。
🗑️ 预览环境已清理
PR #1956 已关闭或合并,对应的预览环境已被清理。