|
|
@ -4,12 +4,12 @@ using BBWYB.Common.Models; |
|
|
|
using BBWYB.Server.Business.Extensions; |
|
|
|
using BBWYB.Server.Business.JD; |
|
|
|
using BBWYB.Server.Model; |
|
|
|
using BBWYB.Server.Model.Core; |
|
|
|
using BBWYB.Server.Model.Db; |
|
|
|
using BBWYB.Server.Model.Db.Mds; |
|
|
|
using BBWYB.Server.Model.Db.MDS; |
|
|
|
using BBWYB.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using JD.Dto; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
@ -398,33 +398,59 @@ namespace BBWYB.Server.Business |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|
//采购单总件数,由于1688运费只存在订单层,sku层没有运费,所以需要以订单总件数为基础等比计算采购运费
|
|
|
|
var purchaseSkuTotalQuantity = purchaseOrderSimpleInfo.ItemList.Sum(x => x.Quantity); |
|
|
|
var belongSkuGroups = cargoParamGroup.CargoParamList.GroupBy(p => p.BelongSkuId); |
|
|
|
var belongSkuIdList = belongSkuGroups.Select(bsg => bsg.Key).ToList(); |
|
|
|
foreach (var belongSkuGroup in belongSkuGroups) |
|
|
|
////采购单总件数,由于1688运费只存在订单层,sku层没有运费,所以需要以订单总件数为基础等比计算采购运费
|
|
|
|
//var purchaseSkuTotalQuantity = purchaseOrderSimpleInfo.ItemList.Sum(x => x.Quantity);
|
|
|
|
//var belongSkuGroups = cargoParamGroup.CargoParamList.GroupBy(p => p.BelongSkuId);
|
|
|
|
//var belongSkuIdList = belongSkuGroups.Select(bsg => bsg.Key).ToList();
|
|
|
|
//foreach (var belongSkuGroup in belongSkuGroups)
|
|
|
|
//{
|
|
|
|
// var belongSkuId = belongSkuGroup.Key;
|
|
|
|
// //var currentOrderSkuCargoParamList = cargoParamGroup.CargoParamList.Where(p => p.BelongSkuId == belongSkuId); //找当前skuId的采购skuId
|
|
|
|
// var currentOrderSkuCargoParamList = belongSkuGroup.ToList();
|
|
|
|
// var currentSkuAmount = 0M; //采购成本
|
|
|
|
// var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
|
|
// var currentPurchaseFreight = purchaseOrderSimpleInfo.FreightAmount *
|
|
|
|
// (1.0M * currentSkuTotalPurchaseQuantity / purchaseSkuTotalQuantity); //采购运费
|
|
|
|
|
|
|
|
// foreach (var currentOrderSkuCargo in currentOrderSkuCargoParamList)
|
|
|
|
// {
|
|
|
|
// var currentPurchaseSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId)
|
|
|
|
// .Sum(p => p.ProductAmount);
|
|
|
|
// var currentPurchaseSkuTotalQuantity = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId)
|
|
|
|
// .Sum(p => p.Quantity);
|
|
|
|
|
|
|
|
// currentSkuAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity / currentPurchaseSkuTotalQuantity);
|
|
|
|
// //currentPurchaseFreight += purchaseOrderSimpleInfo.FreightAmount * (1.0M * currentOrderSkuCargo.Quantity / purchaseSkuTotalQuantity);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #region 成本明细
|
|
|
|
// var orderSku = orderSkus.FirstOrDefault(osku => osku.SkuId == belongSkuId);
|
|
|
|
// var orderCostDetail = new OrderCostDetail()
|
|
|
|
// {
|
|
|
|
// Id = idGenerator.NewLong(),
|
|
|
|
// CreateTime = DateTime.Now,
|
|
|
|
// DeductionQuantity = orderSku.ItemTotal.Value,
|
|
|
|
// OrderId = request.OrderId,
|
|
|
|
// ProductId = orderSku.ProductId,
|
|
|
|
// PurchaseOrderId = purchaseOrderSimpleInfo.OrderId,
|
|
|
|
// SkuId = belongSkuId,
|
|
|
|
// IsEnabled = true
|
|
|
|
// };
|
|
|
|
// orderCostDetail.CalculationOrderCostDetailCostAndProfit(currentSkuAmount,
|
|
|
|
// currentPurchaseFreight,
|
|
|
|
// 0M,
|
|
|
|
// 0M);
|
|
|
|
// insertOrderCostDetails.Add(orderCostDetail);
|
|
|
|
// #endregion
|
|
|
|
//}
|
|
|
|
#region 等比计算采购成本
|
|
|
|
var proportionalCalculationResultList = ProportionalCalculationCost(cargoParamGroup.CargoParamList, purchaseOrderSimpleInfo); |
|
|
|
foreach (var proportionalCalculationResult in proportionalCalculationResultList) |
|
|
|
{ |
|
|
|
var belongSkuId = belongSkuGroup.Key; |
|
|
|
var currentOrderSkuCargoParamList = cargoParamGroup.CargoParamList.Where(p => p.BelongSkuId == belongSkuId); //找当前skuId的采购skuId
|
|
|
|
|
|
|
|
var currentSkuAmount = 0M; //采购成本
|
|
|
|
var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
|
|
var currentPurchaseFreight = purchaseOrderSimpleInfo.FreightAmount * |
|
|
|
(1.0M * currentSkuTotalPurchaseQuantity / purchaseSkuTotalQuantity); //采购运费
|
|
|
|
|
|
|
|
foreach (var currentOrderSkuCargo in currentOrderSkuCargoParamList) |
|
|
|
{ |
|
|
|
var currentPurchaseSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId) |
|
|
|
.Sum(p => p.ProductAmount); |
|
|
|
var currentPurchaseSkuTotalQuantity = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId) |
|
|
|
.Sum(p => p.Quantity); |
|
|
|
var skuId = proportionalCalculationResult.SkuId; |
|
|
|
|
|
|
|
currentSkuAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity / currentPurchaseSkuTotalQuantity); |
|
|
|
//currentPurchaseFreight += purchaseOrderSimpleInfo.FreightAmount * (1.0M * currentOrderSkuCargo.Quantity / purchaseSkuTotalQuantity);
|
|
|
|
} |
|
|
|
|
|
|
|
#region 成本明细
|
|
|
|
var orderSku = orderSkus.FirstOrDefault(osku => osku.SkuId == belongSkuId); |
|
|
|
var orderSku = orderSkus.FirstOrDefault(osku => osku.SkuId == skuId); |
|
|
|
var orderCostDetail = new OrderCostDetail() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
@ -433,18 +459,19 @@ namespace BBWYB.Server.Business |
|
|
|
OrderId = request.OrderId, |
|
|
|
ProductId = orderSku.ProductId, |
|
|
|
PurchaseOrderId = purchaseOrderSimpleInfo.OrderId, |
|
|
|
SkuId = belongSkuId, |
|
|
|
SkuId = skuId, |
|
|
|
IsEnabled = true |
|
|
|
}; |
|
|
|
orderCostDetail.CalculationOrderCostDetailCostAndProfit(currentSkuAmount, |
|
|
|
currentPurchaseFreight, |
|
|
|
orderCostDetail.CalculationOrderCostDetailCostAndProfit(proportionalCalculationResult.ProductAmount, |
|
|
|
proportionalCalculationResult.FreightAmount, |
|
|
|
0M, |
|
|
|
0M); |
|
|
|
insertOrderCostDetails.Add(orderCostDetail); |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 采购订单信息
|
|
|
|
var belongSkuIdList = cargoParamGroup.CargoParamList.Select(c => c.BelongSkuId).Distinct().ToList(); |
|
|
|
var orderPurchaserInfo = new OrderPurchaseInfo() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
@ -1190,32 +1217,54 @@ namespace BBWYB.Server.Business |
|
|
|
|
|
|
|
if (cargoParamList.Count() == 0) |
|
|
|
throw new BusinessException("未匹配到采购方案"); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 等比计算采购成本
|
|
|
|
var assocationOrderCostDetailList = new List<AssocationOrderCostDetailResponse>(); |
|
|
|
var belongSkuGroups = cargoParamList.GroupBy(p => p.BelongSkuId); |
|
|
|
var purchaseSkuTotalQuantity = cargoParamList.Sum(x => x.Quantity); |
|
|
|
foreach (var belongSkuGroup in belongSkuGroups) |
|
|
|
//var belongSkuGroups = cargoParamList.GroupBy(p => p.BelongSkuId);
|
|
|
|
//var purchaseSkuTotalQuantity = cargoParamList.Sum(x => x.Quantity);
|
|
|
|
//foreach (var belongSkuGroup in belongSkuGroups)
|
|
|
|
//{
|
|
|
|
// var skuId = belongSkuGroup.Key;
|
|
|
|
// //var currentOrderSkuCargoParamList = cargoParamList.Where(p => p.BelongSkuId == skuId); //找当前skuId的采购skuId
|
|
|
|
// var currentOrderSkuCargoParamList = belongSkuGroup.ToList(); //找当前skuId的采购skuId
|
|
|
|
|
|
|
|
// var currentSkuAmount = 0M; //采购成本
|
|
|
|
// var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
|
|
// var currentPurchaseFreight = purchaseOrderSimpleInfo.FreightAmount *
|
|
|
|
// (1.0M * currentSkuTotalPurchaseQuantity / purchaseSkuTotalQuantity); //采购运费
|
|
|
|
|
|
|
|
// foreach (var currentOrderSkuCargo in currentOrderSkuCargoParamList)
|
|
|
|
// {
|
|
|
|
// var currentPurchaseSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId)
|
|
|
|
// .Sum(p => p.ProductAmount);
|
|
|
|
|
|
|
|
// var currentPurchaseSkuTotalQuantity = cargoParamList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId)
|
|
|
|
// .Sum(p => p.Quantity);
|
|
|
|
|
|
|
|
// currentSkuAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity / currentPurchaseSkuTotalQuantity);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var orderSku = dbOrderSkuList.FirstOrDefault(osku => osku.SkuId == skuId);
|
|
|
|
// var assocationOrderCostDetail = new AssocationOrderCostDetailResponse()
|
|
|
|
// {
|
|
|
|
// Logo = orderSku.Logo,
|
|
|
|
// Title = orderSku.Title,
|
|
|
|
// SkuId = skuId,
|
|
|
|
// OrderId = orderSku.OrderId,
|
|
|
|
// SkuAmount = currentSkuAmount,
|
|
|
|
// PurchaseQuantity = orderSku.ItemTotal.Value,
|
|
|
|
// PurchaseFreight = currentPurchaseFreight
|
|
|
|
// };
|
|
|
|
// assocationOrderCostDetail.PurchasePrice = assocationOrderCostDetail.SkuAmount / assocationOrderCostDetail.PurchaseQuantity;
|
|
|
|
// assocationOrderCostDetailList.Add(assocationOrderCostDetail);
|
|
|
|
//}
|
|
|
|
|
|
|
|
var proportionalCalculationResultList = ProportionalCalculationCost(cargoParamList, purchaseOrderSimpleInfo); |
|
|
|
foreach (var proportionalCalculationResult in proportionalCalculationResultList) |
|
|
|
{ |
|
|
|
var skuId = belongSkuGroup.Key; |
|
|
|
var currentOrderSkuCargoParamList = cargoParamList.Where(p => p.BelongSkuId == skuId); //找当前skuId的采购skuId
|
|
|
|
|
|
|
|
var currentSkuAmount = 0M; //采购成本
|
|
|
|
var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
|
|
var currentPurchaseFreight = purchaseOrderSimpleInfo.FreightAmount * |
|
|
|
(1.0M * currentSkuTotalPurchaseQuantity / purchaseSkuTotalQuantity); //采购运费
|
|
|
|
|
|
|
|
foreach (var currentOrderSkuCargo in currentOrderSkuCargoParamList) |
|
|
|
{ |
|
|
|
var currentPurchaseSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId) |
|
|
|
.Sum(p => p.ProductAmount); |
|
|
|
|
|
|
|
var currentPurchaseSkuTotalQuantity = cargoParamList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId) |
|
|
|
.Sum(p => p.Quantity); |
|
|
|
|
|
|
|
currentSkuAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity / currentPurchaseSkuTotalQuantity); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var skuId = proportionalCalculationResult.SkuId; |
|
|
|
var orderSku = dbOrderSkuList.FirstOrDefault(osku => osku.SkuId == skuId); |
|
|
|
var assocationOrderCostDetail = new AssocationOrderCostDetailResponse() |
|
|
|
{ |
|
|
@ -1223,17 +1272,17 @@ namespace BBWYB.Server.Business |
|
|
|
Title = orderSku.Title, |
|
|
|
SkuId = skuId, |
|
|
|
OrderId = orderSku.OrderId, |
|
|
|
SkuAmount = currentSkuAmount, |
|
|
|
SkuAmount = proportionalCalculationResult.ProductAmount, |
|
|
|
PurchaseQuantity = orderSku.ItemTotal.Value, |
|
|
|
PurchaseFreight = currentPurchaseFreight |
|
|
|
PurchaseFreight = proportionalCalculationResult.FreightAmount |
|
|
|
}; |
|
|
|
assocationOrderCostDetail.PurchasePrice = assocationOrderCostDetail.SkuAmount / assocationOrderCostDetail.PurchaseQuantity; |
|
|
|
assocationOrderCostDetailList.Add(assocationOrderCostDetail); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
if (assocationOrderCostDetailList.Count() == 0) |
|
|
|
throw new BusinessException("没有匹配到合适的采购方案"); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
return new AssociationPurchaseOrderResponse(assocationOrderCostDetailList) |
|
|
|
{ |
|
|
@ -2779,34 +2828,27 @@ namespace BBWYB.Server.Business |
|
|
|
|
|
|
|
totalPurchaseProductAmount += purchaseOrderSimpleInfo.ProductAmount; |
|
|
|
totalPurchaseFreight += purchaseOrderSimpleInfo.FreightAmount; |
|
|
|
|
|
|
|
var purchaseSkuTotalQuantity = purchaseOrderSimpleInfo.ItemList.Sum(x => x.Quantity); |
|
|
|
var currentPurchaseOrderRelationInfos = dbOrderPurchaseRelationInfos.Where(x => x.PurchaseOrderId == opi.PurchaseOrderId).ToList(); |
|
|
|
|
|
|
|
var belongSkuGroups = currentPurchaseOrderRelationInfos.GroupBy(p => p.BelongSkuId); |
|
|
|
foreach (var belongSkuGroup in belongSkuGroups) |
|
|
|
var cargoParamList = currentPurchaseOrderRelationInfos.Select(x => new CargoParamRequest() |
|
|
|
{ |
|
|
|
var belongSkuId = belongSkuGroup.Key; |
|
|
|
|
|
|
|
var currentOrderSkuCargoParamList = belongSkuGroup.ToList(); //找当前skuId的采购skuId
|
|
|
|
var currentOrderSkuProductAmount = 0M; //采购成本
|
|
|
|
var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
|
|
var currentPurchaseFreight = purchaseOrderSimpleInfo.FreightAmount * |
|
|
|
(1.0M * currentSkuTotalPurchaseQuantity / purchaseSkuTotalQuantity); //采购运费
|
|
|
|
|
|
|
|
foreach (var currentOrderSkuCargo in currentOrderSkuCargoParamList) |
|
|
|
{ |
|
|
|
var currentPurchaseSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.PurchaseSkuId) |
|
|
|
.Sum(p => p.ProductAmount); |
|
|
|
var currentPurchaseSkuTotalQuantity = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.PurchaseSkuId) |
|
|
|
.Sum(p => p.Quantity); |
|
|
|
currentOrderSkuProductAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity.Value / currentPurchaseSkuTotalQuantity); |
|
|
|
} |
|
|
|
SkuId = x.PurchaseSkuId, |
|
|
|
BelongSkuId = x.BelongSkuId, |
|
|
|
ProductId = x.PurchaseProductId, |
|
|
|
Quantity = x.Quantity ?? 1, |
|
|
|
SpecId = x.PurchaseSpecId, |
|
|
|
SchemeId = x.SchemeId.Value |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
#region 等比计算采购成本
|
|
|
|
var proportionalCalculationResultList = ProportionalCalculationCost(cargoParamList, purchaseOrderSimpleInfo); |
|
|
|
foreach (var proportionalCalculationResult in proportionalCalculationResultList) |
|
|
|
{ |
|
|
|
var skuId = proportionalCalculationResult.SkuId; |
|
|
|
|
|
|
|
#region 订单sku平价
|
|
|
|
var orderSku = dbOrderSkus.FirstOrDefault(osku => osku.SkuId == belongSkuId); |
|
|
|
if (isEditOrderPrice) |
|
|
|
{ |
|
|
|
var orderSku = dbOrderSkus.FirstOrDefault(osku => osku.SkuId == skuId); |
|
|
|
if (!oskuPriceEditParamDictionary.TryGetValue(orderSku.SkuId, out OP_EditPriceSkuRequest editSkuPrice)) |
|
|
|
{ |
|
|
|
editSkuPrice = new OP_EditPriceSkuRequest() |
|
|
@ -2817,35 +2859,87 @@ namespace BBWYB.Server.Business |
|
|
|
}; |
|
|
|
oskuPriceEditParamDictionary.Add(orderSku.SkuId, editSkuPrice); |
|
|
|
} |
|
|
|
editSkuPrice.Price += currentOrderSkuProductAmount / (orderSku.ItemTotal ?? 1M); |
|
|
|
editSkuPrice.Freight += currentPurchaseFreight ?? 0M; |
|
|
|
|
|
|
|
//orderSku.Price =
|
|
|
|
//orderSku.BuyerPayFreight = currentPurchaseFreight;
|
|
|
|
//if (!op_EditPriceSkuRequests.Any(x => x.SkuId == orderSku.SkuId))
|
|
|
|
//{
|
|
|
|
// op_EditPriceSkuRequests.Add(new OP_EditPriceSkuRequest()
|
|
|
|
// {
|
|
|
|
// Freight = currentPurchaseFreight ?? 0M,
|
|
|
|
// InPackAmountPrice = orderSku.InPackAmount ?? 0M,
|
|
|
|
// OrderSkuId = orderSku.Id.ToString(),
|
|
|
|
// Price = orderSku.Price ?? 0M,
|
|
|
|
// SkuId = orderSku.SkuId
|
|
|
|
// });
|
|
|
|
// updateOrderSkuList.Add(fsql.Update<OrderSku>(orderSku.Id).Set(osku => osku.Price, orderSku.Price)
|
|
|
|
// .Set(osku => osku.BuyerPayFreight, orderSku.BuyerPayFreight));
|
|
|
|
//}
|
|
|
|
|
|
|
|
editSkuPrice.Price += proportionalCalculationResult.ProductAmount / (orderSku.ItemTotal ?? 1M); |
|
|
|
editSkuPrice.Freight += proportionalCalculationResult.FreightAmount; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
var dbOrderSkuDetail = dbOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == belongSkuId && ocd.PurchaseOrderId == opi.PurchaseOrderId); |
|
|
|
dbOrderSkuDetail.CalculationOrderCostDetailCostAndProfit(currentOrderSkuProductAmount, |
|
|
|
currentPurchaseFreight ?? 0M, |
|
|
|
#region 更新sku成本明细
|
|
|
|
var dbOrderSkuDetail = dbOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == skuId && ocd.PurchaseOrderId == opi.PurchaseOrderId); |
|
|
|
dbOrderSkuDetail.CalculationOrderCostDetailCostAndProfit(proportionalCalculationResult.ProductAmount, |
|
|
|
proportionalCalculationResult.FreightAmount, |
|
|
|
dbOrderSkuDetail.OutPackAmount ?? 0M, |
|
|
|
dbOrderSkuDetail.DeliveryExpressFreight ?? 0M); |
|
|
|
updateOrderCostDetailList.Add(fsql.Update<OrderCostDetail>().SetSource(dbOrderSkuDetail)); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
//var purchaseSkuTotalQuantity = purchaseOrderSimpleInfo.ItemList.Sum(x => x.Quantity);
|
|
|
|
//var belongSkuGroups = currentPurchaseOrderRelationInfos.GroupBy(p => p.BelongSkuId);
|
|
|
|
//foreach (var belongSkuGroup in belongSkuGroups)
|
|
|
|
//{
|
|
|
|
// var belongSkuId = belongSkuGroup.Key;
|
|
|
|
|
|
|
|
// var currentOrderSkuCargoParamList = belongSkuGroup.ToList(); //找当前skuId的采购skuId
|
|
|
|
// var currentOrderSkuProductAmount = 0M; //采购成本
|
|
|
|
// var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
|
|
// var currentPurchaseFreight = purchaseOrderSimpleInfo.FreightAmount *
|
|
|
|
// (1.0M * currentSkuTotalPurchaseQuantity / purchaseSkuTotalQuantity); //采购运费
|
|
|
|
|
|
|
|
// foreach (var currentOrderSkuCargo in currentOrderSkuCargoParamList)
|
|
|
|
// {
|
|
|
|
// var currentPurchaseSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.PurchaseSkuId)
|
|
|
|
// .Sum(p => p.ProductAmount);
|
|
|
|
// var currentPurchaseSkuTotalQuantity = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.PurchaseSkuId)
|
|
|
|
// .Sum(p => p.Quantity);
|
|
|
|
// currentOrderSkuProductAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity.Value / currentPurchaseSkuTotalQuantity);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #region 订单sku平价
|
|
|
|
// var orderSku = dbOrderSkus.FirstOrDefault(osku => osku.SkuId == belongSkuId);
|
|
|
|
// if (isEditOrderPrice)
|
|
|
|
// {
|
|
|
|
// if (!oskuPriceEditParamDictionary.TryGetValue(orderSku.SkuId, out OP_EditPriceSkuRequest editSkuPrice))
|
|
|
|
// {
|
|
|
|
// editSkuPrice = new OP_EditPriceSkuRequest()
|
|
|
|
// {
|
|
|
|
// SkuId = orderSku.SkuId,
|
|
|
|
// OrderSkuId = orderSku.Id.ToString(),
|
|
|
|
// InPackAmountPrice = orderSku.InPackAmount ?? 0M
|
|
|
|
// };
|
|
|
|
// oskuPriceEditParamDictionary.Add(orderSku.SkuId, editSkuPrice);
|
|
|
|
// }
|
|
|
|
// editSkuPrice.Price += currentOrderSkuProductAmount / (orderSku.ItemTotal ?? 1M);
|
|
|
|
// editSkuPrice.Freight += currentPurchaseFreight ?? 0M;
|
|
|
|
|
|
|
|
// //orderSku.Price =
|
|
|
|
// //orderSku.BuyerPayFreight = currentPurchaseFreight;
|
|
|
|
// //if (!op_EditPriceSkuRequests.Any(x => x.SkuId == orderSku.SkuId))
|
|
|
|
// //{
|
|
|
|
// // op_EditPriceSkuRequests.Add(new OP_EditPriceSkuRequest()
|
|
|
|
// // {
|
|
|
|
// // Freight = currentPurchaseFreight ?? 0M,
|
|
|
|
// // InPackAmountPrice = orderSku.InPackAmount ?? 0M,
|
|
|
|
// // OrderSkuId = orderSku.Id.ToString(),
|
|
|
|
// // Price = orderSku.Price ?? 0M,
|
|
|
|
// // SkuId = orderSku.SkuId
|
|
|
|
// // });
|
|
|
|
// // updateOrderSkuList.Add(fsql.Update<OrderSku>(orderSku.Id).Set(osku => osku.Price, orderSku.Price)
|
|
|
|
// // .Set(osku => osku.BuyerPayFreight, orderSku.BuyerPayFreight));
|
|
|
|
// //}
|
|
|
|
|
|
|
|
// }
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
// var dbOrderSkuDetail = dbOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == belongSkuId && ocd.PurchaseOrderId == opi.PurchaseOrderId);
|
|
|
|
// dbOrderSkuDetail.CalculationOrderCostDetailCostAndProfit(currentOrderSkuProductAmount,
|
|
|
|
// currentPurchaseFreight ?? 0M,
|
|
|
|
// dbOrderSkuDetail.OutPackAmount ?? 0M,
|
|
|
|
// dbOrderSkuDetail.DeliveryExpressFreight ?? 0M);
|
|
|
|
// updateOrderCostDetailList.Add(fsql.Update<OrderCostDetail>().SetSource(dbOrderSkuDetail));
|
|
|
|
//}
|
|
|
|
} |
|
|
|
|
|
|
|
if (isEditOrderPrice) |
|
|
@ -3040,5 +3134,47 @@ namespace BBWYB.Server.Business |
|
|
|
} |
|
|
|
return cargoParamList; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 等比计算sku采购成本
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="cargoParamList"></param>
|
|
|
|
/// <param name="purchaseOrderSimpleInfo"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private IList<ProportionalCalculationCostResult> ProportionalCalculationCost(IList<CargoParamRequest> cargoParamList, |
|
|
|
PP_QueryOrderDetailResponse purchaseOrderSimpleInfo) |
|
|
|
{ |
|
|
|
var list = new List<ProportionalCalculationCostResult>(); |
|
|
|
var belongSkuGroups = cargoParamList.GroupBy(p => p.BelongSkuId); |
|
|
|
var purchaseSkuTotalQuantity = cargoParamList.Sum(x => x.Quantity); |
|
|
|
foreach (var belongSkuGroup in belongSkuGroups) |
|
|
|
{ |
|
|
|
var skuId = belongSkuGroup.Key; |
|
|
|
//var currentOrderSkuCargoParamList = cargoParamList.Where(p => p.BelongSkuId == skuId); //找当前skuId的采购skuId
|
|
|
|
var currentOrderSkuCargoParamList = belongSkuGroup.ToList(); //找当前skuId的采购skuId
|
|
|
|
|
|
|
|
var currentSkuAmount = 0M; //采购成本
|
|
|
|
var currentSkuTotalPurchaseQuantity = currentOrderSkuCargoParamList.Sum(x => x.Quantity); //当前skuId的采购数量总和
|
|
|
|
var currentPurchaseFreight = purchaseOrderSimpleInfo.FreightAmount * |
|
|
|
(1.0M * currentSkuTotalPurchaseQuantity / purchaseSkuTotalQuantity); //采购运费
|
|
|
|
|
|
|
|
foreach (var currentOrderSkuCargo in currentOrderSkuCargoParamList) |
|
|
|
{ |
|
|
|
var currentPurchaseSkuProductAmount = purchaseOrderSimpleInfo.ItemList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId) |
|
|
|
.Sum(p => p.ProductAmount); |
|
|
|
|
|
|
|
var currentPurchaseSkuTotalQuantity = cargoParamList.Where(p => p.SkuId == currentOrderSkuCargo.SkuId) |
|
|
|
.Sum(p => p.Quantity); |
|
|
|
|
|
|
|
currentSkuAmount += currentPurchaseSkuProductAmount * (1.0M * currentOrderSkuCargo.Quantity / currentPurchaseSkuTotalQuantity); |
|
|
|
} |
|
|
|
list.Add(new ProportionalCalculationCostResult() |
|
|
|
{ |
|
|
|
SkuId = skuId, |
|
|
|
FreightAmount = currentPurchaseFreight, |
|
|
|
ProductAmount = currentSkuAmount |
|
|
|
}); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|