PlatformBilling 模块提供 SaaS 原生计费,包含订阅生命周期管理、计划目录、用量跟踪、配额执行和发票生成。
端点
| 端点 | 方法 | 描述 |
|---|---|---|
/api/billing/plans | GET | 列出可用计划 |
/api/billing/subscriptions | POST | 开始订阅 |
/api/billing/subscriptions | GET | 列出订阅 |
/api/billing/subscriptions/{id} | GET | 获取订阅详情 |
/api/billing/usage | POST | 记录用量 |
/api/billing/invoices | POST | 生成发票 |
/api/billing/invoices | GET | 列出发票 |
/api/billing/quota | GET | 检查配额状态 |
架构
PlatformBillingService │ ├── IPlatformBillingRepository → SqlSugarPlatformBillingRepository ├── QuotaService → EntitlementResolver └── IPlatformBillingEventPublisher → NullPlatformBillingEventPublisher
CatalogService │ ├── ICatalogRepository → SqlSugarCatalogRepository ├── ICatalogEntitlementMappingStore └── ICatalogEventPublisher关键实体
| 实体 | 用途 |
|---|---|
PlatformBillingPlanEntity | 计划定义(名称、价格、功能) |
PlatformBillingSubscriptionEntity | 租户的活跃订阅 |
PlatformBillingInvoiceEntity | 生成的发票 |
PlatformBillingUsageRecordEntity | 用量跟踪记录 |
CatalogItemEntity | 目录项(计划、附加项、权益) |
订阅生命周期
开始 │ ▼ Active (试用) │ ▼ Active (付费) │ │ ▼ ▼ Paused Cancelled │ │ ▼ ▼ Resumed Expired配额执行
public class QuotaCheckResult{ public bool IsAllowed { get; } public long Remaining { get; } public long Used { get; } public long Limit { get; } public OverQuotaBehavior Behavior { get; }}权益解析
租户 → 活跃订阅 → 计划 → 目录产品 → 权益每个权益映射到一个配额键(例如 storage.files、tickets.open、chat.channels)。
用量记录
模块通过计费服务记录用量:
await billingService.RecordUsageAsync( tenantId: "100", entitlementKey: "storage.files", delta: 1);超额行为
| 策略 | 描述 |
|---|---|
Deny | 以 429/403 阻止操作 |
Warn | 允许但发送警告通知 |
Allow | 无执行(特权租户) |
另见
- Catalog 模块 — 计划定义
- 配额构建块 — 配额基础设施