mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
feat: 全店概览新增商品销量 Top10 榜单,移除冗余的税后盈亏字段
- ShopOverviewStatisticsVO:移除 totalProfitAfterTax,新增 productSalesTop10(按单量排序的销量 Top10 列表) - ShopOverviewStatisticsServiceImpl:新增 fillProductSalesTop10(),从商品横向汇总中按单量取 Top10 - 前端 types.vo.ts:同步更新字段替换 - 前端:移除 FinancialPanel.vue,新增 ProductSalesTop10Panel.vue 商品销量榜单组件
This commit is contained in:
+25
-3
@@ -118,10 +118,10 @@ public class ShopOverviewStatisticsVO {
|
||||
private BigDecimal totalProfitBeforeTax;
|
||||
|
||||
/**
|
||||
* 总税后盈亏
|
||||
* 各商品按单量排序的销量 Top10(与当前筛选时间范围一致)
|
||||
*/
|
||||
@Schema(description = "总税后盈亏", example = "80000.00")
|
||||
private BigDecimal totalProfitAfterTax;
|
||||
@Schema(description = "各商品销量 Top10")
|
||||
private List<ProductSalesRankItem> productSalesTop10;
|
||||
|
||||
/**
|
||||
* 销售额趋势分析
|
||||
@@ -147,6 +147,28 @@ public class ShopOverviewStatisticsVO {
|
||||
@Schema(description = "品类多维度数据汇总")
|
||||
private CategoryOverview categoryOverview;
|
||||
|
||||
/**
|
||||
* 商品销量排行项(概览 Top10)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "商品销量排行项")
|
||||
public static class ProductSalesRankItem {
|
||||
@Schema(description = "商品ID", example = "1")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "商品名称", example = "iPhone 15 Pro")
|
||||
private String productName;
|
||||
|
||||
@Schema(description = "商品编码", example = "IPHONE15PRO")
|
||||
private String productCode;
|
||||
|
||||
@Schema(description = "单量", example = "500")
|
||||
private Integer orderCount;
|
||||
|
||||
@Schema(description = "销售额", example = "50000.00")
|
||||
private BigDecimal salesAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品概览(含合计行和商品列表)
|
||||
*/
|
||||
|
||||
+32
-2
@@ -237,10 +237,9 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
// 7. 计算目标维度的数据
|
||||
calculateTargetData(overviewVO, companyId, queryDTO.getShopId(), startDate, endDate, totalSalesAmount, totalOrderCount);
|
||||
|
||||
// 8. 汇总ROI和总税后盈亏
|
||||
// 8. 汇总ROI
|
||||
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, stat);
|
||||
overviewVO.setTotalROI(totalROI);
|
||||
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
|
||||
|
||||
// 9. 计算趋势分析数据
|
||||
ShopOverviewStatisticsVO.TrendData salesAmountTrend = calculateSalesAmountTrend(orders, startDate, endDate, stat);
|
||||
@@ -258,9 +257,40 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
orders, promotionFees, brushOrders, stat);
|
||||
overviewVO.setCategoryOverview(categoryOverview);
|
||||
|
||||
fillProductSalesTop10(overviewVO);
|
||||
|
||||
return overviewVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从商品横向汇总中按单量取 Top10,供概览榜单展示(不重复计算订单)
|
||||
*/
|
||||
private void fillProductSalesTop10(ShopOverviewStatisticsVO vo) {
|
||||
ShopOverviewStatisticsVO.ProductOverview po = vo.getProductOverview();
|
||||
if (po == null || po.getProducts() == null || po.getProducts().isEmpty()) {
|
||||
vo.setProductSalesTop10(Collections.emptyList());
|
||||
return;
|
||||
}
|
||||
List<ShopOverviewStatisticsVO.ProductSalesRankItem> top10 = po.getProducts().stream()
|
||||
.sorted(Comparator.comparing(
|
||||
(ShopOverviewStatisticsVO.ProductComparison p) ->
|
||||
p.getOrderCount() != null ? p.getOrderCount() : 0,
|
||||
Comparator.reverseOrder()))
|
||||
.limit(10)
|
||||
.map(p -> {
|
||||
ShopOverviewStatisticsVO.ProductSalesRankItem item =
|
||||
new ShopOverviewStatisticsVO.ProductSalesRankItem();
|
||||
item.setProductId(p.getProductId());
|
||||
item.setProductName(p.getProductName());
|
||||
item.setProductCode(p.getProductCode());
|
||||
item.setOrderCount(p.getOrderCount());
|
||||
item.setSalesAmount(p.getSalesAmount());
|
||||
return item;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
vo.setProductSalesTop10(top10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单维度毛利(税前、未扣推广费/刷单费),全店税前盈亏需再减推广费与刷单费
|
||||
*/
|
||||
|
||||
@@ -91,8 +91,8 @@ export namespace ShopVO {
|
||||
refundAmount?: number;
|
||||
/** 店铺税前盈亏(扣销售额税额前) */
|
||||
totalProfitBeforeTax?: number;
|
||||
/** 总税后盈亏 */
|
||||
totalProfitAfterTax?: number;
|
||||
/** 各商品按单量排序的销量 Top10 */
|
||||
productSalesTop10?: ProductSalesRankItem[];
|
||||
/** 销售额趋势分析 */
|
||||
salesAmountTrend?: TrendData;
|
||||
/** 单量趋势分析 */
|
||||
@@ -103,6 +103,15 @@ export namespace ShopVO {
|
||||
categoryOverview?: CategoryOverview;
|
||||
}
|
||||
|
||||
/** 商品销量排行项(店铺概览 Top10) */
|
||||
export interface ProductSalesRankItem {
|
||||
productId?: number;
|
||||
productName?: string;
|
||||
productCode?: string;
|
||||
orderCount?: number;
|
||||
salesAmount?: number;
|
||||
}
|
||||
|
||||
/** 商品汇总数据 */
|
||||
export interface ProductComparison {
|
||||
/** 商品ID */
|
||||
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
interface Props {
|
||||
data: ShopVO.OverviewStatistics | null;
|
||||
taxRate: number;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const formatAmount = (amount: number) => {
|
||||
return `¥${amount.toLocaleString('zh-CN')}`;
|
||||
};
|
||||
|
||||
const formatPercent = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex flex-col rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<h3 class="mb-6 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
财务损益全维度 (P&L)
|
||||
</h3>
|
||||
<div class="flex flex-1 flex-col space-y-4 text-sm">
|
||||
<div class="flex justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pb-2">
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">推广费总支出</span>
|
||||
<span class="font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ data?.totalPromotionFee ? `-${formatAmount(data.totalPromotionFee)}` : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pb-2">
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">客单价 (AOV)</span>
|
||||
<span class="font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ data?.totalSalesAmount && data?.totalOrderCount ? formatAmount(data.totalSalesAmount / data.totalOrderCount) : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pb-2">
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">总税后盈亏 (Profit)</span>
|
||||
<span class="font-bold text-indigo-600 dark:text-indigo-400">
|
||||
{{ data?.totalProfitAfterTax ? formatAmount(data.totalProfitAfterTax) : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 扣除项 -->
|
||||
<div class="mt-4 space-y-3 rounded-2xl bg-slate-50/80 dark:bg-[hsl(240deg_3.7%_15.9%/80)] p-4">
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">销售额 {{ (props.taxRate * 100).toFixed(0) }}% 税额</span>
|
||||
<span class="font-bold text-rose-500 dark:text-rose-400">
|
||||
{{ data?.totalTaxAmount ? formatAmount(data.totalTaxAmount) : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">较上月同期增长</span>
|
||||
<span class="font-black text-emerald-500 dark:text-emerald-400">
|
||||
{{ formatPercent(data?.monthOverMonthGrowth) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 最终结果 -->
|
||||
<div
|
||||
class="mt-auto flex items-center justify-between rounded-2xl bg-slate-900 p-5 text-white shadow-2xl dark:shadow-none"
|
||||
>
|
||||
<div>
|
||||
<p class="text-[10px] font-black uppercase opacity-60">Final Net Profit</p>
|
||||
<p class="text-xs font-bold">税后最终净利</p>
|
||||
</div>
|
||||
<div class="text-3xl font-black">
|
||||
{{ data?.totalNetProfitAfterTax ? formatAmount(data.totalNetProfitAfterTax) : '-' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
interface Props {
|
||||
data: ShopVO.OverviewStatistics | null;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const formatAmount = (amount: number | undefined) => {
|
||||
if (amount === undefined || amount === null) return '-';
|
||||
return `¥${amount.toLocaleString('zh-CN')}`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex flex-col rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<h3 class="mb-1 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
各商品销量 Top10
|
||||
</h3>
|
||||
<p class="mb-5 text-xs font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
按单量排序,与上方时间范围一致
|
||||
</p>
|
||||
|
||||
<div class="max-h-[380px] flex-1 space-y-2 overflow-y-auto pr-1">
|
||||
<template v-if="data?.productSalesTop10?.length">
|
||||
<div
|
||||
v-for="(row, idx) in data.productSalesTop10"
|
||||
:key="row.productId ?? `rank-${idx}`"
|
||||
class="flex items-center gap-3 rounded-xl border border-slate-100/90 bg-slate-50/60 px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/50%)]"
|
||||
>
|
||||
<span
|
||||
class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-sm font-black tabular-nums"
|
||||
:class="
|
||||
idx === 0
|
||||
? 'bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-200'
|
||||
: idx === 1
|
||||
? 'bg-slate-200 text-slate-700 dark:bg-slate-600 dark:text-slate-100'
|
||||
: idx === 2
|
||||
? 'bg-orange-100 text-orange-900 dark:bg-orange-900/30 dark:text-orange-200'
|
||||
: 'bg-slate-100 text-slate-500 dark:bg-slate-700 dark:text-slate-300'
|
||||
"
|
||||
>
|
||||
{{ idx + 1 }}
|
||||
</span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div
|
||||
class="truncate text-sm font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
:title="row.productName"
|
||||
>
|
||||
{{ row.productName || '-' }}
|
||||
</div>
|
||||
<div
|
||||
v-if="row.productCode"
|
||||
class="truncate text-[11px] text-slate-400 dark:text-[hsl(240deg_5%_55%)]"
|
||||
>
|
||||
{{ row.productCode }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="shrink-0 text-right">
|
||||
<div class="text-sm font-black tabular-nums text-indigo-600 dark:text-indigo-400">
|
||||
{{ row.orderCount != null ? row.orderCount.toLocaleString('zh-CN') : '-' }}
|
||||
<span class="text-[10px] font-semibold text-slate-400 dark:text-[hsl(240deg_5%_55%)]">单</span>
|
||||
</div>
|
||||
<div class="text-[11px] font-semibold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ formatAmount(row.salesAmount) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div
|
||||
v-else
|
||||
class="flex flex-1 items-center justify-center py-16 text-sm text-slate-400 dark:text-[hsl(240deg_5%_55%)]"
|
||||
>
|
||||
暂无商品数据
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -21,7 +21,7 @@ import { exportByPost } from '#/utils/export';
|
||||
import TimeRangeBar from './components/TimeRangeBar.vue';
|
||||
import StatCards from './components/StatCards.vue';
|
||||
import SalesTrendChart from './components/SalesTrendChart.vue';
|
||||
import FinancialPanel from './components/FinancialPanel.vue';
|
||||
import ProductSalesTop10Panel from './components/ProductSalesTop10Panel.vue';
|
||||
import ProductCategorySwitcher from './components/ProductCategorySwitcher.vue';
|
||||
|
||||
defineOptions({ name: 'ShopOverview' });
|
||||
@@ -354,10 +354,10 @@ onActivated(async () => {
|
||||
<!-- 第一层:核心统计卡片 -->
|
||||
<StatCards :data="overviewData" :loading="loading" />
|
||||
|
||||
<!-- 第二层:趋势与财务拆解 -->
|
||||
<!-- 第二层:趋势与销量榜 -->
|
||||
<div class="grid grid-cols-1 gap-6 xl:grid-cols-3">
|
||||
<SalesTrendChart :data="overviewData" />
|
||||
<FinancialPanel :data="overviewData" :tax-rate="taxRate" />
|
||||
<ProductSalesTop10Panel :data="overviewData" />
|
||||
</div>
|
||||
|
||||
<!-- 第三层:商品/品类多维度损益汇总表 -->
|
||||
|
||||
Reference in New Issue
Block a user