feat: 商户类目数据库化并增加权限种子

This commit is contained in:
2025-12-03 19:01:53 +08:00
parent a536a554c2
commit 0c329669a9
49 changed files with 1646 additions and 6 deletions

View File

@@ -0,0 +1,74 @@
using System.Collections.Generic;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TakeoutSaaS.Application.App.Merchants.Commands;
using TakeoutSaaS.Application.App.Merchants.Dto;
using TakeoutSaaS.Application.App.Merchants.Queries;
using TakeoutSaaS.Module.Authorization.Attributes;
using TakeoutSaaS.Shared.Abstractions.Constants;
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}/merchant-categories")]
public sealed class MerchantCategoriesController(IMediator mediator) : BaseApiController
{
/// <summary>
/// 列出所有类目。
/// </summary>
[HttpGet]
[PermissionAuthorize("merchant_category:read")]
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<MerchantCategoryDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<IReadOnlyList<MerchantCategoryDto>>> List(CancellationToken cancellationToken)
{
var result = await mediator.Send(new ListMerchantCategoriesQuery(), cancellationToken);
return ApiResponse<IReadOnlyList<MerchantCategoryDto>>.Ok(result);
}
/// <summary>
/// 新增类目。
/// </summary>
[HttpPost]
[PermissionAuthorize("merchant_category:create")]
[ProducesResponseType(typeof(ApiResponse<MerchantCategoryDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<MerchantCategoryDto>> Create([FromBody] CreateMerchantCategoryCommand command, CancellationToken cancellationToken)
{
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<MerchantCategoryDto>.Ok(result);
}
/// <summary>
/// 删除类目。
/// </summary>
[HttpDelete("{categoryId:long}")]
[PermissionAuthorize("merchant_category:delete")]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
public async Task<ApiResponse<object>> Delete(long categoryId, CancellationToken cancellationToken)
{
var success = await mediator.Send(new DeleteMerchantCategoryCommand(categoryId), cancellationToken);
return success
? ApiResponse<object>.Ok(null)
: ApiResponse<object>.Error(ErrorCodes.NotFound, "类目不存在");
}
/// <summary>
/// 批量调整类目排序。
/// </summary>
[HttpPost("reorder")]
[PermissionAuthorize("merchant_category:update")]
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
public async Task<ApiResponse<object>> Reorder([FromBody] ReorderMerchantCategoriesCommand command, CancellationToken cancellationToken)
{
await mediator.Send(command, cancellationToken);
return ApiResponse<object>.Ok(null);
}
}

View File

@@ -99,7 +99,7 @@ public sealed class MerchantsController(IMediator mediator) : BaseApiController
}
/// <summary>
/// 获取商户详情
/// 获取商户概览
/// </summary>
[HttpGet("{merchantId:long}")]
[PermissionAuthorize("merchant:read")]
@@ -112,4 +112,147 @@ public sealed class MerchantsController(IMediator mediator) : BaseApiController
? ApiResponse<MerchantDto>.Error(ErrorCodes.NotFound, "商户不存在")
: ApiResponse<MerchantDto>.Ok(result);
}
/// <summary>
/// 获取商户详细资料(含证照、合同)。
/// </summary>
[HttpGet("{merchantId:long}/detail")]
[PermissionAuthorize("merchant:read")]
[ProducesResponseType(typeof(ApiResponse<MerchantDetailDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<MerchantDetailDto>> FullDetail(long merchantId, CancellationToken cancellationToken)
{
var result = await mediator.Send(new GetMerchantDetailQuery(merchantId), cancellationToken);
return ApiResponse<MerchantDetailDto>.Ok(result);
}
/// <summary>
/// 上传商户证照信息(先通过文件上传接口获取 COS 地址)。
/// </summary>
[HttpPost("{merchantId:long}/documents")]
[PermissionAuthorize("merchant:update")]
[ProducesResponseType(typeof(ApiResponse<MerchantDocumentDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<MerchantDocumentDto>> CreateDocument(
long merchantId,
[FromBody] AddMerchantDocumentCommand body,
CancellationToken cancellationToken)
{
var command = body with { MerchantId = merchantId };
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<MerchantDocumentDto>.Ok(result);
}
/// <summary>
/// 商户证照列表。
/// </summary>
[HttpGet("{merchantId:long}/documents")]
[PermissionAuthorize("merchant:read")]
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<MerchantDocumentDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<IReadOnlyList<MerchantDocumentDto>>> Documents(long merchantId, CancellationToken cancellationToken)
{
var result = await mediator.Send(new GetMerchantDocumentsQuery(merchantId), cancellationToken);
return ApiResponse<IReadOnlyList<MerchantDocumentDto>>.Ok(result);
}
/// <summary>
/// 审核指定证照。
/// </summary>
[HttpPost("{merchantId:long}/documents/{documentId:long}/review")]
[PermissionAuthorize("merchant:review")]
[ProducesResponseType(typeof(ApiResponse<MerchantDocumentDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<MerchantDocumentDto>> ReviewDocument(
long merchantId,
long documentId,
[FromBody] ReviewMerchantDocumentCommand body,
CancellationToken cancellationToken)
{
var command = body with { MerchantId = merchantId, DocumentId = documentId };
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<MerchantDocumentDto>.Ok(result);
}
/// <summary>
/// 新增商户合同。
/// </summary>
[HttpPost("{merchantId:long}/contracts")]
[PermissionAuthorize("merchant:update")]
[ProducesResponseType(typeof(ApiResponse<MerchantContractDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<MerchantContractDto>> CreateContract(
long merchantId,
[FromBody] CreateMerchantContractCommand body,
CancellationToken cancellationToken)
{
var command = body with { MerchantId = merchantId };
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<MerchantContractDto>.Ok(result);
}
/// <summary>
/// 合同列表。
/// </summary>
[HttpGet("{merchantId:long}/contracts")]
[PermissionAuthorize("merchant:read")]
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<MerchantContractDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<IReadOnlyList<MerchantContractDto>>> Contracts(long merchantId, CancellationToken cancellationToken)
{
var result = await mediator.Send(new GetMerchantContractsQuery(merchantId), cancellationToken);
return ApiResponse<IReadOnlyList<MerchantContractDto>>.Ok(result);
}
/// <summary>
/// 更新合同状态(生效/终止等)。
/// </summary>
[HttpPut("{merchantId:long}/contracts/{contractId:long}/status")]
[PermissionAuthorize("merchant:update")]
[ProducesResponseType(typeof(ApiResponse<MerchantContractDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<MerchantContractDto>> UpdateContractStatus(
long merchantId,
long contractId,
[FromBody] UpdateMerchantContractStatusCommand body,
CancellationToken cancellationToken)
{
var command = body with { MerchantId = merchantId, ContractId = contractId };
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<MerchantContractDto>.Ok(result);
}
/// <summary>
/// 审核商户(通过/驳回)。
/// </summary>
[HttpPost("{merchantId:long}/review")]
[PermissionAuthorize("merchant:review")]
[ProducesResponseType(typeof(ApiResponse<MerchantDto>), StatusCodes.Status200OK)]
public async Task<ApiResponse<MerchantDto>> Review(long merchantId, [FromBody] ReviewMerchantCommand body, CancellationToken cancellationToken)
{
var command = body with { MerchantId = merchantId };
var result = await mediator.Send(command, cancellationToken);
return ApiResponse<MerchantDto>.Ok(result);
}
/// <summary>
/// 审核日志。
/// </summary>
[HttpGet("{merchantId:long}/audits")]
[PermissionAuthorize("merchant:read")]
[ProducesResponseType(typeof(ApiResponse<PagedResult<MerchantAuditLogDto>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<PagedResult<MerchantAuditLogDto>>> AuditLogs(
long merchantId,
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
CancellationToken cancellationToken = default)
{
var result = await mediator.Send(new GetMerchantAuditLogsQuery(merchantId, page, pageSize), cancellationToken);
return ApiResponse<PagedResult<MerchantAuditLogDto>>.Ok(result);
}
/// <summary>
/// 可选商户类目列表。
/// </summary>
[HttpGet("categories")]
[PermissionAuthorize("merchant:read")]
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<string>>), StatusCodes.Status200OK)]
public async Task<ApiResponse<IReadOnlyList<string>>> Categories(CancellationToken cancellationToken)
{
var result = await mediator.Send(new GetMerchantCategoriesQuery(), cancellationToken);
return ApiResponse<IReadOnlyList<string>>.Ok(result);
}
}

View File

@@ -173,4 +173,4 @@
"Sampling": "ParentBasedAlwaysOn",
"UseConsoleExporter": true
}
}
}

View File

@@ -173,4 +173,4 @@
"Sampling": "ParentBasedAlwaysOn",
"UseConsoleExporter": true
}
}
}

View File

@@ -46,7 +46,19 @@
"Password": "Admin@123456",
"TenantId": 1000000000001,
"Roles": [ "PlatformAdmin" ],
"Permissions": [ "merchant:*", "store:*", "product:*", "order:*", "payment:*", "delivery:*" ]
"Permissions": [
"merchant:*",
"merchant_category:*",
"merchant_category:read",
"merchant_category:create",
"merchant_category:update",
"merchant_category:delete",
"store:*",
"product:*",
"order:*",
"payment:*",
"delivery:*"
]
}
]
}