Files
tiku-backend.net/Tiku.Api/Controllers/PlatformPaymentSettingsController.cs
xiong c497a3ca8d
Some checks failed
ci / release-gate (push) Has been cancelled
清理代码
2026-08-03 12:31:39 +08:00

97 lines
4.1 KiB
C#

using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Tiku.Api.Contracts;
using Tiku.Api.OpenApi;
using Tiku.Application.PlatformAdmin;
using Tiku.Application.Security;
using Tiku.Domain.Platform;
namespace Tiku.Api.Controllers;
[ApiController]
[Tags("平台端-支付设置")]
[Authorize(Policy = TikuPolicies.PlatformBackofficeBootstrap)]
[Produces("application/json")]
[Route("api/platform/payment-settings")]
public sealed class PlatformPaymentSettingsController(
IPlatformPaymentSettingsService paymentSettingsService,
IPlatformApprovalService approvalService,
ICurrentUser currentUser) : ControllerBase
{
[HttpGet("apps")]
[EndpointSummary("查询平台支付应用")]
[Authorize(Policy = BackendPermissions.PlatformPaymentRead)]
public Task<IReadOnlyCollection<PlatformPaymentApp>> Apps(string? status, int limit = 100,
CancellationToken cancellationToken = default)
{
return paymentSettingsService.GetAppsAsync(Actor(), status, limit, cancellationToken);
}
[HttpPut("apps")]
[EndpointSummary("新增或更新平台支付应用")]
[Authorize(Policy = BackendPermissions.PlatformPaymentWrite)]
public Task<PlatformPaymentApp> UpsertApp(UpsertPlatformPaymentAppDto request, CancellationToken cancellationToken)
{
return paymentSettingsService.UpsertAppAsync(Actor(), request.ToCommand(), cancellationToken);
}
[HttpGet("channels")]
[EndpointSummary("查询平台支付渠道")]
[Authorize(Policy = BackendPermissions.PlatformPaymentRead)]
public Task<IReadOnlyCollection<PlatformPaymentChannel>> Channels(Guid? appId, string? status, int limit = 100,
CancellationToken cancellationToken = default)
{
return paymentSettingsService.GetChannelsAsync(Actor(), appId, status, limit, cancellationToken);
}
[HttpPut("channels")]
[EndpointSummary("新增或更新平台支付渠道")]
[Authorize(Policy = BackendPermissions.PlatformPaymentWrite)]
[PlatformOperationRisk("critical", PlatformApprovalPolicyCodes.PaymentChannelChange)]
[ProducesResponseType<PlatformCommandSubmission>(StatusCodes.Status200OK)]
[ProducesResponseType<PlatformCommandSubmission>(StatusCodes.Status202Accepted)]
public async Task<ActionResult<PlatformCommandSubmission>> UpsertChannel(
UpsertPlatformPaymentChannelDto request,
[FromHeader(Name = "Idempotency-Key")] [Required]
string idempotencyKey,
CancellationToken cancellationToken)
{
var result =
await approvalService.UpsertPaymentChannelAsync(Actor(), request.ToCommand(), idempotencyKey,
cancellationToken);
return result.ExecutionStatus == "pending_approval" ? Accepted(result) : Ok(result);
}
[HttpPost("channels/{id:guid}/disable")]
[EndpointSummary("禁用平台支付渠道")]
[Authorize(Policy = BackendPermissions.PlatformPaymentWrite)]
public Task<PlatformPaymentChannel> DisableChannel(Guid id, CancellationToken cancellationToken)
{
return paymentSettingsService.DisableChannelAsync(Actor(), id, cancellationToken);
}
[HttpGet("events")]
[EndpointSummary("查询平台支付事件")]
[Authorize(Policy = BackendPermissions.PlatformPaymentRead)]
public Task<IReadOnlyCollection<PlatformBillingPaymentEvent>> Events(string? status, int limit = 100,
CancellationToken cancellationToken = default)
{
return paymentSettingsService.GetEventsAsync(Actor(), status, limit, cancellationToken);
}
[HttpGet("rebates/summary")]
[EndpointSummary("查询平台返佣汇总")]
[Authorize(Policy = BackendPermissions.PlatformPaymentRead)]
public Task<PlatformRebateSummary> RebateSummary(CancellationToken cancellationToken)
{
return paymentSettingsService.GetRebateSummaryAsync(Actor(), cancellationToken);
}
private PlatformCapabilityActor Actor()
{
return currentUser.UserId is { } userId
? new PlatformCapabilityActor(userId)
: throw new PlatformCapabilityException("Platform actor was not resolved.", "platform_access_denied");
}
}