feat: add billing pricing rules
This commit is contained in:
+18
@@ -116,6 +116,24 @@
|
||||
}
|
||||
```
|
||||
|
||||
## 计费模块合约(`apps/billing.pricing`)
|
||||
|
||||
T-202 后,计费计算已有独立模块,供后续扣点、生成接口和充值下单调用:
|
||||
|
||||
```python
|
||||
calculate_points_cost(operation_type: str, alias: str, resolution: str | None = None) -> int
|
||||
quote_recharge_points(amount, currency: str = "CNY", at=None) -> RechargeQuote
|
||||
calculate_points_granted(amount, currency: str = "CNY", at=None) -> int
|
||||
```
|
||||
|
||||
要点:
|
||||
|
||||
- `PricingRule` 按 `operation_type + alias + resolution` 查 active 规则;`resolution` 先做大小写归一,优先匹配精确分辨率,再回退到空 `resolution` 的默认价。
|
||||
- 定价绑定**能力别名字符串**,不绑定 `AiModel` 或上游 SKU;后台切换 `ModelAlias` 指向的底层模型,不改变该别名的价格。
|
||||
- 缺计费规则抛 `NoPricingRuleError(code="no_pricing_rule")`,API 层应翻译为上方同名错误码。
|
||||
- `ExchangeRate` 按 `currency + effective_from` 取当前 active 汇率;充值下单时应锁定当时的 `exchange_rate` / `points_granted` 到订单,回调入账不得按新汇率重算。
|
||||
- 金额换点数采用 `floor(amount * points_per_unit)`,点数为整数。
|
||||
|
||||
## 支付充值(自助扫码:微信 V3 native + 支付宝当面付)
|
||||
|
||||
> 协议对齐同支付系统的既有 PHP 实现(微信库 `wechatpayv3` / 支付宝库 `python-alipay-sdk`)。二维码是平台不透明票据、**不含业务数据**,靠 `out_trade_no`(=本地 `order_no`) 在回调关联,付款人由平台识别。**协议已明确,仅商户密钥/证书为真实值待提供。**
|
||||
|
||||
Reference in New Issue
Block a user