20261111 #22

Merged
zzh merged 5 commits from test into master 2026-11-11 17:01:27 +08:00
2 changed files with 73 additions and 11 deletions
Showing only changes of commit 28477e98bb - Show all commits

View File

@ -405,9 +405,11 @@ public partial class SalesProductService
object snapshot;
if (operatorType == PriceOperatorType)
{
var product = await GetProductOrThrowAsync(salesProductId);
var priceSnapshot = await BuildPricePublishSnapshotAsync(salesProductId);
ValidateBillingPriceItemRules(
priceSnapshot.Prices.Select(p => MapPriceSaveInput(p, salesProductId)).ToList());
priceSnapshot.Prices.Select(p => MapPriceSaveInput(p, salesProductId)).ToList(),
product.AdditionalServices);
snapshot = priceSnapshot;
}
else
@ -440,7 +442,8 @@ public partial class SalesProductService
var product = await GetProductOrThrowAsync(salesProductId);
var priceSnapshot = await BuildPricePublishSnapshotAsync(salesProductId);
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 contentHash = ComputeContentHash(content);
var publishUser = ResolvePublishUserName();
@ -652,21 +655,56 @@ public partial class SalesProductService
};
/// <summary>
/// 保险/偏远费等附加费用项的计费条件校验;同一提交批次内费用项不可重复。
/// 费用项 → 产品必须已勾选的附加服务 code(与字典约定一致)。
/// </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));
var allowedServices = ParseAdditionalServiceCodes(productAdditionalServicesJson);
foreach (var price in prices)
{
var costItem = price.CostItem?.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)
|| 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>

View File

@ -213,8 +213,8 @@ public partial class SalesProductService : ApplicationService
[HttpPost("/channel/sales-product/price/create")]
public async Task CreatePriceAsync(SalesProductPriceSaveInput input)
{
await GetProductOrThrowAsync(input.SalesProductId);
ValidateBillingPriceItemRules([input]);
var product = await GetProductOrThrowAsync(input.SalesProductId);
ValidateBillingPriceItemRules([input], product.AdditionalServices);
await EnsureCostItemUniqueAsync(input.SalesProductId, input.CostItem, excludePriceId: null);
await SalesProductRepository.InsertPriceAsync(
new SalesProductPrice
@ -246,7 +246,8 @@ public partial class SalesProductService : ApplicationService
throw new BusinessException("价格项归属不匹配");
}
ValidateBillingPriceItemRules([input]);
var product = await GetProductOrThrowAsync(input.SalesProductId);
ValidateBillingPriceItemRules([input], product.AdditionalServices);
await EnsureCostItemUniqueAsync(input.SalesProductId, input.CostItem, excludePriceId: price.Id);
price.SerialNumber = input.SerialNumber;
price.Status = input.Status;
@ -293,8 +294,8 @@ public partial class SalesProductService : ApplicationService
[HttpPost("/channel/sales-product/price/save")]
public async Task SavePriceAsync(SalesProductPriceSaveAllInput input)
{
await GetProductOrThrowAsync(input.SalesProductId);
ValidateBillingPriceItemRules(input.Prices);
var product = await GetProductOrThrowAsync(input.SalesProductId);
ValidateBillingPriceItemRules(input.Prices, product.AdditionalServices);
var prices = new List<SalesProductPrice>();
var factors = new List<SalesProductPriceFactor>();
var details = new List<SalesProductPriceDetail>();