feat: 完成账单管理模块后端功能开发及API优化

核心功能:
- 账单CRUD操作(创建、查询、详情、更新状态、删除)
- 支付记录管理(创建支付、审核支付)
- 批量操作支持(批量更新账单状态)
- 统计分析功能(账单统计、逾期账单查询)
- 导出功能(Excel/PDF/CSV)

API端点 (16个):
- GET /api/admin/v1/billings - 账单列表(分页、筛选、排序)
- POST /api/admin/v1/billings - 创建账单
- GET /api/admin/v1/billings/{id} - 账单详情
- DELETE /api/admin/v1/billings/{id} - 删除账单
- PUT /api/admin/v1/billings/{id}/status - 更新状态
- POST /api/admin/v1/billings/batch/status - 批量更新
- GET /api/admin/v1/billings/{id}/payments - 支付记录
- POST /api/admin/v1/billings/{id}/payments - 创建支付
- PUT /api/admin/v1/billings/payments/{paymentId}/verify - 审核支付
- GET /api/admin/v1/billings/statistics - 统计数据
- GET /api/admin/v1/billings/overdue - 逾期账单
- POST /api/admin/v1/billings/export - 导出账单

架构优化:
- 采用CQRS模式分离读写(MediatR + Dapper + EF Core)
- 完整的领域模型设计(TenantBillingStatement, TenantPayment等)
- FluentValidation请求验证
- 状态机管理账单和支付状态流转

API设计优化 (三项改进):
1. 导出API响应Content-Type改为application/octet-stream
2. 支付审核API添加Approved和Notes可选参数,支持通过/拒绝
3. 移除TenantBillings API中重复的TenantId参数

数据库变更:
- 新增账单相关表及关系
- 支持Snowflake ID主键
- 完整的审计字段支持

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-18 11:24:44 +08:00
parent 98f49ea7ad
commit 4b53862ded
73 changed files with 12688 additions and 305 deletions

View File

@@ -0,0 +1,25 @@
using MediatR;
using TakeoutSaaS.Domain.Tenants.Enums;
namespace TakeoutSaaS.Application.App.Billings.Commands;
/// <summary>
/// 批量更新账单状态命令。
/// </summary>
public sealed record BatchUpdateStatusCommand : IRequest<int>
{
/// <summary>
/// 账单 ID 列表(雪花算法)。
/// </summary>
public long[] BillingIds { get; init; } = [];
/// <summary>
/// 新状态。
/// </summary>
public TenantBillingStatus NewStatus { get; init; }
/// <summary>
/// 批量操作备注。
/// </summary>
public string? Notes { get; init; }
}

View File

@@ -0,0 +1,19 @@
using MediatR;
namespace TakeoutSaaS.Application.App.Billings.Commands;
/// <summary>
/// 取消账单命令。
/// </summary>
public sealed record CancelBillingCommand : IRequest<Unit>
{
/// <summary>
/// 账单 ID雪花算法
/// </summary>
public long BillingId { get; init; }
/// <summary>
/// 取消原因。
/// </summary>
public string Reason { get; init; } = string.Empty;
}

View File

@@ -0,0 +1,41 @@
using MediatR;
using TakeoutSaaS.Application.App.Billings.Dto;
using TakeoutSaaS.Domain.Tenants.Enums;
namespace TakeoutSaaS.Application.App.Billings.Commands;
/// <summary>
/// 创建账单命令。
/// </summary>
public sealed record CreateBillingCommand : IRequest<BillingDetailDto>
{
/// <summary>
/// 租户 ID雪花算法
/// </summary>
public long TenantId { get; init; }
/// <summary>
/// 账单类型。
/// </summary>
public BillingType BillingType { get; init; }
/// <summary>
/// 应付金额。
/// </summary>
public decimal AmountDue { get; init; }
/// <summary>
/// 到期日UTC
/// </summary>
public DateTime DueDate { get; init; }
/// <summary>
/// 账单明细列表。
/// </summary>
public List<BillingLineItemDto> LineItems { get; init; } = [];
/// <summary>
/// 备注。
/// </summary>
public string? Notes { get; init; }
}

View File

@@ -0,0 +1,15 @@
using MediatR;
using TakeoutSaaS.Application.App.Billings.Dto;
namespace TakeoutSaaS.Application.App.Billings.Commands;
/// <summary>
/// 生成订阅账单命令(自动化场景)。
/// </summary>
public sealed record GenerateSubscriptionBillingCommand : IRequest<BillingDetailDto>
{
/// <summary>
/// 订阅 ID雪花算法
/// </summary>
public long SubscriptionId { get; init; }
}

View File

@@ -0,0 +1,10 @@
using MediatR;
namespace TakeoutSaaS.Application.App.Billings.Commands;
/// <summary>
/// 处理逾期账单命令(后台任务场景)。
/// </summary>
public sealed record ProcessOverdueBillingsCommand : IRequest<int>
{
}

View File

@@ -7,12 +7,12 @@ namespace TakeoutSaaS.Application.App.Billings.Commands;
/// <summary>
/// 记录支付命令。
/// </summary>
public sealed record RecordPaymentCommand : IRequest<PaymentDto>
public sealed record RecordPaymentCommand : IRequest<PaymentRecordDto>
{
/// <summary>
/// 账单 ID雪花算法
/// </summary>
public long BillId { get; init; }
public long BillingId { get; init; }
/// <summary>
/// 支付金额。
@@ -22,7 +22,7 @@ public sealed record RecordPaymentCommand : IRequest<PaymentDto>
/// <summary>
/// 支付方式。
/// </summary>
public PaymentMethod Method { get; init; }
public TenantPaymentMethod Method { get; init; }
/// <summary>
/// 交易号。

View File

@@ -0,0 +1,25 @@
using MediatR;
using TakeoutSaaS.Domain.Tenants.Enums;
namespace TakeoutSaaS.Application.App.Billings.Commands;
/// <summary>
/// 更新账单状态命令。
/// </summary>
public sealed record UpdateBillingStatusCommand : IRequest<Unit>
{
/// <summary>
/// 账单 ID雪花算法
/// </summary>
public long BillingId { get; init; }
/// <summary>
/// 新状态。
/// </summary>
public TenantBillingStatus NewStatus { get; init; }
/// <summary>
/// 备注。
/// </summary>
public string? Notes { get; init; }
}

View File

@@ -0,0 +1,28 @@
using MediatR;
using System.ComponentModel.DataAnnotations;
using TakeoutSaaS.Application.App.Billings.Dto;
namespace TakeoutSaaS.Application.App.Billings.Commands;
/// <summary>
/// 审核支付命令。
/// </summary>
public sealed record VerifyPaymentCommand : IRequest<PaymentRecordDto>
{
/// <summary>
/// 支付记录 ID雪花算法
/// </summary>
[Required]
public long PaymentId { get; init; }
/// <summary>
/// 是否通过审核。
/// </summary>
public bool Approved { get; init; }
/// <summary>
/// 审核备注(可选)。
/// </summary>
[MaxLength(512)]
public string? Notes { get; init; }
}