feat(wallet): 钱包系统替代配额系统,新增支付与退款机制

- 新增钱包余额管理、充值、扣费、退款完整流程
- 新增支付网关抽象层(支持手动/支付宝/微信)
- 用量计费从配额系统迁移到钱包余额扣费
- 新增管理员钱包管理与支付订单管理页面
- 新增用户钱包中心页面
- 移除独立 Key 锁定机制,统一由钱包余额控制
- 新增相关 API 路由、序列化器与数据库迁移
- 新增钱包、支付、退款相关测试
This commit is contained in:
LewisPen
2026-03-08 00:05:48 +08:00
committed by fawney19
parent 9cdcce1b5f
commit 783f654953
108 changed files with 13152 additions and 3372 deletions

View File

@@ -63,7 +63,7 @@ FIELD_NAME_TRANSLATIONS = {
"username": "用户名",
"email": "邮箱",
"role": "角色",
"quota_usd": "配额",
"initial_gift_usd": "初始赠款",
"name": "名称",
"title": "标题",
"content": "内容",
@@ -261,18 +261,25 @@ class ProviderRateLimitException(ProviderException):
)
class QuotaExceededException(ProxyException):
"""配额超限"""
class BalanceInsufficientException(ProxyException):
"""余额或额度不足"""
def __init__(self, quota_type: str = "tokens", remaining: float | None = None):
message = f"{quota_type}配额已用尽"
if remaining is not None:
message += f"(剩余: {remaining}"
def __init__(self, balance_type: str = "tokens", remaining: float | None = None, **kwargs: Any):
# 兼容旧调用方使用 quota_type= 关键字参数
balance_type = kwargs.get("quota_type", balance_type)
if balance_type.upper() == "USD":
message = "余额不足"
if remaining is not None:
message += f"(剩余: ${remaining:.2f}"
else:
message = f"{balance_type}额度已用尽"
if remaining is not None:
message += f"(剩余: {remaining}"
super().__init__(
status_code=status.HTTP_429_TOO_MANY_REQUESTS,
error_type="quota_exceeded",
error_type="balance_exceeded",
message=message,
details={"quota_type": quota_type, "remaining": remaining},
details={"balance_type": balance_type, "remaining": remaining},
)