admin/src/Oms.Application/Services/Orders/ParcelBillingValidators.cs
zzh 89233bc3da feat: add customer marketing module (M1-M6 backend)
Implement referral, points, coupons, commission, member levels, and order integration with migration SQL and background jobs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-23 16:42:08 +08:00

65 lines
2.3 KiB
C#

namespace Oms.Application.Services.Orders;
using Fake.Application;
using Oms.Application.Shared;
using Oms.Domain.OrdersAggregate.Consts;
/// <summary>
/// 小包计费各环节共用的件重尺校验。
/// </summary>
internal static class ParcelBillingValidators
{
/// <summary>
/// 预报/入库/出库:长宽高与实重均须 &gt; 0。
/// </summary>
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");
}
}
/// <summary>
/// 查价:尺寸要么全空(按实重估算),要么三者齐全。
/// </summary>
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)}」,不允许入库收货");
}
}