feat: grant signup bonus points

This commit is contained in:
QiuSW
2026-07-08 15:13:23 +08:00
parent 02aa12e8b9
commit ac8bec7b9c
29 changed files with 399 additions and 61 deletions
+27
View File
@@ -1476,3 +1476,30 @@
- `docs/mvp-acceptance.md`、`docs/phase-4-review.md`、`docs/README.md`:标注 T-501/T-402/Phase 4 审核中的“注册不送点”属于历史口径,已被 T-608 新需求变更。
- 验证:纯文档修改;后续执行 T-608 时需补迁移、目标测试、`check` 和 `git diff --check` 证据。
- 下一步:领取 T-608,先实现 billing 层注册赠点服务和幂等数据结构,再接 allauth adapter、页面文案和测试。
## 2026-07-08 T-608 新用户注册赠送 100 点试用点数落地
- 状态:DONE。
- 代码变更:
- `apps/billing/models.py`:新增 `PointsLedger.ChangeType.SIGNUP_BONUS` 和 `SignupBonusGrant(user UNIQUE)` 幂等标记模型,迁移为 `billing.0007_alter_pointsledger_change_type_signupbonusgrant`。
- `apps/billing/services.py`:新增 `grant_signup_bonus(user, points=100)`,事务内锁/创建钱包、创建幂等记录、加点、写 `PointsLedger(signup_bonus,+100,balance_after,reason="new_user_registration")`;重复调用返回未发放结果,不重复加点。
- `apps/portal/adapters.py`:allauth 注册保存成功后只调用 billing 服务发放注册赠点,不在 portal 直接写 `points_balance`。
- `apps/portal/views.py` 与模板:dashboard 统计充值点数 + 注册赠点为“获得点数”;`/records/usage` 改为点数记录,展示 `signup_bonus` / `consume` / `refund` 流水;公开首页和注册页同步「注册送 100 点」文案。
- `config/settings.py`:新增 `ACCOUNT_RATE_LIMITS["signup"]`,从 `ACCOUNT_SIGNUP_RATE_LIMIT` 读取,默认 `20/m/ip`,由 allauth signup rate limit 执行。
- `apps/billing/admin.py`:新增 `SignupBonusGrant` 只读 admin,便于运营检索注册赠点记录。
- 文档变更:
- `docs/06-tasks.md`:T-608 状态改为 DONE,防刷口径改为显式配置 `ACCOUNT_SIGNUP_RATE_LIMIT`,图形验证码 / 人机验证保留为上线前增强项。
- `README.md`、`docs/00-ai-start-here.md`、`docs/03-tech-stack.md`、`docs/04-architecture.md`、`docs/api.md`、`docs/routes.md`、`docs/current-state.md`、`docs/env.md`、`docs/deployment.md`、`docs/mvp-acceptance.md`、`docs/project-brief.md`、`docs/project-onepager.md`:同步注册赠点已落地、点数记录口径、注册限流配置和当前状态。
- 验证:
- `py -3.12 -m py_compile config\settings.py apps\billing\models.py apps\billing\services.py apps\billing\admin.py apps\portal\adapters.py apps\portal\views.py apps\billing\tests.py apps\portal\tests.py`:通过。
- `py -3.12 manage.py check`:通过,0 issues。
- `py -3.12 manage.py makemigrations --check --dry-run`:通过,No changes detected。
- `py -3.12 manage.py migrate billing --noinput`:通过,No migrations to apply。
- `py -3.12 manage.py test apps.billing.tests.BillingServiceTests.test_grant_signup_bonus_creates_wallet_ledger_and_is_idempotent apps.billing.tests.BillingServiceTests.test_grant_signup_bonus_adds_to_existing_wallet_balance apps.billing.tests.ConcurrentSignupBonusTests --keepdb --noinput --verbosity 2`:3 tests OK。
- `py -3.12 manage.py test apps.portal.tests.PortalAccountFlowTests.test_signup_rate_limit_is_configured --keepdb --noinput --verbosity 2`:1 test OK。
- `py -3.12 manage.py test apps.portal.tests.PortalAccountFlowTests.test_signup_grants_100_points_writes_signup_bonus_ledger_and_can_login apps.portal.tests.PortalAccountFlowTests.test_homepage_is_public_and_shows_anonymous_onboarding_without_release apps.portal.tests.PortalAccountFlowTests.test_homepage_shows_dashboard_entry_for_authenticated_user apps.portal.tests.PortalAccountFlowTests.test_authenticated_nav_highlights_current_page_only apps.portal.tests.PortalAccountFlowTests.test_dashboard_shows_account_summary_recent_records_for_current_user_only apps.portal.tests.PortalAccountFlowTests.test_usage_records_require_login_and_only_show_current_user_usage --keepdb --noinput --verbosity 2`:6 tests OK。
- `py -3.12 manage.py test apps.billing.tests.BillingCoreModelTests.test_billing_models_are_registered_in_admin --keepdb --noinput --verbosity 2`:1 test OK。
- `.\init.ps1`:收尾验证通过(Python 3.12.3,依赖已满足,`manage.py check` 0 issues,打印启动命令)。
- `git diff --check`:通过,仅 Windows CRLF 提示。
- 已知测试环境现象:一次 portal 目标测试启动阶段因远程 MySQL `43.128.3.240` 连接超时中断;随后 `Test-NetConnection 43.128.3.240 -Port 3306` 显示端口可达,拆分重跑全部目标用例通过。测试期仍保留 allauth `account.EmailAddress` 条件唯一约束在 MySQL 上不可创建的既有 `models.W036` 警告。
- 下一步:当前任务看板暂无新的编号 TODO;建议按业务优先级拆真实支付回调到账闭环、客户端下载包发布、真实图片耗时验证,或从 Backlog 创建新任务。