forked from xiongyuxing/tiku-backend.net
- Added tags to BrowserAuthController for browser authentication endpoints. - Added tags to CatalogController for public catalog access. - Added tags to CommerceController for student transaction operations. - Added tags to CommissionController for tenant commission management. - Added tags to CrmController for tenant CRM functionalities. - Added tags to HealthController for system health checks. - Added tags to LearningController for student learning resources. - Added tags to MeController for current user information. - Added tags to PlatformAdminController for platform management. - Introduced PlatformBackofficeController for backend permissions management. - Added tags to PlatformBillingCallbackController for billing callbacks. - Added tags to PlatformPaymentSettingsController for payment settings management. - Added tags to PlatformSaasController for SaaS package management. - Added tags to PlatformTenantCapabilitiesController for tenant capabilities. - Added tags to PointsController for student points management. - Added tags to ProfileController for student profile management. - Added tags to QuestionVideosController for question video resources. - Added tags to ReferralController for referral growth management. - Added tags to RuntimeController for runtime configurations. - Added tags to ScorelineController for scoreline management. - Added tags to TaxonomyController for category management. - Added tags to TenantAdminDirectController for tenant operations management. - Introduced TenantBackofficeController for tenant backend permissions. - Added tags to TenantBillingController for tenant billing operations. - Added tags to TenantCommerceController for tenant commerce operations. - Added tags to TenantContentController for tenant content management. - Added tags to TenantContentDirectController for direct content management. - Added tags to TenantFrontendConfigController for frontend configurations. - Added tags to TenantOnboardingController for onboarding guidance. - Added tags to TenantPublicController for public tenant configurations. - Added tags to TenantsController for current tenant information. - Added tags to VideosController for student video resources.
86 lines
4.8 KiB
C#
86 lines
4.8 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Tiku.Api.Contracts;
|
|
using Tiku.Application.PlatformBilling;
|
|
using Tiku.Application.Security;
|
|
using Tiku.Domain.Platform;
|
|
|
|
namespace Tiku.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Tags("租户端-账务")]
|
|
[Route("api/tenant-billing")]
|
|
[Authorize(Policy = BackendPermissions.TenantBillingManage)]
|
|
public sealed class TenantBillingController(
|
|
ITenantBillingService billingService,
|
|
ICurrentAccessContext accessContext) : ControllerBase
|
|
{
|
|
[HttpGet("catalog")]
|
|
[EndpointSummary("查询租户可购买 SaaS 目录")]
|
|
public async Task<TenantBillingCatalog> Catalog(CancellationToken cancellationToken) =>
|
|
await billingService.GetCatalogAsync(await ActorAsync(cancellationToken), cancellationToken);
|
|
|
|
[HttpPost("quotes")]
|
|
[EndpointSummary("创建租户账务报价")]
|
|
public async Task<PlatformBillingQuoteView> Quote(CreatePlatformBillingQuoteDto request, CancellationToken cancellationToken) =>
|
|
await billingService.CreateQuoteAsync(await ActorAsync(cancellationToken), request.ToCommand(), cancellationToken);
|
|
|
|
[HttpPost("orders")]
|
|
[EndpointSummary("创建租户账务订单")]
|
|
public async Task<PlatformBillingOrderView> CreateOrder(CreatePlatformBillingOrderDto request, CancellationToken cancellationToken) =>
|
|
await billingService.CreateOrderAsync(await ActorAsync(cancellationToken), request.ToCommand(), cancellationToken);
|
|
|
|
[HttpPost("orders/{orderNo}/payments")]
|
|
[EndpointSummary("创建租户账务订单支付")]
|
|
public async Task<PlatformBillingPaymentView> CreatePayment(string orderNo, CreatePlatformBillingPaymentDto request, CancellationToken cancellationToken) =>
|
|
await billingService.CreatePaymentAsync(await ActorAsync(cancellationToken), request.ToCommand(orderNo), cancellationToken);
|
|
|
|
[HttpGet("orders")]
|
|
[EndpointSummary("查询租户账务订单")]
|
|
public async Task<IReadOnlyCollection<PlatformBillingOrderView>> Orders(int limit = 100, CancellationToken cancellationToken = default) =>
|
|
await billingService.GetOrdersAsync(await ActorAsync(cancellationToken), limit, cancellationToken);
|
|
|
|
[HttpGet("orders/{orderNo}")]
|
|
[EndpointSummary("查询租户账务订单详情")]
|
|
public async Task<PlatformBillingOrderView> Order(string orderNo, CancellationToken cancellationToken) =>
|
|
await billingService.GetOrderAsync(await ActorAsync(cancellationToken), orderNo, cancellationToken);
|
|
|
|
[HttpGet("subscription")]
|
|
[EndpointSummary("查询当前租户 SaaS 订阅")]
|
|
public async Task<TenantSubscriptionView?> Subscription(CancellationToken cancellationToken) =>
|
|
await billingService.GetSubscriptionAsync(await ActorAsync(cancellationToken), cancellationToken);
|
|
|
|
[HttpPost("subscription/change")]
|
|
[EndpointSummary("变更当前租户 SaaS 订阅")]
|
|
public async Task<PlatformBillingOrderView> Change(ChangeTenantSubscriptionDto request, CancellationToken cancellationToken) =>
|
|
await billingService.ChangeSubscriptionAsync(await ActorAsync(cancellationToken), request.ToCommand(), request.IdempotencyKey, cancellationToken);
|
|
|
|
[HttpPost("subscription/renew")]
|
|
[EndpointSummary("续费当前租户 SaaS 订阅")]
|
|
public async Task<PlatformBillingOrderView> Renew(IdempotentTenantBillingDto request, CancellationToken cancellationToken) =>
|
|
await billingService.RenewSubscriptionAsync(await ActorAsync(cancellationToken), request.IdempotencyKey, cancellationToken);
|
|
|
|
[HttpPost("subscription/cancel")]
|
|
[EndpointSummary("取消当前租户 SaaS 订阅")]
|
|
public async Task<TenantSubscriptionView> Cancel(CancellationToken cancellationToken) =>
|
|
await billingService.CancelSubscriptionAsync(await ActorAsync(cancellationToken), cancellationToken);
|
|
|
|
[HttpGet("usage")]
|
|
[EndpointSummary("查询当前租户功能用量")]
|
|
public async Task<IReadOnlyCollection<FeatureQuotaSnapshot>> Usage(CancellationToken cancellationToken) =>
|
|
await billingService.GetUsageAsync(await ActorAsync(cancellationToken), cancellationToken);
|
|
|
|
[HttpGet("invoices")]
|
|
[EndpointSummary("查询当前租户发票")]
|
|
public async Task<IReadOnlyCollection<PlatformBillingInvoice>> Invoices(int limit = 100, CancellationToken cancellationToken = default) =>
|
|
await billingService.GetInvoicesAsync(await ActorAsync(cancellationToken), limit, cancellationToken);
|
|
|
|
private async Task<TenantBillingActor> ActorAsync(CancellationToken cancellationToken)
|
|
{
|
|
var access = await accessContext.GetAsync(cancellationToken);
|
|
return access.UserId is { } userId && access.TenantId is { } tenantId && access.IsCurrentTenantMember
|
|
? new TenantBillingActor(userId, tenantId)
|
|
: throw new PlatformBillingException("Tenant billing actor was not resolved.", "tenant_access_denied");
|
|
}
|
|
}
|