diff --git a/src/Oms.Application/Dtos/Orders/FulfillWorkplaceStatsOutput.cs b/src/Oms.Application/Dtos/Orders/FulfillWorkplaceStatsOutput.cs
index e269cb6..c7757ba 100644
--- a/src/Oms.Application/Dtos/Orders/FulfillWorkplaceStatsOutput.cs
+++ b/src/Oms.Application/Dtos/Orders/FulfillWorkplaceStatsOutput.cs
@@ -5,7 +5,7 @@ namespace Oms.Application.Dtos.Orders;
///
public class FulfillWorkplaceStatsOutput
{
- /// 待绑定包裹/库存。
+ /// 历史字段:创建代发必绑后工作台恒为 0,保留兼容旧前端。
public int PendingBind { get; set; }
/// 国内快递在途。
diff --git a/src/Oms.Application/Services/Orders/OrderService.StockBind.cs b/src/Oms.Application/Services/Orders/OrderService.StockBind.cs
index a9abbc2..16e8b09 100644
--- a/src/Oms.Application/Services/Orders/OrderService.StockBind.cs
+++ b/src/Oms.Application/Services/Orders/OrderService.StockBind.cs
@@ -1,5 +1,7 @@
+using System.Data;
using Fake.Application;
using Fake.Domain.Exceptions;
+using Fake.UnitOfWork;
using Microsoft.AspNetCore.Mvc;
using Oms.Application.Dtos.Orders;
using Oms.Application.Dtos.Shared;
@@ -189,20 +191,23 @@ public partial class OrderService
/// 保存绑定(全量覆盖 + 冻结)。
///
[HttpPost("/order/stock-bind/save")]
+ [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
public async Task SaveStockBindAsync([FromBody] OrderStockBindSaveInput input)
{
var order = await GetOrderOrThrowAsync(input.OrderId);
EnsureOrderCanBindStock(order);
await EnsureNoDeductedBindsAsync(order.Id);
- var customerId = await ResolveStockBindCustomerIdAsync(order);
- var warehouseId = ResolveBindWarehouseId(order, null);
var items = input.Items ?? [];
- if (items.Count > 0)
+ // 空明细 = 清空绑定:仓内代发不可处于「已建单未绑定」,清空后回退直发
+ if (items.Count == 0)
{
- await EnsureProxyPackingConfiguredForOrderAsync(order);
+ return await ClearStockBindCoreAsync(order);
}
+ var customerId = await ResolveStockBindCustomerIdAsync(order);
+ var warehouseId = ResolveBindWarehouseId(order, null);
+ await EnsureProxyPackingConfiguredForOrderAsync(order);
await ReleaseBoundBindsAsync(order.Id);
foreach (var item in items)
@@ -234,19 +239,16 @@ public partial class OrderService
needOrderUpdate = true;
}
- if (items.Count > 0)
+ if (!FulfillmentTypeCodes.IsWarehouse(order.FulfillmentType))
{
- if (!FulfillmentTypeCodes.IsWarehouse(order.FulfillmentType))
- {
- order.FulfillmentType = FulfillmentTypeCodes.Warehouse;
- needOrderUpdate = true;
- }
+ order.FulfillmentType = FulfillmentTypeCodes.Warehouse;
+ needOrderUpdate = true;
+ }
- if (string.IsNullOrWhiteSpace(order.FulfillmentSource))
- {
- order.FulfillmentSource = FulfillmentSourceCodes.PostBind;
- needOrderUpdate = true;
- }
+ if (string.IsNullOrWhiteSpace(order.FulfillmentSource))
+ {
+ order.FulfillmentSource = FulfillmentSourceCodes.PostBind;
+ needOrderUpdate = true;
}
if (needOrderUpdate)
@@ -261,16 +263,31 @@ public partial class OrderService
}
///
- /// 清空绑定并释放冻结。
+ /// 清空绑定并释放冻结;若原为仓内代发则回退为直发(创建代发必绑,禁止无绑定的 warehouse 单)。
///
[HttpPost("/order/stock-bind/clear")]
+ [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
public async Task ClearStockBindAsync([FromBody] OrderStockBindOrderInput input)
{
var order = await GetOrderOrThrowAsync(input.OrderId);
EnsureOrderCanBindStock(order);
await EnsureNoDeductedBindsAsync(order.Id);
+ return await ClearStockBindCoreAsync(order);
+ }
+
+ private async Task ClearStockBindCoreAsync(Order order)
+ {
await ReleaseBoundBindsAsync(order.Id);
order = await GetOrderOrThrowAsync(order.Id);
+
+ if (FulfillmentTypeCodes.IsWarehouse(order.FulfillmentType))
+ {
+ order.FulfillmentType = FulfillmentTypeCodes.Direct;
+ order.FulfillmentSource = null;
+ await UpdateOrderAsync(order);
+ order = await GetOrderOrThrowAsync(order.Id);
+ }
+
await SyncProxyPackingFeeByStockBindAsync(order);
return await BuildStockBindDetailAsync(order);
}
@@ -279,6 +296,7 @@ public partial class OrderService
/// 确认扣减:将 bound 明细转为 deducted,扣减实物并释放冻结。
///
[HttpPost("/order/stock-bind/confirm-deduct")]
+ [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
public async Task ConfirmStockBindDeductAsync([FromBody] OrderStockBindOrderInput input)
{
var order = await GetOrderOrThrowAsync(input.OrderId);
diff --git a/src/Oms.Application/Services/Orders/OrderService.Workplace.cs b/src/Oms.Application/Services/Orders/OrderService.Workplace.cs
index 3c3ee54..47e9618 100644
--- a/src/Oms.Application/Services/Orders/OrderService.Workplace.cs
+++ b/src/Oms.Application/Services/Orders/OrderService.Workplace.cs
@@ -101,7 +101,8 @@ public partial class OrderService
StoreOrderPending = storeOrderPending,
Fulfill = new FulfillWorkplaceStatsOutput
{
- PendingBind = FulfillCount(FulfillmentProgressCodes.PendingBind),
+ // 创建代发必绑:工作台不再统计「待绑定」
+ PendingBind = 0,
DomesticInTransit = FulfillCount(FulfillmentProgressCodes.DomesticInTransit),
ArrivedPendingPick = FulfillCount(FulfillmentProgressCodes.ArrivedPendingPick),
OutboundDone = FulfillCount(FulfillmentProgressCodes.OutboundDone),
diff --git a/src/Oms.Application/Services/Orders/OrderService.cs b/src/Oms.Application/Services/Orders/OrderService.cs
index 9088641..4ca0c09 100644
--- a/src/Oms.Application/Services/Orders/OrderService.cs
+++ b/src/Oms.Application/Services/Orders/OrderService.cs
@@ -478,6 +478,7 @@ public partial class OrderService : ApplicationService
/// 入参:订单操作参数。
/// 无返回体,仅完成删除订单。
[HttpPost("/order/delete")]
+ [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
public async Task DeleteAsync(OrderActionInput input)
{
var order = await GetOrderOrThrowAsync(input.Id);
@@ -486,6 +487,10 @@ public partial class OrderService : ApplicationService
throw new BusinessException("仅草稿或已预报订单可删除");
}
+ // 删除前释放库存/包裹冻结;仓内代发回退直发,避免删单后冻结残留
+ await ClearStockBindCoreAsync(order);
+ order = await GetOrderOrThrowAsync(input.Id);
+
// 业务删除:只改 OrderStatus=deleted,不做 IsDeleted 软删,否则「已删除」Tab 因全局软删过滤永远查不到。
order.OrderStatus = OrderStatusCodes.Deleted;
if (order.IsPaid > 0 && order.CustomerId.HasValue)
diff --git a/src/Oms.Application/Services/Orders/PlatformStoreOrderService.cs b/src/Oms.Application/Services/Orders/PlatformStoreOrderService.cs
index acda47b..9a89851 100644
--- a/src/Oms.Application/Services/Orders/PlatformStoreOrderService.cs
+++ b/src/Oms.Application/Services/Orders/PlatformStoreOrderService.cs
@@ -623,19 +623,13 @@ public class PlatformStoreOrderService : ApplicationService
try
{
- // 确保物流单带仓库,绑定校验依赖 WarehouseId
+ // 先只落仓库,FulfillmentType 在绑定成功后写入,避免出现「warehouse 但未绑定」
if (resolvedWarehouseId is > 0)
{
var logisticsOrder = await OrderRepository.FirstOrDefaultAsync(x => x.Id == parcelOutput.OrderId);
- if (logisticsOrder != null)
+ if (logisticsOrder != null && logisticsOrder.WarehouseId is not > 0)
{
- if (logisticsOrder.WarehouseId is not > 0)
- {
- logisticsOrder.WarehouseId = resolvedWarehouseId;
- }
-
- logisticsOrder.FulfillmentType = FulfillmentTypeCodes.Warehouse;
- logisticsOrder.FulfillmentSource = FulfillmentSourceCodes.StoreFulfill;
+ logisticsOrder.WarehouseId = resolvedWarehouseId;
await OrderRepository.UpdateAsync(logisticsOrder);
}
}
@@ -645,6 +639,32 @@ public class PlatformStoreOrderService : ApplicationService
OrderId = parcelOutput.OrderId,
Items = bindItems
});
+
+ var boundOrder = await OrderRepository.FirstOrDefaultAsync(x => x.Id == parcelOutput.OrderId);
+ if (boundOrder != null)
+ {
+ var needUpdate = false;
+ if (!string.Equals(
+ boundOrder.FulfillmentSource,
+ FulfillmentSourceCodes.StoreFulfill,
+ StringComparison.OrdinalIgnoreCase))
+ {
+ boundOrder.FulfillmentSource = FulfillmentSourceCodes.StoreFulfill;
+ needUpdate = true;
+ }
+
+ if (!FulfillmentTypeCodes.IsWarehouse(boundOrder.FulfillmentType))
+ {
+ boundOrder.FulfillmentType = FulfillmentTypeCodes.Warehouse;
+ needUpdate = true;
+ }
+
+ if (needUpdate)
+ {
+ await OrderRepository.UpdateAsync(boundOrder);
+ }
+ }
+
return parcelOutput;
}
catch (Exception)
diff --git a/src/Oms.Domain/OrdersAggregate/Consts/FulfillmentProgressCodes.cs b/src/Oms.Domain/OrdersAggregate/Consts/FulfillmentProgressCodes.cs
index 6bc3904..3836b4f 100644
--- a/src/Oms.Domain/OrdersAggregate/Consts/FulfillmentProgressCodes.cs
+++ b/src/Oms.Domain/OrdersAggregate/Consts/FulfillmentProgressCodes.cs
@@ -5,7 +5,9 @@ namespace Oms.Domain.OrdersAggregate.Consts;
///
public static class FulfillmentProgressCodes
{
- /// 待绑定包裹/库存。
+ ///
+ /// 历史兼容:仓内代发但无绑定明细。现网「创建代发必绑」,新单不应再落入此进度。
+ ///
public const string PendingBind = "pendingBind";
/// 国内快递在途,未到仓。
diff --git a/src/Oms.SqlSugarCore/Orders/OrderRepository.cs b/src/Oms.SqlSugarCore/Orders/OrderRepository.cs
index daf4ba9..929073f 100644
--- a/src/Oms.SqlSugarCore/Orders/OrderRepository.cs
+++ b/src/Oms.SqlSugarCore/Orders/OrderRepository.cs
@@ -1616,10 +1616,10 @@ public class OrderRepository : OmsSqlSugarRepository, IOrderRepository, I
return await query.CountAsync(cancellationToken);
}
+ // 创建代发必绑:进度聚合不再返回 pendingBind(筛选接口仍兼容该值)
var result = new Dictionary(StringComparer.OrdinalIgnoreCase)
{
["all"] = await CountAsync(null),
- [FulfillmentProgressCodes.PendingBind] = await CountAsync(FulfillmentProgressCodes.PendingBind),
[FulfillmentProgressCodes.DomesticInTransit] = await CountAsync(FulfillmentProgressCodes.DomesticInTransit),
[FulfillmentProgressCodes.ArrivedPendingPick] = await CountAsync(FulfillmentProgressCodes.ArrivedPendingPick),
[FulfillmentProgressCodes.OutboundDone] = await CountAsync(FulfillmentProgressCodes.OutboundDone),