mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
feat: 优化工作台计算
This commit is contained in:
+4
@@ -58,6 +58,7 @@ public class BiOrderStatQueryService {
|
||||
OverviewAggRows.DailyRow r = new OverviewAggRows.DailyRow();
|
||||
r.setStatDate(d);
|
||||
r.setSalesAmount(BigDecimal.ZERO);
|
||||
r.setDealAmount(BigDecimal.ZERO);
|
||||
r.setRefundAmount(BigDecimal.ZERO);
|
||||
r.setProductCost(BigDecimal.ZERO);
|
||||
r.setFreightCost(BigDecimal.ZERO);
|
||||
@@ -66,6 +67,7 @@ public class BiOrderStatQueryService {
|
||||
return r;
|
||||
});
|
||||
row.setSalesAmount(nz(row.getSalesAmount()).add(nz(doc.getSalesAmount())));
|
||||
row.setDealAmount(nz(row.getDealAmount()).add(nz(doc.getDealAmount())));
|
||||
row.setRefundAmount(nz(row.getRefundAmount()).add(nz(doc.getRefundAmount())));
|
||||
row.setProductCost(nz(row.getProductCost()).add(nz(doc.getProductCost())));
|
||||
row.setFreightCost(nz(row.getFreightCost()).add(nz(doc.getFreightCost())));
|
||||
@@ -181,6 +183,7 @@ public class BiOrderStatQueryService {
|
||||
OverviewAggRows.DailyRow r = new OverviewAggRows.DailyRow();
|
||||
r.setStatDate(d);
|
||||
r.setSalesAmount(BigDecimal.ZERO);
|
||||
r.setDealAmount(BigDecimal.ZERO);
|
||||
r.setRefundAmount(BigDecimal.ZERO);
|
||||
r.setProductCost(BigDecimal.ZERO);
|
||||
r.setFreightCost(BigDecimal.ZERO);
|
||||
@@ -189,6 +192,7 @@ public class BiOrderStatQueryService {
|
||||
return r;
|
||||
});
|
||||
row.setSalesAmount(nz(row.getSalesAmount()).add(nz(doc.getSalesAmount())));
|
||||
row.setDealAmount(nz(row.getDealAmount()).add(nz(doc.getDealAmount())));
|
||||
row.setRefundAmount(nz(row.getRefundAmount()).add(nz(doc.getRefundAmount())));
|
||||
row.setProductCost(nz(row.getProductCost()).add(nz(doc.getProductCost())));
|
||||
row.setFreightCost(nz(row.getFreightCost()).add(nz(doc.getFreightCost())));
|
||||
|
||||
+1
@@ -35,6 +35,7 @@ public final class OverviewAggRows {
|
||||
public static class DailyRow {
|
||||
private LocalDate statDate;
|
||||
private BigDecimal salesAmount;
|
||||
private BigDecimal dealAmount;
|
||||
private BigDecimal refundAmount;
|
||||
private BigDecimal productCost;
|
||||
private BigDecimal freightCost;
|
||||
|
||||
+16
-18
@@ -47,23 +47,21 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
this.categoryService = categoryService;
|
||||
}
|
||||
|
||||
private BigDecimal salesTaxOnNetSales(BigDecimal salesAmount, BigDecimal refundAmount) {
|
||||
private BigDecimal salesTaxOnSales(BigDecimal salesAmount) {
|
||||
BigDecimal sales = salesAmount != null ? salesAmount : BigDecimal.ZERO;
|
||||
BigDecimal refund = refundAmount != null ? refundAmount : BigDecimal.ZERO;
|
||||
BigDecimal base = sales.subtract(refund);
|
||||
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||
base = BigDecimal.ZERO;
|
||||
if (sales.compareTo(BigDecimal.ZERO) < 0) {
|
||||
sales = BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal rate = taxRate != null ? taxRate : DEFAULT_TAX_RATE;
|
||||
return base.multiply(rate).setScale(2, RoundingMode.HALF_UP);
|
||||
return sales.multiply(rate).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/** 计算ROI:(销售额 - 退款金额)/ 推广费用 */
|
||||
private BigDecimal calculateSalesROI(BigDecimal netSales, BigDecimal promotionFee) {
|
||||
/** 计算ROI:实际销售额 / 推广费用 */
|
||||
private BigDecimal calculateSalesROI(BigDecimal salesAmount, BigDecimal promotionFee) {
|
||||
if (promotionFee == null || promotionFee.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return netSales.divide(promotionFee, 4, RoundingMode.HALF_UP);
|
||||
return salesAmount.divide(promotionFee, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/** 计算店铺汇总的合计行 */
|
||||
@@ -102,7 +100,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||
BigDecimal salesTax = salesTaxOnNetSales(totalSales, totalRefund);
|
||||
BigDecimal salesTax = salesTaxOnSales(totalSales);
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||
@@ -177,7 +175,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund)
|
||||
.subtract(totalPromoFee).subtract(totalBrushFee);
|
||||
BigDecimal salesTax = salesTaxOnNetSales(totalSales, totalRefund);
|
||||
BigDecimal salesTax = salesTaxOnSales(totalSales);
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||
@@ -245,7 +243,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||
BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount)
|
||||
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
||||
BigDecimal salesTax = salesTaxOnNetSales(totalSalesAmount, totalRefundAmount);
|
||||
BigDecimal salesTax = salesTaxOnSales(totalSalesAmount);
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||
BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP)
|
||||
@@ -539,9 +537,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
s.setGrossProfit(m.grossProfit().setScale(2, RoundingMode.HALF_UP));
|
||||
BigDecimal pbt = m.grossProfit().subtract(promo).subtract(brush);
|
||||
s.setTotalProfitBeforeTax(pbt);
|
||||
s.setSalesTaxAmount(salesTaxOnNetSales(m.sales, m.refund));
|
||||
s.setSalesTaxAmount(salesTaxOnSales(m.sales));
|
||||
s.setProfitAfterTax(pbt.subtract(s.getSalesTaxAmount()).setScale(2, RoundingMode.HALF_UP));
|
||||
s.setRoi(calculateSalesROI(m.sales.subtract(m.refund), promo));
|
||||
s.setRoi(calculateSalesROI(m.sales, promo));
|
||||
s.setTargetAmount(targetAmt);
|
||||
s.setTargetOrderCount(targetOrders);
|
||||
s.setSalesAmountAchievementRate(achievementRate(m.sales, targetAmt));
|
||||
@@ -566,9 +564,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
s.setGrossProfit(m.grossProfit().setScale(2, RoundingMode.HALF_UP));
|
||||
BigDecimal pbt = m.grossProfit().subtract(promo).subtract(brush);
|
||||
s.setTotalProfitBeforeTax(pbt);
|
||||
s.setSalesTaxAmount(salesTaxOnNetSales(m.sales, m.refund));
|
||||
s.setSalesTaxAmount(salesTaxOnSales(m.sales));
|
||||
s.setProfitAfterTax(pbt.subtract(s.getSalesTaxAmount()).setScale(2, RoundingMode.HALF_UP));
|
||||
s.setRoi(calculateSalesROI(m.sales.subtract(m.refund), promo));
|
||||
s.setRoi(calculateSalesROI(m.sales, promo));
|
||||
}
|
||||
|
||||
private void fillPlatformLikeMetrics(CompanyOverviewVO.PlatformSummary s, AggMetrics m,
|
||||
@@ -589,9 +587,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
s.setGrossProfit(m.grossProfit().setScale(2, RoundingMode.HALF_UP));
|
||||
BigDecimal pbt = m.grossProfit().subtract(promo).subtract(brush);
|
||||
s.setTotalProfitBeforeTax(pbt);
|
||||
s.setSalesTaxAmount(salesTaxOnNetSales(m.sales, m.refund));
|
||||
s.setSalesTaxAmount(salesTaxOnSales(m.sales));
|
||||
s.setProfitAfterTax(pbt.subtract(s.getSalesTaxAmount()).setScale(2, RoundingMode.HALF_UP));
|
||||
s.setRoi(calculateSalesROI(m.sales.subtract(m.refund), promo));
|
||||
s.setRoi(calculateSalesROI(m.sales, promo));
|
||||
s.setTargetAmount(targetAmt);
|
||||
s.setTargetOrderCount(targetOrders);
|
||||
s.setSalesAmountAchievementRate(achievementRate(m.sales, targetAmt));
|
||||
|
||||
+5
-2
@@ -12,19 +12,22 @@ import java.math.BigDecimal;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "工作台-GM/利润趋势点(元,两位小数)")
|
||||
@Schema(description = "工作台-经营趋势点(元,两位小数)")
|
||||
public class WorkbenchTrendPointVO {
|
||||
|
||||
@Schema(description = "横轴日期,如 M/d")
|
||||
private String date;
|
||||
|
||||
@Schema(description = "成交金额(元,两位小数):全部订单状态商家实收合计")
|
||||
private BigDecimal dealYuan;
|
||||
|
||||
@Schema(description = "实际销售额(元,两位小数),与计入销售额的订单状态配置一致")
|
||||
private BigDecimal salesYuan;
|
||||
|
||||
@Schema(description = "日毛利润(元,两位小数)= 销售额−成本−退款,与 KPI「毛利润」按日拆解口径一致")
|
||||
private BigDecimal profitYuan;
|
||||
|
||||
@Schema(description = "日净利润(元,两位小数)= 毛利润−按日销售额占比分摊的推广费、刷单费−按日净销售额占比分摊的税额,与 KPI「净利润」及多维分析分摊口径一致")
|
||||
@Schema(description = "日净利润(元,两位小数)= 毛利润−按日销售额占比分摊的推广费、刷单费、税额,与 KPI「净利润」及多维分析分摊口径一致")
|
||||
private BigDecimal netProfitYuan;
|
||||
|
||||
@Schema(description = "退款(元,两位小数)")
|
||||
|
||||
+34
-66
@@ -57,7 +57,7 @@ import java.util.stream.Collectors;
|
||||
* <li>「实际销售额、成本、退款、多维行、趋势」等与 {@link OrderStatusStatSets} 一致:仅统计配置为「计入销售额」的订单状态,
|
||||
* 金额字段由 {@code stat} 解析商家实收、成本、退款等。</li>
|
||||
* <li>「成交金额」为同店铺、同时间范围内<strong>全部订单状态</strong>的商家实收合计(由汇总表 KPI 提供)。</li>
|
||||
* <li>推广费、刷单费为区间汇总;多维行与趋势中的「净利润」按销售额 / 净销售额占比将区间推广、刷单、税额<strong>分摊</strong>到各维度或各日,
|
||||
* <li>推广费、刷单费为区间汇总;多维行与趋势中的「净利润」按销售额占比将区间推广、刷单、税额<strong>分摊</strong>到各维度或各日,
|
||||
* 与 {@link #totalsFromOrderRows} 得到的区间总毛利润、总税额自洽。</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
@@ -367,7 +367,7 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
BigDecimal cost = pc.add(fc).add(oc);
|
||||
BigDecimal gross = sales.subtract(cost).subtract(refund);
|
||||
BigDecimal pbt = gross.subtract(promotion).subtract(brush);
|
||||
BigDecimal tax = salesTaxOnNetSales(sales, refund, taxRate);
|
||||
BigDecimal tax = salesTaxOnSales(sales, taxRate);
|
||||
BigDecimal aov = orderCount > 0
|
||||
? sales.divide(BigDecimal.valueOf(orderCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
BigDecimal dealAov = dealOrderCount > 0
|
||||
@@ -390,26 +390,24 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
}
|
||||
}
|
||||
BigDecimal salesTotal = periodTotals.totalSales();
|
||||
BigDecimal netSum = BigDecimal.ZERO;
|
||||
for (LocalDate d = range.startDate(); !d.isAfter(range.endDate()); d = d.plusDays(1)) {
|
||||
netSum = netSum.add(dayNetSales(byDay.get(d)));
|
||||
}
|
||||
List<WorkbenchTrendPointVO> list = new ArrayList<>();
|
||||
for (LocalDate d = range.startDate(); !d.isAfter(range.endDate()); d = d.plusDays(1)) {
|
||||
OverviewAggRows.DailyRow row = byDay.get(d);
|
||||
BigDecimal sales = row != null ? nz(row.getSalesAmount()) : BigDecimal.ZERO;
|
||||
BigDecimal deal = row != null ? nz(row.getDealAmount()) : BigDecimal.ZERO;
|
||||
BigDecimal refund = row != null ? nz(row.getRefundAmount()) : BigDecimal.ZERO;
|
||||
BigDecimal cost = row != null
|
||||
? nz(row.getProductCost()).add(nz(row.getFreightCost())).add(nz(row.getOtherCost())) : BigDecimal.ZERO;
|
||||
BigDecimal gross = sales.subtract(cost).subtract(refund);
|
||||
BigDecimal promoB = allocShare(sales, salesTotal, periodTotals.promotion());
|
||||
BigDecimal brushB = allocShare(sales, salesTotal, periodTotals.brush());
|
||||
BigDecimal taxB = allocShare(dayNetSales(row), netSum.max(BigDecimal.ONE), periodTotals.tax());
|
||||
if (netSum.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
BigDecimal taxB = allocShare(sales, salesTotal.max(BigDecimal.ONE), periodTotals.tax());
|
||||
if (salesTotal.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
taxB = BigDecimal.ZERO;
|
||||
}
|
||||
list.add(WorkbenchTrendPointVO.builder()
|
||||
.date(d.format(TREND_DATE_FMT))
|
||||
.dealYuan(yuan2(deal))
|
||||
.salesYuan(yuan2(sales))
|
||||
.profitYuan(yuan2(gross))
|
||||
.netProfitYuan(yuan2(gross.subtract(promoB).subtract(brushB).subtract(taxB)))
|
||||
@@ -427,13 +425,6 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
.stream().collect(Collectors.toMap(CategoryPO::getId, CategoryPO::getName, (a, b) -> a));
|
||||
}
|
||||
|
||||
private static BigDecimal dayNetSales(OverviewAggRows.DailyRow row) {
|
||||
if (row == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return nz(row.getSalesAmount()).subtract(nz(row.getRefundAmount())).max(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
private static LocalDate minDate(LocalDate... dates) {
|
||||
LocalDate min = dates[0];
|
||||
for (LocalDate d : dates) {
|
||||
@@ -584,7 +575,7 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
|
||||
/**
|
||||
* 将「字符串 key → 聚合桶」转为多维表格行:每行毛利润 = 销售−成本−退款;
|
||||
* 推广费、刷单费按该行销售额占 {@code salesTotalCompany} 比例分摊;税额按该行净销售额占全部分桶净销售额之和比例分摊;
|
||||
* 推广费、刷单费、税额均按该行销售额占 {@code salesTotalCompany} 比例分摊;
|
||||
* 净利润 = 毛利润 − 分摊推广 − 分摊刷单 − 分摊税。
|
||||
*/
|
||||
private List<WorkbenchDimRowVO> buildDimRows(Map<String, Agg> aggs,
|
||||
@@ -593,10 +584,6 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
BigDecimal promoTotal,
|
||||
BigDecimal brushTotal,
|
||||
BigDecimal taxTotal) {
|
||||
BigDecimal netSum = aggs.values().stream()
|
||||
.map(Agg::netSalesBase)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
List<WorkbenchDimRowVO> rows = new ArrayList<>();
|
||||
for (Map.Entry<String, Agg> e : aggs.entrySet()) {
|
||||
Agg a = e.getValue();
|
||||
@@ -606,8 +593,8 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
BigDecimal gross = a.sales.subtract(a.cost).subtract(a.refund);
|
||||
BigDecimal promoB = allocShare(a.sales, salesTotalCompany, promoTotal);
|
||||
BigDecimal brushB = allocShare(a.sales, salesTotalCompany, brushTotal);
|
||||
BigDecimal taxB = allocShare(a.netSalesBase(), netSum.max(BigDecimal.ONE), taxTotal);
|
||||
if (netSum.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
BigDecimal taxB = allocShare(a.sales, salesTotalCompany.max(BigDecimal.ONE), taxTotal);
|
||||
if (salesTotalCompany.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
taxB = BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal net = gross.subtract(promoB).subtract(brushB).subtract(taxB);
|
||||
@@ -695,17 +682,16 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
private List<WorkbenchKpiItemVO> buildKpis(Totals cur, Totals prev, Totals yoy, DateRange range, BigDecimal taxRate) {
|
||||
int days = (int) (range.endDate().toEpochDay() - range.startDate().toEpochDay() + 1);
|
||||
|
||||
BigDecimal netRecv = cur.netSales();
|
||||
BigDecimal grossMarginPct = safePct(cur.grossOrder(), cur.totalSales());
|
||||
BigDecimal netMarginPct = safePct(cur.netProfit(), cur.totalSales());
|
||||
BigDecimal refundRate = safePct(cur.totalRefund(), cur.totalSales());
|
||||
BigDecimal costRate = safePct(cur.totalCost(), cur.totalSales());
|
||||
BigDecimal roi = cur.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||
? netRecv.divide(cur.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
? cur.totalSales().divide(cur.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
BigDecimal yoyRoi = yoy.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||
? yoy.netSales().divide(yoy.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
? yoy.totalSales().divide(yoy.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
BigDecimal prevRoi = prev.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||
? prev.netSales().divide(prev.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
? prev.totalSales().divide(prev.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
|
||||
BigDecimal avgDailySalesOrders = days > 0
|
||||
? BigDecimal.valueOf(cur.orderCount()).divide(BigDecimal.valueOf(days), 1, RoundingMode.HALF_UP)
|
||||
@@ -713,54 +699,48 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
BigDecimal avgDailyDealOrders = days > 0
|
||||
? BigDecimal.valueOf(cur.dealOrderCount()).divide(BigDecimal.valueOf(days), 1, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal dealSalesGap = cur.totalDealAmount().subtract(cur.totalSales());
|
||||
|
||||
List<WorkbenchKpiItemVO> list = new ArrayList<>();
|
||||
|
||||
// —— 成交口径(全状态)——
|
||||
list.add(kpi("成交金额", formatYuanComma(cur.totalDealAmount()), "元", cur.totalDealAmount(), prev.totalDealAmount(), yoy.totalDealAmount(),
|
||||
"全状态商家实收", cur.totalDealAmount(), true));
|
||||
"全状态实收", cur.totalDealAmount(), true));
|
||||
list.add(kpiCount("成交单量", cur.dealOrderCount(), prev.dealOrderCount(), yoy.dealOrderCount(), "单",
|
||||
"日均约 " + avgDailyDealOrders.stripTrailingZeros().toPlainString() + " 单"));
|
||||
list.add(kpiCount("成交销量", cur.dealQuantitySum(), prev.dealQuantitySum(), yoy.dealQuantitySum(), "件", "全状态件数合计"));
|
||||
"日均 " + avgDailyDealOrders.stripTrailingZeros().toPlainString() + " 单"));
|
||||
list.add(kpiCount("成交销量", cur.dealQuantitySum(), prev.dealQuantitySum(), yoy.dealQuantitySum(), "件", "全状态件数"));
|
||||
list.add(kpi("成交客单价", formatYuanComma(cur.dealAverageOrderValue()), "元",
|
||||
cur.dealAverageOrderValue(), prev.dealAverageOrderValue(), yoy.dealAverageOrderValue(),
|
||||
"成交金额÷成交单量", cur.dealAverageOrderValue(), false));
|
||||
"成交金额/成交单量", cur.dealAverageOrderValue(), false));
|
||||
list.add(kpi("成交件单价", formatYuanComma(cur.dealPiecePrice()), "元",
|
||||
cur.dealPiecePrice(), prev.dealPiecePrice(), yoy.dealPiecePrice(),
|
||||
"成交金额÷成交销量", cur.dealPiecePrice(), false));
|
||||
"成交金额/成交销量", cur.dealPiecePrice(), false));
|
||||
|
||||
// —— 实际销售口径(计入销售额状态)——
|
||||
list.add(kpi("实际销售额", formatYuanComma(cur.totalSales()), "元", cur.totalSales(), prev.totalSales(), yoy.totalSales(),
|
||||
"计入销售额的订单状态", cur.totalSales(), true));
|
||||
"计入销售状态", cur.totalSales(), true));
|
||||
list.add(kpiCount("销售单量", cur.orderCount(), prev.orderCount(), yoy.orderCount(), "单",
|
||||
"日均约 " + avgDailySalesOrders.stripTrailingZeros().toPlainString() + " 单"));
|
||||
"日均 " + avgDailySalesOrders.stripTrailingZeros().toPlainString() + " 单"));
|
||||
list.add(kpiCount("实际销量", cur.salesQuantitySum(), prev.salesQuantitySum(), yoy.salesQuantitySum(), "件",
|
||||
"计入销售额状态件数"));
|
||||
"计入销售件数"));
|
||||
list.add(kpi("客单价", formatYuanComma(cur.averageOrderValue()), "元",
|
||||
cur.averageOrderValue(), prev.averageOrderValue(), yoy.averageOrderValue(),
|
||||
"销售额÷销售单量", cur.averageOrderValue(), false));
|
||||
"销售额/销售单量", cur.averageOrderValue(), false));
|
||||
list.add(kpi("销售件单价", formatYuanComma(cur.salesPiecePrice()), "元",
|
||||
cur.salesPiecePrice(), prev.salesPiecePrice(), yoy.salesPiecePrice(),
|
||||
"销售额÷实际销量", cur.salesPiecePrice(), false));
|
||||
"销售额/实际销量", cur.salesPiecePrice(), false));
|
||||
|
||||
// —— 净收与退款 ——
|
||||
list.add(kpi("净销售额", formatYuanComma(netRecv), "元", netRecv, prev.netSales(), yoy.netSales(),
|
||||
"实际销售额−退款", netRecv, true));
|
||||
list.add(kpi("退款额", formatYuanComma(cur.totalRefund()), "元", cur.totalRefund(), prev.totalRefund(), yoy.totalRefund(),
|
||||
"计入退款状态口径", cur.totalRefund(), true));
|
||||
"计入退款状态", cur.totalRefund(), true));
|
||||
list.add(kpi("退款率", refundRate.setScale(2, RoundingMode.HALF_UP).toPlainString(), "%",
|
||||
refundRate, safePct(prev.totalRefund(), prev.totalSales()), safePct(yoy.totalRefund(), yoy.totalSales()),
|
||||
"退款÷实际销售额", null, null));
|
||||
list.add(kpi("成交与销售差额", formatYuanComma(dealSalesGap), "元", dealSalesGap,
|
||||
prev.totalDealAmount().subtract(prev.totalSales()), yoy.totalDealAmount().subtract(yoy.totalSales()),
|
||||
"成交金额−实际销售额", dealSalesGap, true));
|
||||
"退款/实际销售额", null, null));
|
||||
|
||||
// —— 成本 ——
|
||||
list.add(kpi("订单成本", formatYuanComma(cur.totalCost()), "元", cur.totalCost(), prev.totalCost(), yoy.totalCost(),
|
||||
"成本率 " + costRate.stripTrailingZeros().toPlainString() + "%", cur.totalCost(), true));
|
||||
list.add(kpi("商品成本", formatYuanComma(cur.productCost()), "元", cur.productCost(), prev.productCost(), yoy.productCost(),
|
||||
"按状态配置计入", cur.productCost(), true));
|
||||
null, cur.productCost(), true));
|
||||
list.add(kpi("运费成本", formatYuanComma(cur.freightCost()), "元", cur.freightCost(), prev.freightCost(), yoy.freightCost(),
|
||||
null, cur.freightCost(), true));
|
||||
list.add(kpi("其他成本", formatYuanComma(cur.otherCost()), "元", cur.otherCost(), prev.otherCost(), yoy.otherCost(),
|
||||
@@ -770,11 +750,11 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
list.add(kpi("毛利润", formatYuanComma(cur.grossOrder()), "元", cur.grossOrder(), prev.grossOrder(), yoy.grossOrder(),
|
||||
"毛利率 " + grossMarginPct.stripTrailingZeros().toPlainString() + "%", cur.grossOrder(), true));
|
||||
list.add(kpi("推广费", formatYuanComma(cur.promotion()), "元", cur.promotion(), prev.promotion(), yoy.promotion(),
|
||||
"区间推广费合计", cur.promotion(), true));
|
||||
null, cur.promotion(), true));
|
||||
list.add(kpi("刷单费", formatYuanComma(cur.brush()), "元", cur.brush(), prev.brush(), yoy.brush(),
|
||||
"区间刷单费合计", cur.brush(), true));
|
||||
null, cur.brush(), true));
|
||||
list.add(kpi("税额", formatYuanComma(cur.tax()), "元", cur.tax(), prev.tax(), yoy.tax(),
|
||||
"税率 " + taxRate.multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%(净销售额口径)",
|
||||
"税率 " + taxRate.multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%",
|
||||
cur.tax(), true));
|
||||
list.add(kpi("净利润", formatYuanComma(cur.netProfit()), "元", cur.netProfit(), prev.netProfit(), yoy.netProfit(),
|
||||
"净利率 " + netMarginPct.stripTrailingZeros().toPlainString() + "%",
|
||||
@@ -782,7 +762,7 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
|
||||
// —— 运营效率 ——
|
||||
list.add(kpi("广告ROI", roi.stripTrailingZeros().toPlainString(), ":1", roi, prevRoi, yoyRoi,
|
||||
"净销售额÷推广费", null, null));
|
||||
"实际销售额/推广费", null, null));
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -837,17 +817,15 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 与单店概览一致:订单流水中「销售额−成本」的合计,再扣推广、刷单得税前;再扣税得净利。
|
||||
* 税额 = 实际销售额 * 税率(实际销售额已按状态剔除退款单,不再二次扣退款)。
|
||||
*/
|
||||
private BigDecimal salesTaxOnNetSales(BigDecimal salesAmount, BigDecimal refundAmount, BigDecimal rate) {
|
||||
private BigDecimal salesTaxOnSales(BigDecimal salesAmount, BigDecimal rate) {
|
||||
BigDecimal sales = salesAmount != null ? salesAmount : BigDecimal.ZERO;
|
||||
BigDecimal ref = refundAmount != null ? refundAmount : BigDecimal.ZERO;
|
||||
BigDecimal base = sales.subtract(ref);
|
||||
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||
base = BigDecimal.ZERO;
|
||||
if (sales.compareTo(BigDecimal.ZERO) < 0) {
|
||||
sales = BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal r = rate != null ? rate : DEFAULT_TAX_RATE;
|
||||
return base.multiply(r).setScale(2, RoundingMode.HALF_UP);
|
||||
return sales.multiply(r).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/** 解析前端传入的 1 个或 2 个日期为闭区间 [start, end] */
|
||||
@@ -960,10 +938,6 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
BigDecimal dealAverageOrderValue,
|
||||
BigDecimal salesPiecePrice,
|
||||
BigDecimal dealPiecePrice) {
|
||||
|
||||
BigDecimal netSales() {
|
||||
return totalSales.subtract(totalRefund);
|
||||
}
|
||||
}
|
||||
|
||||
/** 多维或按日聚合用的累加桶:累计销售额、退款、成本 */
|
||||
@@ -978,11 +952,5 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
refund = refund.add(nz(row.getRefundAmount()));
|
||||
cost = cost.add(nz(row.getProductCost())).add(nz(row.getFreightCost())).add(nz(row.getOtherCost()));
|
||||
}
|
||||
|
||||
/** 桶内净销售额 max(0, 销售−退款),用于税额分摊 */
|
||||
BigDecimal netSalesBase() {
|
||||
BigDecimal b = sales.subtract(refund);
|
||||
return b.max(BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user