fix: 卖价费用项依赖附加服务时校验产品已勾选对应服务
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m17s
避免保险费/代打包费在产品未开通附加服务时仍可保存或发布,下单无法勾选导致收不到费。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9e45e7f185
commit
28477e98bb
@ -405,9 +405,11 @@ public partial class SalesProductService
|
|||||||
object snapshot;
|
object snapshot;
|
||||||
if (operatorType == PriceOperatorType)
|
if (operatorType == PriceOperatorType)
|
||||||
{
|
{
|
||||||
|
var product = await GetProductOrThrowAsync(salesProductId);
|
||||||
var priceSnapshot = await BuildPricePublishSnapshotAsync(salesProductId);
|
var priceSnapshot = await BuildPricePublishSnapshotAsync(salesProductId);
|
||||||
ValidateBillingPriceItemRules(
|
ValidateBillingPriceItemRules(
|
||||||
priceSnapshot.Prices.Select(p => MapPriceSaveInput(p, salesProductId)).ToList());
|
priceSnapshot.Prices.Select(p => MapPriceSaveInput(p, salesProductId)).ToList(),
|
||||||
|
product.AdditionalServices);
|
||||||
snapshot = priceSnapshot;
|
snapshot = priceSnapshot;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -440,7 +442,8 @@ public partial class SalesProductService
|
|||||||
var product = await GetProductOrThrowAsync(salesProductId);
|
var product = await GetProductOrThrowAsync(salesProductId);
|
||||||
var priceSnapshot = await BuildPricePublishSnapshotAsync(salesProductId);
|
var priceSnapshot = await BuildPricePublishSnapshotAsync(salesProductId);
|
||||||
ValidateBillingPriceItemRules(
|
ValidateBillingPriceItemRules(
|
||||||
priceSnapshot.Prices.Select(p => MapPriceSaveInput(p, salesProductId)).ToList());
|
priceSnapshot.Prices.Select(p => MapPriceSaveInput(p, salesProductId)).ToList(),
|
||||||
|
product.AdditionalServices);
|
||||||
var content = OmsDocHelper.CanonicalizeSalesProductPriceSnapshotJson(priceSnapshot);
|
var content = OmsDocHelper.CanonicalizeSalesProductPriceSnapshotJson(priceSnapshot);
|
||||||
var contentHash = ComputeContentHash(content);
|
var contentHash = ComputeContentHash(content);
|
||||||
var publishUser = ResolvePublishUserName();
|
var publishUser = ResolvePublishUserName();
|
||||||
@ -652,21 +655,56 @@ public partial class SalesProductService
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保险/偏远费等附加费用项的计费条件校验;同一提交批次内费用项不可重复。
|
/// 费用项 → 产品必须已勾选的附加服务 code(与字典约定一致)。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void ValidateBillingPriceItemRules(IReadOnlyList<SalesProductPriceSaveInput> prices)
|
private static readonly IReadOnlyDictionary<string, string> CostItemRequiredAdditionalService =
|
||||||
|
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
["insurance"] = "insurance",
|
||||||
|
["proxyPacking"] = "proxyPacking",
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保险/代打包/偏远费等费用项规则:计费条件 + 产品附加服务依赖;同一提交批次内费用项不可重复。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prices">待校验价格项。</param>
|
||||||
|
/// <param name="productAdditionalServicesJson">产品 AdditionalServices JSON(如 ["insurance"])。</param>
|
||||||
|
private static void ValidateBillingPriceItemRules(
|
||||||
|
IReadOnlyList<SalesProductPriceSaveInput> prices,
|
||||||
|
string? productAdditionalServicesJson = null)
|
||||||
{
|
{
|
||||||
EnsureUniqueCostItemsInBatch(prices.Select(x => x.CostItem));
|
EnsureUniqueCostItemsInBatch(prices.Select(x => x.CostItem));
|
||||||
|
var allowedServices = ParseAdditionalServiceCodes(productAdditionalServicesJson);
|
||||||
foreach (var price in prices)
|
foreach (var price in prices)
|
||||||
{
|
{
|
||||||
var costItem = price.CostItem?.Trim() ?? string.Empty;
|
var costItem = price.CostItem?.Trim() ?? string.Empty;
|
||||||
var condition = price.ChargingCondition?.Trim() ?? string.Empty;
|
var condition = price.ChargingCondition?.Trim() ?? string.Empty;
|
||||||
if (costItem.Equals("insurance", StringComparison.OrdinalIgnoreCase))
|
|
||||||
|
if (CostItemRequiredAdditionalService.TryGetValue(costItem, out var requiredService))
|
||||||
{
|
{
|
||||||
|
if (!allowedServices.Contains(requiredService, StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
var serviceLabel = requiredService switch
|
||||||
|
{
|
||||||
|
"insurance" => "保险",
|
||||||
|
"proxyPacking" => "代打包",
|
||||||
|
_ => requiredService,
|
||||||
|
};
|
||||||
|
throw new Fake.Application.BusinessException(
|
||||||
|
$"请先在产品配置勾选附加服务「{serviceLabel}」,再配置此费用项");
|
||||||
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(condition)
|
if (string.IsNullOrWhiteSpace(condition)
|
||||||
|| string.Equals(condition, "无", StringComparison.OrdinalIgnoreCase))
|
|| string.Equals(condition, "无", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
throw new Fake.Application.BusinessException("保险费用项必须配置非空计费条件(不能为「无」)");
|
throw new Fake.Application.BusinessException(
|
||||||
|
$"费用项「{costItem}」必须配置非空计费条件(不能为「无」)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!condition.Contains("附加服务包含", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
throw new Fake.Application.BusinessException(
|
||||||
|
$"费用项「{costItem}」的计费条件必须包含「附加服务包含」");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,6 +720,29 @@ public partial class SalesProductService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析产品附加服务 JSON 为 code 列表。
|
||||||
|
/// </summary>
|
||||||
|
private static List<string> ParseAdditionalServiceCodes(string? raw)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(raw))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var codes = OmsDocHelper.DeserializeJson<List<string>>(raw.Trim());
|
||||||
|
if (codes == null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return codes
|
||||||
|
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||||
|
.Select(x => x.Trim())
|
||||||
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同一销售产品下每种费用项只能有一条卖价配置。
|
/// 同一销售产品下每种费用项只能有一条卖价配置。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -213,8 +213,8 @@ public partial class SalesProductService : ApplicationService
|
|||||||
[HttpPost("/channel/sales-product/price/create")]
|
[HttpPost("/channel/sales-product/price/create")]
|
||||||
public async Task CreatePriceAsync(SalesProductPriceSaveInput input)
|
public async Task CreatePriceAsync(SalesProductPriceSaveInput input)
|
||||||
{
|
{
|
||||||
await GetProductOrThrowAsync(input.SalesProductId);
|
var product = await GetProductOrThrowAsync(input.SalesProductId);
|
||||||
ValidateBillingPriceItemRules([input]);
|
ValidateBillingPriceItemRules([input], product.AdditionalServices);
|
||||||
await EnsureCostItemUniqueAsync(input.SalesProductId, input.CostItem, excludePriceId: null);
|
await EnsureCostItemUniqueAsync(input.SalesProductId, input.CostItem, excludePriceId: null);
|
||||||
await SalesProductRepository.InsertPriceAsync(
|
await SalesProductRepository.InsertPriceAsync(
|
||||||
new SalesProductPrice
|
new SalesProductPrice
|
||||||
@ -246,7 +246,8 @@ public partial class SalesProductService : ApplicationService
|
|||||||
throw new BusinessException("价格项归属不匹配");
|
throw new BusinessException("价格项归属不匹配");
|
||||||
}
|
}
|
||||||
|
|
||||||
ValidateBillingPriceItemRules([input]);
|
var product = await GetProductOrThrowAsync(input.SalesProductId);
|
||||||
|
ValidateBillingPriceItemRules([input], product.AdditionalServices);
|
||||||
await EnsureCostItemUniqueAsync(input.SalesProductId, input.CostItem, excludePriceId: price.Id);
|
await EnsureCostItemUniqueAsync(input.SalesProductId, input.CostItem, excludePriceId: price.Id);
|
||||||
price.SerialNumber = input.SerialNumber;
|
price.SerialNumber = input.SerialNumber;
|
||||||
price.Status = input.Status;
|
price.Status = input.Status;
|
||||||
@ -293,8 +294,8 @@ public partial class SalesProductService : ApplicationService
|
|||||||
[HttpPost("/channel/sales-product/price/save")]
|
[HttpPost("/channel/sales-product/price/save")]
|
||||||
public async Task SavePriceAsync(SalesProductPriceSaveAllInput input)
|
public async Task SavePriceAsync(SalesProductPriceSaveAllInput input)
|
||||||
{
|
{
|
||||||
await GetProductOrThrowAsync(input.SalesProductId);
|
var product = await GetProductOrThrowAsync(input.SalesProductId);
|
||||||
ValidateBillingPriceItemRules(input.Prices);
|
ValidateBillingPriceItemRules(input.Prices, product.AdditionalServices);
|
||||||
var prices = new List<SalesProductPrice>();
|
var prices = new List<SalesProductPrice>();
|
||||||
var factors = new List<SalesProductPriceFactor>();
|
var factors = new List<SalesProductPriceFactor>();
|
||||||
var details = new List<SalesProductPriceDetail>();
|
var details = new List<SalesProductPriceDetail>();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user