From 28477e98bbd700fa3044fa2fab705270e5673da6 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Wed, 11 Nov 2026 10:14:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8D=96=E4=BB=B7=E8=B4=B9=E7=94=A8?= =?UTF-8?q?=E9=A1=B9=E4=BE=9D=E8=B5=96=E9=99=84=E5=8A=A0=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=97=B6=E6=A0=A1=E9=AA=8C=E4=BA=A7=E5=93=81=E5=B7=B2=E5=8B=BE?= =?UTF-8?q?=E9=80=89=E5=AF=B9=E5=BA=94=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免保险费/代打包费在产品未开通附加服务时仍可保存或发布,下单无法勾选导致收不到费。 Co-authored-by: Cursor --- .../Channels/SalesProductService.Helpers.cs | 73 +++++++++++++++++-- .../Services/Channels/SalesProductService.cs | 11 +-- 2 files changed, 73 insertions(+), 11 deletions(-) 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();