From 0ec6730a563f34af64c794a9eeaabd2675944b65 Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Sat, 11 Nov 2023 11:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=9F=E8=B1=A1=E7=BB=9F=E8=AE=A1=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BA=97=E9=93=BA=E5=AE=9E=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Statistics/StatisticsBusiness.cs | 51 +++++++++++-------- .../Response/Order/XingXinagSearchResponse.cs | 17 +++---- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/BBWY.Server.Business/Statistics/StatisticsBusiness.cs b/BBWY.Server.Business/Statistics/StatisticsBusiness.cs index 8e5c9b8f..a99d7736 100644 --- a/BBWY.Server.Business/Statistics/StatisticsBusiness.cs +++ b/BBWY.Server.Business/Statistics/StatisticsBusiness.cs @@ -144,7 +144,8 @@ namespace BBWY.Server.Business return list; } - private void XingXiangCumulative(IList detailList, string spuId, bool isSD, decimal profit, decimal spuProductAmount, decimal sdProductAmount, decimal sdCost) + private void XingXiangCumulative(IList detailList, + string spuId, bool isSD, decimal profit, decimal actualAmount, decimal sdCost) { var xxRespose = detailList.FirstOrDefault(xx => xx.Spu == spuId); if (xxRespose == null) @@ -153,11 +154,11 @@ namespace BBWY.Server.Business detailList.Add(xxRespose); } xxRespose.Profit += profit; - xxRespose.ActualAmount += spuProductAmount; + xxRespose.ActualAmount += actualAmount; if (isSD) { xxRespose.SDOrderCount++; - xxRespose.SDOrderAmount += sdProductAmount; + xxRespose.SDOrderAmount += actualAmount; xxRespose.SDOrderCost += sdCost; } } @@ -207,6 +208,7 @@ namespace BBWY.Server.Business var spuIdList = orderSkuList.Select(osku => osku.ProductId).Distinct().ToList(); List spuGoiList = null; GOIByShop shopGoi = null; + #region spu goi { var httpResult = restApiService.SendRequest("http://snapi.qiyue666.com/", "Api/GOI/QueryPopularizeLevelGOIBySpuId", new @@ -246,45 +248,49 @@ namespace BBWY.Server.Business if (order.StorageType == Enums.StorageType.SD) { - XingXiangCumulative(detailList, currentOrderSkuList[0].ProductId, true, order.Profit ?? 0M, order.OrderSellerPrice, order.OrderSellerPrice + order.FreightPrice, Math.Abs(order.Profit ?? 0M)); + //XingXiangCumulative(detailList, currentOrderSkuList[0].ProductId, true, order.Profit ?? 0M, order.OrderSellerPrice, order.OrderSellerPrice + order.FreightPrice, Math.Abs(order.Profit ?? 0M)); + XingXiangCumulative(detailList, currentOrderSkuList[0].ProductId, true, order.Profit ?? 0M, order.OrderSellerPrice + order.FreightPrice, Math.Abs(order.Profit ?? 0M)); continue; } var currentOrderCostDetailList = orderCostDetailList.Where(ocd => ocd.OrderId == order.Id); var spuGroups = currentOrderSkuList.GroupBy(osku => osku.ProductId); - var tempOrderProdcutAmount = currentOrderSkuList.Sum(osku => osku.ItemTotal * osku.Price) ?? 0M; - var tempOrderCost = currentOrderCostDetailList.Count() > 0 ? currentOrderCostDetailList.Sum(ocd => ocd.TotalCost) : 0M; - var tempOrderProfit = tempOrderProdcutAmount - tempOrderCost; + //var tempOrderProdcutAmount = currentOrderSkuList.Sum(osku => osku.ItemTotal * osku.Price) ?? 0M; + //var tempOrderCost = currentOrderCostDetailList.Count() > 0 ? currentOrderCostDetailList.Sum(ocd => ocd.TotalCost) : 0M; + //var tempOrderProfit = tempOrderProdcutAmount - tempOrderCost; foreach (var spuGroup in spuGroups) { var currentSpuCostDetailList = currentOrderCostDetailList.Where(ocd => ocd.ProductId == spuGroup.Key); + var currentSkuOrderSkuList = currentOrderSkuList.Where(osku => osku.ProductId == spuGroup.Key); + + var totalActualAmount = currentSkuOrderSkuList.Sum(osku => osku.ShouldPay ?? 0M); + var totalProfit = currentSpuCostDetailList.Sum(ocd => ocd.SkuGrossProfit); - var tempSpuProductAmount = spuGroup.Sum(osku => osku.Price * osku.ItemTotal) ?? 0M; - var tempSpuCost = currentSpuCostDetailList.Count() > 0 ? currentSpuCostDetailList.Sum(ocd => ocd.TotalCost) : 0M; - var tempSpuProfit = tempSpuProductAmount - tempSpuCost; - var spuProfitPercent = tempOrderProfit == 0M ? 0M : tempSpuProfit / tempOrderProfit; + XingXiangCumulative(detailList, spuGroup.Key, false, totalProfit, totalActualAmount, 0); - var realSpuProfit = (order.Profit ?? 0M) * spuProfitPercent; - XingXiangCumulative(detailList, spuGroup.Key, false, realSpuProfit, tempSpuProductAmount, 0, 0); + //var tempSpuProductAmount = spuGroup.Sum(osku => osku.Price * osku.ItemTotal) ?? 0M; + //var tempSpuCost = currentSpuCostDetailList.Count() > 0 ? currentSpuCostDetailList.Sum(ocd => ocd.TotalCost) : 0M; + //var tempSpuProfit = tempSpuProductAmount - tempSpuCost; + //var spuProfitPercent = tempOrderProfit == 0M ? 0M : tempSpuProfit / tempOrderProfit; + + //var realSpuProfit = (order.Profit ?? 0M) * spuProfitPercent; + //XingXiangCumulative(detailList, spuGroup.Key, false, realSpuProfit, tempSpuProductAmount, 0, 0); } } - var shopProductAmount = orderSkuList.Sum(osku => osku.ItemTotal * osku.Price); + //var shopProductAmount = orderSkuList.Sum(osku => osku.ItemTotal * osku.Price); + var shopActualAmount = orderSkuList.Sum(osku => osku.ShouldPay ?? 0M); foreach (var d in detailList) { var spuGoi = spuGoiList?.FirstOrDefault(x => x.Spu == d.Spu); if (spuGoi != null) { - var productAmount = orderSkuList.Where(osku => osku.ProductId == d.Spu).Sum(osku => osku.ItemTotal * osku.Price); - d.SpuYingLiRatio = Math.Round((spuGoi.Profit - spuGoi.Cost) / productAmount.Value, 2); - //d.SpuYingLiRatio = Math.Round((d.Profit - spuGoi.Cost) / productAmount.Value, 2); + //var spuActualAmount = orderSkuList.Where(osku => osku.ProductId == d.Spu).Sum(osku => osku.ShouldPay ?? 0M); + d.SpuYingLiRatio = d.ActualAmount == 0 ? 0 : Math.Round((spuGoi.Profit - spuGoi.Cost) / d.ActualAmount, 2); } - - d.ShopYingLiRatio = shopProductAmount == 0 ? 0 : Math.Round((shopGoi.Profit - shopGoi.Cost) / shopProductAmount.Value, 2); - d.ShopProfitRatio = shopProductAmount == 0 ? 0 : Math.Round(shopGoi.Profit / shopProductAmount.Value, 2); } @@ -297,8 +303,9 @@ namespace BBWY.Server.Business TotalSDOrderCount = sdOrderList.Count(), TotalSDOrderCost = detailList.Sum(xx => xx.SDOrderCost), TotalProfit = detailList.Sum(xx => xx.Profit), - ShopYingLiRatio = detailList.FirstOrDefault()?.ShopYingLiRatio, - ShopProfitRatio = detailList.FirstOrDefault()?.ShopProfitRatio + ShopYingLiRatio = shopActualAmount == 0 ? 0 : Math.Round((shopGoi.Profit - shopGoi.Cost) / shopActualAmount, 2), + ShopProfitRatio = shopActualAmount == 0 ? 0 : Math.Round(shopGoi.Profit / shopActualAmount, 2), + ShopActualAmount = shopActualAmount }; } diff --git a/BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs b/BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs index 071513ef..bf08aee3 100644 --- a/BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs +++ b/BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs @@ -39,6 +39,11 @@ namespace BBWY.Server.Model.Dto /// 店铺盈利率 /// public decimal? ShopYingLiRatio { get; set; } + + /// + /// 店铺实收金额 + /// + public decimal ShopActualAmount { get; set; } } public class XingXiangItemResponse @@ -83,19 +88,11 @@ namespace BBWY.Server.Model.Dto /// public decimal SDOrderAmount { get; set; } - /// - /// 店铺毛利率 - /// - public decimal? ShopProfitRatio { get; set; } - - /// - /// 店铺盈利率 - /// - public decimal? ShopYingLiRatio { get; set; } - /// /// SPU盈利率 /// public decimal? SpuYingLiRatio { get; set; } + + } }