diff --git a/src/Oms.Application/Services/Orders/OrderService.ParcelBilling.cs b/src/Oms.Application/Services/Orders/OrderService.ParcelBilling.cs
index b9ffdda..c688f14 100644
--- a/src/Oms.Application/Services/Orders/OrderService.ParcelBilling.cs
+++ b/src/Oms.Application/Services/Orders/OrderService.ParcelBilling.cs
@@ -169,13 +169,14 @@ public partial class OrderService
var snapshotBinding = await ResolveSnapshotBindingAsync(product, bindTime);
var country = await GetCountryOrThrowAsync(input.Receiver.CountryCode);
- var channelCode = string.IsNullOrWhiteSpace(input.ChannelCode)
- ? product.ProductCode
+ // 单号上下文里的 ChannelCode 仅在入参显式指定时带上;未排货前不要用产品编码冒充渠道。
+ var channelCodeForDoc = string.IsNullOrWhiteSpace(input.ChannelCode)
+ ? null
: input.ChannelCode.Trim();
var numberContext = new DocNumberGenerateContext
{
ProductCode = product.ProductCode,
- ChannelCode = channelCode,
+ ChannelCode = channelCodeForDoc,
CountryCode = country.CountryCode,
CustomerId = sessionCustomer.Id
};
@@ -1030,10 +1031,12 @@ public partial class OrderService
var previousChannelCode = order.ChannelCode?.Trim();
var newChannelCode = selectedCandidate.Channel.ChannelCode?.Trim() ?? string.Empty;
- var channelChanged = !string.Equals(
- previousChannelCode,
- newChannelCode,
- StringComparison.OrdinalIgnoreCase);
+ // 仅「已有渠道 → 换成另一渠道」才算换渠道;首次从空排到渠道不算,避免误清跟踪号。
+ var channelChanged = !string.IsNullOrWhiteSpace(previousChannelCode)
+ && !string.Equals(
+ previousChannelCode,
+ newChannelCode,
+ StringComparison.OrdinalIgnoreCase);
order.ChannelCode = selectedCandidate.Channel.ChannelCode;
AllocationProviderSnapshotEnricher.ApplyDownstreamFieldsToOrder(
@@ -1633,10 +1636,40 @@ public partial class OrderService
{
var message = ex.Message.Trim();
order.AllocationPendingReason = message.Length > 512 ? message[..512] : message;
+ // 清掉历史「用产品 code 占位 ChannelCode」的脏数据;已真实排过的渠道(含与产品同码)予以保留。
+ ClearUnallocatedProductCodeChannelPlaceholder(order);
return false;
}
}
+ ///
+ /// 未真正排货成功前,曾把 ProductCode 写入 ChannelCode 作占位;排货失败时清掉该占位,避免详情误显示。
+ /// 若 ChannelCode 与产品同码但已带下游字段,视为真实渠道,不清。
+ ///
+ private static void ClearUnallocatedProductCodeChannelPlaceholder(Order order)
+ {
+ if (string.IsNullOrWhiteSpace(order.ChannelCode) || string.IsNullOrWhiteSpace(order.ProductCode))
+ {
+ return;
+ }
+
+ if (!string.Equals(order.ChannelCode.Trim(), order.ProductCode.Trim(), StringComparison.OrdinalIgnoreCase))
+ {
+ return;
+ }
+
+ var hasDownstream = !string.IsNullOrWhiteSpace(order.DownstreamSupplierCode)
+ || !string.IsNullOrWhiteSpace(order.DownstreamSupplierName)
+ || !string.IsNullOrWhiteSpace(order.ChannelForecastCode)
+ || order.DownstreamAppId is > 0;
+ if (hasDownstream)
+ {
+ return;
+ }
+
+ order.ChannelCode = null;
+ }
+
private async Task> ResolveAllocationProvidersAsync(
SalesProduct product,
SalesProductRulesPublishSnapshotDto rulesSnapshot)
@@ -2642,7 +2675,8 @@ public partial class OrderService
TrackNo = input.TrackNo,
ServiceNo = serviceNo,
ProductCode = input.ProductCode,
- ChannelCode = input.ChannelCode ?? product.ProductCode,
+ // 服务渠道仅排货成功后写入;未排货保持空,避免详情把产品 code 当成渠道 code。
+ ChannelCode = string.IsNullOrWhiteSpace(input.ChannelCode) ? null : input.ChannelCode.Trim(),
ConsigneeCountry = consigneeCountry,
ConsigneeCountryName = consigneeCountryName,
CargoAttribute = input.CargoAttribute ?? CargoAttributeCodes.General,