namespace Oms.Application.Services.Orders; using Fake.Application; using Oms.Application.Shared; using Oms.Domain.OrdersAggregate.Consts; /// /// 小包计费各环节共用的件重尺校验。 /// internal static class ParcelBillingValidators { /// /// 预报/入库/出库:长宽高与实重均须 > 0。 /// public static void EnsurePositiveDimensions( decimal? length, decimal? width, decimal? height, decimal? actualWeight, string stageLabel) { if (!length.HasValue || !width.HasValue || !height.HasValue || !actualWeight.HasValue || length <= 0 || width <= 0 || height <= 0 || actualWeight <= 0) { throw new BusinessException($"{stageLabel}实重与长宽高不能为空且须大于 0"); } } /// /// 查价:尺寸要么全空(按实重估算),要么三者齐全。 /// public static void EnsurePriceCheckDimensions( decimal? length, decimal? width, decimal? height) { var hasPartial = length is > 0 || width is > 0 || height is > 0; var hasFull = length is > 0 && width is > 0 && height is > 0; if (hasPartial && !hasFull) { throw new BusinessException("尺寸请填写完整的长、宽、高,或全部留空按实重估算"); } } public static bool HasFullDimensions(decimal? length, decimal? width, decimal? height) => length is > 0 && width is > 0 && height is > 0; public static void EnsureInboundOrderStatus(string? orderStatus) { if (orderStatus is OrderStatusCodes.Predeclared or OrderStatusCodes.PendingAllocation) { return; } if (orderStatus is OrderStatusCodes.PendingPayment or OrderStatusCodes.PendingShip or OrderStatusCodes.PendingOnline or OrderStatusCodes.Shipping or OrderStatusCodes.DeliverySuccess or OrderStatusCodes.DeliveryFailed) { throw new BusinessException("订单已入库,无需重复收货"); } throw new BusinessException($"订单状态为「{OmsDocHelper.GetOrderStatusName(orderStatus ?? string.Empty)}」,不允许入库收货"); } }