利润统计 功能开放
统计页面增加新的统计功能
This commit is contained in:
1 parent
f12a7f14ea
commit
d25374956e
10 files changed
+571
-323
No files matched your search
@@ -92,30 +92,39 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
|
||||
public static bool IsRefunded(ShopRevenueStatisticsRow row)
|
||||
{
|
||||
if (row == null) return false;
|
||||
return row.RefundStatus == 4 || row.RefundStatus == 11 || row.Status == StatusCancelAfterAfterSale;
|
||||
return row.RefundStatus > 1 || row.RefundStatusString == "MERCHANT_REFUND_SUCCESS" || row.RefundStatusString == "MERCHANT_RETURN_SUCCESS";
|
||||
}
|
||||
|
||||
/// <summary>是否有效订单(已付款且未退款)</summary>
|
||||
public static bool IsValidOrder(ShopRevenueStatisticsRow row)
|
||||
{
|
||||
return IsPaidOrder(row) && !IsRefunded(row);
|
||||
return !IsRefunded(row);
|
||||
}
|
||||
/// <summary>买手号退款成功</summary>
|
||||
public static bool IsBuyerRefundSuccessful(ShopRevenueStatisticsRow row)
|
||||
{
|
||||
return row.BuyerRefundStatus == "退款成功";
|
||||
}
|
||||
|
||||
/// <summary>汇总卡片</summary>
|
||||
public static ShopRevenueSummary GetSummary(IEnumerable<ShopRevenueStatisticsRow> rows)
|
||||
{
|
||||
var list = (rows ?? new List<ShopRevenueStatisticsRow>()).ToList();
|
||||
var list = (rows ?? new List<ShopRevenueStatisticsRow>()).Where(a => a.OutAmount > 0).ToList(); //买手付钱后的订单数量
|
||||
var valid = list.Where(IsValidOrder).ToList();
|
||||
var refunded = list.Where(IsRefunded).ToList();
|
||||
|
||||
decimal salesAmount = valid.Sum(r => (decimal)(r.OrderPrice)) / 100m;
|
||||
decimal profit = valid.Sum(r => (decimal)(r.Profit )) / 100m;
|
||||
decimal salesAmount = list.Sum(r => (decimal)(r.OrderPrice)) / 100m;
|
||||
decimal profit = valid.Concat(refunded).Sum(r => (decimal)(r.Profit)) / 100m;
|
||||
decimal refundAmount = refunded.Sum(r => (decimal)(r.OrderPrice)) / 100m;
|
||||
decimal platformFeeTotal = valid.Sum(r => (decimal)(r.PredictCommissionFee)) / 100m;
|
||||
decimal commission = valid.Sum(r => (decimal)(r.CommissionAmount)) / 100m;
|
||||
decimal purchaseAmount = valid.Sum(r => (decimal)(r.PurchasePrice)) / 100m;
|
||||
decimal purchaseAmount = valid.Sum(r => (decimal)(r.OutAmount)) / 100m;
|
||||
decimal buyerPaymentAmount = list.Sum(r => (decimal)(r.OutAmount)) / 100m; //买手号付款金额(采购金额)
|
||||
decimal buyerRefundAmount = refunded.Sum(r => (decimal)(r.OutAmount)) / 100m; //买手号退款金额(采购退款金额)
|
||||
decimal buyerRefundSuccessedAmount = refunded.Where(IsBuyerRefundSuccessful).Sum(r => (decimal)(r.BuyerRefundAmount)) / 100m; //买手号退款成功金额
|
||||
|
||||
int validOrderCount = valid.Select(r => r.OrderId).Distinct().Count();
|
||||
// 总订单数(退款率分母)= 已付款订单 + 已退款订单(含售后取消 200),不含未付款的 10/250
|
||||
|
||||
// 总订单数(退款率分母)= 已付款订单 + 已退款订单,不含未付款的 10/250
|
||||
int totalOrderCount = list.Where(r => IsPaidOrder(r) || IsRefunded(r)).Select(r => r.OrderId).Distinct().Count();
|
||||
int refundOrderCount = refunded.Select(r => r.OrderId).Distinct().Count();
|
||||
|
||||
@@ -125,12 +134,15 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
|
||||
ValidOrderCount = validOrderCount,
|
||||
Profit = profit,
|
||||
RefundAmount = refundAmount,
|
||||
ProductSalesVolume = valid.Count,
|
||||
RefundOrderCount = refundOrderCount,
|
||||
PlatformFeeTotal = platformFeeTotal,
|
||||
Commission = commission,
|
||||
AvgOrderAmount = validOrderCount == 0 ? 0m : salesAmount / validOrderCount,
|
||||
RefundRate = totalOrderCount == 0 ? 0m : (decimal)refundOrderCount * 100m / totalOrderCount,
|
||||
AverageProfitRate = purchaseAmount == 0m ? 0m : profit / purchaseAmount * 100m
|
||||
AverageProfitRate = purchaseAmount == 0m ? 0m : profit / purchaseAmount * 100m,
|
||||
BuyerPaymentAmount = buyerPaymentAmount,
|
||||
BuyerRefundAmount = buyerRefundAmount,
|
||||
BuyerRefundSuccessedAmount = buyerRefundSuccessedAmount,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -164,14 +176,14 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
|
||||
public static List<ShopSalesProportionItem> GetShopSalesProportion(IEnumerable<ShopRevenueStatisticsRow> rows)
|
||||
{
|
||||
var list = (rows ?? new List<ShopRevenueStatisticsRow>()).Where(IsValidOrder).ToList();
|
||||
decimal total = list.Sum(r => (decimal)(r.OrderPrice )) / 100m;
|
||||
decimal total = list.Sum(r => (decimal)(r.OrderPrice)) / 100m;
|
||||
|
||||
return list
|
||||
.GroupBy(r => r.ShopName)
|
||||
.Select(g => new ShopSalesProportionItem
|
||||
{
|
||||
ShopName = string.IsNullOrEmpty(g.Key) ? "未知店铺" : g.Key,
|
||||
SalesAmount = g.Sum(r => (decimal)(r.OrderPrice )) / 100m,
|
||||
SalesAmount = g.Sum(r => (decimal)(r.OrderPrice)) / 100m,
|
||||
Percentage = total == 0m ? 0d : (double)(g.Sum(r => (decimal)(r.OrderPrice)) / 100m / total * 100m)
|
||||
})
|
||||
.OrderByDescending(i => i.SalesAmount)
|
||||
@@ -181,7 +193,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
|
||||
/// <summary>店铺统计表格</summary>
|
||||
public static List<ShopStatisticsItem> GetShopStatistics(IEnumerable<ShopRevenueStatisticsRow> rows)
|
||||
{
|
||||
var list = (rows ?? new List<ShopRevenueStatisticsRow>()).ToList();
|
||||
var list = (rows ?? new List<ShopRevenueStatisticsRow>()).Where(a => a.OutAmount > 0).ToList(); //买手付钱后的订单
|
||||
|
||||
return list
|
||||
.GroupBy(r => r.ShopName)
|
||||
@@ -189,15 +201,17 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
|
||||
{
|
||||
var valid = g.Where(IsValidOrder).ToList();
|
||||
var refunded = g.Where(IsRefunded).ToList();
|
||||
decimal salesAmount = valid.Sum(r => (decimal)(r.OrderPrice)) / 100m;
|
||||
decimal salesAmount = g.Sum(r => (decimal)(r.OrderPrice)) / 100m; //与 GetSummary 一致:含已退款订单的销售额
|
||||
int orderCount = valid.Select(r => r.OrderId).Distinct().Count();
|
||||
decimal profit = valid.Sum(r => (decimal)(r.Profit)) / 100m;
|
||||
decimal purchaseAmount = valid.Sum(r => (decimal)(r.PurchasePrice)) / 100m;
|
||||
decimal profit = valid.Concat(refunded).Sum(r => (decimal)(r.Profit)) / 100m; //与 GetSummary 一致:有效+退款订单利润
|
||||
decimal purchaseAmount = valid.Sum(r => (decimal)(r.OutAmount)) / 100m; //与 GetSummary 一致:买手付款金额(采购金额)
|
||||
decimal buyerPaymentAmount = list.Sum(r => (decimal)(r.OutAmount)) / 100m; //买手号付款金额(采购金额)
|
||||
return new ShopStatisticsItem
|
||||
{
|
||||
ShopName = string.IsNullOrEmpty(g.Key) ? "未知店铺" : g.Key,
|
||||
OrderCount = orderCount,
|
||||
SalesAmount = salesAmount,
|
||||
BuyerPaymentAmount = buyerPaymentAmount,
|
||||
Profit = profit,
|
||||
RefundAmount = refunded.Sum(r => (decimal)(r.OrderPrice)) / 100m,
|
||||
PlatformFeeTotal = valid.Sum(r => (decimal)(r.PredictCommissionFee)) / 100m,
|
||||
@@ -213,7 +227,7 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
|
||||
/// <summary>天/周/月周期统计表格(每天/每周/每月各一行,无数据的周期也补一行,金额单位:元)</summary>
|
||||
public static List<ShopPeriodStatisticsItem> GetPeriodStatistics(IEnumerable<ShopRevenueStatisticsRow> rows, DateTime startDate, DateTime endDate, PeriodStatisticType periodType)
|
||||
{
|
||||
var list = (rows ?? new List<ShopRevenueStatisticsRow>()).ToList();
|
||||
var list = (rows ?? new List<ShopRevenueStatisticsRow>()).Where(a => a.OutAmount > 0).ToList(); //买手付钱后的订单
|
||||
|
||||
// 有数据的周期
|
||||
var map = list
|
||||
@@ -224,16 +238,19 @@ namespace _29WxOrderWpf.Ctrls.Statistics.Services
|
||||
{
|
||||
var valid = g.Where(IsValidOrder).ToList();
|
||||
var refunded = g.Where(IsRefunded).ToList();
|
||||
decimal salesAmount = valid.Sum(r => (decimal)(r.OrderPrice)) / 100m;
|
||||
decimal profit = valid.Sum(r => (decimal)(r.Profit)) / 100m;
|
||||
decimal purchaseAmount = valid.Sum(r => (decimal)(r.PurchasePrice)) / 100m;
|
||||
decimal salesAmount = g.Sum(r => (decimal)(r.OrderPrice)) / 100m; //与 GetSummary 一致:含已退款订单的销售额
|
||||
decimal profit = valid.Concat(refunded).Sum(r => (decimal)(r.Profit)) / 100m; //与 GetSummary 一致:有效+退款订单利润
|
||||
decimal purchaseAmount = valid.Sum(r => (decimal)(r.OutAmount)) / 100m; //与 GetSummary 一致:买手付款金额(采购金额)
|
||||
int orderCount = valid.Select(r => r.OrderId).Distinct().Count();
|
||||
decimal buyerPaymentAmount = list.Sum(r => (decimal)(r.OutAmount)) / 100m; //买手号付款金额(采购金额)
|
||||
|
||||
return new ShopPeriodStatisticsItem
|
||||
{
|
||||
PeriodStart = g.Key,
|
||||
Period = GetPeriodText(g.Key, periodType),
|
||||
OrderCount = orderCount,
|
||||
SalesAmount = salesAmount,
|
||||
BuyerPaymentAmount = buyerPaymentAmount,
|
||||
Profit = profit,
|
||||
RefundAmount = refunded.Sum(r => (decimal)(r.OrderPrice)) / 100m,
|
||||
PlatformFeeTotal = valid.Sum(r => (decimal)(r.PredictCommissionFee)) / 100m,
|
||||
|
||||
Reference in new issue
Block a user