fix(#1895): points API 字段对齐(P0 修复 + P1 补全) #1951

Merged
auto-approve-bot merged 2 commits from fix/1895-points-api-align into develop 2026-09-16 09:17:34 +08:00
Owner

P0 阻塞项修复

  1. POST /points/check 未知 scene 500→400:对未注册 scene_key(如 ai_script)在路由层提前校验,返回 {code: UNKNOWN_SCENE, valid_scenes: [...], message} 而不是让 calculate_points_cost 的 ValueError 冒泡成 500。
  2. POST /points/recharge 响应补字段:新增 points_amount(从 POINTS_PACKAGES 查)、pay_params(当前 {},待支付通道接入后填充 prepay_id/payment_url)、expire_at(创建后 48 小时,ISO 8601)。

P1 补全

  1. PointRuleItem.description:POINTS_SCENES 每个场景补中文描述;GET /points/rules 返回时带上。
  2. GET /subscription/plans 新增端点:返回 monthly/quarterly/yearly 三档位,含 price_cents/monthly_price_cents/duration_days/points_discount/features。前端会员购买页可直接拉,不用硬编码。
  3. multiplier 确认:FREE_USER_MULTIPLIER=1.15 既用于前端展示也用于实际扣费(calculate_points_cost 统一入口)。ai_title 非会员 ceil(1*1.15)=2 正确。
  4. is_member/member_type/member_expires_at 保留:PointsBalanceResponse 三字段暂不删除(前端已调 /points/subscription/membership,后续版本移除)。
  5. refund 类型:refund 走 add_points,type=add + source=refund:{scene},流水无独立 refund type。前端用 signedAmount 或 source 前缀判断。

测试

  • 新增 tests/unit/test_points_routes.py(10 个测试)覆盖 P0/P1 行为
  • 全量单测 15523 passed
## P0 阻塞项修复 1. **POST /points/check 未知 scene 500→400**:对未注册 scene_key(如 ai_script)在路由层提前校验,返回 {code: UNKNOWN_SCENE, valid_scenes: [...], message} 而不是让 calculate_points_cost 的 ValueError 冒泡成 500。 2. **POST /points/recharge 响应补字段**:新增 points_amount(从 POINTS_PACKAGES 查)、pay_params(当前 {},待支付通道接入后填充 prepay_id/payment_url)、expire_at(创建后 48 小时,ISO 8601)。 ## P1 补全 3. **PointRuleItem.description**:POINTS_SCENES 每个场景补中文描述;GET /points/rules 返回时带上。 4. **GET /subscription/plans 新增端点**:返回 monthly/quarterly/yearly 三档位,含 price_cents/monthly_price_cents/duration_days/points_discount/features。前端会员购买页可直接拉,不用硬编码。 5. **multiplier 确认**:FREE_USER_MULTIPLIER=1.15 既用于前端展示也用于实际扣费(calculate_points_cost 统一入口)。ai_title 非会员 ceil(1*1.15)=2 正确。 6. **is_member/member_type/member_expires_at 保留**:PointsBalanceResponse 三字段暂不删除(前端已调 /points/subscription/membership,后续版本移除)。 7. **refund 类型**:refund 走 add_points,type=add + source=refund:{scene},流水无独立 refund type。前端用 signedAmount 或 source 前缀判断。 ## 测试 - 新增 tests/unit/test_points_routes.py(10 个测试)覆盖 P0/P1 行为 - 全量单测 15523 passed
xiaoxia added 1 commit 2026-09-16 08:46:34 +08:00
fix(#1895): points API field alignment for frontend
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 27s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 43s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m29s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m55s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m4s
AI Code Review / AI Code Review (pull_request) Successful in 6m41s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Failing after 10m58s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m51s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 2m58s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 11m5s
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
1b8209bd06
P0 fixes:
- POST /points/check: unknown scene_key returns 400 (UNKNOWN_SCENE) instead of 500
- POST /points/recharge: response now includes points_amount, pay_params (empty dict
  until payment integration), expire_at (48h from creation)

P1 additions:
- PointRuleItem.description: Chinese description for each scene for frontend display
- GET /points/rules: returns description field
- GET /subscription/plans (new): returns all membership tiers with price/duration/discount/features
- FREE_USER_MULTIPLIER confirmed: applied to both display AND actual deduction
  (calculate_points_cost is the single source of truth; ai_title non-member = ceil(1*1.15)=2)

Decisions:
- PointsBalanceResponse.is_member/member_type/member_expires_at: kept but marked
  deprecated (frontend already calls /points/subscription/membership); removal in future
- Refund transactions: type='add' with source prefix 'refund:{scene}' (no separate refund type)
- pay_params currently {} — to be filled when WeChat/Alipay is integrated

Tests: 10 new tests in test_points_routes.py covering all above behaviors.
Full suite: 15523 passed.

🚀 预览环境已部署

项目 详情
PR号 #1951
预览链接 https://pr-1951.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1951 | | 预览链接 | [https://pr-1951.preview.xiaoxiajianji.com](https://pr-1951.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot added 1 commit 2026-09-16 09:04:46 +08:00
style: auto-format with black + isort + ruff + prettier [skip ci-format-check]
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 5s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 47s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 47s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m7s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m5s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m31s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 3m42s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 4m40s
AI Code Review / AI Code Review (pull_request) Successful in 6m33s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 7m51s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 11m50s
CI/CD Pipeline / CI Gate (pull_request) Successful in 5s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 8m23s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 52s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m5s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 6h6m56s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 6h18m35s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 6h18m44s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 6h6m0s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 6h17m56s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 6h17m57s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 6h17m47s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 6h17m50s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 6h17m52s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 6h17m54s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 6h17m54s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 6h17m55s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 6h18m2s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 6h6m4s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 6h5m59s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 6h6m4s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 6h17m43s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 6h17m44s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 6h17m57s
7ab8d4b8e8
auto-approve-bot merged commit 13c302c037 into develop 2026-09-16 09:17:34 +08:00
auto-approve-bot deleted branch fix/1895-points-api-align 2026-09-16 09:17:39 +08:00

🗑️ 预览环境已清理

PR #1951 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1951 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.