mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat(ecom-dmb): 新增平台维度汇总功能
后端: - CompanyOverviewVO 新增 platformSummary 平台维度汇总数据 - CompanyOverviewServiceImpl 新增 calculatePlatformSummary() 方法,按平台聚合数据 - PlatformExportDTO 导出参数 DTO - ExportService/ExportServiceImpl 新增 exportPlatformOverview 导出方法 - ExportController 新增 POST /ec/platform-overview/export 接口 前端: - PlatformSummaryCard 组件显示各平台多维度经营明细对比 - 支持指定平台导出和导出全部两种模式 - 组件优先使用动态数据,无数据时降级到 mock 数据 - types.vo.ts 新增 PlatformSummary 类型定义 - index.vue 集成平台导出功能
This commit is contained in:
+12
@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CategoryExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.PlatformExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.service.ExportService;
|
||||
|
||||
@@ -75,6 +76,17 @@ public class ExportController {
|
||||
writeExcel(response, filename, data);
|
||||
}
|
||||
|
||||
@Operation(summary = "导出平台维度汇总Excel", description = "导出平台维度汇总数据为Excel文件,支持指定平台或导出全部")
|
||||
@PostMapping("/platform-overview/export")
|
||||
@RequirePermission(value = "data:export", description = "导出平台维度汇总", allowSuper = true)
|
||||
public void exportPlatformOverview(@Valid @RequestBody PlatformExportDTO dto, HttpServletResponse response) {
|
||||
byte[] data = exportService.exportPlatformOverview(dto);
|
||||
String dateRange = dto.getDateRange().get(0).format(FILE_NAME_FMT) + "-" +
|
||||
dto.getDateRange().get(dto.getDateRange().size() - 1).format(FILE_NAME_FMT);
|
||||
String filename = "平台维度汇总_" + dateRange + ".xlsx";
|
||||
writeExcel(response, filename, data);
|
||||
}
|
||||
|
||||
private void writeExcel(HttpServletResponse response, String filename, byte[] data) {
|
||||
try {
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 平台维度汇总导出DTO
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Schema(description = "平台维度汇总导出DTO")
|
||||
public class PlatformExportDTO {
|
||||
|
||||
@Schema(description = "日期范围数组", example = "[\"2024-01-01\", \"2024-01-31\"]", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "日期范围不能为空")
|
||||
@Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期")
|
||||
private List<LocalDate> dateRange;
|
||||
|
||||
@Schema(description = "平台ID列表,不传则导出全部平台", example = "[1, 2]")
|
||||
private List<Long> platformIds;
|
||||
|
||||
@Schema(description = "税率,默认 0.04", example = "0.04")
|
||||
private BigDecimal taxRate = new BigDecimal("0.04");
|
||||
}
|
||||
+73
@@ -79,6 +79,12 @@ public class CompanyOverviewVO {
|
||||
@Schema(description = "多品类数据横向对比")
|
||||
private List<CategoryComparison> categoryComparisons;
|
||||
|
||||
/**
|
||||
* 平台维度汇总
|
||||
*/
|
||||
@Schema(description = "平台维度汇总")
|
||||
private List<PlatformSummary> platformSummary;
|
||||
|
||||
/**
|
||||
* 汇总ROI
|
||||
*/
|
||||
@@ -287,5 +293,72 @@ public class CompanyOverviewVO {
|
||||
@Schema(description = "ROI", example = "1.5")
|
||||
private BigDecimal roi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台维度汇总
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "平台维度汇总")
|
||||
public static class PlatformSummary {
|
||||
@Schema(description = "平台ID", example = "1")
|
||||
private Long platformId;
|
||||
|
||||
@Schema(description = "平台名称", example = "淘宝")
|
||||
private String platformName;
|
||||
|
||||
@Schema(description = "目标单量", example = "5000")
|
||||
private Integer targetOrderCount;
|
||||
|
||||
@Schema(description = "单量达成率", example = "90.4")
|
||||
private BigDecimal orderCountAchievementRate;
|
||||
|
||||
@Schema(description = "目标销售额", example = "320000.00")
|
||||
private BigDecimal targetAmount;
|
||||
|
||||
@Schema(description = "销售额达成率", example = "88.6")
|
||||
private BigDecimal salesAmountAchievementRate;
|
||||
|
||||
@Schema(description = "销售额", example = "283600.00")
|
||||
private BigDecimal salesAmount;
|
||||
|
||||
@Schema(description = "单量", example = "4521")
|
||||
private Integer orderCount;
|
||||
|
||||
@Schema(description = "客单价", example = "62.70")
|
||||
private BigDecimal averageOrderValue;
|
||||
|
||||
@Schema(description = "商品成本", example = "156000.00")
|
||||
private BigDecimal productCost;
|
||||
|
||||
@Schema(description = "运费", example = "8500.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
@Schema(description = "其他成本", example = "3200.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
@Schema(description = "退款金额", example = "12600.00")
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
@Schema(description = "推广费", example = "9800.00")
|
||||
private BigDecimal totalPromotionFee;
|
||||
|
||||
@Schema(description = "刷单费用", example = "4200.00")
|
||||
private BigDecimal brushFee;
|
||||
|
||||
@Schema(description = "费比", example = "0.187")
|
||||
private BigDecimal feeRatio;
|
||||
|
||||
@Schema(description = "税前盈亏", example = "98600.00")
|
||||
private BigDecimal totalProfitBeforeTax;
|
||||
|
||||
@Schema(description = "销售额4%税额", example = "11344.00")
|
||||
private BigDecimal salesTaxAmount;
|
||||
|
||||
@Schema(description = "ROI", example = "2.34")
|
||||
private BigDecimal roi;
|
||||
|
||||
@Schema(description = "税后盈亏", example = "87256.00")
|
||||
private BigDecimal profitAfterTax;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -2,6 +2,7 @@ package top.xyquan.ecomdmbbackend.modules.ecom.overview.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CategoryExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.PlatformExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopExportDTO;
|
||||
|
||||
/**
|
||||
@@ -32,4 +33,12 @@ public interface ExportService {
|
||||
* @return Excel文件字节数组
|
||||
*/
|
||||
byte[] exportCategoryOverview(CategoryExportDTO dto);
|
||||
|
||||
/**
|
||||
* 导出平台维度汇总Excel
|
||||
*
|
||||
* @param dto 导出参数
|
||||
* @return Excel文件字节数组
|
||||
*/
|
||||
byte[] exportPlatformOverview(PlatformExportDTO dto);
|
||||
}
|
||||
|
||||
+212
-1
@@ -224,7 +224,12 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate);
|
||||
overviewVO.setCategoryComparisons(categoryComparisons);
|
||||
|
||||
// 11. 汇总ROI和总税后盈亏
|
||||
// 11. 平台维度汇总
|
||||
List<CompanyOverviewVO.PlatformSummary> platformSummary = calculatePlatformSummary(
|
||||
shops, orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate);
|
||||
overviewVO.setPlatformSummary(platformSummary);
|
||||
|
||||
// 12. 汇总ROI和总税后盈亏
|
||||
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusId);
|
||||
overviewVO.setTotalROI(totalROI);
|
||||
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
|
||||
@@ -897,5 +902,211 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
.map(OrderStatusPO::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算平台维度汇总
|
||||
*/
|
||||
private List<CompanyOverviewVO.PlatformSummary> calculatePlatformSummary(
|
||||
List<ShopPO> shops, List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders, Long refundStatusId, Long companyId,
|
||||
LocalDate startDate, LocalDate endDate) {
|
||||
|
||||
List<CompanyOverviewVO.PlatformSummary> platformSummaries = new ArrayList<>();
|
||||
|
||||
// 获取所有平台
|
||||
List<PlatformPO> allPlatforms = platformMapper.selectList(null);
|
||||
Map<Long, PlatformPO> platformMap = allPlatforms.stream()
|
||||
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
|
||||
|
||||
// 按平台分组店铺
|
||||
Map<Long, List<ShopPO>> shopsByPlatform = shops.stream()
|
||||
.filter(shop -> shop.getPlatformId() != null)
|
||||
.collect(Collectors.groupingBy(ShopPO::getPlatformId));
|
||||
|
||||
// 生成目标月份列表
|
||||
List<LocalDate> targetMonths = new ArrayList<>();
|
||||
LocalDate currentMonth = startDate.withDayOfMonth(1);
|
||||
LocalDate endMonth = endDate.withDayOfMonth(1);
|
||||
while (!currentMonth.isAfter(endMonth)) {
|
||||
targetMonths.add(currentMonth);
|
||||
currentMonth = currentMonth.plusMonths(1);
|
||||
}
|
||||
|
||||
// 查询所有店铺的目标数据
|
||||
LambdaQueryWrapper<ShopMonthlyTargetPO> targetWrapper = new LambdaQueryWrapper<>();
|
||||
targetWrapper.eq(ShopMonthlyTargetPO::getCompanyId, companyId)
|
||||
.in(ShopMonthlyTargetPO::getTargetMonth, targetMonths);
|
||||
List<ShopMonthlyTargetPO> allTargets = shopMonthlyTargetMapper.selectList(targetWrapper);
|
||||
Map<Long, List<ShopMonthlyTargetPO>> targetsByShop = allTargets.stream()
|
||||
.collect(Collectors.groupingBy(ShopMonthlyTargetPO::getShopId));
|
||||
|
||||
// 按店铺分组订单和费用
|
||||
Map<Long, List<OrderPO>> ordersByShop = orders.stream()
|
||||
.collect(Collectors.groupingBy(OrderPO::getShopId));
|
||||
Map<Long, List<PromotionFeePO>> promotionFeesByShop = promotionFees.stream()
|
||||
.collect(Collectors.groupingBy(PromotionFeePO::getShopId));
|
||||
Map<Long, List<BrushOrderPO>> brushOrdersByShop = brushOrders.stream()
|
||||
.collect(Collectors.groupingBy(BrushOrderPO::getShopId));
|
||||
|
||||
// 计算每个平台的数据
|
||||
for (Map.Entry<Long, List<ShopPO>> entry : shopsByPlatform.entrySet()) {
|
||||
Long platformId = entry.getKey();
|
||||
List<ShopPO> platformShops = entry.getValue();
|
||||
PlatformPO platform = platformMap.get(platformId);
|
||||
|
||||
if (platform == null) continue;
|
||||
|
||||
// 汇总该平台下所有店铺的数据
|
||||
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 : platformShops) {
|
||||
List<OrderPO> shopOrders = ordersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<PromotionFeePO> shopPromotionFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<ShopMonthlyTargetPO> shopTargets = targetsByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
|
||||
// 销售额
|
||||
BigDecimal shopSales = shopOrders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalSalesAmount = totalSalesAmount.add(shopSales);
|
||||
|
||||
// 订单数
|
||||
totalOrderCount += shopOrders.size();
|
||||
|
||||
// 退款金额
|
||||
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);
|
||||
totalRefundAmount = totalRefundAmount.add(shopRefund);
|
||||
|
||||
// 商品成本
|
||||
BigDecimal shopProductCost = shopOrders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal cost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
|
||||
return cost.multiply(new BigDecimal(quantity));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalProductCost = totalProductCost.add(shopProductCost);
|
||||
|
||||
// 运费成本
|
||||
BigDecimal shopShippingCost = shopOrders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal cost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
|
||||
return cost.multiply(new BigDecimal(quantity));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalShippingCost = totalShippingCost.add(shopShippingCost);
|
||||
|
||||
// 其他成本
|
||||
BigDecimal shopOtherCost = shopOrders.stream()
|
||||
.map(order -> order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalOtherCost = totalOtherCost.add(shopOtherCost);
|
||||
|
||||
// 推广费
|
||||
BigDecimal shopPromoFee = shopPromotionFees.stream()
|
||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalPromotionFee = totalPromotionFee.add(shopPromoFee);
|
||||
|
||||
// 刷单费
|
||||
BigDecimal shopBrush = shopBrushOrders.stream()
|
||||
.map(brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalBrushFee = totalBrushFee.add(shopBrush);
|
||||
|
||||
// 目标金额和目标单量
|
||||
BigDecimal shopTargetAmount = shopTargets.stream()
|
||||
.map(target -> target.getTargetAmount() != null ? target.getTargetAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalTargetAmount = totalTargetAmount.add(shopTargetAmount);
|
||||
|
||||
int shopTargetOrderCount = shopTargets.stream()
|
||||
.mapToInt(target -> target.getTargetOrderCount() != null ? target.getTargetOrderCount() : 0)
|
||||
.sum();
|
||||
totalTargetOrderCount += shopTargetOrderCount;
|
||||
}
|
||||
|
||||
// 计算派生指标
|
||||
BigDecimal averageOrderValue = BigDecimal.ZERO;
|
||||
if (totalOrderCount > 0) {
|
||||
averageOrderValue = totalSalesAmount.divide(new BigDecimal(totalOrderCount), 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
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 = BigDecimal.ZERO;
|
||||
if (totalPromotionFee.compareTo(BigDecimal.ZERO) > 0) {
|
||||
roi = totalSalesAmount.subtract(totalRefundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
BigDecimal feeRatio = BigDecimal.ZERO;
|
||||
if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
feeRatio = totalPromotionFee.add(totalBrushFee).divide(totalSalesAmount, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
// 计算达成率
|
||||
BigDecimal salesAmountAchievementRate = BigDecimal.ZERO;
|
||||
if (totalTargetAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
salesAmountAchievementRate = totalSalesAmount.divide(totalTargetAmount, 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"));
|
||||
} else if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
salesAmountAchievementRate = new BigDecimal("100");
|
||||
}
|
||||
|
||||
BigDecimal orderCountAchievementRate = BigDecimal.ZERO;
|
||||
if (totalTargetOrderCount > 0) {
|
||||
orderCountAchievementRate = new BigDecimal(totalOrderCount)
|
||||
.divide(new BigDecimal(totalTargetOrderCount), 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"));
|
||||
} else if (totalOrderCount > 0) {
|
||||
orderCountAchievementRate = new BigDecimal("100");
|
||||
}
|
||||
|
||||
CompanyOverviewVO.PlatformSummary platformSummary = new CompanyOverviewVO.PlatformSummary();
|
||||
platformSummary.setPlatformId(platformId);
|
||||
platformSummary.setPlatformName(platform.getPlatformName());
|
||||
platformSummary.setTargetOrderCount(totalTargetOrderCount);
|
||||
platformSummary.setOrderCountAchievementRate(orderCountAchievementRate);
|
||||
platformSummary.setTargetAmount(totalTargetAmount);
|
||||
platformSummary.setSalesAmountAchievementRate(salesAmountAchievementRate);
|
||||
platformSummary.setSalesAmount(totalSalesAmount);
|
||||
platformSummary.setOrderCount(totalOrderCount);
|
||||
platformSummary.setAverageOrderValue(averageOrderValue);
|
||||
platformSummary.setProductCost(totalProductCost);
|
||||
platformSummary.setShippingCost(totalShippingCost);
|
||||
platformSummary.setOtherCost(totalOtherCost);
|
||||
platformSummary.setRefundAmount(totalRefundAmount);
|
||||
platformSummary.setTotalPromotionFee(totalPromotionFee);
|
||||
platformSummary.setBrushFee(totalBrushFee);
|
||||
platformSummary.setFeeRatio(feeRatio);
|
||||
platformSummary.setTotalProfitBeforeTax(profitBeforeTax);
|
||||
platformSummary.setSalesTaxAmount(salesTaxAmount);
|
||||
platformSummary.setRoi(roi);
|
||||
platformSummary.setProfitAfterTax(profitAfterTax);
|
||||
|
||||
platformSummaries.add(platformSummary);
|
||||
}
|
||||
|
||||
// 按销售额降序排序
|
||||
platformSummaries.sort(Comparator.comparing(CompanyOverviewVO.PlatformSummary::getSalesAmount).reversed());
|
||||
return platformSummaries;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+292
@@ -16,6 +16,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.ShopOverviewStat
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.service.ShopOverviewStatisticsService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CategoryExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.PlatformExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.service.ExportService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
|
||||
@@ -1278,4 +1279,295 @@ public class ExportServiceImpl implements ExportService {
|
||||
cell.setCellValue(value);
|
||||
cell.setCellStyle(style);
|
||||
}
|
||||
|
||||
private void setCell(Row row, int col, int value, CellStyle style) {
|
||||
Cell cell = row.createCell(col);
|
||||
cell.setCellValue(value);
|
||||
cell.setCellStyle(style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] exportPlatformOverview(PlatformExportDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LocalDate[] dateRange = parseDateRange(dto.getDateRange());
|
||||
LocalDate startDate = dateRange[0];
|
||||
LocalDate endDate = dateRange[1];
|
||||
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
|
||||
BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE;
|
||||
|
||||
List<Long> autoStatusIds = getAutoStatusIds(companyId);
|
||||
Long refundStatusId = getRefundStatusId(companyId);
|
||||
|
||||
// 查询所有店铺并按平台分组
|
||||
List<ShopPO> allShops = shopService.list(
|
||||
new LambdaQueryWrapper<ShopPO>().eq(ShopPO::getCompanyId, companyId)
|
||||
);
|
||||
Map<Long, List<ShopPO>> shopsByPlatform = allShops.stream()
|
||||
.filter(shop -> shop.getPlatformId() != null)
|
||||
.collect(Collectors.groupingBy(ShopPO::getPlatformId));
|
||||
|
||||
// 按平台过滤
|
||||
if (dto.getPlatformIds() != null && !dto.getPlatformIds().isEmpty()) {
|
||||
Set<Long> allowedPlatformIds = new HashSet<>(dto.getPlatformIds());
|
||||
shopsByPlatform = shopsByPlatform.entrySet().stream()
|
||||
.filter(e -> allowedPlatformIds.contains(e.getKey()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
// 获取所有平台信息
|
||||
List<PlatformPO> allPlatforms = platformMapper.selectList(null);
|
||||
Map<Long, PlatformPO> platformMap = allPlatforms.stream()
|
||||
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
|
||||
|
||||
// 生成目标月份列表
|
||||
List<LocalDate> targetMonths = new ArrayList<>();
|
||||
LocalDate currentMonth = startDate.withDayOfMonth(1);
|
||||
LocalDate endMonth = endDate.withDayOfMonth(1);
|
||||
while (!currentMonth.isAfter(endMonth)) {
|
||||
targetMonths.add(currentMonth);
|
||||
currentMonth = currentMonth.plusMonths(1);
|
||||
}
|
||||
|
||||
// 查询所有目标数据
|
||||
LambdaQueryWrapper<ShopMonthlyTargetPO> targetWrapper = new LambdaQueryWrapper<>();
|
||||
targetWrapper.eq(ShopMonthlyTargetPO::getCompanyId, companyId)
|
||||
.in(ShopMonthlyTargetPO::getTargetMonth, targetMonths);
|
||||
List<ShopMonthlyTargetPO> allTargets = shopMonthlyTargetMapper.selectList(targetWrapper);
|
||||
Map<Long, List<ShopMonthlyTargetPO>> targetsByShop = allTargets.stream()
|
||||
.collect(Collectors.groupingBy(ShopMonthlyTargetPO::getShopId));
|
||||
|
||||
// 查询所有订单
|
||||
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
|
||||
orderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.ge(OrderPO::getOrderTime, startDateTime)
|
||||
.le(OrderPO::getOrderTime, endDateTime);
|
||||
if (!autoStatusIds.isEmpty()) {
|
||||
orderWrapper.in(OrderPO::getStatusId, autoStatusIds);
|
||||
} else {
|
||||
orderWrapper.isNull(OrderPO::getId);
|
||||
}
|
||||
List<OrderPO> allOrders = orderMapper.selectList(orderWrapper);
|
||||
Map<Long, List<OrderPO>> ordersByShop = allOrders.stream()
|
||||
.collect(Collectors.groupingBy(OrderPO::getShopId));
|
||||
|
||||
// 查询推广费
|
||||
LambdaQueryWrapper<PromotionFeePO> promoWrapper = new LambdaQueryWrapper<>();
|
||||
promoWrapper.eq(PromotionFeePO::getCompanyId, companyId)
|
||||
.ge(PromotionFeePO::getFeeDate, startDate)
|
||||
.le(PromotionFeePO::getFeeDate, endDate);
|
||||
List<PromotionFeePO> allPromotionFees = promotionFeeMapper.selectList(promoWrapper);
|
||||
Map<Long, List<PromotionFeePO>> promotionFeesByShop = allPromotionFees.stream()
|
||||
.collect(Collectors.groupingBy(PromotionFeePO::getShopId));
|
||||
|
||||
// 查询刷单费
|
||||
LambdaQueryWrapper<BrushOrderPO> brushWrapper = new LambdaQueryWrapper<>();
|
||||
brushWrapper.eq(BrushOrderPO::getCompanyId, companyId)
|
||||
.ge(BrushOrderPO::getBrushTime, startDateTime)
|
||||
.le(BrushOrderPO::getBrushTime, endDateTime);
|
||||
List<BrushOrderPO> allBrushOrders = brushOrderMapper.selectList(brushWrapper);
|
||||
Map<Long, List<BrushOrderPO>> brushOrdersByShop = allBrushOrders.stream()
|
||||
.collect(Collectors.groupingBy(BrushOrderPO::getShopId));
|
||||
|
||||
// 按平台聚合数据
|
||||
List<Map<String, Object>> platformDataList = new ArrayList<>();
|
||||
for (Map.Entry<Long, List<ShopPO>> entry : shopsByPlatform.entrySet()) {
|
||||
Long platformId = entry.getKey();
|
||||
List<ShopPO> platformShops = entry.getValue();
|
||||
PlatformPO platform = platformMap.get(platformId);
|
||||
if (platform == null) continue;
|
||||
|
||||
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 : platformShops) {
|
||||
List<OrderPO> shopOrders = ordersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<PromotionFeePO> shopPromoFees = promotionFeesByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<BrushOrderPO> shopBrushOrders = brushOrdersByShop.getOrDefault(shop.getId(), new ArrayList<>());
|
||||
List<ShopMonthlyTargetPO> 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 = shopPromoFees.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 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 salesTaxAmount = totalSalesAmount.multiply(taxRate).setScale(2, RoundingMode.HALF_UP);
|
||||
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"))
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal orderAchievementRate = totalTargetOrderCount > 0
|
||||
? new BigDecimal(totalOrderCount)
|
||||
.divide(new BigDecimal(totalTargetOrderCount), 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"))
|
||||
: BigDecimal.ZERO;
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("platformId", platformId);
|
||||
data.put("platformName", platform.getPlatformName());
|
||||
data.put("targetOrderCount", totalTargetOrderCount);
|
||||
data.put("orderCountAchievementRate", orderAchievementRate);
|
||||
data.put("targetAmount", totalTargetAmount);
|
||||
data.put("salesAmountAchievementRate", salesAchievementRate);
|
||||
data.put("salesAmount", totalSalesAmount);
|
||||
data.put("orderCount", totalOrderCount);
|
||||
data.put("avgOrderValue", avgOrderValue);
|
||||
data.put("productCost", totalProductCost);
|
||||
data.put("shippingCost", totalShippingCost);
|
||||
data.put("otherCost", totalOtherCost);
|
||||
data.put("refundAmount", totalRefundAmount);
|
||||
data.put("totalPromotionFee", totalPromotionFee);
|
||||
data.put("brushFee", totalBrushFee);
|
||||
data.put("feeRatio", feeRatio);
|
||||
data.put("totalProfitBeforeTax", profitBeforeTax);
|
||||
data.put("salesTaxAmount", salesTaxAmount);
|
||||
data.put("roi", roi);
|
||||
data.put("profitAfterTax", profitAfterTax);
|
||||
platformDataList.add(data);
|
||||
}
|
||||
|
||||
platformDataList.sort((a, b) ->
|
||||
((BigDecimal) b.get("salesAmount")).compareTo((BigDecimal) a.get("salesAmount")));
|
||||
|
||||
String dateRangeLabel = startDate.format(DATE_FMT) + " 至 " + endDate.format(DATE_FMT);
|
||||
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
Sheet sheet = workbook.createSheet("平台明细");
|
||||
createPlatformDetailSheet(sheet, dateRangeLabel, platformDataList, taxRate);
|
||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
workbook.write(out);
|
||||
return out.toByteArray();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("导出平台Excel失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void createPlatformDetailSheet(Sheet sheet, String dateRangeLabel,
|
||||
List<Map<String, Object>> platformDataList,
|
||||
BigDecimal taxRate) {
|
||||
CellStyle titleStyle = createTitleStyle(sheet.getWorkbook());
|
||||
CellStyle headerStyle = createHeaderStyle(sheet.getWorkbook());
|
||||
CellStyle dataStyle = createDataStyle(sheet.getWorkbook());
|
||||
|
||||
Row titleRow = sheet.createRow(0);
|
||||
Cell titleCell = titleRow.createCell(0);
|
||||
titleCell.setCellValue("平台维度汇总 | " + dateRangeLabel);
|
||||
titleCell.setCellStyle(titleStyle);
|
||||
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 17));
|
||||
|
||||
String taxLabel = taxRate.multiply(new BigDecimal("100")).setScale(0, RoundingMode.HALF_UP).toPlainString() + "%税额";
|
||||
String[] headers = {
|
||||
"平台名称", "目标单量", "单量达成率(%)", "目标额", "销售达成率(%)",
|
||||
"实际销售额", "单量", "客单价",
|
||||
"商品成本", "运费", "其他成本", "退款金额", "推广费", "刷单费用", "费比",
|
||||
"税前盈亏", taxLabel, "ROI", "税后盈亏"
|
||||
};
|
||||
|
||||
Row headerRow = sheet.createRow(1);
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
Cell cell = headerRow.createCell(i);
|
||||
cell.setCellValue(headers[i]);
|
||||
cell.setCellStyle(headerStyle);
|
||||
}
|
||||
|
||||
int rowIdx = 2;
|
||||
for (Map<String, Object> data : platformDataList) {
|
||||
Row row = sheet.createRow(rowIdx++);
|
||||
setCell(row, 0, (String) data.get("platformName"), dataStyle);
|
||||
setCell(row, 1, objToDouble(data.get("targetOrderCount")), dataStyle);
|
||||
setCell(row, 2, objToPct(data.get("orderCountAchievementRate")), dataStyle);
|
||||
setCell(row, 3, objToDouble(data.get("targetAmount")), dataStyle);
|
||||
setCell(row, 4, objToPct(data.get("salesAmountAchievementRate")), dataStyle);
|
||||
setCell(row, 5, objToDouble(data.get("salesAmount")), dataStyle);
|
||||
setCell(row, 6, objToDouble(data.get("orderCount")), dataStyle);
|
||||
setCell(row, 7, objToDouble(data.get("avgOrderValue")), dataStyle);
|
||||
setCell(row, 8, objToDouble(data.get("productCost")), dataStyle);
|
||||
setCell(row, 9, objToDouble(data.get("shippingCost")), dataStyle);
|
||||
setCell(row, 10, objToDouble(data.get("otherCost")), dataStyle);
|
||||
setCell(row, 11, objToDouble(data.get("refundAmount")), dataStyle);
|
||||
setCell(row, 12, objToDouble(data.get("totalPromotionFee")), dataStyle);
|
||||
setCell(row, 13, objToDouble(data.get("brushFee")), dataStyle);
|
||||
setCell(row, 14, objToPct(data.get("feeRatio")), dataStyle);
|
||||
setCell(row, 15, objToDouble(data.get("totalProfitBeforeTax")), dataStyle);
|
||||
setCell(row, 16, objToDouble(data.get("salesTaxAmount")), dataStyle);
|
||||
setCell(row, 17, objToDouble(data.get("roi")), dataStyle);
|
||||
setCell(row, 18, objToDouble(data.get("profitAfterTax")), dataStyle);
|
||||
}
|
||||
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
sheet.setColumnWidth(i, 3200);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ export namespace CompanyOverviewVO {
|
||||
shopComparisons?: ShopComparison[];
|
||||
/** 多品类数据横向对比 */
|
||||
categoryComparisons?: CategoryComparison[];
|
||||
/** 平台维度汇总 */
|
||||
platformSummary?: PlatformSummary[];
|
||||
/** 汇总ROI */
|
||||
totalROI?: number;
|
||||
/** 总税后盈亏 */
|
||||
@@ -148,4 +150,48 @@ export namespace CompanyOverviewVO {
|
||||
/** ROI */
|
||||
roi?: number;
|
||||
}
|
||||
|
||||
/** 平台维度汇总 */
|
||||
export interface PlatformSummary {
|
||||
/** 平台ID */
|
||||
platformId: number;
|
||||
/** 平台名称 */
|
||||
platformName: string;
|
||||
/** 目标单量 */
|
||||
targetOrderCount?: number;
|
||||
/** 单量达成率 */
|
||||
orderCountAchievementRate?: number;
|
||||
/** 目标销售额 */
|
||||
targetAmount?: number;
|
||||
/** 销售额达成率 */
|
||||
salesAmountAchievementRate?: number;
|
||||
/** 销售额 */
|
||||
salesAmount: number;
|
||||
/** 单量 */
|
||||
orderCount?: number;
|
||||
/** 客单价 */
|
||||
averageOrderValue?: number;
|
||||
/** 商品成本 */
|
||||
productCost?: number;
|
||||
/** 运费 */
|
||||
shippingCost?: number;
|
||||
/** 其他成本 */
|
||||
otherCost?: number;
|
||||
/** 退款金额 */
|
||||
refundAmount?: number;
|
||||
/** 推广费 */
|
||||
totalPromotionFee?: number;
|
||||
/** 刷单费用 */
|
||||
brushFee?: number;
|
||||
/** 费比 */
|
||||
feeRatio?: number;
|
||||
/** 税前盈亏 */
|
||||
totalProfitBeforeTax?: number;
|
||||
/** 销售额4%税额 */
|
||||
salesTaxAmount?: number;
|
||||
/** ROI */
|
||||
roi?: number;
|
||||
/** 税后盈亏 */
|
||||
profitAfterTax?: number;
|
||||
}
|
||||
}
|
||||
|
||||
+405
@@ -0,0 +1,405 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import type { CompanyOverviewVO } from '#/api/ecommerce/company-overview';
|
||||
|
||||
defineOptions({ name: 'PlatformSummaryCard' });
|
||||
|
||||
interface Props {
|
||||
taxRate?: number;
|
||||
platformSummary?: CompanyOverviewVO.PlatformSummary[];
|
||||
platformExportMode?: boolean;
|
||||
selectedExportPlatformIds?: number[];
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:selectedExportPlatformIds', ids: number[]): void;
|
||||
(e: 'togglePlatformExportMode', enabled: boolean): void;
|
||||
(e: 'export'): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
platformExportMode: false,
|
||||
selectedExportPlatformIds: () => [],
|
||||
});
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const allPlatformsSelected = computed(() => {
|
||||
const total = platformData.value.length;
|
||||
return total > 0 && props.selectedExportPlatformIds.length === total;
|
||||
});
|
||||
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')}`;
|
||||
};
|
||||
|
||||
const formatPercentPlain = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value.toFixed(1)}%`;
|
||||
};
|
||||
|
||||
const taxRateNum = computed(() => (props.taxRate ?? 0.04) * 100);
|
||||
|
||||
// 优先使用动态数据,否则降级到静态mock
|
||||
const platformData = computed(() => {
|
||||
if (props.platformSummary && props.platformSummary.length > 0) {
|
||||
return props.platformSummary.map(p => ({
|
||||
platformId: p.platformId,
|
||||
platformName: p.platformName,
|
||||
targetOrderCount: p.targetOrderCount ?? 0,
|
||||
orderCountAchievementRate: p.orderCountAchievementRate ?? 0,
|
||||
targetAmount: p.targetAmount ?? 0,
|
||||
salesAmountAchievementRate: p.salesAmountAchievementRate ?? 0,
|
||||
salesAmount: p.salesAmount ?? 0,
|
||||
orderCount: p.orderCount ?? 0,
|
||||
averageOrderValue: p.averageOrderValue ?? 0,
|
||||
productCost: p.productCost ?? 0,
|
||||
shippingCost: p.shippingCost ?? 0,
|
||||
otherCost: p.otherCost ?? 0,
|
||||
refundAmount: p.refundAmount ?? 0,
|
||||
totalPromotionFee: p.totalPromotionFee ?? 0,
|
||||
brushFee: p.brushFee ?? 0,
|
||||
feeRatio: p.feeRatio ?? 0,
|
||||
totalProfitBeforeTax: p.totalProfitBeforeTax ?? 0,
|
||||
salesTaxAmount: p.salesTaxAmount ?? 0,
|
||||
roi: p.roi ?? 0,
|
||||
profitAfterTax: p.profitAfterTax ?? 0,
|
||||
}));
|
||||
}
|
||||
return mockPlatformData;
|
||||
});
|
||||
|
||||
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 sortField = ref<string>('salesAmount');
|
||||
const sortOrder = ref<'asc' | 'desc'>('desc');
|
||||
|
||||
const sortedData = computed(() => {
|
||||
return [...platformData.value].sort((a: any, b: any) => {
|
||||
const diff = b[sortField.value] - a[sortField.value];
|
||||
return sortOrder.value === 'desc' ? diff : -diff;
|
||||
});
|
||||
});
|
||||
|
||||
const toggleSort = (field: string) => {
|
||||
if (sortField.value === field) {
|
||||
sortOrder.value = sortOrder.value === 'desc' ? 'asc' : 'desc';
|
||||
} else {
|
||||
sortField.value = field;
|
||||
sortOrder.value = 'desc';
|
||||
}
|
||||
};
|
||||
|
||||
const sortIcon = (field: string) => {
|
||||
if (sortField.value !== field) return '';
|
||||
return sortOrder.value === 'desc' ? '↓' : '↑';
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="overflow-hidden rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
|
||||
>
|
||||
<!-- Header -->
|
||||
<div
|
||||
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] p-8 md:flex-row md:items-center"
|
||||
>
|
||||
<div>
|
||||
<h3 class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
各平台多维度经营明细对比
|
||||
</h3>
|
||||
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
目标达成 · 规模 · 成本费用 · 盈利分析,四大维度完整对比
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<template v-if="platformExportMode">
|
||||
<button
|
||||
class="rounded-2xl border border-slate-300 bg-white px-4 py-2 text-sm font-bold text-slate-700 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
@click="emit('togglePlatformExportMode', false)"
|
||||
>
|
||||
取消选择
|
||||
</button>
|
||||
<button
|
||||
class="rounded-2xl bg-blue-600 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
|
||||
:disabled="selectedExportPlatformIds.length === 0"
|
||||
@click="emit('export')"
|
||||
>
|
||||
导出已选平台 ({{ selectedExportPlatformIds.length }})
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<button
|
||||
class="rounded-2xl border border-slate-300 bg-white px-4 py-2 text-sm font-bold text-slate-700 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
@click="emit('togglePlatformExportMode', true)"
|
||||
>
|
||||
指定平台导出
|
||||
</button>
|
||||
<button
|
||||
class="rounded-2xl bg-slate-900 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
|
||||
@click="emit('export')"
|
||||
>
|
||||
导出全部
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full whitespace-nowrap text-left text-sm">
|
||||
<thead
|
||||
class="bg-slate-50 dark:bg-[hsl(240deg_3.7%_15.9%)] text-xs font-black uppercase text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
v-if="platformExportMode"
|
||||
rowspan="2"
|
||||
class="border-b border-r-2 border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-slate-100 p-3 text-center dark:bg-[hsl(240deg_3.7%_22%)]"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="h-4 w-4 cursor-pointer accent-blue-600"
|
||||
:checked="allPlatformsSelected"
|
||||
:indeterminate="somePlatformsSelected && !allPlatformsSelected"
|
||||
@change="
|
||||
(e) => {
|
||||
if ((e.target as HTMLInputElement).checked) {
|
||||
emit(
|
||||
'update:selectedExportPlatformIds',
|
||||
platformData.map((p) => p.platformId) || [],
|
||||
);
|
||||
} else {
|
||||
emit('update:selectedExportPlatformIds', []);
|
||||
}
|
||||
}
|
||||
"
|
||||
/>
|
||||
</th>
|
||||
<!-- 平台名著 -->
|
||||
<th
|
||||
rowspan="2"
|
||||
class="sticky-col border-b border-r-2 border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 text-base font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)] shadow-sm dark:shadow-none"
|
||||
>
|
||||
平台名称
|
||||
</th>
|
||||
<!-- 目标达成 -->
|
||||
<th
|
||||
colspan="4"
|
||||
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] p-3 text-center bg-blue-50/50 dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)] text-blue-700 dark:text-blue-400"
|
||||
>
|
||||
目标达成维度
|
||||
</th>
|
||||
<!-- 规模 -->
|
||||
<th
|
||||
colspan="3"
|
||||
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] p-3 text-center bg-slate-100/50 dark:bg-[hsl(240deg_3.7%_22%/50%)]"
|
||||
>
|
||||
经营规模维度
|
||||
</th>
|
||||
<!-- 成本 -->
|
||||
<th
|
||||
colspan="7"
|
||||
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] p-3 text-center bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/50%)] text-orange-700 dark:text-orange-400"
|
||||
>
|
||||
成本费用维度
|
||||
</th>
|
||||
<!-- 盈利 -->
|
||||
<th
|
||||
colspan="5"
|
||||
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] p-3 text-center bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%/20%)] text-emerald-700 dark:text-emerald-400"
|
||||
>
|
||||
盈利分析维度
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="bg-slate-50/80 dark:bg-[hsl(240deg_3.7%_15.9%/80)] text-sm">
|
||||
<!-- 目标子列 -->
|
||||
<th class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">目标单量</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 text-blue-600 dark:text-blue-400">单量达成率</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">目标额</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 text-blue-600 dark:text-blue-400">销售达成率</th>
|
||||
<!-- 规模子列 -->
|
||||
<th class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">实际销售额</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">单量</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">客单价</th>
|
||||
<!-- 成本子列 -->
|
||||
<th class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">商品成本</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">运费</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">其他成本</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-bold text-rose-600 dark:text-rose-400">退款金额</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">推广费</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 text-orange-600 dark:text-orange-400">刷单费用</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">费比%</th>
|
||||
<!-- 盈利子列 -->
|
||||
<th class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-bold">税前盈亏</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ taxRateNum.toFixed(0) }}%税额</th>
|
||||
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-indigo-700 dark:text-indigo-400">ROI</th>
|
||||
<th class="border-b bg-emerald-600 dark:bg-emerald-600 px-6 py-4 font-black text-white">税后盈亏</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
|
||||
<tr
|
||||
v-for="p in sortedData"
|
||||
:key="p.platformId"
|
||||
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)] dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)]"
|
||||
>
|
||||
<!-- 平台名 -->
|
||||
<td
|
||||
class="sticky-col border-r-2 border-slate-100 bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 font-bold shadow-sm dark:shadow-none"
|
||||
>
|
||||
<span class="rounded-full bg-blue-50 dark:bg-blue-900/30 px-3 py-1 text-sm font-bold text-blue-600 dark:text-blue-400">
|
||||
{{ p.platformName }}
|
||||
</span>
|
||||
</td>
|
||||
<!-- 目标 -->
|
||||
<td class="p-6 font-medium">{{ p.targetOrderCount.toLocaleString('zh-CN') }}</td>
|
||||
<td class="p-6 font-black text-blue-600 dark:text-blue-400">{{ formatPercentPlain(p.orderCountAchievementRate) }}</td>
|
||||
<td class="p-6 font-medium">{{ formatAmount(p.targetAmount) }}</td>
|
||||
<td class="p-6 font-black text-blue-600 dark:text-blue-400">{{ formatPercentPlain(p.salesAmountAchievementRate) }}</td>
|
||||
<!-- 规模 -->
|
||||
<td class="p-6 font-black">{{ formatAmount(p.salesAmount) }}</td>
|
||||
<td class="p-6 font-medium">{{ p.orderCount.toLocaleString('zh-CN') }}</td>
|
||||
<td class="p-6 font-medium">{{ formatAmount(p.averageOrderValue) }}</td>
|
||||
<!-- 成本 -->
|
||||
<td class="p-6">{{ formatAmount(p.productCost) }}</td>
|
||||
<td class="p-6">{{ formatAmount(p.shippingCost) }}</td>
|
||||
<td class="p-6">{{ formatAmount(p.otherCost) }}</td>
|
||||
<td class="p-6 font-bold text-rose-600 dark:text-rose-400">{{ formatAmount(p.refundAmount) }}</td>
|
||||
<td class="p-6">{{ formatAmount(p.totalPromotionFee) }}</td>
|
||||
<td class="p-6 text-orange-600 dark:text-orange-400">{{ formatAmount(p.brushFee) }}</td>
|
||||
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatPercentPlain(p.feeRatio) }}</td>
|
||||
<!-- 盈利 -->
|
||||
<td class="p-6 font-bold" :class="p.totalProfitBeforeTax >= 0 ? 'text-slate-800 dark:text-[hsl(0deg_0%_95%)]' : 'text-rose-600 dark:text-rose-400'">
|
||||
{{ formatAmount(p.totalProfitBeforeTax) }}
|
||||
</td>
|
||||
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatAmount(p.salesTaxAmount) }}</td>
|
||||
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">{{ p.roi.toFixed(2) }}</td>
|
||||
<td
|
||||
class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-6 text-base font-black"
|
||||
:class="p.profitAfterTax >= 0 ? 'text-emerald-600' : 'text-rose-600'"
|
||||
>
|
||||
{{ formatAmount(p.profitAfterTax) }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<!-- 合计行 -->
|
||||
<tfoot class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
|
||||
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
<td class="sticky-col border-r-2 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] p-6 text-base">合计</td>
|
||||
<!-- 目标 -->
|
||||
<td class="p-6">{{ platformData.reduce((s, p) => s + p.targetOrderCount, 0).toLocaleString() }}</td>
|
||||
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.targetAmount, 0)) }}</td>
|
||||
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
|
||||
<!-- 规模 -->
|
||||
<td class="p-6">{{ formatAmount(totalSales) }}</td>
|
||||
<td class="p-6">{{ totalOrderCount.toLocaleString() }}</td>
|
||||
<td class="p-6">-</td>
|
||||
<!-- 成本 -->
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.productCost, 0)) }}</td>
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.shippingCost, 0)) }}</td>
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.otherCost, 0)) }}</td>
|
||||
<td class="p-6 text-rose-600 dark:text-rose-400">{{ formatAmount(platformData.reduce((s, p) => s + p.refundAmount, 0)) }}</td>
|
||||
<td class="p-6">{{ formatAmount(platformData.reduce((s, p) => s + p.totalPromotionFee, 0)) }}</td>
|
||||
<td class="p-6 text-orange-600 dark:text-orange-400">{{ formatAmount(platformData.reduce((s, p) => s + p.brushFee, 0)) }}</td>
|
||||
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ formatPercentPlain(
|
||||
totalSales > 0
|
||||
? platformData.reduce((s, p) => s + p.productCost + p.shippingCost + p.otherCost + p.refundAmount + p.totalPromotionFee + p.brushFee, 0) / totalSales * 100
|
||||
: 0,
|
||||
) }}
|
||||
</td>
|
||||
<!-- 盈利 -->
|
||||
<td class="p-6">
|
||||
{{ formatAmount(platformData.reduce((s, p) => s + p.totalProfitBeforeTax, 0)) }}
|
||||
</td>
|
||||
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ formatAmount(platformData.reduce((s, p) => s + p.salesTaxAmount, 0)) }}
|
||||
</td>
|
||||
<td class="p-6 text-indigo-700 dark:text-indigo-400">
|
||||
{{
|
||||
(() => {
|
||||
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) : '-';
|
||||
})()
|
||||
}}
|
||||
</td>
|
||||
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base">
|
||||
{{ formatAmount(totalProfitAfterTax) }}
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -26,6 +26,7 @@ import { exportByPost } from '#/utils/export';
|
||||
import CategoryComparisonTable from './components/CategoryComparisonTable.vue';
|
||||
import KpiCards from './components/KpiCards.vue';
|
||||
import ShopCharts from './components/ShopCharts.vue';
|
||||
import PlatformSummaryCard from './components/PlatformSummaryCard.vue';
|
||||
import ShopComparisonTable from './components/ShopComparisonTable.vue';
|
||||
|
||||
defineOptions({ name: 'CompanyOverview' });
|
||||
@@ -44,6 +45,10 @@ const shopCount = ref(0);
|
||||
const shopExportMode = ref(false);
|
||||
const selectedExportShopIds = ref<number[]>([]);
|
||||
|
||||
// 指定平台导出模式
|
||||
const platformExportMode = ref(false);
|
||||
const selectedExportPlatformIds = ref<number[]>([]);
|
||||
|
||||
// 日期范围
|
||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||
dayjs().subtract(30, 'day'),
|
||||
@@ -406,6 +411,40 @@ const toggleShopExportMode = (enabled: boolean) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 切换平台导出模式
|
||||
const togglePlatformExportMode = (enabled: boolean) => {
|
||||
platformExportMode.value = enabled;
|
||||
if (!enabled) {
|
||||
selectedExportPlatformIds.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
// 导出平台维度汇总
|
||||
const handlePlatformExport = async () => {
|
||||
try {
|
||||
exportLoading.value = true;
|
||||
const [startDate, endDate] = dateRange.value;
|
||||
const filename = `平台维度汇总_${startDate.format('YYYYMMDD')}_${endDate.format('YYYYMMDD')}.xlsx`;
|
||||
await exportByPost(
|
||||
'/ec/platform-overview/export',
|
||||
{
|
||||
dateRange: [
|
||||
startDate.format('YYYY-MM-DD'),
|
||||
endDate.format('YYYY-MM-DD'),
|
||||
],
|
||||
platformIds: selectedExportPlatformIds.value.length > 0
|
||||
? selectedExportPlatformIds.value
|
||||
: undefined,
|
||||
taxRate: taxRate.value,
|
||||
},
|
||||
filename,
|
||||
);
|
||||
platformExportMode.value = false;
|
||||
} finally {
|
||||
exportLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 跳转到店铺详情页
|
||||
const navigateToShopOverview = (shopId: number) => {
|
||||
router.push({
|
||||
@@ -539,7 +578,18 @@ const navigateToShopOverview = (shopId: number) => {
|
||||
:shop-efficiency-quadrants="overviewData?.shopEfficiencyQuadrants"
|
||||
/>
|
||||
|
||||
<!-- 第三层:横向对比大表 -->
|
||||
<!-- 第三层:平台维度汇总 -->
|
||||
<PlatformSummaryCard
|
||||
:platform-summary="overviewData?.platformSummary"
|
||||
:tax-rate="taxRate"
|
||||
:platform-export-mode="platformExportMode"
|
||||
:selected-export-platform-ids="selectedExportPlatformIds"
|
||||
@update:selected-export-platform-ids="(ids) => (selectedExportPlatformIds = ids)"
|
||||
@toggle-platform-export-mode="togglePlatformExportMode"
|
||||
@export="handlePlatformExport"
|
||||
/>
|
||||
|
||||
<!-- 第四层:横向对比大表 -->
|
||||
<ShopComparisonTable
|
||||
:shop-comparisons="overviewData?.shopComparisons"
|
||||
:tax-rate="taxRate"
|
||||
@@ -551,7 +601,7 @@ const navigateToShopOverview = (shopId: number) => {
|
||||
@navigate="navigateToShopOverview"
|
||||
/>
|
||||
|
||||
<!-- 第四层:品类多维度经营明细对比 -->
|
||||
<!-- 第五层:品类多维度经营明细对比 -->
|
||||
<CategoryComparisonTable
|
||||
:category-comparisons="overviewData?.categoryComparisons"
|
||||
:tax-rate="taxRate"
|
||||
|
||||
Reference in New Issue
Block a user