feat: 新增配额包/支付相关实体与迁移

App:新增 operation_logs/quota_packages/tenant_payments/tenant_quota_package_purchases 表

Identity:修正 Avatar 字段类型(varchar(256)->text),保持现有数据不变
This commit is contained in:
2025-12-17 17:27:45 +08:00
parent 9c28790f5e
commit ab59e2e3e2
103 changed files with 14450 additions and 4 deletions

View File

@@ -0,0 +1,121 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using TakeoutSaaS.Application.App.Billings.Commands;
using TakeoutSaaS.Application.App.Billings.Dto;
using TakeoutSaaS.Application.App.Billings.Queries;
using TakeoutSaaS.Module.Authorization.Attributes;
using TakeoutSaaS.Shared.Abstractions.Results;
using TakeoutSaaS.Shared.Web.Api;
namespace TakeoutSaaS.AdminApi.Controllers;
/// <summary>
/// 账单管理。
/// </summary>
[ApiVersion("1.0")]
[Authorize]
[Route("api/admin/v{version:apiVersion}/bills")]
public sealed class BillingsController(IMediator mediator) : BaseApiController
{
/// <summary>
/// 分页查询账单列表。
/// </summary>
/// <returns>账单分页结果。</returns>
[HttpGet]
[PermissionAuthorize("bill:read")]
[ProducesResponseType(typeof(ApiResponse<PagedResult<BillDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<PagedResult<BillDto>>> GetList([FromQuery] GetBillListQuery query, CancellationToken cancellationToken)
{
var result = await mediator.Send(query, cancellationToken);
return ApiResponse<PagedResult<BillDto>>.Ok(result);
}
/// <summary>
/// 获取账单详情。
/// </summary>
/// <param name="id">账单 ID。</param>
/// <param name="cancellationToken">取消标记。</param>
/// <returns>账单详情。</returns>
[HttpGet("{id:long}")]
[PermissionAuthorize("bill:read")]
[ProducesResponseType(typeof(ApiResponse<BillDetailDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<BillDetailDto>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<BillDetailDto>> GetDetail(long id, CancellationToken cancellationToken)
{
var result = await mediator.Send(new GetBillDetailQuery { BillId = id }, cancellationToken);
return result is null
? ApiResponse<BillDetailDto>.Error(StatusCodes.Status404NotFound, "账单不存在")
: ApiResponse<BillDetailDto>.Ok(result);
}
/// <summary>
/// 手动创建账单。
/// </summary>
/// <param name="command">创建账单命令。</param>
/// <param name="cancellationToken">取消标记。</param>
/// <returns>创建的账单信息。</returns>
[HttpPost]
[PermissionAuthorize("bill:create")]
[ProducesResponseType(typeof(ApiResponse<BillDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<BillDto>> Create([FromBody, Required] CreateBillCommand command, CancellationToken cancellationToken)
{
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<BillDto>.Ok(result);
}
/// <summary>
/// 更新账单状态。
/// </summary>
/// <param name="id">账单 ID。</param>
/// <param name="command">更新状态命令。</param>
/// <param name="cancellationToken">取消标记。</param>
/// <returns>更新后的账单信息。</returns>
[HttpPut("{id:long}/status")]
[PermissionAuthorize("bill:update")]
[ProducesResponseType(typeof(ApiResponse<BillDto>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<BillDto>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<BillDto>> UpdateStatus(long id, [FromBody, Required] UpdateBillStatusCommand command, CancellationToken cancellationToken)
{
command = command with { BillId = id };
var result = await mediator.Send(command, cancellationToken);
return result is null
? ApiResponse<BillDto>.Error(StatusCodes.Status404NotFound, "账单不存在")
: ApiResponse<BillDto>.Ok(result);
}
/// <summary>
/// 获取账单支付记录。
/// </summary>
/// <param name="billId">账单 ID。</param>
/// <param name="cancellationToken">取消标记。</param>
/// <returns>支付记录列表。</returns>
[HttpGet("{billId:long}/payments")]
[PermissionAuthorize("bill:read")]
[ProducesResponseType(typeof(ApiResponse<List<PaymentDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<List<PaymentDto>>> GetPayments(long billId, CancellationToken cancellationToken)
{
var result = await mediator.Send(new GetTenantPaymentsQuery { BillId = billId }, cancellationToken);
return ApiResponse<List<PaymentDto>>.Ok(result);
}
/// <summary>
/// 记录支付(线下支付确认)。
/// </summary>
/// <param name="billId">账单 ID。</param>
/// <param name="command">记录支付命令。</param>
/// <param name="cancellationToken">取消标记。</param>
/// <returns>支付记录信息。</returns>
[HttpPost("{billId:long}/payments")]
[PermissionAuthorize("bill:pay")]
[ProducesResponseType(typeof(ApiResponse<PaymentDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<PaymentDto>> RecordPayment(long billId, [FromBody, Required] RecordPaymentCommand command, CancellationToken cancellationToken)
{
command = command with { BillId = billId };
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<PaymentDto>.Ok(result);
}
}