fix: 未排货时不再用产品编码占位 ChannelCode
All checks were successful
Build and Deploy / deploy (push) Successful in 1m23s

建单与单号上下文不再把 ProductCode 写入 ChannelCode;排货失败清掉历史占位,首次排货成功不再误清跟踪号。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-11-27 10:01:08 +08:00
parent caca756c94
commit 955b673226

View File

@ -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,7 +1031,9 @@ public partial class OrderService
var previousChannelCode = order.ChannelCode?.Trim();
var newChannelCode = selectedCandidate.Channel.ChannelCode?.Trim() ?? string.Empty;
var channelChanged = !string.Equals(
// 仅「已有渠道 → 换成另一渠道」才算换渠道;首次从空排到渠道不算,避免误清跟踪号。
var channelChanged = !string.IsNullOrWhiteSpace(previousChannelCode)
&& !string.Equals(
previousChannelCode,
newChannelCode,
StringComparison.OrdinalIgnoreCase);
@ -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;
}
}
/// <summary>
/// 未真正排货成功前,曾把 ProductCode 写入 ChannelCode 作占位;排货失败时清掉该占位,避免详情误显示。
/// 若 ChannelCode 与产品同码但已带下游字段,视为真实渠道,不清。
/// </summary>
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<List<SalesProductAllocationProviderSnapshotDto>> 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,