merge: T2 任务奖励领取(POST /quota/tasks/{task_key}/claim,FR-BILL-03)

This commit is contained in:
xsl
2026-08-14 16:23:46 +08:00
7 changed files with 587 additions and 5 deletions
+32 -3
View File
@@ -1,4 +1,4 @@
"""``GET /quota`` and ``GET /quota/ledger`` (架构文档 §9.3 配额).
"""``GET /quota``、``GET /quota/ledger``、``POST /quota/tasks/{task_key}/claim``.
FR-BILL-07: 额度相关文案中**不得出现任何价格、购买、会员、升级字样**。
Only two recovery paths may ever be surfaced: 等待恢复 and 做任务换额度.
@@ -6,11 +6,12 @@ Only two recovery paths may ever be surfaced: 等待恢复 and 做任务换额
from __future__ import annotations
from fastapi import APIRouter, Query
from fastapi import APIRouter, Path, Query
from apps.api.deps import BillingServiceDep, CurrentUserId
from apps.api.deps import BillingServiceDep, CurrentUserId, SettingsDep
from apps.api.schemas import LedgerEntry, QuotaResponse
from packages.agent.service import QUOTA_KEY_AGENT_CHAT
from packages.billing.schemas import TaskBonusClaimResponse
from packages.shared.response import ok
router = APIRouter(prefix="/quota", tags=["quota"])
@@ -59,3 +60,31 @@ async def get_ledger(
for row in rows
]
)
@router.post("/tasks/{task_key}/claim", summary="做任务换额度:领取任务奖励(FR-BILL-03)")
async def claim_task_bonus(
user_id: CurrentUserId,
billing: BillingServiceDep,
settings: SettingsDep,
task_key: str = Path(max_length=64),
) -> dict[str, object]:
"""同一任务同一周期只能领一次(重复领返回 40910),受规则封顶(40310).
奖励数值由 ``TASK_BONUS_RULES_JSON`` 配置驱动(FR-BILL-04),当前是占位值,
产品定稿后改 env 即生效。
"""
claim = await billing.claim_task_bonus(
user_id=user_id,
task_key=task_key,
rules=dict(settings.task_bonus_rules),
)
return ok(
TaskBonusClaimResponse(
task_key=claim.task_key,
quota_key=claim.quota_key,
amount=claim.amount,
bonus_granted=claim.bonus_granted,
remaining=claim.remaining,
).model_dump()
)