feat: 增加组合币种校验,交易币种必须和组合本位币一致

This commit is contained in:
claw_bot 2026-03-10 03:41:41 +00:00
parent 35222fbf26
commit a23937eac8
2 changed files with 27 additions and 0 deletions

View File

@ -358,6 +358,27 @@ public class PortfolioController : ControllerBase
});
}
// 校验交易币种必须和组合本位币一致
var portfolio = _databaseService.GetDb().Queryable<Portfolio>().Where(p => p.Id == request.portfolioId && p.UserId == userId).First();
if (portfolio == null)
{
return NotFound(new ApiResponse<CreateTransactionResponse>
{
code = AssetManager.Models.StatusCodes.NotFound,
data = null,
message = "投资组合不存在"
});
}
if (!string.IsNullOrEmpty(request.currency) && !request.currency.Equals(portfolio.Currency, StringComparison.OrdinalIgnoreCase))
{
return BadRequest(new ApiResponse<CreateTransactionResponse>
{
code = AssetManager.Models.StatusCodes.BadRequest,
data = null,
message = $"该组合本位币为 {portfolio.Currency},只能添加相同币种的标的"
});
}
// 校验资产类型
if (!string.IsNullOrEmpty(request.assetType))
{

View File

@ -365,6 +365,12 @@ public class PortfolioService : IPortfolioService
throw new Exception("Portfolio not found or access denied");
}
// 校验交易币种必须和组合本位币一致(双重校验)
if (!string.IsNullOrEmpty(request.currency) && !request.currency.Equals(portfolio.Currency, StringComparison.OrdinalIgnoreCase))
{
throw new Exception($"该组合本位币为 {portfolio.Currency},只能添加相同币种的标的");
}
// 卖出操作校验
if (request.type?.ToLower() == "sell")
{