diff --git a/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs b/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs
index 5cf2a96..6c68753 100644
--- a/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs
+++ b/src/Oms.Application/Services/Channels/SalesProductService.Helpers.cs
@@ -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
};
///
- /// 保险/偏远费等附加费用项的计费条件校验;同一提交批次内费用项不可重复。
+ /// 费用项 → 产品必须已勾选的附加服务 code(与字典约定一致)。
///
- private static void ValidateBillingPriceItemRules(IReadOnlyList prices)
+ private static readonly IReadOnlyDictionary CostItemRequiredAdditionalService =
+ new Dictionary(StringComparer.OrdinalIgnoreCase)
+ {
+ ["insurance"] = "insurance",
+ ["proxyPacking"] = "proxyPacking",
+ };
+
+ ///
+ /// 保险/代打包/偏远费等费用项规则:计费条件 + 产品附加服务依赖;同一提交批次内费用项不可重复。
+ ///
+ /// 待校验价格项。
+ /// 产品 AdditionalServices JSON(如 ["insurance"])。
+ private static void ValidateBillingPriceItemRules(
+ IReadOnlyList 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
}
}
+ ///
+ /// 解析产品附加服务 JSON 为 code 列表。
+ ///
+ private static List ParseAdditionalServiceCodes(string? raw)
+ {
+ if (string.IsNullOrWhiteSpace(raw))
+ {
+ return [];
+ }
+
+ var codes = OmsDocHelper.DeserializeJson>(raw.Trim());
+ if (codes == null)
+ {
+ return [];
+ }
+
+ return codes
+ .Where(x => !string.IsNullOrWhiteSpace(x))
+ .Select(x => x.Trim())
+ .Distinct(StringComparer.OrdinalIgnoreCase)
+ .ToList();
+ }
+
///
/// 同一销售产品下每种费用项只能有一条卖价配置。
///
diff --git a/src/Oms.Application/Services/Channels/SalesProductService.cs b/src/Oms.Application/Services/Channels/SalesProductService.cs
index f923a0d..fccb185 100644
--- a/src/Oms.Application/Services/Channels/SalesProductService.cs
+++ b/src/Oms.Application/Services/Channels/SalesProductService.cs
@@ -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();
var factors = new List();
var details = new List();