From 60e3efab819a39cb4630c1724be5ea163fe301c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Thu, 23 Apr 2026 20:45:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ecom-dmb):=20=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E7=BB=B4=E5=BA=A6=E6=A6=82=E8=A7=88=E6=94=B9=E4=B8=BA=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=BB=93=E6=9E=84=EF=BC=88=E5=90=AB=E5=90=88=E8=AE=A1?= =?UTF-8?q?=E8=A1=8C=EF=BC=89=E5=B9=B6=E4=BC=98=E5=8C=96=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../overview/model/vo/CompanyOverviewVO.java | 15 +- .../impl/CompanyOverviewServiceImpl.java | 238 +++++++++++++++++- .../company-overview/types/types.vo.ts | 12 +- .../components/PlatformSummaryCard.vue | 130 +++------- .../src/views/ecommerce/order/index.vue | 1 - 5 files changed, 288 insertions(+), 108 deletions(-) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/vo/CompanyOverviewVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/vo/CompanyOverviewVO.java index d27427cf..89e22081 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/vo/CompanyOverviewVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/model/vo/CompanyOverviewVO.java @@ -79,11 +79,24 @@ public class CompanyOverviewVO { @Schema(description = "多品类数据横向对比") private List categoryComparisons; + /** + * 平台维度概览(包含合计行和平台列表) + */ + @Data + @Schema(description = "平台维度概览") + public static class PlatformOverview { + @Schema(description = "合计行") + private PlatformSummary total; + + @Schema(description = "各平台汇总列表") + private List platforms; + } + /** * 平台维度汇总 */ @Schema(description = "平台维度汇总") - private List platformSummary; + private PlatformOverview platformSummary; /** * 汇总ROI diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java index a0dea639..41daa4e0 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java @@ -225,9 +225,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { overviewVO.setCategoryComparisons(categoryComparisons); // 11. 平台维度汇总 - List platformSummary = calculatePlatformSummary( + CompanyOverviewVO.PlatformOverview platformOverview = calculatePlatformSummary( shops, orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate); - overviewVO.setPlatformSummary(platformSummary); + overviewVO.setPlatformSummary(platformOverview); // 12. 汇总ROI和总税后盈亏 BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusId); @@ -906,7 +906,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { /** * 计算平台维度汇总 */ - private List calculatePlatformSummary( + private CompanyOverviewVO.PlatformOverview calculatePlatformSummary( List shops, List orders, List promotionFees, List brushOrders, Long refundStatusId, Long companyId, LocalDate startDate, LocalDate endDate) { @@ -920,11 +920,16 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { Map platformMap = allPlatforms.stream() .collect(Collectors.toMap(PlatformPO::getId, p -> p)); - // 按平台分组店铺 + // 按平台分组店铺(有platformId的) Map> shopsByPlatform = shops.stream() .filter(shop -> shop.getPlatformId() != null) .collect(Collectors.groupingBy(ShopPO::getPlatformId)); + // 没有platformId的店铺,汇总为"其他平台" + List shopsWithoutPlatform = shops.stream() + .filter(shop -> shop.getPlatformId() == null) + .collect(Collectors.toList()); + // 生成目标月份列表 List targetMonths = new ArrayList<>(); LocalDate currentMonth = startDate.withDayOfMonth(1); @@ -1106,9 +1111,232 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { platformSummaries.add(platformSummary); } + // 处理没有平台的店铺,汇总为"其他平台" + if (!shopsWithoutPlatform.isEmpty()) { + CompanyOverviewVO.PlatformSummary otherSummary = calculateOtherPlatformSummary( + shopsWithoutPlatform, ordersByShop, promotionFeesByShop, brushOrdersByShop, + targetsByShop, refundStatusId, taxRate); + if (otherSummary.getOrderCount() > 0) { + platformSummaries.add(otherSummary); + } + } + // 按销售额降序排序 platformSummaries.sort(Comparator.comparing(CompanyOverviewVO.PlatformSummary::getSalesAmount).reversed()); - return platformSummaries; + + // 计算合计行 + CompanyOverviewVO.PlatformSummary total = computePlatformTotal(platformSummaries); + + // 封装为 PlatformOverview + CompanyOverviewVO.PlatformOverview overview = new CompanyOverviewVO.PlatformOverview(); + overview.setTotal(total); + overview.setPlatforms(platformSummaries); + return overview; + } + + /** + * 计算平台汇总的合计行 + */ + private CompanyOverviewVO.PlatformSummary computePlatformTotal(List platforms) { + BigDecimal totalSalesAmount = BigDecimal.ZERO; + int totalOrderCount = 0; + BigDecimal totalTargetAmount = BigDecimal.ZERO; + int totalTargetOrderCount = 0; + BigDecimal totalProductCost = BigDecimal.ZERO; + BigDecimal totalShippingCost = BigDecimal.ZERO; + BigDecimal totalOtherCost = BigDecimal.ZERO; + BigDecimal totalRefundAmount = BigDecimal.ZERO; + BigDecimal totalPromotionFee = BigDecimal.ZERO; + BigDecimal totalBrushFee = BigDecimal.ZERO; + + for (CompanyOverviewVO.PlatformSummary p : platforms) { + totalSalesAmount = totalSalesAmount.add(p.getSalesAmount() != null ? p.getSalesAmount() : BigDecimal.ZERO); + totalOrderCount += p.getOrderCount() != null ? p.getOrderCount() : 0; + totalTargetAmount = totalTargetAmount.add(p.getTargetAmount() != null ? p.getTargetAmount() : BigDecimal.ZERO); + totalTargetOrderCount += p.getTargetOrderCount() != null ? p.getTargetOrderCount() : 0; + totalProductCost = totalProductCost.add(p.getProductCost() != null ? p.getProductCost() : BigDecimal.ZERO); + totalShippingCost = totalShippingCost.add(p.getShippingCost() != null ? p.getShippingCost() : BigDecimal.ZERO); + totalOtherCost = totalOtherCost.add(p.getOtherCost() != null ? p.getOtherCost() : BigDecimal.ZERO); + totalRefundAmount = totalRefundAmount.add(p.getRefundAmount() != null ? p.getRefundAmount() : BigDecimal.ZERO); + totalPromotionFee = totalPromotionFee.add(p.getTotalPromotionFee() != null ? p.getTotalPromotionFee() : BigDecimal.ZERO); + totalBrushFee = totalBrushFee.add(p.getBrushFee() != null ? p.getBrushFee() : BigDecimal.ZERO); + } + + BigDecimal avgOrderValue = totalOrderCount > 0 + ? totalSalesAmount.divide(new BigDecimal(totalOrderCount), 2, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost); + BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount); + BigDecimal taxRate = new BigDecimal("0.04"); + BigDecimal salesTax = totalSalesAmount.multiply(taxRate); + BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax); + BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0 + ? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal feeRatio = totalSalesAmount.compareTo(BigDecimal.ZERO) > 0 + ? totalPromotionFee.add(totalBrushFee).divide(totalSalesAmount, 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal salesAchievementRate = totalTargetAmount.compareTo(BigDecimal.ZERO) > 0 + ? totalSalesAmount.divide(totalTargetAmount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) + : totalSalesAmount.compareTo(BigDecimal.ZERO) > 0 ? new BigDecimal("100") : BigDecimal.ZERO; + BigDecimal orderAchievementRate = totalTargetOrderCount > 0 + ? new BigDecimal(totalOrderCount).divide(new BigDecimal(totalTargetOrderCount), 4, RoundingMode.HALF_UP) + .multiply(new BigDecimal("100")) + : totalOrderCount > 0 ? new BigDecimal("100") : BigDecimal.ZERO; + + CompanyOverviewVO.PlatformSummary total = new CompanyOverviewVO.PlatformSummary(); + total.setPlatformId(0L); + total.setPlatformName("合计"); + total.setSalesAmount(totalSalesAmount); + total.setOrderCount(totalOrderCount); + total.setAverageOrderValue(avgOrderValue); + total.setTargetAmount(totalTargetAmount); + total.setTargetOrderCount(totalTargetOrderCount); + total.setSalesAmountAchievementRate(salesAchievementRate); + total.setOrderCountAchievementRate(orderAchievementRate); + total.setProductCost(totalProductCost); + total.setShippingCost(totalShippingCost); + total.setOtherCost(totalOtherCost); + total.setRefundAmount(totalRefundAmount); + total.setTotalPromotionFee(totalPromotionFee); + total.setBrushFee(totalBrushFee); + total.setFeeRatio(feeRatio); + total.setTotalProfitBeforeTax(profitBeforeTax); + total.setSalesTaxAmount(salesTax); + total.setRoi(roi); + total.setProfitAfterTax(profitAfterTax); + return total; + } + + /** + * 计算"其他平台"汇总(没有绑定平台的店铺) + */ + private CompanyOverviewVO.PlatformSummary calculateOtherPlatformSummary( + List shops, + Map> ordersByShop, + Map> promotionFeesByShop, + Map> brushOrdersByShop, + Map> targetsByShop, + Long refundStatusId, + BigDecimal taxRate) { + + BigDecimal totalSalesAmount = BigDecimal.ZERO; + int totalOrderCount = 0; + BigDecimal totalRefundAmount = BigDecimal.ZERO; + BigDecimal totalProductCost = BigDecimal.ZERO; + BigDecimal totalShippingCost = BigDecimal.ZERO; + BigDecimal totalOtherCost = BigDecimal.ZERO; + BigDecimal totalPromotionFee = BigDecimal.ZERO; + BigDecimal totalBrushFee = BigDecimal.ZERO; + BigDecimal totalTargetAmount = BigDecimal.ZERO; + int totalTargetOrderCount = 0; + + for (ShopPO shop : shops) { + List shopOrders = ordersByShop.getOrDefault(shop.getId(), new ArrayList<>()); + List shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>()); + List shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>()); + List shopTargets = targetsByShop.getOrDefault(shop.getId(), new ArrayList<>()); + + BigDecimal shopSales = shopOrders.stream() + .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) + .reduce(BigDecimal.ZERO, BigDecimal::add); + totalSalesAmount = totalSalesAmount.add(shopSales); + totalOrderCount += shopOrders.size(); + + BigDecimal shopRefund = shopOrders.stream() + .filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId())) + .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) + .reduce(BigDecimal.ZERO, BigDecimal::add); + totalRefundAmount = totalRefundAmount.add(shopRefund); + + BigDecimal shopProductCost = shopOrders.stream() + .map(o -> { + BigDecimal c = o.getProductCost() != null ? o.getProductCost() : BigDecimal.ZERO; + int qty = o.getQuantity() != null ? o.getQuantity() : 1; + return c.multiply(new BigDecimal(qty)); + }) + .reduce(BigDecimal.ZERO, BigDecimal::add); + totalProductCost = totalProductCost.add(shopProductCost); + + BigDecimal shopShippingCost = shopOrders.stream() + .map(o -> { + BigDecimal c = o.getShippingCost() != null ? o.getShippingCost() : BigDecimal.ZERO; + int qty = o.getQuantity() != null ? o.getQuantity() : 1; + return c.multiply(new BigDecimal(qty)); + }) + .reduce(BigDecimal.ZERO, BigDecimal::add); + totalShippingCost = totalShippingCost.add(shopShippingCost); + + BigDecimal shopOtherCost = shopOrders.stream() + .map(o -> o.getOtherCost() != null ? o.getOtherCost() : BigDecimal.ZERO) + .reduce(BigDecimal.ZERO, BigDecimal::add); + totalOtherCost = totalOtherCost.add(shopOtherCost); + + BigDecimal shopPromoFee = shopPromotionFees.stream() + .map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO) + .reduce(BigDecimal.ZERO, BigDecimal::add); + totalPromotionFee = totalPromotionFee.add(shopPromoFee); + + BigDecimal shopBrush = shopBrushOrders.stream() + .map(b -> b.getBrushAmount() != null ? b.getBrushAmount() : BigDecimal.ZERO) + .reduce(BigDecimal.ZERO, BigDecimal::add); + totalBrushFee = totalBrushFee.add(shopBrush); + + BigDecimal shopTargetAmount = shopTargets.stream() + .map(t -> t.getTargetAmount() != null ? t.getTargetAmount() : BigDecimal.ZERO) + .reduce(BigDecimal.ZERO, BigDecimal::add); + totalTargetAmount = totalTargetAmount.add(shopTargetAmount); + + int shopTargetOrderCount = shopTargets.stream() + .mapToInt(t -> t.getTargetOrderCount() != null ? t.getTargetOrderCount() : 0) + .sum(); + totalTargetOrderCount += shopTargetOrderCount; + } + + BigDecimal averageOrderValue = totalOrderCount > 0 + ? totalSalesAmount.divide(new BigDecimal(totalOrderCount), 2, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost); + BigDecimal profitBeforeTax = totalSalesAmount.subtract(totalCost).subtract(totalRefundAmount); + BigDecimal salesTaxAmount = totalSalesAmount.multiply(taxRate); + BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount); + BigDecimal roi = totalPromotionFee.compareTo(BigDecimal.ZERO) > 0 + ? totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal feeRatio = totalSalesAmount.compareTo(BigDecimal.ZERO) > 0 + ? totalPromotionFee.add(totalBrushFee).divide(totalSalesAmount, 4, RoundingMode.HALF_UP) + : BigDecimal.ZERO; + BigDecimal salesAchievementRate = totalTargetAmount.compareTo(BigDecimal.ZERO) > 0 + ? totalSalesAmount.divide(totalTargetAmount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) + : totalSalesAmount.compareTo(BigDecimal.ZERO) > 0 ? new BigDecimal("100") : BigDecimal.ZERO; + BigDecimal orderAchievementRate = totalTargetOrderCount > 0 + ? new BigDecimal(totalOrderCount).divide(new BigDecimal(totalTargetOrderCount), 4, RoundingMode.HALF_UP) + .multiply(new BigDecimal("100")) + : totalOrderCount > 0 ? new BigDecimal("100") : BigDecimal.ZERO; + + CompanyOverviewVO.PlatformSummary summary = new CompanyOverviewVO.PlatformSummary(); + summary.setPlatformId(0L); // 0表示"其他平台" + summary.setPlatformName("其他平台"); + summary.setTargetOrderCount(totalTargetOrderCount); + summary.setOrderCountAchievementRate(orderAchievementRate); + summary.setTargetAmount(totalTargetAmount); + summary.setSalesAmountAchievementRate(salesAchievementRate); + summary.setSalesAmount(totalSalesAmount); + summary.setOrderCount(totalOrderCount); + summary.setAverageOrderValue(averageOrderValue); + summary.setProductCost(totalProductCost); + summary.setShippingCost(totalShippingCost); + summary.setOtherCost(totalOtherCost); + summary.setRefundAmount(totalRefundAmount); + summary.setTotalPromotionFee(totalPromotionFee); + summary.setBrushFee(totalBrushFee); + summary.setFeeRatio(feeRatio); + summary.setTotalProfitBeforeTax(profitBeforeTax); + summary.setSalesTaxAmount(salesTaxAmount); + summary.setRoi(roi); + summary.setProfitAfterTax(profitAfterTax); + + return summary; } private String getPlatformNameById(Long platformId) { diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/company-overview/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/company-overview/types/types.vo.ts index 6f1f3a19..6417b26b 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/company-overview/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/company-overview/types/types.vo.ts @@ -27,8 +27,8 @@ export namespace CompanyOverviewVO { shopComparisons?: ShopComparison[]; /** 多品类数据横向对比 */ categoryComparisons?: CategoryComparison[]; - /** 平台维度汇总 */ - platformSummary?: PlatformSummary[]; + /** 平台维度概览(包含合计行和平台列表) */ + platformSummary?: PlatformOverview; /** 汇总ROI */ totalROI?: number; /** 总税后盈亏 */ @@ -194,4 +194,12 @@ export namespace CompanyOverviewVO { /** 税后盈亏 */ profitAfterTax?: number; } + + /** 平台维度概览 */ + export interface PlatformOverview { + /** 合计行 */ + total: PlatformSummary; + /** 各平台汇总列表 */ + platforms: PlatformSummary[]; + } } diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/components/PlatformSummaryCard.vue b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/components/PlatformSummaryCard.vue index 708ff72f..dfcf8a45 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/components/PlatformSummaryCard.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/components/PlatformSummaryCard.vue @@ -6,7 +6,7 @@ defineOptions({ name: 'PlatformSummaryCard' }); interface Props { taxRate?: number; - platformSummary?: CompanyOverviewVO.PlatformSummary[]; + platformSummary?: CompanyOverviewVO.PlatformOverview; platformExportMode?: boolean; selectedExportPlatformIds?: number[]; } @@ -31,70 +31,6 @@ const somePlatformsSelected = computed(() => { return props.selectedExportPlatformIds.length > 0; }); -// 静态模拟数据 - 按平台汇总(字段与店铺明细表对齐) -const mockPlatformData = [ - { - platformId: 1, platformName: '淘宝', - targetOrderCount: 5000, orderCountAchievementRate: 90.4, - targetAmount: 320000, salesAmountAchievementRate: 88.6, - salesAmount: 283600, orderCount: 4521, averageOrderValue: 62.7, - productCost: 156000, shippingCost: 8500, otherCost: 3200, - refundAmount: 12600, totalPromotionFee: 9800, brushFee: 4200, - feeRatio: 18.7, - totalProfitBeforeTax: 98600, salesTaxAmount: 11344, roi: 2.34, profitAfterTax: 87256, - }, - { - platformId: 2, platformName: '京东', - targetOrderCount: 3500, orderCountAchievementRate: 93.7, - targetAmount: 210000, salesAmountAchievementRate: 93.7, - salesAmount: 196800, orderCount: 3280, averageOrderValue: 60.0, - productCost: 108000, shippingCost: 6200, otherCost: 1800, - refundAmount: 8900, totalPromotionFee: 6800, brushFee: 2100, - feeRatio: 17.6, - totalProfitBeforeTax: 71000, salesTaxAmount: 7872, roi: 2.61, profitAfterTax: 63128, - }, - { - platformId: 3, platformName: '拼多多', - targetOrderCount: 6500, orderCountAchievementRate: 90.6, - targetAmount: 170000, salesAmountAchievementRate: 90.7, - salesAmount: 154200, orderCount: 5890, averageOrderValue: 26.2, - productCost: 92400, shippingCost: 11800, otherCost: 2200, - refundAmount: 18200, totalPromotionFee: 5600, brushFee: 3800, - feeRatio: 25.9, - totalProfitBeforeTax: 22200, salesTaxAmount: 6168, roi: 0.76, profitAfterTax: 16032, - }, - { - platformId: 4, platformName: '抖音', - targetOrderCount: 2200, orderCountAchievementRate: 95.5, - targetAmount: 60000, salesAmountAchievementRate: 103.3, - salesAmount: 62000, orderCount: 2100, averageOrderValue: 29.5, - productCost: 34100, shippingCost: 4200, otherCost: 1500, - refundAmount: 3100, totalPromotionFee: 3200, brushFee: 0, - feeRatio: 19.7, - totalProfitBeforeTax: 15900, salesTaxAmount: 2480, roi: 2.12, profitAfterTax: 13420, - }, - { - platformId: 5, platformName: '天猫', - targetOrderCount: 700, orderCountAchievementRate: 97.1, - targetAmount: 36000, salesAmountAchievementRate: 98.3, - salesAmount: 35400, orderCount: 680, averageOrderValue: 52.1, - productCost: 19400, shippingCost: 680, otherCost: 560, - refundAmount: 1100, totalPromotionFee: 1800, brushFee: 0, - feeRatio: 11.5, - totalProfitBeforeTax: 12860, salesTaxAmount: 1416, roi: 3.89, profitAfterTax: 11444, - }, - { - platformId: 6, platformName: '快手', - targetOrderCount: 600, orderCountAchievementRate: 86.7, - targetAmount: 15000, salesAmountAchievementRate: 85.3, - salesAmount: 12800, orderCount: 520, averageOrderValue: 24.6, - productCost: 7680, shippingCost: 1040, otherCost: 280, - refundAmount: 620, totalPromotionFee: 960, brushFee: 0, - feeRatio: 19.5, - totalProfitBeforeTax: 2220, salesTaxAmount: 512, roi: 1.52, profitAfterTax: 1708, - }, -]; - const formatAmount = (amount: number) => { return `¥${amount.toLocaleString('zh-CN')}`; }; @@ -106,10 +42,10 @@ const formatPercentPlain = (value: number | undefined) => { const taxRateNum = computed(() => (props.taxRate ?? 0.04) * 100); -// 优先使用动态数据,否则降级到静态mock +// 使用后端返回的平台列表数据 const platformData = computed(() => { - if (props.platformSummary && props.platformSummary.length > 0) { - return props.platformSummary.map(p => ({ + if (props.platformSummary?.platforms && props.platformSummary.platforms.length > 0) { + return props.platformSummary.platforms.map(p => ({ platformId: p.platformId, platformName: p.platformName, targetOrderCount: p.targetOrderCount ?? 0, @@ -132,12 +68,11 @@ const platformData = computed(() => { profitAfterTax: p.profitAfterTax ?? 0, })); } - return mockPlatformData; + return []; }); -const totalSales = computed(() => platformData.value.reduce((sum, p) => sum + p.salesAmount, 0)); -const totalOrderCount = computed(() => platformData.value.reduce((sum, p) => sum + p.orderCount, 0)); -const totalProfitAfterTax = computed(() => platformData.value.reduce((sum, p) => sum + p.profitAfterTax, 0)); +// 后端返回的合计行数据 +const totalData = computed(() => props.platformSummary?.total ?? null); // 表格排序 const sortField = ref('salesAmount'); @@ -352,53 +287,50 @@ const sortIcon = (field: string) => { - + 合计 - {{ platformData.reduce((s, p) => s + p.targetOrderCount, 0).toLocaleString() }} + {{ totalData.targetOrderCount?.toLocaleString() }} - - {{ formatAmount(platformData.reduce((s, p) => s + p.targetAmount, 0)) }} + {{ formatAmount(totalData.targetAmount) }} - - {{ formatAmount(totalSales) }} - {{ totalOrderCount.toLocaleString() }} + {{ formatAmount(totalData.salesAmount) }} + {{ totalData.orderCount?.toLocaleString() }} - - {{ formatAmount(platformData.reduce((s, p) => s + p.productCost, 0)) }} - {{ formatAmount(platformData.reduce((s, p) => s + p.shippingCost, 0)) }} - {{ formatAmount(platformData.reduce((s, p) => s + p.otherCost, 0)) }} - {{ formatAmount(platformData.reduce((s, p) => s + p.refundAmount, 0)) }} - {{ formatAmount(platformData.reduce((s, p) => s + p.totalPromotionFee, 0)) }} - {{ formatAmount(platformData.reduce((s, p) => s + p.brushFee, 0)) }} + {{ formatAmount(totalData.productCost) }} + {{ formatAmount(totalData.shippingCost) }} + {{ formatAmount(totalData.otherCost) }} + {{ formatAmount(totalData.refundAmount) }} + {{ formatAmount(totalData.totalPromotionFee) }} + {{ formatAmount(totalData.brushFee) }} - {{ formatPercentPlain( - totalSales > 0 - ? platformData.reduce((s, p) => s + p.productCost + p.shippingCost + p.otherCost + p.refundAmount + p.totalPromotionFee + p.brushFee, 0) / totalSales * 100 - : 0, - ) }} + {{ formatPercentPlain(totalData.feeRatio) }} - {{ formatAmount(platformData.reduce((s, p) => s + p.totalProfitBeforeTax, 0)) }} + {{ formatAmount(totalData.totalProfitBeforeTax) }} - {{ formatAmount(platformData.reduce((s, p) => s + p.salesTaxAmount, 0)) }} + {{ formatAmount(totalData.salesTaxAmount) }} - {{ - (() => { - const totalProfit = platformData.reduce((s, p) => s + p.totalProfitBeforeTax, 0); - const totalCost = platformData.reduce((s, p) => s + p.productCost + p.shippingCost + p.otherCost + p.refundAmount + p.totalPromotionFee + p.brushFee, 0); - return totalCost > 0 ? (totalProfit / totalCost).toFixed(2) : '-'; - })() - }} + {{ totalData.roi?.toFixed(2) }} - - {{ formatAmount(totalProfitAfterTax) }} + + {{ formatAmount(totalData.profitAfterTax) }} + + + 暂无数据 + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order/index.vue index 0074f1b1..13d1b9ce 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order/index.vue @@ -16,7 +16,6 @@ import dayjs from 'dayjs'; import { Button, - DatePicker, message, Popconfirm, Popover,