feat: 经营趋势增加单量统计

This commit is contained in:
2026-08-14 20:56:53 +08:00
parent e39d34700e
commit 070b555dde
6 changed files with 89 additions and 8 deletions
@@ -64,6 +64,7 @@ public class BiOrderStatQueryService {
r.setFreightCost(BigDecimal.ZERO);
r.setOtherCost(BigDecimal.ZERO);
r.setOrderCount(0L);
r.setDealOrderCount(0L);
return r;
});
row.setSalesAmount(nz(row.getSalesAmount()).add(nz(doc.getSalesAmount())));
@@ -73,6 +74,7 @@ public class BiOrderStatQueryService {
row.setFreightCost(nz(row.getFreightCost()).add(nz(doc.getFreightCost())));
row.setOtherCost(nz(row.getOtherCost()).add(nz(doc.getOtherCost())));
row.setOrderCount(nzLong(row.getOrderCount()) + nzInt(doc.getSalesOrderCount()));
row.setDealOrderCount(nzLong(row.getDealOrderCount()) + nzInt(doc.getDealOrderCount()));
}
return new ArrayList<>(byDay.values());
}
@@ -189,6 +191,7 @@ public class BiOrderStatQueryService {
r.setFreightCost(BigDecimal.ZERO);
r.setOtherCost(BigDecimal.ZERO);
r.setOrderCount(0L);
r.setDealOrderCount(0L);
return r;
});
row.setSalesAmount(nz(row.getSalesAmount()).add(nz(doc.getSalesAmount())));
@@ -198,6 +201,7 @@ public class BiOrderStatQueryService {
row.setFreightCost(nz(row.getFreightCost()).add(nz(doc.getFreightCost())));
row.setOtherCost(nz(row.getOtherCost()).add(nz(doc.getOtherCost())));
row.setOrderCount(nzLong(row.getOrderCount()) + nzInt(doc.getSalesOrderCount()));
row.setDealOrderCount(nzLong(row.getDealOrderCount()) + nzInt(doc.getDealOrderCount()));
}
return new ArrayList<>(byDay.values());
}
@@ -40,8 +40,10 @@ public final class OverviewAggRows {
private BigDecimal productCost;
private BigDecimal freightCost;
private BigDecimal otherCost;
/** 当日销售单量合计(店铺/商品日汇聚 salesOrderCount) */
/** 当日销售单量合计(店铺/商品日汇聚 salesOrderCount,与「实际销售额」同口径) */
private Long orderCount;
/** 当日成交单量合计(店铺/商品日汇聚 dealOrderCount) */
private Long dealOrderCount;
}
@Data
@@ -21,9 +21,15 @@ public class WorkbenchTrendPointVO {
@Schema(description = "成交金额(元,两位小数):全部订单状态商家实收合计")
private BigDecimal dealYuan;
@Schema(description = "成交单量:全部订单状态的订单笔数,与 KPI「成交单量」同口径")
private Integer dealOrderCount;
@Schema(description = "实际销售额(元,两位小数),与计入销售额的订单状态配置一致")
private BigDecimal salesYuan;
@Schema(description = "实际销售单量:计入销售额状态的订单笔数,与 KPI「销售单量」同口径")
private Integer salesOrderCount;
@Schema(description = "日毛利润(元,两位小数)= 销售额−成本−退款,与 KPI「毛利润」按日拆解口径一致")
private BigDecimal profitYuan;
@@ -395,6 +395,8 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
OverviewAggRows.DailyRow row = byDay.get(d);
BigDecimal sales = row != null ? nz(row.getSalesAmount()) : BigDecimal.ZERO;
BigDecimal deal = row != null ? nz(row.getDealAmount()) : BigDecimal.ZERO;
int salesOrders = row != null && row.getOrderCount() != null ? row.getOrderCount().intValue() : 0;
int dealOrders = row != null && row.getDealOrderCount() != null ? row.getDealOrderCount().intValue() : 0;
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;
@@ -408,7 +410,9 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
list.add(WorkbenchTrendPointVO.builder()
.date(d.format(TREND_DATE_FMT))
.dealYuan(yuan2(deal))
.dealOrderCount(dealOrders)
.salesYuan(yuan2(sales))
.salesOrderCount(salesOrders)
.profitYuan(yuan2(gross))
.netProfitYuan(yuan2(gross.subtract(promoB).subtract(brushB).subtract(taxB)))
.refundYuan(yuan2(refund))
@@ -37,8 +37,12 @@ export namespace WorkbenchVO {
date: string;
/** 日成交金额(元):全部订单状态商家实收 */
dealYuan?: number;
/** 日成交单量:与 KPI「成交单量」同口径 */
dealOrderCount?: number;
/** 日实际销售额(元),与 KPI「实际销售额」同口径 */
salesYuan?: number;
/** 日实际销售单量:与 KPI「销售单量」同口径 */
salesOrderCount?: number;
/** 日毛利润(元)= 销售额−成本−退款 */
profitYuan?: number;
/** 日净利润(元),与 KPI「净利润」及多维分析分摊口径一致 */
@@ -29,6 +29,8 @@ const hasData = computed(
(d) =>
Number(d.dealYuan ?? 0) !== 0 ||
Number(d.salesYuan ?? 0) !== 0 ||
Number(d.dealOrderCount ?? 0) !== 0 ||
Number(d.salesOrderCount ?? 0) !== 0 ||
Number(d.profitYuan ?? 0) !== 0 ||
Number(d.netProfitYuan ?? 0) !== 0,
),
@@ -39,15 +41,19 @@ const periodSummary = computed(() => {
let sales = 0;
let gross = 0;
let net = 0;
let dealOrders = 0;
let salesOrders = 0;
for (const d of props.trend) {
deal += Number(d.dealYuan ?? 0);
sales += Number(d.salesYuan ?? 0);
gross += Number(d.profitYuan ?? 0);
net += Number(d.netProfitYuan ?? 0);
dealOrders += Number(d.dealOrderCount ?? 0);
salesOrders += Number(d.salesOrderCount ?? 0);
}
const netMarginPct =
sales > 0 ? Number(((net / sales) * 100).toFixed(1)) : null;
return { deal, sales, gross, net, netMarginPct };
return { deal, sales, gross, net, netMarginPct, dealOrders, salesOrders };
});
function pctOfSales(part: number, sales: number): string {
@@ -79,6 +85,8 @@ function drawFinanceTrend() {
const dealWan = props.trend.map((d) => yuanToWanNum(Number(d.dealYuan ?? 0)));
const salesWan = props.trend.map((d) => yuanToWanNum(Number(d.salesYuan ?? 0)));
const dealOrders = props.trend.map((d) => Number(d.dealOrderCount ?? 0));
const salesOrders = props.trend.map((d) => Number(d.salesOrderCount ?? 0));
const grossWan = props.trend.map((d) => yuanToWanNum(Number(d.profitYuan ?? 0)));
const netWan = props.trend.map((d) => yuanToWanNum(Number(d.netProfitYuan ?? 0)));
const refundWan = props.trend.map((d) => yuanToWanNum(Number(d.refundYuan ?? 0)));
@@ -105,6 +113,8 @@ function drawFinanceTrend() {
if (!row) return '';
const deal = Number(row.dealYuan ?? 0);
const sales = Number(row.salesYuan ?? 0);
const dealOrder = Number(row.dealOrderCount ?? 0);
const salesOrder = Number(row.salesOrderCount ?? 0);
const gross = Number(row.profitYuan ?? 0);
const net = Number(row.netProfitYuan ?? 0);
const refund = Number(row.refundYuan ?? 0);
@@ -114,7 +124,9 @@ function drawFinanceTrend() {
const lines: string[] = [
`<div style="font-weight:800;margin-bottom:6px">${title}</div>`,
`<span style="color:${isDark ? '#fbbf24' : '#d97706'}">●</span> 成交金额:${formatWanWithYuanDetail(deal)}`,
`<span style="color:${isDark ? '#f59e0b' : '#b45309'}">●</span> 成交单量:${dealOrder} 单`,
`<span style="color:${isDark ? '#60a5fa' : '#1d4ed8'}">●</span> 实际销售额:${formatWanWithYuanDetail(sales)}`,
`<span style="color:${isDark ? '#38bdf8' : '#0369a1'}">●</span> 实际销售单量:${salesOrder} 单`,
`<span style="color:${isDark ? '#34d399' : '#059669'}">●</span> 毛利:${formatWanWithYuanDetail(gross)} <span style="opacity:0.75">(毛利率 ${pctOfSales(gross, sales)})</span>`,
`<span style="color:${isDark ? '#c4b5fd' : '#6d28d9'}">●</span> 净利:${formatWanWithYuanDetail(net)} <span style="opacity:0.75">(净利率 ${pctOfSales(net, sales)})</span>`,
];
@@ -134,6 +146,8 @@ function drawFinanceTrend() {
data: [
'成交金额',
'实际销售额',
'成交单量',
'实际销售单量',
'毛利',
'净利',
'退款',
@@ -141,13 +155,14 @@ function drawFinanceTrend() {
],
selected: {
退款: props.trend.some((d) => Number(d.refundYuan ?? 0) > 0),
净利率: false,
},
},
grid: {
left: '2%',
right: '4%',
right: '6%',
bottom: showDataZoom ? 48 : '3%',
top: 72,
top: 88,
containLabel: true,
},
dataZoom: showDataZoom
@@ -189,9 +204,19 @@ function drawFinanceTrend() {
},
{
type: 'value',
name: '净利率(%)',
name: '单量',
nameTextStyle: { color: axisLabel, fontSize: 11, fontWeight: 700 },
splitLine: { show: false },
axisLabel: {
color: axisLabel,
formatter: (v: number) => (Number.isFinite(v) ? String(v) : ''),
},
},
{
type: 'value',
name: '净利率(%)',
show: false,
splitLine: { show: false },
axisLabel: {
color: axisLabel,
formatter: (v: number) => `${v}%`,
@@ -240,6 +265,40 @@ function drawFinanceTrend() {
data: salesWan,
z: 1,
},
{
name: '成交单量',
type: 'line',
yAxisIndex: 1,
smooth: 0.35,
symbol: 'circle',
symbolSize: 6,
showSymbol: props.trend.length <= 31,
lineStyle: { width: 2.5, color: isDark ? '#f59e0b' : '#b45309' },
itemStyle: {
color: isDark ? '#f59e0b' : '#b45309',
borderWidth: 2,
borderColor: isDark ? '#0f172a' : '#fff',
},
data: dealOrders,
z: 5,
},
{
name: '实际销售单量',
type: 'line',
yAxisIndex: 1,
smooth: 0.35,
symbol: 'circle',
symbolSize: 6,
showSymbol: props.trend.length <= 31,
lineStyle: { width: 2.5, color: isDark ? '#38bdf8' : '#0369a1' },
itemStyle: {
color: isDark ? '#38bdf8' : '#0369a1',
borderWidth: 2,
borderColor: isDark ? '#0f172a' : '#fff',
},
data: salesOrders,
z: 5,
},
{
name: '毛利',
type: 'line',
@@ -288,7 +347,7 @@ function drawFinanceTrend() {
{
name: '净利率',
type: 'line',
yAxisIndex: 1,
yAxisIndex: 2,
smooth: 0.35,
symbol: 'none',
lineStyle: {
@@ -298,7 +357,7 @@ function drawFinanceTrend() {
},
itemStyle: { color: isDark ? '#94a3b8' : '#64748b' },
data: netMarginPct,
z: 5,
z: 6,
},
],
});
@@ -374,7 +433,7 @@ defineExpose({ redraw });
经营趋势
</h3>
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
柱状为成交金额 / 实际销售额,折线为毛利 / 净利;右轴为日净利率
柱状为成交金额 / 实际销售额,折线含成交单量 / 实际销售单量与毛利 / 净利
</p>
</div>
<div
@@ -385,11 +444,13 @@ defineExpose({ redraw });
class="rounded-lg bg-amber-50 px-2.5 py-1 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300"
>
区间成交 {{ formatWanWithYuanDetail(periodSummary.deal) }}
· {{ periodSummary.dealOrders }} 单
</span>
<span
class="rounded-lg bg-blue-50 px-2.5 py-1 text-blue-600 dark:bg-blue-950/50 dark:text-blue-300"
>
区间销售 {{ formatWanWithYuanDetail(periodSummary.sales) }}
· {{ periodSummary.salesOrders }} 单
</span>
<span
class="rounded-lg bg-violet-50 px-2.5 py-1 text-violet-600 dark:bg-violet-950/50 dark:text-violet-300"