feat(points): P1 points rules — daily gift/expiry/gift-first deduction/admin top-up - #75
Merged
Merged
Conversation
- quotas.gift_balance + gift_grants 明细表(迁移 v3,幂等;SCHEMA_VERSION 2→3) - gift.rs:注册 10 天窗口每日 1 点(当日 23:59:59 过期),懒加载补发 + 惰性过期清理 - billing.rs settle:先扣最早到期赠送,不足再扣永久 balance(可用余额 = gift + permanent) - 网关预检(stream/非 stream)改用可用余额口径 - routes/admin.rs:POST /api/admin/credits(role=admin 403 保护)+ GET users/usage; seed 管理员 admin@aitokenpool.local / admin1234 - wallet 返回 gift_balance;transactions type 过滤支持 topup - 测试 49→61(+12:赠送/跨天扣减顺序/过期/混合结算/管理员 403/充值/列表/钱包赠送)
argszero
added a commit
that referenced
this pull request
Aug 18, 2026
- §4.1 网关层标注已实现:OpenAI/Anthropic 双协议 + SSE 流式 + 余额预检(可用余额口径)+ 完整 API 一览 - §4.2 补上游 key AES-256-GCM 加密(v1:<nonce>:<cipher>,ATP_MASTER_KEY → config.master_key → dev 随机兜底) - §4.3/4.4 计量与账本标注已实现:点数公式、事务性 settle、双余额账户、每日赠送/惰性过期清理、先赠后永扣减、SHARE_RATIO=0.9、管理员充值 topup - §4.6 管理台补管理员 API(role 判定/403、种子账号) - §5 数据库设计改为实表(gift_grants/schema_version/quotas 双列),§6 补配置说明 - §7 路线勾掉 P0/P1(v0.1.0→v0.3.0,PR #71–#75) Co-authored-by: argszero <argszero@argszerodeMac-mini.local>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backend P1 — points rules refinement (rant
2026-08-18T11:03:02.350807, "后端实现 P1 — 点数规则细化(赠送/有效期/扣减顺序/管理员充值)"). Implements the ledger rules from user-stories v1.7:quotas.gift_balancecolumn (currently-valid gift points); existingbalance= permanent points (sharing earnings / admin top-up)gift_grantstable (id/user_id/amount/granted_at/expires_at/status) for auditsrc/gift.rs): 1 point/day for 10 consecutive days from registration, valid until day's 23:59:59; lazyensure_daily_giftbefore wallet/dashboard/settle; lazy expiry cleanup (no cron)settle): gift points with earliest expiry first, then permanent balance; gateway precheck (stream + non-stream) uses available = gift + permanentsrc/routes/admin.rs):POST /api/admin/credits(role=admin, else 403) +GET /api/admin/users+GET /api/admin/usage; seed admin accountadmin@aitokenpool.local/admin1234gift_balance; transactionstypefilter now supportstopupTests
cargo build+cargo test+cargo fmt --check+cargo clippy --all-targets -- -D warningsall cleangift_balance=1; admin top-up +50 credited to permanent; non-admin 403; topup transaction written; migrate idempotent on restartRelated
Rant:
2026-08-18T11:03:02.350807(backend P1 points rules)