diff --git a/BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs b/BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs index 75248b4..6b7f948 100644 --- a/BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs +++ b/BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs @@ -255,6 +255,23 @@ namespace BBWYB.Server.Business var isRepurchase = fsql.Select(dbOrder.Id).Any(); var orderSkus = fsql.Select().Where(osku => osku.OrderId == request.OrderId).ToList(); var orderPurchaseInfoList = fsql.Select().Where(opi => opi.OrderId == request.OrderId && opi.IsEnabled == true).ToList(); + var orderCostDetailList = fsql.Select().Where(ocd => ocd.OrderId == request.OrderId && ocd.IsEnabled == true).ToList(); + + foreach (var cargoParamGroup in request.CargoParamGroupList) + { + var purchaseOrder = orderPurchaseInfoList.FirstOrDefault(opi => opi.PurchaserId == cargoParamGroup.PurchaserId); + if (purchaseOrder != null) + { + foreach (var cargoParam in cargoParamGroup.CargoParamList) + { + if (purchaseOrder.BelongSkuIds.Contains(cargoParam.BelongSkuId)) + { + //throw new BusinessException($"订单sku[{cargoParam.BelongSkuId}]已经存在同一个商家[{cargoParamGroup.PurchaserId}][{cargoParamGroup.PurchaserName}]的另一笔采购单中[{purchaseOrder.PurchaseOrderId}],请不要为同一笔订单sku进行同商家采购"); + throw new BusinessException($"提示:请勿为同一个订单中的sku重复向同一个商家下采购单\r\n重复信息:\r\n- 订单sku:{cargoParam.BelongSkuId}\r\n- 商家:{cargoParamGroup.PurchaserName}"); + } + } + } + } var extJArray = JsonConvert.DeserializeObject(request.Extensions); @@ -279,8 +296,8 @@ namespace BBWYB.Server.Business IInsert insertOrderCost = null; IUpdate updateOrderCost = null; - var totalPurchaseProductAmount = 0M; - var totalPurchaseFreight = 0M; + //var totalPurchaseProductAmount = 0M; + //var totalPurchaseFreight = 0M; foreach (var cargoParamGroup in request.CargoParamGroupList) { @@ -326,8 +343,8 @@ namespace BBWYB.Server.Business OrderId = createOrderResponse.OrderId }); - totalPurchaseProductAmount += purchaseOrderSimpleInfo.ProductAmount; - totalPurchaseFreight += purchaseOrderSimpleInfo.FreightAmount; + //totalPurchaseProductAmount += purchaseOrderSimpleInfo.ProductAmount; + //totalPurchaseFreight += purchaseOrderSimpleInfo.FreightAmount; foreach (var cargoParam in cargoParamGroup.CargoParamList) { @@ -478,9 +495,12 @@ namespace BBWYB.Server.Business CreateTime = DateTime.Now, IsManualEdited = false }; + + var totalPurchaseProductAmount = orderCostDetailList.Union(insertOrderCostDetails).Sum(ocd => ocd.SkuAmount); + var totalPurchaseFreight = orderCostDetailList.Union(insertOrderCostDetails).Sum(ocd => ocd.PurchaseFreight); orderCost.CalculationOrderCostCostAndProfit(dbOrder.OrderTotalPrice.Value, - totalPurchaseProductAmount, - totalPurchaseFreight, + totalPurchaseProductAmount ?? 0M, + totalPurchaseFreight ?? 0M, 0M, 0M);