mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 02:29:19 +08:00
fix: ROI计算公式改为(销售额-退款金额)/推广费用,应用于公司概览、店铺概览及导出功能
This commit is contained in:
+45
-15
@@ -205,7 +205,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
overviewVO.setShopComparisons(shopComparisons);
|
overviewVO.setShopComparisons(shopComparisons);
|
||||||
|
|
||||||
// 10. 汇总ROI和总税后盈亏
|
// 10. 汇总ROI和总税后盈亏
|
||||||
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders);
|
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusId);
|
||||||
overviewVO.setTotalROI(totalROI);
|
overviewVO.setTotalROI(totalROI);
|
||||||
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
|
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
|
||||||
|
|
||||||
@@ -361,9 +361,18 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||||
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||||
|
|
||||||
|
BigDecimal shopSales = shopOrders.stream()
|
||||||
|
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal shopRefund = shopOrders.stream()
|
||||||
|
.filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId()))
|
||||||
|
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal shopPromotionFee = shopPromotionFees.stream()
|
||||||
|
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal roi = calculateSalesROI(shopSales.subtract(shopRefund), shopPromotionFee);
|
||||||
BigDecimal profit = calculateShopProfit(shopOrders, refundStatusId);
|
BigDecimal profit = calculateShopProfit(shopOrders, refundStatusId);
|
||||||
BigDecimal totalCost = calculateShopTotalCost(shopPromotionFees, shopBrushOrders);
|
|
||||||
BigDecimal roi = calculateShopROI(profit, totalCost);
|
|
||||||
BigDecimal netProfit = calculateShopNetProfit(profit);
|
BigDecimal netProfit = calculateShopNetProfit(profit);
|
||||||
|
|
||||||
allROIs.add(roi);
|
allROIs.add(roi);
|
||||||
@@ -383,9 +392,18 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||||
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||||
|
|
||||||
|
BigDecimal shopSales = shopOrders.stream()
|
||||||
|
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal shopRefund = shopOrders.stream()
|
||||||
|
.filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId()))
|
||||||
|
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal shopPromotionFee = shopPromotionFees.stream()
|
||||||
|
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal roi = calculateSalesROI(shopSales.subtract(shopRefund), shopPromotionFee);
|
||||||
BigDecimal profit = calculateShopProfit(shopOrders, refundStatusId);
|
BigDecimal profit = calculateShopProfit(shopOrders, refundStatusId);
|
||||||
BigDecimal totalCost = calculateShopTotalCost(shopPromotionFees, shopBrushOrders);
|
|
||||||
BigDecimal roi = calculateShopROI(profit, totalCost);
|
|
||||||
BigDecimal netProfit = calculateShopNetProfit(profit);
|
BigDecimal netProfit = calculateShopNetProfit(profit);
|
||||||
|
|
||||||
int quadrant;
|
int quadrant;
|
||||||
@@ -507,8 +525,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
// 税后盈亏(扣除销售额4%税额)
|
// 税后盈亏(扣除销售额4%税额)
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
|
|
||||||
BigDecimal totalCostForROI = totalPromotionFee.add(brushFee);
|
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), totalPromotionFee);
|
||||||
BigDecimal roi = calculateShopROI(profitBeforeTax, totalCostForROI);
|
|
||||||
|
|
||||||
BigDecimal feeRatio = BigDecimal.ZERO;
|
BigDecimal feeRatio = BigDecimal.ZERO;
|
||||||
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
@@ -634,6 +651,16 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
return profit.divide(totalCost, 4, RoundingMode.HALF_UP);
|
return profit.divide(totalCost, 4, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算ROI(新公式):(销售额 - 退款金额)/ 推广费用
|
||||||
|
*/
|
||||||
|
private BigDecimal calculateSalesROI(BigDecimal netSales, BigDecimal promotionFee) {
|
||||||
|
if (promotionFee == null || promotionFee.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return netSales.divide(promotionFee, 4, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算店铺净利(税后)
|
* 计算店铺净利(税后)
|
||||||
*/
|
*/
|
||||||
@@ -643,19 +670,22 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算汇总ROI
|
* 计算汇总ROI(新公式):(销售额 - 退款金额)/ 推广费用
|
||||||
*/
|
*/
|
||||||
private BigDecimal calculateTotalROI(List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
private BigDecimal calculateTotalROI(List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||||
List<BrushOrderPO> brushOrders) {
|
List<BrushOrderPO> brushOrders, Long refundStatusId) {
|
||||||
BigDecimal totalProfit = calculateTotalProfit(orders);
|
BigDecimal totalSales = orders.stream()
|
||||||
|
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal totalRefund = orders.stream()
|
||||||
|
.filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId()))
|
||||||
|
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal netSales = totalSales.subtract(totalRefund);
|
||||||
BigDecimal totalPromotionFee = promotionFees.stream()
|
BigDecimal totalPromotionFee = promotionFees.stream()
|
||||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
BigDecimal totalBrushFee = brushOrders.stream()
|
return calculateSalesROI(netSales, totalPromotionFee);
|
||||||
.map(brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO)
|
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
||||||
BigDecimal totalCost = totalPromotionFee.add(totalBrushFee);
|
|
||||||
return calculateShopROI(totalProfit, totalCost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+8
-6
@@ -97,6 +97,7 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
BigDecimal totalPromotionFee = BigDecimal.ZERO;
|
BigDecimal totalPromotionFee = BigDecimal.ZERO;
|
||||||
BigDecimal totalBrushFee = BigDecimal.ZERO;
|
BigDecimal totalBrushFee = BigDecimal.ZERO;
|
||||||
BigDecimal totalProfitBeforeTax = BigDecimal.ZERO;
|
BigDecimal totalProfitBeforeTax = BigDecimal.ZERO;
|
||||||
|
BigDecimal totalRefundAmount = BigDecimal.ZERO;
|
||||||
|
|
||||||
BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE;
|
BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE;
|
||||||
|
|
||||||
@@ -107,6 +108,7 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
totalSales = totalSales.add((BigDecimal) data.get("salesAmount"));
|
totalSales = totalSales.add((BigDecimal) data.get("salesAmount"));
|
||||||
totalOrders = totalOrders.add(new BigDecimal((Integer) data.get("orderCount")));
|
totalOrders = totalOrders.add(new BigDecimal((Integer) data.get("orderCount")));
|
||||||
totalPromotionFee = totalPromotionFee.add((BigDecimal) data.get("totalPromotionFee"));
|
totalPromotionFee = totalPromotionFee.add((BigDecimal) data.get("totalPromotionFee"));
|
||||||
|
totalRefundAmount = totalRefundAmount.add((BigDecimal) data.get("refundAmount"));
|
||||||
totalBrushFee = totalBrushFee.add((BigDecimal) data.get("brushFee"));
|
totalBrushFee = totalBrushFee.add((BigDecimal) data.get("brushFee"));
|
||||||
totalProfitBeforeTax = totalProfitBeforeTax.add((BigDecimal) data.get("totalProfitBeforeTax"));
|
totalProfitBeforeTax = totalProfitBeforeTax.add((BigDecimal) data.get("totalProfitBeforeTax"));
|
||||||
}
|
}
|
||||||
@@ -115,8 +117,8 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
BigDecimal totalTax = totalProfitBeforeTax.multiply(taxRate).setScale(2, RoundingMode.HALF_UP);
|
BigDecimal totalTax = totalProfitBeforeTax.multiply(taxRate).setScale(2, RoundingMode.HALF_UP);
|
||||||
BigDecimal totalProfitAfterTax = totalProfitBeforeTax.subtract(totalTax);
|
BigDecimal totalProfitAfterTax = totalProfitBeforeTax.subtract(totalTax);
|
||||||
BigDecimal totalCost = totalPromotionFee.add(totalBrushFee);
|
BigDecimal totalCost = totalPromotionFee.add(totalBrushFee);
|
||||||
BigDecimal totalRoi = totalCost.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal totalRoi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalProfitBeforeTax.divide(totalCost, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
? totalSales.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
BigDecimal avgFeeRatio = totalSales.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal avgFeeRatio = totalSales.compareTo(BigDecimal.ZERO) > 0
|
||||||
? totalPromotionFee.divide(totalSales, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
? totalPromotionFee.divide(totalSales, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
|
||||||
@@ -475,8 +477,8 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
BigDecimal promotionFee = BigDecimal.ZERO;
|
BigDecimal promotionFee = BigDecimal.ZERO;
|
||||||
BigDecimal brushFee = BigDecimal.ZERO;
|
BigDecimal brushFee = BigDecimal.ZERO;
|
||||||
|
|
||||||
BigDecimal roi = totalCost.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = promotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? profitBeforeTax.divide(totalCost, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
? salesAmount.subtract(refundAmount).divide(promotionFee, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
BigDecimal feeRatio = salesAmount.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal feeRatio = salesAmount.compareTo(BigDecimal.ZERO) > 0
|
||||||
? promotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
? promotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
|
||||||
@@ -877,8 +879,8 @@ public class ExportServiceImpl implements ExportService {
|
|||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(tax);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(tax);
|
||||||
BigDecimal feeRatio = salesAmount.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal feeRatio = salesAmount.compareTo(BigDecimal.ZERO) > 0
|
||||||
? promotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
? promotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
BigDecimal roi = promotionFee.add(brushFee).compareTo(BigDecimal.ZERO) > 0
|
BigDecimal roi = promotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||||
? profitBeforeTax.divide(promotionFee.add(brushFee), 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
? salesAmount.subtract(refundAmount).divide(promotionFee, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
|
||||||
BigDecimal salesAchievementRate = targetAmount.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal salesAchievementRate = targetAmount.compareTo(BigDecimal.ZERO) > 0
|
||||||
? salesAmount.divide(targetAmount, 4, RoundingMode.HALF_UP)
|
? salesAmount.divide(targetAmount, 4, RoundingMode.HALF_UP)
|
||||||
|
|||||||
+21
-10
@@ -206,7 +206,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
calculateTargetData(overviewVO, companyId, queryDTO.getShopId(), startDate, endDate, totalSalesAmount, totalOrderCount);
|
calculateTargetData(overviewVO, companyId, queryDTO.getShopId(), startDate, endDate, totalSalesAmount, totalOrderCount);
|
||||||
|
|
||||||
// 8. 汇总ROI和总税后盈亏
|
// 8. 汇总ROI和总税后盈亏
|
||||||
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders);
|
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusId);
|
||||||
overviewVO.setTotalROI(totalROI);
|
overviewVO.setTotalROI(totalROI);
|
||||||
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
|
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
|
||||||
|
|
||||||
@@ -300,16 +300,28 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
* 计算汇总ROI
|
* 计算汇总ROI
|
||||||
*/
|
*/
|
||||||
private BigDecimal calculateTotalROI(List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
private BigDecimal calculateTotalROI(List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||||
List<BrushOrderPO> brushOrders) {
|
List<BrushOrderPO> brushOrders, Long refundStatusId) {
|
||||||
BigDecimal totalProfit = calculateTotalProfit(orders);
|
BigDecimal totalSales = orders.stream()
|
||||||
|
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal totalRefund = orders.stream()
|
||||||
|
.filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId()))
|
||||||
|
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
BigDecimal totalPromotionFee = promotionFees.stream()
|
BigDecimal totalPromotionFee = promotionFees.stream()
|
||||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
BigDecimal totalBrushFee = brushOrders.stream()
|
return calculateSalesROI(totalSales.subtract(totalRefund), totalPromotionFee);
|
||||||
.map(brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO)
|
}
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
||||||
BigDecimal totalCost = totalPromotionFee.add(totalBrushFee);
|
/**
|
||||||
return calculateROI(totalProfit, totalCost);
|
* 计算ROI(新公式):(销售额 - 退款金额)/ 推广费用
|
||||||
|
*/
|
||||||
|
private BigDecimal calculateSalesROI(BigDecimal netSales, BigDecimal promotionFee) {
|
||||||
|
if (promotionFee == null || promotionFee.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return netSales.divide(promotionFee, 4, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -416,8 +428,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
|||||||
// 税后盈亏(扣除销售额4%税额)
|
// 税后盈亏(扣除销售额4%税额)
|
||||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
|
|
||||||
BigDecimal totalCostForROI = productPromotionFee.add(brushFee);
|
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), productPromotionFee);
|
||||||
BigDecimal roi = calculateROI(profitBeforeTax, totalCostForROI);
|
|
||||||
|
|
||||||
BigDecimal feeRatio = BigDecimal.ZERO;
|
BigDecimal feeRatio = BigDecimal.ZERO;
|
||||||
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user