Browse Source

星象统计增加店铺实收

AddValidOverTime
shanji 2 years ago
parent
commit
0ec6730a56
  1. 51
      BBWY.Server.Business/Statistics/StatisticsBusiness.cs
  2. 17
      BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs

51
BBWY.Server.Business/Statistics/StatisticsBusiness.cs

@ -144,7 +144,8 @@ namespace BBWY.Server.Business
return list;
}
private void XingXiangCumulative(IList<XingXiangItemResponse> detailList, string spuId, bool isSD, decimal profit, decimal spuProductAmount, decimal sdProductAmount, decimal sdCost)
private void XingXiangCumulative(IList<XingXiangItemResponse> 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<GOIBySpu> 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
};
}

17
BBWY.Server.Model/Dto/Response/Order/XingXinagSearchResponse.cs

@ -39,6 +39,11 @@ namespace BBWY.Server.Model.Dto
/// 店铺盈利率
/// </summary>
public decimal? ShopYingLiRatio { get; set; }
/// <summary>
/// 店铺实收金额
/// </summary>
public decimal ShopActualAmount { get; set; }
}
public class XingXiangItemResponse
@ -83,19 +88,11 @@ namespace BBWY.Server.Model.Dto
/// </summary>
public decimal SDOrderAmount { get; set; }
/// <summary>
/// 店铺毛利率
/// </summary>
public decimal? ShopProfitRatio { get; set; }
/// <summary>
/// 店铺盈利率
/// </summary>
public decimal? ShopYingLiRatio { get; set; }
/// <summary>
/// SPU盈利率
/// </summary>
public decimal? SpuYingLiRatio { get; set; }
}
}

Loading…
Cancel
Save