mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:49:20 +08:00
feat: 完成工作台页的后端接口实现和前端对接
This commit is contained in:
+16
@@ -132,6 +132,22 @@ public class CompanyOverviewVO {
|
|||||||
private List<CategorySummary> categories;
|
private List<CategorySummary> categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作台底部四张汇总表(与全店概览「店铺/平台/品类」及扩展「商品」表同源计算)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "工作台汇总表(与全店概览表结构一致)")
|
||||||
|
public static class WorkbenchTableBundle {
|
||||||
|
@Schema(description = "店铺汇总表")
|
||||||
|
private ShopOverview shopTable;
|
||||||
|
@Schema(description = "平台汇总表")
|
||||||
|
private PlatformOverview platformTable;
|
||||||
|
@Schema(description = "品类汇总表")
|
||||||
|
private CategoryOverview categoryTable;
|
||||||
|
@Schema(description = "商品汇总表(行结构同品类表;categoryId 存商品 ID)")
|
||||||
|
private CategoryOverview productTable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台维度汇总
|
* 平台维度汇总
|
||||||
*/
|
*/
|
||||||
|
|||||||
+35
@@ -1,7 +1,16 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.ecom.overview.service;
|
package top.xyquan.ecomdmbbackend.modules.ecom.overview.service;
|
||||||
|
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatSets;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyOverviewQueryDTO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyOverviewQueryDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.CompanyOverviewVO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.CompanyOverviewVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全店铺概览服务接口
|
* 全店铺概览服务接口
|
||||||
@@ -15,5 +24,31 @@ public interface CompanyOverviewService {
|
|||||||
* @return 全店铺概览VO
|
* @return 全店铺概览VO
|
||||||
*/
|
*/
|
||||||
CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO);
|
CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建工作台底部四张汇总表:与 {@link #getCompanyOverview(CompanyOverviewQueryDTO)} 中
|
||||||
|
* shopSummary / platformSummary / categorySummary 同源(另含按商品聚合表)。
|
||||||
|
* 入参订单、推广费、刷单费须已按工作台筛选(店铺、日期等)准备好。
|
||||||
|
*
|
||||||
|
* @param taxRate 请求税率(与概览接口一致)
|
||||||
|
* @param companyId 当前公司
|
||||||
|
* @param shops 参与汇总的店铺列表(须属于该公司)
|
||||||
|
* @param orders 已筛选订单
|
||||||
|
* @param promotionFees 已筛选推广费
|
||||||
|
* @param brushOrders 已筛选刷单费
|
||||||
|
* @param stat 订单状态统计集合
|
||||||
|
* @param startDate 开始日期
|
||||||
|
* @param endDate 结束日期
|
||||||
|
*/
|
||||||
|
CompanyOverviewVO.WorkbenchTableBundle buildWorkbenchSummaryTables(
|
||||||
|
BigDecimal taxRate,
|
||||||
|
Long companyId,
|
||||||
|
List<ShopPO> shops,
|
||||||
|
List<OrderPO> orders,
|
||||||
|
List<PromotionFeePO> promotionFees,
|
||||||
|
List<BrushOrderPO> brushOrders,
|
||||||
|
OrderStatusStatSets stat,
|
||||||
|
LocalDate startDate,
|
||||||
|
LocalDate endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+221
@@ -114,6 +114,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO) {
|
public CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO) {
|
||||||
|
synchronized (this) {
|
||||||
// 取请求参数中的税率,默认4%
|
// 取请求参数中的税率,默认4%
|
||||||
this.taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE;
|
this.taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE;
|
||||||
|
|
||||||
@@ -286,6 +287,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
calculateTargetData(overviewVO, companyId, startDate, endDate, totalSalesAmount, totalOrderCount);
|
calculateTargetData(overviewVO, companyId, startDate, endDate, totalSalesAmount, totalOrderCount);
|
||||||
|
|
||||||
return overviewVO;
|
return overviewVO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1553,5 +1555,224 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
|||||||
trendData.setDailyDataList(dailyDataList);
|
trendData.setDailyDataList(dailyDataList);
|
||||||
return trendData;
|
return trendData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompanyOverviewVO.WorkbenchTableBundle buildWorkbenchSummaryTables(
|
||||||
|
BigDecimal taxRate,
|
||||||
|
Long companyId,
|
||||||
|
List<ShopPO> shops,
|
||||||
|
List<OrderPO> orders,
|
||||||
|
List<PromotionFeePO> promotionFees,
|
||||||
|
List<BrushOrderPO> brushOrders,
|
||||||
|
OrderStatusStatSets stat,
|
||||||
|
LocalDate startDate,
|
||||||
|
LocalDate endDate) {
|
||||||
|
synchronized (this) {
|
||||||
|
BigDecimal saved = this.taxRate;
|
||||||
|
try {
|
||||||
|
this.taxRate = taxRate != null ? taxRate : DEFAULT_TAX_RATE;
|
||||||
|
CompanyOverviewVO.WorkbenchTableBundle bundle = new CompanyOverviewVO.WorkbenchTableBundle();
|
||||||
|
bundle.setShopTable(calculateShopSummary(shops, orders, promotionFees, brushOrders, stat, companyId, startDate, endDate));
|
||||||
|
bundle.setPlatformTable(calculatePlatformSummary(shops, orders, promotionFees, brushOrders, stat, companyId, startDate, endDate));
|
||||||
|
bundle.setCategoryTable(calculateCategorySummary(orders, promotionFees, brushOrders, stat, companyId, startDate, endDate));
|
||||||
|
bundle.setProductTable(calculateProductSummaryAsCategory(orders, promotionFees, brushOrders, stat, companyId, startDate, endDate));
|
||||||
|
return bundle;
|
||||||
|
} finally {
|
||||||
|
this.taxRate = saved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品维度横向汇总(与 {@link #calculateCategorySummary} 同款推广/刷单/税额逻辑;
|
||||||
|
* 行使用 {@link CompanyOverviewVO.CategorySummary},categoryId 存商品 ID)。
|
||||||
|
*/
|
||||||
|
private CompanyOverviewVO.CategoryOverview calculateProductSummaryAsCategory(
|
||||||
|
List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||||
|
List<BrushOrderPO> brushOrders, OrderStatusStatSets stat, Long companyId,
|
||||||
|
LocalDate startDate, LocalDate endDate) {
|
||||||
|
|
||||||
|
Map<Long, Long> specIdToProductId = orderSpecIdToProductIdMap(orders);
|
||||||
|
List<Long> productIds = specIdToProductId.values().stream().filter(Objects::nonNull).distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Map<Long, Long> productCategoryMap = new java.util.HashMap<>();
|
||||||
|
Map<Long, String> productNameMap = new java.util.HashMap<>();
|
||||||
|
if (!productIds.isEmpty()) {
|
||||||
|
LambdaQueryWrapper<ProductPO> productWrapper = new LambdaQueryWrapper<>();
|
||||||
|
productWrapper.in(ProductPO::getId, productIds).select(ProductPO::getId, ProductPO::getCategoryId, ProductPO::getName);
|
||||||
|
List<ProductPO> products = productMapper.selectList(productWrapper);
|
||||||
|
for (ProductPO product : products) {
|
||||||
|
productCategoryMap.put(product.getId(), product.getCategoryId());
|
||||||
|
productNameMap.put(product.getId(), product.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Long, List<OrderPO>> ordersByProduct = orders.stream()
|
||||||
|
.collect(Collectors.groupingBy(order -> {
|
||||||
|
Long specId = order.getProductSpecId();
|
||||||
|
Long productId = specId != null ? specIdToProductId.get(specId) : null;
|
||||||
|
return productId != null ? productId : -1L;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Map<Long, BigDecimal> directPromotionByProduct = promotionFees.stream()
|
||||||
|
.filter(fee -> fee.getProductId() != null)
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
PromotionFeePO::getProductId,
|
||||||
|
Collectors.reducing(
|
||||||
|
BigDecimal.ZERO,
|
||||||
|
fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO,
|
||||||
|
BigDecimal::add)));
|
||||||
|
Map<Long, BigDecimal> directPromotionByCategory = promotionFees.stream()
|
||||||
|
.filter(fee -> fee.getProductId() == null && fee.getCategoryId() != null)
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
PromotionFeePO::getCategoryId,
|
||||||
|
Collectors.reducing(
|
||||||
|
BigDecimal.ZERO,
|
||||||
|
fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO,
|
||||||
|
BigDecimal::add)));
|
||||||
|
BigDecimal ratioPool = promotionFees.stream()
|
||||||
|
.filter(fee -> fee.getProductId() == null && fee.getCategoryId() == null)
|
||||||
|
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
|
BigDecimal totalSalesForRatioPool = orders.stream()
|
||||||
|
.map(stat::receivedForSales)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
|
Map<Long, BigDecimal> salesByCategory = new java.util.HashMap<>();
|
||||||
|
for (OrderPO o : orders) {
|
||||||
|
Long specId = o.getProductSpecId();
|
||||||
|
Long pid = specId != null ? specIdToProductId.get(specId) : null;
|
||||||
|
if (pid == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Long cid = productCategoryMap.get(pid);
|
||||||
|
if (cid == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
salesByCategory.merge(cid, stat.receivedForSales(o), BigDecimal::add);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Long, BigDecimal> shopTotalBrushFeeMap = brushOrders.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
BrushOrderPO::getShopId,
|
||||||
|
Collectors.reducing(BigDecimal.ZERO,
|
||||||
|
brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO,
|
||||||
|
BigDecimal::add)));
|
||||||
|
|
||||||
|
List<CompanyOverviewVO.CategorySummary> summaries = new ArrayList<>();
|
||||||
|
for (Map.Entry<Long, List<OrderPO>> entry : ordersByProduct.entrySet()) {
|
||||||
|
Long productId = entry.getKey();
|
||||||
|
List<OrderPO> productOrders = entry.getValue();
|
||||||
|
|
||||||
|
BigDecimal salesAmount = productOrders.stream()
|
||||||
|
.map(stat::receivedForSales)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
int orderCount = (int) productOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||||
|
BigDecimal refundAmount = productOrders.stream()
|
||||||
|
.map(stat::receivedForRefund)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal productCost = productOrders.stream()
|
||||||
|
.map(stat::productCostForStats)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal shippingCost = productOrders.stream()
|
||||||
|
.map(stat::freightCostForStats)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal otherCost = productOrders.stream()
|
||||||
|
.map(stat::otherCostForStats)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
|
Map<Long, BigDecimal> productSalesByShop = productOrders.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
OrderPO::getShopId,
|
||||||
|
Collectors.reducing(BigDecimal.ZERO, stat::receivedForSales, BigDecimal::add)));
|
||||||
|
BigDecimal productTotalSales = productSalesByShop.values().stream()
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
|
BigDecimal directP = BigDecimal.ZERO;
|
||||||
|
if (productId > 0) {
|
||||||
|
directP = directPromotionByProduct.getOrDefault(productId, BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal fromCategoryPool = BigDecimal.ZERO;
|
||||||
|
if (productId > 0) {
|
||||||
|
Long cid = productCategoryMap.get(productId);
|
||||||
|
if (cid != null && cid > 0) {
|
||||||
|
BigDecimal pool = directPromotionByCategory.getOrDefault(cid, BigDecimal.ZERO);
|
||||||
|
BigDecimal catSales = salesByCategory.getOrDefault(cid, BigDecimal.ZERO);
|
||||||
|
if (catSales.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
fromCategoryPool = pool.multiply(salesAmount).divide(catSales, 4, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal totalPromotionFee = directP.add(fromCategoryPool);
|
||||||
|
if (ratioPool.compareTo(BigDecimal.ZERO) > 0 && totalSalesForRatioPool.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
totalPromotionFee = totalPromotionFee.add(
|
||||||
|
ratioPool.multiply(salesAmount).divide(totalSalesForRatioPool, 4, RoundingMode.HALF_UP));
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal totalBrushFee = BigDecimal.ZERO;
|
||||||
|
if (productTotalSales.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
for (Map.Entry<Long, BigDecimal> shopEntry : productSalesByShop.entrySet()) {
|
||||||
|
Long shopId = shopEntry.getKey();
|
||||||
|
BigDecimal shopProductSales = shopEntry.getValue();
|
||||||
|
BigDecimal ratio = shopProductSales.divide(productTotalSales, 6, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal shopBrushFee = shopTotalBrushFeeMap.getOrDefault(shopId, BigDecimal.ZERO);
|
||||||
|
totalBrushFee = totalBrushFee.add(shopBrushFee.multiply(ratio));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal totalCost = productCost.add(shippingCost).add(otherCost);
|
||||||
|
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount)
|
||||||
|
.subtract(totalPromotionFee).subtract(totalBrushFee);
|
||||||
|
BigDecimal salesTaxAmount = salesTaxOnNetSales(salesAmount, refundAmount);
|
||||||
|
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||||
|
|
||||||
|
BigDecimal roi = BigDecimal.ZERO;
|
||||||
|
if (totalPromotionFee.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
roi = salesAmount.subtract(refundAmount).divide(totalPromotionFee, 4, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal feeRatio = BigDecimal.ZERO;
|
||||||
|
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
feeRatio = totalPromotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal averageOrderValue = BigDecimal.ZERO;
|
||||||
|
if (orderCount > 0) {
|
||||||
|
averageOrderValue = salesAmount.divide(new BigDecimal(orderCount), 2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
String productName = productId == -1L ? "未匹配商品" : productNameMap.getOrDefault(productId, "Unknown");
|
||||||
|
CompanyOverviewVO.CategorySummary summary = new CompanyOverviewVO.CategorySummary();
|
||||||
|
summary.setCategoryId(productId == -1L ? null : productId);
|
||||||
|
summary.setCategoryName(productName);
|
||||||
|
summary.setSalesAmount(salesAmount);
|
||||||
|
summary.setOrderCount(orderCount);
|
||||||
|
summary.setAverageOrderValue(averageOrderValue);
|
||||||
|
summary.setProductCost(productCost);
|
||||||
|
summary.setShippingCost(shippingCost);
|
||||||
|
summary.setOtherCost(otherCost);
|
||||||
|
summary.setTotalCost(totalCost);
|
||||||
|
summary.setRefundAmount(refundAmount);
|
||||||
|
summary.setTotalPromotionFee(totalPromotionFee);
|
||||||
|
summary.setBrushFee(totalBrushFee);
|
||||||
|
summary.setFeeRatio(feeRatio);
|
||||||
|
summary.setTotalProfitBeforeTax(profitBeforeTax);
|
||||||
|
summary.setSalesTaxAmount(salesTaxAmount);
|
||||||
|
summary.setProfitAfterTax(profitAfterTax.setScale(2, RoundingMode.HALF_UP));
|
||||||
|
summary.setRoi(roi);
|
||||||
|
summaries.add(summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
summaries.sort(Comparator.comparing(CompanyOverviewVO.CategorySummary::getSalesAmount).reversed());
|
||||||
|
CompanyOverviewVO.CategorySummary total = computeCategoryTotal(summaries);
|
||||||
|
CompanyOverviewVO.CategoryOverview overview = new CompanyOverviewVO.CategoryOverview();
|
||||||
|
overview.setTotal(total);
|
||||||
|
overview.setCategories(summaries);
|
||||||
|
return overview;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.dto.WorkbenchQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.service.WorkbenchService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电商运营工作台:一次返回经营概览、多维分析、排行等聚合数据。
|
||||||
|
*/
|
||||||
|
@Tag(name = "电商-工作台", description = "工作台聚合统计")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/ec/workbench")
|
||||||
|
public class WorkbenchController {
|
||||||
|
|
||||||
|
private final WorkbenchService workbenchService;
|
||||||
|
|
||||||
|
public WorkbenchController(WorkbenchService workbenchService) {
|
||||||
|
this.workbenchService = workbenchService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "工作台汇总", description = "按日期范围(及可选平台、店铺)返回 finance / multiAnalysis / salesRank 聚合数据")
|
||||||
|
@PostMapping("/summary")
|
||||||
|
@RequirePermission(value = "ecom:shop:read", description = "查询工作台", allowSuper = true)
|
||||||
|
public ApiResponse<WorkbenchVO> summary(@Valid @RequestBody WorkbenchQueryDTO queryDTO) {
|
||||||
|
return ApiResponse.success("获取工作台数据成功", workbenchService.summary(queryDTO));
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作台聚合查询:一次请求返回经营概览、多维分析、排行等所需数据。
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Schema(description = "工作台聚合查询 DTO")
|
||||||
|
public class WorkbenchQueryDTO {
|
||||||
|
|
||||||
|
@Schema(description = "日期范围 [开始, 结束],单元素表示当天", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "日期范围不能为空")
|
||||||
|
@Size(min = 1, max = 2, message = "日期范围必须包含 1~2 个日期")
|
||||||
|
private List<LocalDate> dateRange;
|
||||||
|
|
||||||
|
@Schema(description = "税率,默认 0.04", example = "0.04")
|
||||||
|
private BigDecimal taxRate = new BigDecimal("0.04");
|
||||||
|
|
||||||
|
@Schema(description = "平台 ID,不传表示全平台")
|
||||||
|
private Long platformId;
|
||||||
|
|
||||||
|
@Schema(description = "店铺 ID,不传表示所选平台下全部店铺(仍受公司数据权限约束)")
|
||||||
|
private Long shopId;
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "成本结构扇区(万元;pct 为占销售额比例 %)")
|
||||||
|
public class WorkbenchCostSliceVO {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private BigDecimal value;
|
||||||
|
|
||||||
|
private BigDecimal pct;
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 与前端多维卡片一致:金额单位为「万元」,比例为百分比。
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "工作台-维度汇总行(万元 / %)")
|
||||||
|
public class WorkbenchDimRowVO {
|
||||||
|
|
||||||
|
@Schema(description = "维度唯一键")
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
@Schema(description = "展示名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "销售额(万元)")
|
||||||
|
private BigDecimal gmvWan;
|
||||||
|
|
||||||
|
@Schema(description = "毛利额(万元)")
|
||||||
|
private BigDecimal grossProfitWan;
|
||||||
|
|
||||||
|
@Schema(description = "净利额(万元)")
|
||||||
|
private BigDecimal netProfitWan;
|
||||||
|
|
||||||
|
@Schema(description = "退款金额(万元)")
|
||||||
|
private BigDecimal refundWan;
|
||||||
|
|
||||||
|
@Schema(description = "毛利率 %")
|
||||||
|
private BigDecimal grossMarginPct;
|
||||||
|
|
||||||
|
@Schema(description = "净利率 %")
|
||||||
|
private BigDecimal netMarginPct;
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "工作台-经营概览区")
|
||||||
|
public class WorkbenchFinancePanelVO {
|
||||||
|
|
||||||
|
private List<WorkbenchKpiItemVO> kpis;
|
||||||
|
|
||||||
|
private List<WorkbenchTrendPointVO> gmvTrend;
|
||||||
|
|
||||||
|
private List<WorkbenchCostSliceVO> costStructure;
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "工作台-KPI 卡片项")
|
||||||
|
public class WorkbenchKpiItemVO {
|
||||||
|
|
||||||
|
@Schema(description = "标题")
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
@Schema(description = "主展示值(字符串便于千分位等)")
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
@Schema(description = "单位,如 万、单、元、%")
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
@Schema(description = "环比/同比变化百分比;广告 ROI 场景可为绝对增量")
|
||||||
|
private BigDecimal changePct;
|
||||||
|
|
||||||
|
@Schema(description = "是否上涨(前端箭头颜色)")
|
||||||
|
private Boolean up;
|
||||||
|
|
||||||
|
@Schema(description = "副文案")
|
||||||
|
private String sub;
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "工作台-多维分析(四维度行列表)")
|
||||||
|
public class WorkbenchMultiAnalysisPanelVO {
|
||||||
|
|
||||||
|
private List<WorkbenchDimRowVO> platform;
|
||||||
|
|
||||||
|
private List<WorkbenchDimRowVO> shop;
|
||||||
|
|
||||||
|
private List<WorkbenchDimRowVO> category;
|
||||||
|
|
||||||
|
private List<WorkbenchDimRowVO> product;
|
||||||
|
}
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "工作台-GM/利润趋势点(万元)")
|
||||||
|
public class WorkbenchTrendPointVO {
|
||||||
|
|
||||||
|
@Schema(description = "横轴日期,如 M/d")
|
||||||
|
private String date;
|
||||||
|
|
||||||
|
@Schema(description = "GMV(万元)")
|
||||||
|
private BigDecimal gmv;
|
||||||
|
|
||||||
|
@Schema(description = "日毛利近似(万元)= 销售额-成本-退款")
|
||||||
|
private BigDecimal profit;
|
||||||
|
|
||||||
|
@Schema(description = "退款(万元)")
|
||||||
|
private BigDecimal refund;
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.CompanyOverviewVO;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Schema(description = "工作台聚合 VO(一次返回多 Tab 数据)")
|
||||||
|
public class WorkbenchVO {
|
||||||
|
|
||||||
|
@Schema(description = "经营概览:KPI、趋势、成本结构")
|
||||||
|
private WorkbenchFinancePanelVO finance;
|
||||||
|
|
||||||
|
@Schema(description = "多维分析:平台/店铺/品类/商品")
|
||||||
|
private WorkbenchMultiAnalysisPanelVO multiAnalysis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 与 multiAnalysis 相同维度数据;前端可自行按 gmv 排序做排行图。
|
||||||
|
* 预留字段便于后续后端预排序或增加环比字段。
|
||||||
|
*/
|
||||||
|
@Schema(description = "销售额排行:当前与 multiAnalysis 同源,便于扩展环比等字段")
|
||||||
|
private WorkbenchMultiAnalysisPanelVO salesRank;
|
||||||
|
|
||||||
|
@Schema(description = "底部四张汇总表:与全店概览同源口径(税额、ROI、推广/刷单、目标等)")
|
||||||
|
private CompanyOverviewVO.WorkbenchTableBundle summaryTables;
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.service;
|
||||||
|
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.dto.WorkbenchQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchVO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作台:一次聚合经营概览、多维分析、排行等数据。
|
||||||
|
*/
|
||||||
|
public interface WorkbenchService {
|
||||||
|
|
||||||
|
WorkbenchVO summary(WorkbenchQueryDTO queryDTO);
|
||||||
|
}
|
||||||
+700
@@ -0,0 +1,700 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ecom.workbench.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.mapper.BrushOrderMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.category.model.po.CategoryPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.category.service.CategoryService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatResolver;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatSets;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.CompanyOverviewVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.overview.service.CompanyOverviewService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductSpecMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.dto.WorkbenchQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchCostSliceVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchDimRowVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchFinancePanelVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchKpiItemVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchMultiAnalysisPanelVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchTrendPointVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.model.vo.WorkbenchVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ecom.workbench.service.WorkbenchService;
|
||||||
|
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.DecimalFormatSymbols;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作台聚合:订单口径与 {@link top.xyquan.ecomdmbbackend.modules.ecom.overview.service.impl.ShopOverviewStatisticsServiceImpl} 一致
|
||||||
|
* ({@link OrderStatusStatSets} + 推广费 / 刷单费 / 税额)。
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class WorkbenchServiceImpl implements WorkbenchService {
|
||||||
|
|
||||||
|
private static final BigDecimal WAN = new BigDecimal("10000");
|
||||||
|
private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04");
|
||||||
|
private static final DateTimeFormatter TREND_DATE_FMT = DateTimeFormatter.ofPattern("M/d");
|
||||||
|
|
||||||
|
private final CurrentUserContext currentUserContext;
|
||||||
|
private final OrderMapper orderMapper;
|
||||||
|
private final ShopService shopService;
|
||||||
|
private final OrderStatusStatResolver orderStatusStatResolver;
|
||||||
|
private final PromotionFeeMapper promotionFeeMapper;
|
||||||
|
private final BrushOrderMapper brushOrderMapper;
|
||||||
|
private final ProductSpecMapper productSpecMapper;
|
||||||
|
private final ProductMapper productMapper;
|
||||||
|
private final CategoryService categoryService;
|
||||||
|
private final PlatformMapper platformMapper;
|
||||||
|
private final CompanyOverviewService companyOverviewService;
|
||||||
|
|
||||||
|
public WorkbenchServiceImpl(CurrentUserContext currentUserContext,
|
||||||
|
OrderMapper orderMapper,
|
||||||
|
ShopService shopService,
|
||||||
|
OrderStatusStatResolver orderStatusStatResolver,
|
||||||
|
PromotionFeeMapper promotionFeeMapper,
|
||||||
|
BrushOrderMapper brushOrderMapper,
|
||||||
|
ProductSpecMapper productSpecMapper,
|
||||||
|
ProductMapper productMapper,
|
||||||
|
CategoryService categoryService,
|
||||||
|
PlatformMapper platformMapper,
|
||||||
|
CompanyOverviewService companyOverviewService) {
|
||||||
|
this.currentUserContext = currentUserContext;
|
||||||
|
this.orderMapper = orderMapper;
|
||||||
|
this.shopService = shopService;
|
||||||
|
this.orderStatusStatResolver = orderStatusStatResolver;
|
||||||
|
this.promotionFeeMapper = promotionFeeMapper;
|
||||||
|
this.brushOrderMapper = brushOrderMapper;
|
||||||
|
this.productSpecMapper = productSpecMapper;
|
||||||
|
this.productMapper = productMapper;
|
||||||
|
this.categoryService = categoryService;
|
||||||
|
this.platformMapper = platformMapper;
|
||||||
|
this.companyOverviewService = companyOverviewService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorkbenchVO summary(WorkbenchQueryDTO queryDTO) {
|
||||||
|
BigDecimal taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE;
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
DateRange range = parseDateRange(queryDTO);
|
||||||
|
OrderStatusStatSets stat = orderStatusStatResolver.resolve(companyId);
|
||||||
|
List<Long> unionStatusIds = stat.getUnionStatusIds();
|
||||||
|
|
||||||
|
List<ShopPO> shops = loadFilteredShops(companyId, queryDTO.getPlatformId(), queryDTO.getShopId());
|
||||||
|
if (shops.isEmpty()) {
|
||||||
|
return emptyWorkbench();
|
||||||
|
}
|
||||||
|
List<Long> shopIds = shops.stream().map(ShopPO::getId).filter(Objects::nonNull).toList();
|
||||||
|
Map<Long, ShopPO> shopById = shops.stream().collect(Collectors.toMap(ShopPO::getId, s -> s, (a, b) -> a));
|
||||||
|
|
||||||
|
List<OrderPO> orders = loadOrders(companyId, shopIds, range.startDateTime(), range.endDateTime(), unionStatusIds);
|
||||||
|
List<PromotionFeePO> promotionFees = loadPromotionFees(companyId, shopIds, range.startDate(), range.endDate());
|
||||||
|
List<BrushOrderPO> brushOrders = loadBrushOrders(companyId, shopIds, range.startDateTime(), range.endDateTime());
|
||||||
|
|
||||||
|
DateRange lastRange = lastMonthSameSpan(range);
|
||||||
|
List<OrderPO> lastOrders = loadOrders(companyId, shopIds, lastRange.startDateTime(), lastRange.endDateTime(), unionStatusIds);
|
||||||
|
List<PromotionFeePO> lastPromo = loadPromotionFees(companyId, shopIds, lastRange.startDate(), lastRange.endDate());
|
||||||
|
List<BrushOrderPO> lastBrush = loadBrushOrders(companyId, shopIds, lastRange.startDateTime(), lastRange.endDateTime());
|
||||||
|
|
||||||
|
Totals cur = aggregateTotals(orders, stat, promotionFees, brushOrders, taxRate);
|
||||||
|
Totals prev = aggregateTotals(lastOrders, stat, lastPromo, lastBrush, taxRate);
|
||||||
|
|
||||||
|
Map<Long, Long> specToProduct = buildSpecToProductMap(orders);
|
||||||
|
Map<Long, ProductPO> productById = loadProducts(specToProduct.values());
|
||||||
|
Map<Long, String> categoryNames = loadCategoryNames(productById.values());
|
||||||
|
Map<Long, String> platformNames = loadPlatformNames(shops);
|
||||||
|
|
||||||
|
Map<String, Agg> platformAgg = new HashMap<>();
|
||||||
|
Map<String, Agg> shopAgg = new HashMap<>();
|
||||||
|
Map<String, Agg> categoryAgg = new HashMap<>();
|
||||||
|
Map<String, Agg> productAgg = new HashMap<>();
|
||||||
|
|
||||||
|
for (OrderPO o : orders) {
|
||||||
|
ShopPO shop = shopById.get(o.getShopId());
|
||||||
|
if (shop == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
long platformKey = shop.getPlatformId() != null ? shop.getPlatformId() : 0L;
|
||||||
|
long shopKey = shop.getId() != null ? shop.getId() : 0L;
|
||||||
|
long productId = o.getProductSpecId() != null
|
||||||
|
? specToProduct.getOrDefault(o.getProductSpecId(), -1L)
|
||||||
|
: -1L;
|
||||||
|
long categoryKey = 0L;
|
||||||
|
if (productId > 0) {
|
||||||
|
ProductPO p = productById.get(productId);
|
||||||
|
if (p != null && p.getCategoryId() != null) {
|
||||||
|
categoryKey = p.getCategoryId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addOrder(platformAgg, String.valueOf(platformKey), o, stat);
|
||||||
|
addOrder(shopAgg, String.valueOf(shopKey), o, stat);
|
||||||
|
addOrder(categoryAgg, String.valueOf(categoryKey), o, stat);
|
||||||
|
addOrder(productAgg, String.valueOf(productId), o, stat);
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal salesAllocBase = cur.totalSales();
|
||||||
|
|
||||||
|
WorkbenchMultiAnalysisPanelVO multi = WorkbenchMultiAnalysisPanelVO.builder()
|
||||||
|
.platform(buildDimRows(platformAgg, k -> platformNames.getOrDefault(Long.parseLong(k), "未知平台"),
|
||||||
|
salesAllocBase, cur.promotion(), cur.brush(), cur.tax()))
|
||||||
|
.shop(buildDimRows(shopAgg, k -> {
|
||||||
|
ShopPO s = shopById.get(Long.parseLong(k));
|
||||||
|
return s != null ? s.getName() : "未知店铺";
|
||||||
|
}, salesAllocBase, cur.promotion(), cur.brush(), cur.tax()))
|
||||||
|
.category(buildDimRows(categoryAgg, k -> {
|
||||||
|
if ("0".equals(k)) {
|
||||||
|
return "未分类";
|
||||||
|
}
|
||||||
|
return categoryNames.getOrDefault(Long.parseLong(k), "类目" + k);
|
||||||
|
}, salesAllocBase, cur.promotion(), cur.brush(), cur.tax()))
|
||||||
|
.product(buildDimRows(productAgg, k -> {
|
||||||
|
if (k.startsWith("-") || "0".equals(k)) {
|
||||||
|
return "未匹配商品";
|
||||||
|
}
|
||||||
|
ProductPO p = productById.get(Long.parseLong(k));
|
||||||
|
return p != null ? p.getName() : ("商品" + k);
|
||||||
|
}, salesAllocBase, cur.promotion(), cur.brush(), cur.tax()))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
WorkbenchMultiAnalysisPanelVO salesRank = WorkbenchMultiAnalysisPanelVO.builder()
|
||||||
|
.platform(sortByGmvDesc(multi.getPlatform()))
|
||||||
|
.shop(sortByGmvDesc(multi.getShop()))
|
||||||
|
.category(sortByGmvDesc(multi.getCategory()))
|
||||||
|
.product(sortByGmvDesc(multi.getProduct()))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
WorkbenchFinancePanelVO finance = WorkbenchFinancePanelVO.builder()
|
||||||
|
.kpis(buildKpis(cur, prev, range, taxRate))
|
||||||
|
.gmvTrend(buildTrend(orders, stat, range.startDate(), range.endDate()))
|
||||||
|
.costStructure(buildCostSlices(cur))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
CompanyOverviewVO.WorkbenchTableBundle summaryTables = companyOverviewService.buildWorkbenchSummaryTables(
|
||||||
|
taxRate,
|
||||||
|
companyId,
|
||||||
|
shops,
|
||||||
|
orders,
|
||||||
|
promotionFees,
|
||||||
|
brushOrders,
|
||||||
|
stat,
|
||||||
|
range.startDate(),
|
||||||
|
range.endDate());
|
||||||
|
|
||||||
|
return WorkbenchVO.builder()
|
||||||
|
.finance(finance)
|
||||||
|
.multiAnalysis(multi)
|
||||||
|
.salesRank(salesRank)
|
||||||
|
.summaryTables(summaryTables)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private WorkbenchVO emptyWorkbench() {
|
||||||
|
return WorkbenchVO.builder()
|
||||||
|
.finance(WorkbenchFinancePanelVO.builder()
|
||||||
|
.kpis(Collections.emptyList())
|
||||||
|
.gmvTrend(Collections.emptyList())
|
||||||
|
.costStructure(Collections.emptyList())
|
||||||
|
.build())
|
||||||
|
.multiAnalysis(WorkbenchMultiAnalysisPanelVO.builder()
|
||||||
|
.platform(Collections.emptyList())
|
||||||
|
.shop(Collections.emptyList())
|
||||||
|
.category(Collections.emptyList())
|
||||||
|
.product(Collections.emptyList())
|
||||||
|
.build())
|
||||||
|
.salesRank(WorkbenchMultiAnalysisPanelVO.builder()
|
||||||
|
.platform(Collections.emptyList())
|
||||||
|
.shop(Collections.emptyList())
|
||||||
|
.category(Collections.emptyList())
|
||||||
|
.product(Collections.emptyList())
|
||||||
|
.build())
|
||||||
|
.summaryTables(null)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ShopPO> loadFilteredShops(Long companyId, Long platformId, Long shopId) {
|
||||||
|
LambdaQueryWrapper<ShopPO> w = new LambdaQueryWrapper<>();
|
||||||
|
w.eq(ShopPO::getCompanyId, companyId);
|
||||||
|
if (shopId != null) {
|
||||||
|
ShopPO one = shopService.getById(shopId);
|
||||||
|
if (one == null || !companyId.equals(one.getCompanyId())) {
|
||||||
|
throw new BusinessException("店铺不存在");
|
||||||
|
}
|
||||||
|
if (platformId != null && one.getPlatformId() != null && !platformId.equals(one.getPlatformId())) {
|
||||||
|
throw new BusinessException("店铺与所选平台不一致");
|
||||||
|
}
|
||||||
|
return List.of(one);
|
||||||
|
}
|
||||||
|
if (platformId != null) {
|
||||||
|
w.eq(ShopPO::getPlatformId, platformId);
|
||||||
|
}
|
||||||
|
return shopService.list(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<OrderPO> loadOrders(Long companyId, List<Long> shopIds,
|
||||||
|
LocalDateTime start, LocalDateTime end, List<Long> unionStatusIds) {
|
||||||
|
if (shopIds.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
|
||||||
|
orderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||||
|
.in(OrderPO::getShopId, shopIds)
|
||||||
|
.ge(OrderPO::getOrderTime, start)
|
||||||
|
.le(OrderPO::getOrderTime, end);
|
||||||
|
if (!unionStatusIds.isEmpty()) {
|
||||||
|
orderWrapper.in(OrderPO::getStatusId, unionStatusIds);
|
||||||
|
} else {
|
||||||
|
orderWrapper.isNull(OrderPO::getId);
|
||||||
|
}
|
||||||
|
return orderMapper.selectList(orderWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PromotionFeePO> loadPromotionFees(Long companyId, List<Long> shopIds, LocalDate start, LocalDate end) {
|
||||||
|
if (shopIds.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<PromotionFeePO> w = new LambdaQueryWrapper<>();
|
||||||
|
w.eq(PromotionFeePO::getCompanyId, companyId)
|
||||||
|
.in(PromotionFeePO::getShopId, shopIds)
|
||||||
|
.ge(PromotionFeePO::getFeeDate, start)
|
||||||
|
.le(PromotionFeePO::getFeeDate, end);
|
||||||
|
return promotionFeeMapper.selectList(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<BrushOrderPO> loadBrushOrders(Long companyId, List<Long> shopIds, LocalDateTime start, LocalDateTime end) {
|
||||||
|
if (shopIds.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<BrushOrderPO> w = new LambdaQueryWrapper<>();
|
||||||
|
w.eq(BrushOrderPO::getCompanyId, companyId)
|
||||||
|
.in(BrushOrderPO::getShopId, shopIds)
|
||||||
|
.ge(BrushOrderPO::getBrushTime, start)
|
||||||
|
.le(BrushOrderPO::getBrushTime, end);
|
||||||
|
return brushOrderMapper.selectList(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Long, Long> buildSpecToProductMap(List<OrderPO> orders) {
|
||||||
|
List<Long> specIds = orders.stream()
|
||||||
|
.map(OrderPO::getProductSpecId)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
if (specIds.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
List<ProductSpecPO> specs = productSpecMapper.selectList(new LambdaQueryWrapper<ProductSpecPO>()
|
||||||
|
.in(ProductSpecPO::getId, specIds)
|
||||||
|
.select(ProductSpecPO::getId, ProductSpecPO::getProductId));
|
||||||
|
Map<Long, Long> map = new HashMap<>();
|
||||||
|
for (ProductSpecPO s : specs) {
|
||||||
|
map.put(s.getId(), s.getProductId());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Long, ProductPO> loadProducts(Iterable<Long> productIds) {
|
||||||
|
List<Long> ids = new ArrayList<>();
|
||||||
|
for (Long id : productIds) {
|
||||||
|
if (id != null && id > 0) {
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ids = ids.stream().distinct().toList();
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
List<ProductPO> list = productMapper.selectList(new LambdaQueryWrapper<ProductPO>().in(ProductPO::getId, ids));
|
||||||
|
return list.stream().collect(Collectors.toMap(ProductPO::getId, p -> p, (a, b) -> a));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Long, String> loadCategoryNames(Iterable<ProductPO> products) {
|
||||||
|
List<Long> catIds = new ArrayList<>();
|
||||||
|
for (ProductPO p : products) {
|
||||||
|
if (p.getCategoryId() != null) {
|
||||||
|
catIds.add(p.getCategoryId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catIds = catIds.stream().distinct().toList();
|
||||||
|
if (catIds.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
List<CategoryPO> cats = categoryService.list(new LambdaQueryWrapper<CategoryPO>().in(CategoryPO::getId, catIds));
|
||||||
|
return cats.stream().collect(Collectors.toMap(CategoryPO::getId, CategoryPO::getName, (a, b) -> a));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Long, String> loadPlatformNames(List<ShopPO> shops) {
|
||||||
|
List<Long> pids = shops.stream()
|
||||||
|
.map(ShopPO::getPlatformId)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
if (pids.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
List<PlatformPO> list = platformMapper.selectList(new LambdaQueryWrapper<PlatformPO>().in(PlatformPO::getId, pids));
|
||||||
|
return list.stream().collect(Collectors.toMap(PlatformPO::getId, PlatformPO::getPlatformName, (a, b) -> a));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addOrder(Map<String, Agg> map, String key, OrderPO o, OrderStatusStatSets stat) {
|
||||||
|
map.computeIfAbsent(key, k -> new Agg()).add(o, stat);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<WorkbenchDimRowVO> buildDimRows(Map<String, Agg> aggs,
|
||||||
|
java.util.function.Function<String, String> nameFn,
|
||||||
|
BigDecimal salesTotalCompany,
|
||||||
|
BigDecimal promoTotal,
|
||||||
|
BigDecimal brushTotal,
|
||||||
|
BigDecimal taxTotal) {
|
||||||
|
BigDecimal netSum = aggs.values().stream()
|
||||||
|
.map(Agg::netSalesBase)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
|
List<WorkbenchDimRowVO> rows = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, Agg> e : aggs.entrySet()) {
|
||||||
|
Agg a = e.getValue();
|
||||||
|
if (a.sales.compareTo(BigDecimal.ZERO) <= 0 && a.refund.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BigDecimal gross = a.sales.subtract(a.cost).subtract(a.refund);
|
||||||
|
BigDecimal promoB = allocShare(a.sales, salesTotalCompany, promoTotal);
|
||||||
|
BigDecimal brushB = allocShare(a.sales, salesTotalCompany, brushTotal);
|
||||||
|
BigDecimal taxB = allocShare(a.netSalesBase(), netSum.max(BigDecimal.ONE), taxTotal);
|
||||||
|
if (netSum.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
taxB = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
BigDecimal net = gross.subtract(promoB).subtract(brushB).subtract(taxB);
|
||||||
|
|
||||||
|
BigDecimal gmvWan = toWan(a.sales);
|
||||||
|
BigDecimal grossWan = toWan(gross);
|
||||||
|
BigDecimal netWan = toWan(net);
|
||||||
|
BigDecimal refundWan = toWan(a.refund);
|
||||||
|
|
||||||
|
BigDecimal grossMarginPct = safePct(gross, a.sales);
|
||||||
|
BigDecimal netMarginPct = safePct(net, a.sales);
|
||||||
|
|
||||||
|
rows.add(WorkbenchDimRowVO.builder()
|
||||||
|
.key(e.getKey())
|
||||||
|
.name(nameFn.apply(e.getKey()))
|
||||||
|
.gmvWan(gmvWan)
|
||||||
|
.grossProfitWan(grossWan)
|
||||||
|
.netProfitWan(netWan)
|
||||||
|
.refundWan(refundWan)
|
||||||
|
.grossMarginPct(grossMarginPct)
|
||||||
|
.netMarginPct(netMarginPct)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
rows.sort(Comparator.comparing(WorkbenchDimRowVO::getGmvWan, Comparator.nullsFirst(BigDecimal::compareTo)).reversed());
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<WorkbenchDimRowVO> sortByGmvDesc(List<WorkbenchDimRowVO> in) {
|
||||||
|
if (in == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return in.stream()
|
||||||
|
.sorted(Comparator.comparing(WorkbenchDimRowVO::getGmvWan, Comparator.nullsFirst(BigDecimal::compareTo)).reversed())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal allocShare(BigDecimal part, BigDecimal total, BigDecimal amount) {
|
||||||
|
if (amount == null || amount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
if (total == null || total.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return amount.multiply(part).divide(total, 4, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<WorkbenchTrendPointVO> buildTrend(List<OrderPO> orders, OrderStatusStatSets stat,
|
||||||
|
LocalDate start, LocalDate end) {
|
||||||
|
Map<LocalDate, Agg> byDay = new HashMap<>();
|
||||||
|
for (OrderPO o : orders) {
|
||||||
|
if (o.getOrderTime() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LocalDate day = o.getOrderTime().toLocalDate();
|
||||||
|
byDay.computeIfAbsent(day, x -> new Agg()).add(o, stat);
|
||||||
|
}
|
||||||
|
List<WorkbenchTrendPointVO> list = new ArrayList<>();
|
||||||
|
LocalDate d = start;
|
||||||
|
while (!d.isAfter(end)) {
|
||||||
|
Agg a = byDay.getOrDefault(d, new Agg());
|
||||||
|
BigDecimal gmvWan = toWan(a.sales);
|
||||||
|
BigDecimal profitWan = toWan(a.sales.subtract(a.cost).subtract(a.refund));
|
||||||
|
BigDecimal refundWan = toWan(a.refund);
|
||||||
|
list.add(WorkbenchTrendPointVO.builder()
|
||||||
|
.date(d.format(TREND_DATE_FMT))
|
||||||
|
.gmv(gmvWan)
|
||||||
|
.profit(profitWan)
|
||||||
|
.refund(refundWan)
|
||||||
|
.build());
|
||||||
|
d = d.plusDays(1);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<WorkbenchCostSliceVO> buildCostSlices(Totals t) {
|
||||||
|
BigDecimal denom = t.totalSales().max(BigDecimal.ONE);
|
||||||
|
List<WorkbenchCostSliceVO> slices = new ArrayList<>();
|
||||||
|
slices.add(slice("商品成本", t.productCost(), denom));
|
||||||
|
slices.add(slice("物流费用", t.freightCost(), denom));
|
||||||
|
slices.add(slice("其他成本", t.otherCost(), denom));
|
||||||
|
slices.add(slice("推广费", t.promotion(), denom));
|
||||||
|
slices.add(slice("刷单费", t.brush(), denom));
|
||||||
|
slices.add(slice("税费", t.tax(), denom));
|
||||||
|
slices.add(slice("净利润", t.netProfit(), denom));
|
||||||
|
return slices;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WorkbenchCostSliceVO slice(String name, BigDecimal yuan, BigDecimal denom) {
|
||||||
|
BigDecimal wan = toWan(yuan);
|
||||||
|
BigDecimal pct = yuan.multiply(new BigDecimal("100")).divide(denom, 2, RoundingMode.HALF_UP);
|
||||||
|
return WorkbenchCostSliceVO.builder().name(name).value(wan).pct(pct).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<WorkbenchKpiItemVO> buildKpis(Totals cur, Totals prev, DateRange range, BigDecimal taxRate) {
|
||||||
|
int days = (int) (range.endDate().toEpochDay() - range.startDate().toEpochDay() + 1);
|
||||||
|
DecimalFormat df = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.CHINA));
|
||||||
|
|
||||||
|
BigDecimal netRecv = cur.totalSales().subtract(cur.totalRefund());
|
||||||
|
BigDecimal grossMarginPct = safePct(cur.grossOrder(), cur.totalSales());
|
||||||
|
BigDecimal netMarginPct = safePct(cur.netProfit(), cur.totalSales());
|
||||||
|
BigDecimal refundRate = safePct(cur.totalRefund(), cur.totalSales());
|
||||||
|
BigDecimal roi = cur.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||||
|
? netRecv.divide(cur.promotion(), 2, RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
|
||||||
|
BigDecimal avgDaily = days > 0
|
||||||
|
? BigDecimal.valueOf(cur.orderCount()).divide(BigDecimal.valueOf(days), 1, RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
|
||||||
|
List<WorkbenchKpiItemVO> list = new ArrayList<>();
|
||||||
|
list.add(kpi("总GMV", formatWan(cur.totalSales()), "万", cur.totalSales(), prev.totalSales(),
|
||||||
|
"税率 " + taxRate.multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%"));
|
||||||
|
list.add(kpi("实收金额", formatWan(netRecv), "万", netRecv, prev.totalSales().subtract(prev.totalRefund()),
|
||||||
|
"退款 " + formatWan(cur.totalRefund()) + " 万"));
|
||||||
|
list.add(kpi("毛利润", formatWan(cur.grossOrder()), "万", cur.grossOrder(), prev.grossOrder(),
|
||||||
|
"毛利率 " + grossMarginPct.stripTrailingZeros().toPlainString() + "%"));
|
||||||
|
list.add(kpi("净利润", formatWan(cur.netProfit()), "万", cur.netProfit(), prev.netProfit(),
|
||||||
|
"净利率 " + netMarginPct.stripTrailingZeros().toPlainString() + "%"));
|
||||||
|
list.add(kpi("订单量", df.format(cur.orderCount()), "单",
|
||||||
|
BigDecimal.valueOf(cur.orderCount()), BigDecimal.valueOf(prev.orderCount()),
|
||||||
|
"日均约 " + avgDaily.stripTrailingZeros().toPlainString() + " 单"));
|
||||||
|
list.add(kpi("客单价", formatYuan(cur.averageOrderValue()), "元",
|
||||||
|
cur.averageOrderValue(), prev.averageOrderValue(), "按计入销售额单量"));
|
||||||
|
list.add(kpi("退款率", refundRate.setScale(2, RoundingMode.HALF_UP).toPlainString(), "%",
|
||||||
|
refundRate, safePct(prev.totalRefund(), prev.totalSales()), "销售额口径"));
|
||||||
|
list.add(kpi("广告ROI", roi.stripTrailingZeros().toPlainString(), ":1", roi,
|
||||||
|
prev.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||||
|
? prev.totalSales().subtract(prev.totalRefund()).divide(prev.promotion(), 2, RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO,
|
||||||
|
"推广花费 " + formatWan(cur.promotion()) + " 万"));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WorkbenchKpiItemVO kpi(String label, String value, String unit,
|
||||||
|
BigDecimal curAmt, BigDecimal prevAmt, String sub) {
|
||||||
|
BigDecimal change = pctChange(curAmt, prevAmt);
|
||||||
|
boolean up = curAmt.compareTo(prevAmt) >= 0;
|
||||||
|
return WorkbenchKpiItemVO.builder()
|
||||||
|
.label(label)
|
||||||
|
.value(value)
|
||||||
|
.unit(unit)
|
||||||
|
.changePct(change)
|
||||||
|
.up(up)
|
||||||
|
.sub(sub)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal pctChange(BigDecimal cur, BigDecimal prev) {
|
||||||
|
if (prev == null || prev.compareTo(BigDecimal.ZERO) == 0) {
|
||||||
|
if (cur != null && cur.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
return new BigDecimal("100");
|
||||||
|
}
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return cur.subtract(prev).divide(prev, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
||||||
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Totals aggregateTotals(List<OrderPO> orders, OrderStatusStatSets stat,
|
||||||
|
List<PromotionFeePO> promotionFees, List<BrushOrderPO> brushOrders,
|
||||||
|
BigDecimal taxRate) {
|
||||||
|
BigDecimal sales = BigDecimal.ZERO;
|
||||||
|
BigDecimal refund = BigDecimal.ZERO;
|
||||||
|
BigDecimal cost = BigDecimal.ZERO;
|
||||||
|
BigDecimal productCost = BigDecimal.ZERO;
|
||||||
|
BigDecimal freight = BigDecimal.ZERO;
|
||||||
|
BigDecimal other = BigDecimal.ZERO;
|
||||||
|
int orderCount = 0;
|
||||||
|
for (OrderPO o : orders) {
|
||||||
|
sales = sales.add(stat.receivedForSales(o));
|
||||||
|
refund = refund.add(stat.receivedForRefund(o));
|
||||||
|
productCost = productCost.add(stat.productCostForStats(o));
|
||||||
|
freight = freight.add(stat.freightCostForStats(o));
|
||||||
|
other = other.add(stat.otherCostForStats(o));
|
||||||
|
cost = cost.add(stat.totalCostForStats(o));
|
||||||
|
if (stat.includesSales(o.getStatusId())) {
|
||||||
|
orderCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BigDecimal promotion = promotionFees.stream()
|
||||||
|
.map(f -> f.getFeeAmount() != null ? f.getFeeAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
BigDecimal brush = brushOrders.stream()
|
||||||
|
.map(b -> b.getBrushAmount() != null ? b.getBrushAmount() : BigDecimal.ZERO)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
|
BigDecimal grossOrder = sales.subtract(cost).subtract(refund);
|
||||||
|
BigDecimal profitBeforeTax = grossOrder.subtract(promotion).subtract(brush);
|
||||||
|
BigDecimal tax = salesTaxOnNetSales(sales, refund, taxRate);
|
||||||
|
BigDecimal netProfit = profitBeforeTax.subtract(tax);
|
||||||
|
|
||||||
|
BigDecimal aov = orderCount > 0
|
||||||
|
? sales.divide(BigDecimal.valueOf(orderCount), 2, RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
|
||||||
|
return new Totals(sales, refund, cost, productCost, freight, other, promotion, brush, tax,
|
||||||
|
grossOrder, netProfit, orderCount, aov);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 与单店概览一致:订单流水中「销售额−成本」的合计,再扣推广、刷单得税前;再扣税得净利。
|
||||||
|
*/
|
||||||
|
private BigDecimal salesTaxOnNetSales(BigDecimal salesAmount, BigDecimal refundAmount, BigDecimal rate) {
|
||||||
|
BigDecimal sales = salesAmount != null ? salesAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal ref = refundAmount != null ? refundAmount : BigDecimal.ZERO;
|
||||||
|
BigDecimal base = sales.subtract(ref);
|
||||||
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
base = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
BigDecimal r = rate != null ? rate : DEFAULT_TAX_RATE;
|
||||||
|
return base.multiply(r).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateRange parseDateRange(WorkbenchQueryDTO queryDTO) {
|
||||||
|
List<LocalDate> dr = queryDTO.getDateRange();
|
||||||
|
LocalDate start;
|
||||||
|
LocalDate end;
|
||||||
|
if (dr.size() == 1) {
|
||||||
|
start = dr.get(0);
|
||||||
|
end = start;
|
||||||
|
} else {
|
||||||
|
start = dr.get(0);
|
||||||
|
end = dr.get(1);
|
||||||
|
if (start.isAfter(end)) {
|
||||||
|
throw new BusinessException("开始日期不能晚于结束日期");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new DateRange(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateRange lastMonthSameSpan(DateRange range) {
|
||||||
|
return new DateRange(range.startDate().minusMonths(1), range.endDate().minusMonths(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BigDecimal toWan(BigDecimal yuan) {
|
||||||
|
if (yuan == null) {
|
||||||
|
return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
return yuan.divide(WAN, 2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatWan(BigDecimal yuan) {
|
||||||
|
return toWan(yuan).stripTrailingZeros().toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formatYuan(BigDecimal yuan) {
|
||||||
|
if (yuan == null) {
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
return yuan.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BigDecimal safePct(BigDecimal num, BigDecimal den) {
|
||||||
|
if (den == null || den.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
if (num == null) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
return num.multiply(new BigDecimal("100")).divide(den, 2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private record DateRange(LocalDate startDate, LocalDate endDate) {
|
||||||
|
LocalDateTime startDateTime() {
|
||||||
|
return startDate.atStartOfDay();
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalDateTime endDateTime() {
|
||||||
|
return endDate.atTime(23, 59, 59);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Totals(BigDecimal totalSales,
|
||||||
|
BigDecimal totalRefund,
|
||||||
|
BigDecimal totalCost,
|
||||||
|
BigDecimal productCost,
|
||||||
|
BigDecimal freightCost,
|
||||||
|
BigDecimal otherCost,
|
||||||
|
BigDecimal promotion,
|
||||||
|
BigDecimal brush,
|
||||||
|
BigDecimal tax,
|
||||||
|
BigDecimal grossOrder,
|
||||||
|
BigDecimal netProfit,
|
||||||
|
int orderCount,
|
||||||
|
BigDecimal averageOrderValue) {
|
||||||
|
BigDecimal netSalesBase() {
|
||||||
|
BigDecimal b = totalSales.subtract(totalRefund);
|
||||||
|
return b.max(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class Agg {
|
||||||
|
BigDecimal sales = BigDecimal.ZERO;
|
||||||
|
BigDecimal refund = BigDecimal.ZERO;
|
||||||
|
BigDecimal cost = BigDecimal.ZERO;
|
||||||
|
int orders;
|
||||||
|
|
||||||
|
void add(OrderPO o, OrderStatusStatSets stat) {
|
||||||
|
sales = sales.add(stat.receivedForSales(o));
|
||||||
|
refund = refund.add(stat.receivedForRefund(o));
|
||||||
|
cost = cost.add(stat.totalCostForStats(o));
|
||||||
|
if (stat.includesSales(o.getStatusId())) {
|
||||||
|
orders++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal netSalesBase() {
|
||||||
|
BigDecimal b = sales.subtract(refund);
|
||||||
|
return b.max(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -244,4 +244,12 @@ export namespace CompanyOverviewVO {
|
|||||||
/** 各品类汇总列表 */
|
/** 各品类汇总列表 */
|
||||||
categories: CategorySummary[];
|
categories: CategorySummary[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 工作台底部四张汇总表(与全店概览同源字段) */
|
||||||
|
export interface WorkbenchTableBundle {
|
||||||
|
shopTable?: ShopOverview | null;
|
||||||
|
platformTable?: PlatformOverview | null;
|
||||||
|
categoryTable?: CategoryOverview | null;
|
||||||
|
productTable?: CategoryOverview | null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import type { WorkbenchDTO, WorkbenchVO } from './types';
|
||||||
|
|
||||||
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
|
/** 工作台一次聚合:经营概览 + 多维 + 排行 */
|
||||||
|
export async function getWorkbenchSummaryApi(data: WorkbenchDTO.Query) {
|
||||||
|
return requestClient.post<WorkbenchVO.Info>('/ec/workbench/summary', data);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './apis';
|
||||||
|
export * from './types';
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './types.dto';
|
||||||
|
export * from './types.vo';
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* 工作台查询 DTO(与后端 WorkbenchQueryDTO 对齐)
|
||||||
|
*/
|
||||||
|
export namespace WorkbenchDTO {
|
||||||
|
export interface Query {
|
||||||
|
/** 日期范围 [开始, 结束],单元素表示当天 */
|
||||||
|
dateRange: string[];
|
||||||
|
/** 税率,默认 0.04 */
|
||||||
|
taxRate?: number;
|
||||||
|
/** 平台 ID,不传表示全平台 */
|
||||||
|
platformId?: number;
|
||||||
|
/** 店铺 ID,不传表示当前筛选下全部门店 */
|
||||||
|
shopId?: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
* 工作台聚合 VO(与后端 Workbench*VO 对齐)
|
||||||
|
*/
|
||||||
|
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview/types';
|
||||||
|
|
||||||
|
export namespace WorkbenchVO {
|
||||||
|
export interface DimRow {
|
||||||
|
key: string;
|
||||||
|
name: string;
|
||||||
|
gmvWan?: number;
|
||||||
|
grossProfitWan?: number;
|
||||||
|
netProfitWan?: number;
|
||||||
|
refundWan?: number;
|
||||||
|
grossMarginPct?: number;
|
||||||
|
netMarginPct?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface KpiItem {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
unit: string;
|
||||||
|
changePct?: number;
|
||||||
|
up?: boolean;
|
||||||
|
sub?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TrendPoint {
|
||||||
|
date: string;
|
||||||
|
gmv?: number;
|
||||||
|
profit?: number;
|
||||||
|
refund?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CostSlice {
|
||||||
|
name: string;
|
||||||
|
value?: number;
|
||||||
|
pct?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FinancePanel {
|
||||||
|
kpis: KpiItem[];
|
||||||
|
gmvTrend: TrendPoint[];
|
||||||
|
costStructure: CostSlice[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MultiPanel {
|
||||||
|
platform: DimRow[];
|
||||||
|
shop: DimRow[];
|
||||||
|
category: DimRow[];
|
||||||
|
product: DimRow[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Info {
|
||||||
|
finance: FinancePanel;
|
||||||
|
multiAnalysis: MultiPanel;
|
||||||
|
salesRank: MultiPanel;
|
||||||
|
/** 底部四表:与全店概览同源(税额、ROI、推广/刷单、目标等) */
|
||||||
|
summaryTables?: CompanyOverviewVO.WorkbenchTableBundle | null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,19 +5,36 @@ import { useRouter } from 'vue-router';
|
|||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import { createIconifyIcon } from '@vben/icons';
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { Button, DatePicker, InputNumber, Select, Tabs } from 'ant-design-vue';
|
import { Button, DatePicker, InputNumber, message, Select, Spin, Tabs } from 'ant-design-vue';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
|
import { getActivePlatformsApi } from '#/api/ecommerce/platform/apis';
|
||||||
|
import type { PlatformVO } from '#/api/ecommerce/platform/types';
|
||||||
|
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
|
||||||
|
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||||
|
import { getWorkbenchSummaryApi } from '#/api/ecommerce/workbench/apis';
|
||||||
|
import type { WorkbenchDTO, WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { normalizeOverviewRangePickerChange } from '#/utils/overview-date-range';
|
import { normalizeOverviewRangePickerChange } from '#/utils/overview-date-range';
|
||||||
|
|
||||||
import { PLATFORM_OPTIONS, STORES } from './data';
|
|
||||||
import WorkbenchFinanceTab from './tabs/finance/WorkbenchFinanceTab.vue';
|
import WorkbenchFinanceTab from './tabs/finance/WorkbenchFinanceTab.vue';
|
||||||
import WorkbenchMultiTab from './tabs/multi/WorkbenchMultiTab.vue';
|
import WorkbenchMultiTab from './tabs/multi/WorkbenchMultiTab.vue';
|
||||||
import WorkbenchSalesRankTab from './tabs/sales-rank/WorkbenchSalesRankTab.vue';
|
import WorkbenchSalesRankTab from './tabs/sales-rank/WorkbenchSalesRankTab.vue';
|
||||||
|
|
||||||
defineOptions({ name: 'PddWorkbench' });
|
defineOptions({ name: 'PddWorkbench' });
|
||||||
|
|
||||||
|
const EMPTY_WORKBENCH: WorkbenchVO.Info = {
|
||||||
|
finance: { kpis: [], gmvTrend: [], costStructure: [] },
|
||||||
|
multiAnalysis: {
|
||||||
|
platform: [],
|
||||||
|
shop: [],
|
||||||
|
category: [],
|
||||||
|
product: [],
|
||||||
|
},
|
||||||
|
salesRank: { platform: [], shop: [], category: [], product: [] },
|
||||||
|
summaryTables: null,
|
||||||
|
};
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const ImportOrderIcon = createIconifyIcon('lucide:upload');
|
const ImportOrderIcon = createIconifyIcon('lucide:upload');
|
||||||
@@ -26,7 +43,7 @@ function goToImportOrder() {
|
|||||||
void router.push('/import');
|
void router.push('/import');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 与全店概览右上角一致:快捷区间 + 自定义 RangePicker(演示页仅本地状态) */
|
/** 与全店概览一致:快捷区间 + 自定义 RangePicker */
|
||||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||||
dayjs().startOf('month'),
|
dayjs().startOf('month'),
|
||||||
dayjs(),
|
dayjs(),
|
||||||
@@ -95,7 +112,7 @@ const handleCustomDateRangeChange = (
|
|||||||
dateRange.value = dates;
|
dateRange.value = dates;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 税率(与全店/店铺概览共用 localStorage,便于切换页面时值一致) */
|
/** 税率(与全店/店铺概览共用 localStorage) */
|
||||||
const TAX_RATE_KEY = 'overview-tax-rate';
|
const TAX_RATE_KEY = 'overview-tax-rate';
|
||||||
const taxRate = ref<number>(0.04);
|
const taxRate = ref<number>(0.04);
|
||||||
taxRate.value = Number(localStorage.getItem(TAX_RATE_KEY)) || 0.04;
|
taxRate.value = Number(localStorage.getItem(TAX_RATE_KEY)) || 0.04;
|
||||||
@@ -116,20 +133,103 @@ const parseTaxRate = (value: string | undefined) => {
|
|||||||
return Number.isFinite(num) ? num / 100 : 0;
|
return Number.isFinite(num) ? num / 100 : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
const activeTab = ref('finance');
|
const platforms = ref<PlatformVO.Info[]>([]);
|
||||||
const selectedStoreIndex = ref(0);
|
const shops = ref<ShopVO.Info[]>([]);
|
||||||
const selectedPlatform = ref<string>('pdd');
|
const metaLoaded = ref(false);
|
||||||
|
|
||||||
const storeSelectOptions = computed(() =>
|
const selectedPlatformSlug = ref<string>('all');
|
||||||
STORES.map((s, i) => ({
|
const selectedShopSlug = ref<string>('all');
|
||||||
label: `${s.name}(${s.star})`,
|
|
||||||
value: i,
|
const filteredShops = computed(() => {
|
||||||
|
if (selectedPlatformSlug.value === 'all') {
|
||||||
|
return shops.value;
|
||||||
|
}
|
||||||
|
const pid = Number(selectedPlatformSlug.value);
|
||||||
|
return shops.value.filter((s) => s.platformId === pid);
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(filteredShops, (list) => {
|
||||||
|
if (selectedShopSlug.value === 'all') return;
|
||||||
|
const ok = list.some((s) => String(s.id) === selectedShopSlug.value);
|
||||||
|
if (!ok) selectedShopSlug.value = 'all';
|
||||||
|
});
|
||||||
|
|
||||||
|
const platformSelectOptions = computed(() => [
|
||||||
|
{ label: '全平台', value: 'all' },
|
||||||
|
...platforms.value.map((p) => ({
|
||||||
|
label: p.platformName,
|
||||||
|
value: String(p.id),
|
||||||
})),
|
})),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const shopSelectOptions = computed(() => [
|
||||||
|
{ label: '全部门店', value: 'all' },
|
||||||
|
...filteredShops.value.map((s) => ({
|
||||||
|
label: s.name,
|
||||||
|
value: String(s.id),
|
||||||
|
})),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const workbenchData = ref<WorkbenchVO.Info | null>(null);
|
||||||
|
const workbenchLoading = ref(false);
|
||||||
|
|
||||||
|
const financePanel = computed(
|
||||||
|
() => workbenchData.value?.finance ?? EMPTY_WORKBENCH.finance,
|
||||||
|
);
|
||||||
|
const multiPanel = computed(
|
||||||
|
() => workbenchData.value?.multiAnalysis ?? EMPTY_WORKBENCH.multiAnalysis,
|
||||||
|
);
|
||||||
|
const salesRankPanel = computed(
|
||||||
|
() => workbenchData.value?.salesRank ?? EMPTY_WORKBENCH.salesRank,
|
||||||
|
);
|
||||||
|
const summaryTablesPanel = computed(
|
||||||
|
() => workbenchData.value?.summaryTables ?? null,
|
||||||
);
|
);
|
||||||
|
|
||||||
const platformSelectOptions = computed(() =>
|
async function fetchWorkbenchSummary() {
|
||||||
PLATFORM_OPTIONS.map((o) => ({ label: o.label, value: o.value })),
|
if (!metaLoaded.value) return;
|
||||||
);
|
workbenchLoading.value = true;
|
||||||
|
try {
|
||||||
|
const query: WorkbenchDTO.Query = {
|
||||||
|
dateRange: [
|
||||||
|
dateRange.value[0].format('YYYY-MM-DD'),
|
||||||
|
dateRange.value[1].format('YYYY-MM-DD'),
|
||||||
|
],
|
||||||
|
taxRate: taxRate.value,
|
||||||
|
};
|
||||||
|
if (selectedPlatformSlug.value !== 'all') {
|
||||||
|
query.platformId = Number(selectedPlatformSlug.value);
|
||||||
|
}
|
||||||
|
if (selectedShopSlug.value !== 'all') {
|
||||||
|
query.shopId = Number(selectedShopSlug.value);
|
||||||
|
}
|
||||||
|
workbenchData.value = await getWorkbenchSummaryApi(query);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
const msg = e instanceof Error ? e.message : '工作台数据加载失败';
|
||||||
|
message.error(msg);
|
||||||
|
workbenchData.value = EMPTY_WORKBENCH;
|
||||||
|
} finally {
|
||||||
|
workbenchLoading.value = false;
|
||||||
|
await nextTick();
|
||||||
|
void redrawActiveTabCharts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadShopAndPlatformMeta() {
|
||||||
|
try {
|
||||||
|
const [platList, shopRes] = await Promise.all([
|
||||||
|
getActivePlatformsApi(),
|
||||||
|
getShopPageApi({ page: 1, pageSize: 500, filters: {} }),
|
||||||
|
]);
|
||||||
|
platforms.value = platList ?? [];
|
||||||
|
shops.value = shopRes?.records ?? [];
|
||||||
|
} catch {
|
||||||
|
message.error('店铺或平台列表加载失败');
|
||||||
|
}
|
||||||
|
metaLoaded.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeTab = ref('finance');
|
||||||
|
|
||||||
const financeTabRef = ref<InstanceType<typeof WorkbenchFinanceTab> | null>(
|
const financeTabRef = ref<InstanceType<typeof WorkbenchFinanceTab> | null>(
|
||||||
null,
|
null,
|
||||||
@@ -164,9 +264,19 @@ watch(activeTab, () => {
|
|||||||
}, 80);
|
}, 80);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
[() => dateRange.value, taxRate, selectedPlatformSlug, selectedShopSlug],
|
||||||
|
() => {
|
||||||
|
void fetchWorkbenchSummary();
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
|
|
||||||
let darkObserver: MutationObserver | null = null;
|
let darkObserver: MutationObserver | null = null;
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
|
await loadShopAndPlatformMeta();
|
||||||
|
await fetchWorkbenchSummary();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
void redrawActiveTabCharts();
|
void redrawActiveTabCharts();
|
||||||
}, 120);
|
}, 120);
|
||||||
@@ -202,7 +312,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
<template #description>
|
<template #description>
|
||||||
<span class="text-sm text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
<span class="text-sm text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
多店铺 · 多维度经营数据(演示数据,接口就绪后可替换)
|
数据来自接口 POST /ec/workbench/summary,统计口径与「全店概览」一致(订单列表内存聚合)
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -234,7 +344,7 @@ onUnmounted(() => {
|
|||||||
平台
|
平台
|
||||||
</span>
|
</span>
|
||||||
<Select
|
<Select
|
||||||
v-model:value="selectedPlatform"
|
v-model:value="selectedPlatformSlug"
|
||||||
size="small"
|
size="small"
|
||||||
:options="platformSelectOptions"
|
:options="platformSelectOptions"
|
||||||
placeholder="选择平台"
|
placeholder="选择平台"
|
||||||
@@ -250,9 +360,9 @@ onUnmounted(() => {
|
|||||||
店铺
|
店铺
|
||||||
</span>
|
</span>
|
||||||
<Select
|
<Select
|
||||||
v-model:value="selectedStoreIndex"
|
v-model:value="selectedShopSlug"
|
||||||
size="small"
|
size="small"
|
||||||
:options="storeSelectOptions"
|
:options="shopSelectOptions"
|
||||||
placeholder="选择店铺"
|
placeholder="选择店铺"
|
||||||
class="workbench-header-select min-w-0 flex-1"
|
class="workbench-header-select min-w-0 flex-1"
|
||||||
/>
|
/>
|
||||||
@@ -374,17 +484,31 @@ onUnmounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="workbench-page-body min-w-0">
|
<div class="workbench-page-body min-w-0">
|
||||||
<Tabs v-model:active-key="activeTab" class="workbench-tabs">
|
<Spin :spinning="workbenchLoading">
|
||||||
<Tabs.TabPane key="finance" tab="经营概览">
|
<Tabs v-model:active-key="activeTab" class="workbench-tabs">
|
||||||
<WorkbenchFinanceTab ref="financeTabRef" :tax-rate="taxRate" />
|
<Tabs.TabPane key="finance" tab="经营概览">
|
||||||
</Tabs.TabPane>
|
<WorkbenchFinanceTab
|
||||||
<Tabs.TabPane key="multi" tab="多维分析">
|
ref="financeTabRef"
|
||||||
<WorkbenchMultiTab ref="multiTabRef" />
|
:tax-rate="taxRate"
|
||||||
</Tabs.TabPane>
|
:finance="financePanel"
|
||||||
<Tabs.TabPane key="salesRank" tab="销售额排行榜">
|
:multi-analysis="multiPanel"
|
||||||
<WorkbenchSalesRankTab ref="salesRankTabRef" />
|
:summary-tables="summaryTablesPanel"
|
||||||
</Tabs.TabPane>
|
/>
|
||||||
</Tabs>
|
</Tabs.TabPane>
|
||||||
|
<Tabs.TabPane key="multi" tab="多维分析">
|
||||||
|
<WorkbenchMultiTab
|
||||||
|
ref="multiTabRef"
|
||||||
|
:multi-analysis="multiPanel"
|
||||||
|
/>
|
||||||
|
</Tabs.TabPane>
|
||||||
|
<Tabs.TabPane key="salesRank" tab="销售额排行榜">
|
||||||
|
<WorkbenchSalesRankTab
|
||||||
|
ref="salesRankTabRef"
|
||||||
|
:sales-rank="salesRankPanel"
|
||||||
|
/>
|
||||||
|
</Tabs.TabPane>
|
||||||
|
</Tabs>
|
||||||
|
</Spin>
|
||||||
</div>
|
</div>
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
+51
-6
@@ -1,17 +1,50 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { nextTick, ref } from 'vue';
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
||||||
|
|
||||||
|
import { computed, nextTick, ref } from 'vue';
|
||||||
|
|
||||||
import WorkbenchFinanceCostPieChart from './components/WorkbenchFinanceCostPieChart.vue';
|
import WorkbenchFinanceCostPieChart from './components/WorkbenchFinanceCostPieChart.vue';
|
||||||
import WorkbenchFinanceKpiGrid from './components/WorkbenchFinanceKpiGrid.vue';
|
import WorkbenchFinanceKpiGrid from './components/WorkbenchFinanceKpiGrid.vue';
|
||||||
import WorkbenchFinanceTrendChart from './components/WorkbenchFinanceTrendChart.vue';
|
import WorkbenchFinanceTrendChart from './components/WorkbenchFinanceTrendChart.vue';
|
||||||
import WorkbenchOverviewTables from './components/WorkbenchOverviewTables.vue';
|
import WorkbenchOverviewTables from './components/WorkbenchOverviewTables.vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
buildCategoryOverviewFromDimRows,
|
||||||
|
buildPlatformOverviewFromDimRows,
|
||||||
|
buildShopOverviewFromDimRows,
|
||||||
|
} from '../../workbench-overview-bridge';
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchFinanceTab' });
|
defineOptions({ name: 'WorkbenchFinanceTab' });
|
||||||
|
|
||||||
defineProps<{
|
const props = defineProps<{
|
||||||
taxRate: number;
|
taxRate: number;
|
||||||
|
finance: WorkbenchVO.FinancePanel;
|
||||||
|
multiAnalysis: WorkbenchVO.MultiPanel;
|
||||||
|
summaryTables?: CompanyOverviewVO.WorkbenchTableBundle | null;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const shopOverview = computed(
|
||||||
|
() =>
|
||||||
|
props.summaryTables?.shopTable ??
|
||||||
|
buildShopOverviewFromDimRows(props.multiAnalysis.shop),
|
||||||
|
);
|
||||||
|
const platformOverview = computed(
|
||||||
|
() =>
|
||||||
|
props.summaryTables?.platformTable ??
|
||||||
|
buildPlatformOverviewFromDimRows(props.multiAnalysis.platform),
|
||||||
|
);
|
||||||
|
const categoryOverview = computed(
|
||||||
|
() =>
|
||||||
|
props.summaryTables?.categoryTable ??
|
||||||
|
buildCategoryOverviewFromDimRows(props.multiAnalysis.category),
|
||||||
|
);
|
||||||
|
const productOverview = computed(
|
||||||
|
() =>
|
||||||
|
props.summaryTables?.productTable ??
|
||||||
|
buildCategoryOverviewFromDimRows(props.multiAnalysis.product),
|
||||||
|
);
|
||||||
|
|
||||||
const trendChartRef = ref<InstanceType<
|
const trendChartRef = ref<InstanceType<
|
||||||
typeof WorkbenchFinanceTrendChart
|
typeof WorkbenchFinanceTrendChart
|
||||||
> | null>(null);
|
> | null>(null);
|
||||||
@@ -30,11 +63,23 @@ defineExpose({ redraw });
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="mt-4 space-y-6">
|
<div class="mt-4 space-y-6">
|
||||||
<WorkbenchFinanceKpiGrid />
|
<WorkbenchFinanceKpiGrid :kpis="finance.kpis" />
|
||||||
<div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
|
<div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
|
||||||
<WorkbenchFinanceTrendChart ref="trendChartRef" />
|
<WorkbenchFinanceTrendChart
|
||||||
<WorkbenchFinanceCostPieChart ref="costPieRef" />
|
ref="trendChartRef"
|
||||||
|
:trend="finance.gmvTrend"
|
||||||
|
/>
|
||||||
|
<WorkbenchFinanceCostPieChart
|
||||||
|
ref="costPieRef"
|
||||||
|
:cost-structure="finance.costStructure"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<WorkbenchOverviewTables :tax-rate="taxRate" />
|
<WorkbenchOverviewTables
|
||||||
|
:tax-rate="taxRate"
|
||||||
|
:shop-summary="shopOverview"
|
||||||
|
:platform-summary="platformOverview"
|
||||||
|
:category-summary="categoryOverview"
|
||||||
|
:product-summary="productOverview"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
+36
-12
@@ -1,19 +1,34 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||||
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||||
|
|
||||||
import { COST_STRUCTURE, COST_STRUCTURE_PIE_COLORS } from '../../../data';
|
import { COST_STRUCTURE_PIE_COLORS } from '../../../data';
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchFinanceCostPieChart' });
|
defineOptions({ name: 'WorkbenchFinanceCostPieChart' });
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
costStructure: WorkbenchVO.CostSlice[];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const SLICE_COLOR_BY_NAME: Record<string, string> = {
|
||||||
|
商品成本: COST_STRUCTURE_PIE_COLORS[1] ?? '#f97316',
|
||||||
|
物流费用: COST_STRUCTURE_PIE_COLORS[4] ?? '#fb923c',
|
||||||
|
其他成本: COST_STRUCTURE_PIE_COLORS[5] ?? '#fdba74',
|
||||||
|
推广费: COST_STRUCTURE_PIE_COLORS[2] ?? '#ea580c',
|
||||||
|
刷单费: COST_STRUCTURE_PIE_COLORS[3] ?? '#f43f5e',
|
||||||
|
税费: COST_STRUCTURE_PIE_COLORS[5] ?? '#94a3b8',
|
||||||
|
净利润: COST_STRUCTURE_PIE_COLORS[0] ?? '#059669',
|
||||||
|
};
|
||||||
|
|
||||||
const chartOverviewShell =
|
const chartOverviewShell =
|
||||||
'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]';
|
'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]';
|
||||||
|
|
||||||
const costTotal = computed(() =>
|
const costTotal = computed(() =>
|
||||||
COST_STRUCTURE.reduce((a, x) => a + x.value, 0),
|
props.costStructure.reduce((a, x) => a + (Number(x.value) || 0), 0),
|
||||||
);
|
);
|
||||||
|
|
||||||
const costPieChartRef = ref<EchartsUIType>();
|
const costPieChartRef = ref<EchartsUIType>();
|
||||||
@@ -34,10 +49,8 @@ function drawCostPie() {
|
|||||||
formatter: (params: any) => {
|
formatter: (params: any) => {
|
||||||
const name = String(params.name ?? '');
|
const name = String(params.name ?? '');
|
||||||
const val = Number(params.value ?? 0);
|
const val = Number(params.value ?? 0);
|
||||||
const row = COST_STRUCTURE.find((r) => r.name === name);
|
const row = props.costStructure.find((r) => r.name === name);
|
||||||
const pctText = row
|
const pctText = row?.pct != null ? `${row.pct}%(占销售额)` : '';
|
||||||
? `${row.pct}%(占实收)`
|
|
||||||
: `${Number(params.percent ?? 0).toFixed(1)}%`;
|
|
||||||
return `${name}<br/>${val} 万<br/>${pctText}`;
|
return `${name}<br/>${val} 万<br/>${pctText}`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -72,11 +85,14 @@ function drawCostPie() {
|
|||||||
length2: 8,
|
length2: 8,
|
||||||
lineStyle: { color: isDark ? 'hsl(240deg 3.7% 35%)' : '#cbd5e1' },
|
lineStyle: { color: isDark ? 'hsl(240deg 3.7% 35%)' : '#cbd5e1' },
|
||||||
},
|
},
|
||||||
data: COST_STRUCTURE.map((row, i) => ({
|
data: props.costStructure.map((row, i) => ({
|
||||||
name: row.name,
|
name: row.name,
|
||||||
value: row.value,
|
value: row.value ?? 0,
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: COST_STRUCTURE_PIE_COLORS[i] ?? '#6366f1',
|
color:
|
||||||
|
SLICE_COLOR_BY_NAME[row.name] ??
|
||||||
|
COST_STRUCTURE_PIE_COLORS[i] ??
|
||||||
|
'#6366f1',
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
@@ -93,6 +109,14 @@ onMounted(() => {
|
|||||||
void redraw();
|
void redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.costStructure,
|
||||||
|
() => {
|
||||||
|
void redraw();
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
|
|
||||||
defineExpose({ redraw });
|
defineExpose({ redraw });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -104,13 +128,13 @@ defineExpose({ redraw });
|
|||||||
<h3
|
<h3
|
||||||
class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||||
>
|
>
|
||||||
成本结构拆解(占实收比例示意)
|
成本结构(占销售额 %)
|
||||||
</h3>
|
</h3>
|
||||||
<p
|
<p
|
||||||
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
合计约 {{ costTotal.toFixed(1) }} 万 ·
|
合计约 {{ costTotal.toFixed(1) }} 万 ·
|
||||||
扇区按金额(万)占比;悬浮可见占实收比例
|
扇区金额单位:万元;悬浮可见占销售额比例
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-6 py-5 md:px-8 md:py-6">
|
<div class="px-6 py-5 md:px-8 md:py-6">
|
||||||
|
|||||||
+14
-4
@@ -1,15 +1,25 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { FINANCE_KPIS } from '../../../data';
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchFinanceKpiGrid' });
|
defineOptions({ name: 'WorkbenchFinanceKpiGrid' });
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
kpis: WorkbenchVO.KpiItem[];
|
||||||
|
}>();
|
||||||
|
|
||||||
const kpiCardClass =
|
const kpiCardClass =
|
||||||
'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%)] p-5 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px] sm:p-6';
|
'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%)] p-5 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px] sm:p-6';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
<div
|
||||||
<div v-for="(kpi, idx) in FINANCE_KPIS" :key="idx" :class="kpiCardClass">
|
v-if="kpis.length === 0"
|
||||||
|
class="rounded-2xl border border-dashed border-slate-200 bg-white/60 px-6 py-10 text-center text-sm font-bold text-slate-400 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
|
>
|
||||||
|
暂无 KPI 数据(请调整筛选或日期范围)
|
||||||
|
</div>
|
||||||
|
<div v-else class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||||
|
<div v-for="(kpi, idx) in kpis" :key="idx" :class="kpiCardClass">
|
||||||
<div class="mb-3 flex items-start justify-between gap-2">
|
<div class="mb-3 flex items-start justify-between gap-2">
|
||||||
<span
|
<span
|
||||||
class="text-xs font-black text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="text-xs font-black text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
@@ -24,7 +34,7 @@ const kpiCardClass =
|
|||||||
: 'bg-red-50 text-red-600 dark:bg-red-900/25 dark:text-red-400'
|
: 'bg-red-50 text-red-600 dark:bg-red-900/25 dark:text-red-400'
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
{{ kpi.up ? '▲' : '▼' }}{{ kpi.changePct
|
{{ kpi.up ? '▲' : '▼' }}{{ kpi.changePct ?? 0
|
||||||
}}{{ kpi.label === '广告ROI' ? '' : '%' }}
|
}}{{ kpi.label === '广告ROI' ? '' : '%' }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+22
-11
@@ -1,14 +1,17 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||||
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
import { nextTick, onMounted, ref } from 'vue';
|
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||||
|
|
||||||
import { GMV_TREND } from '../../../data';
|
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchFinanceTrendChart' });
|
defineOptions({ name: 'WorkbenchFinanceTrendChart' });
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
trend: WorkbenchVO.TrendPoint[];
|
||||||
|
}>();
|
||||||
|
|
||||||
const chartOverviewShell =
|
const chartOverviewShell =
|
||||||
'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]';
|
'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]';
|
||||||
|
|
||||||
@@ -30,7 +33,7 @@ function drawFinanceTrend() {
|
|||||||
legend: {
|
legend: {
|
||||||
top: 0,
|
top: 0,
|
||||||
textStyle: { color: axisLabel, fontWeight: 700 },
|
textStyle: { color: axisLabel, fontWeight: 700 },
|
||||||
data: ['GMV(万)', '净利润(万)', '退款(万)'],
|
data: ['GMV(万)', '毛利(万)', '退款(万)'],
|
||||||
},
|
},
|
||||||
grid: {
|
grid: {
|
||||||
left: '3%',
|
left: '3%',
|
||||||
@@ -41,7 +44,7 @@ function drawFinanceTrend() {
|
|||||||
},
|
},
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'category',
|
type: 'category',
|
||||||
data: GMV_TREND.map((d) => d.date),
|
data: props.trend.map((d) => d.date),
|
||||||
axisLine: { lineStyle: { color: split } },
|
axisLine: { lineStyle: { color: split } },
|
||||||
axisLabel: { color: axisLabel, fontSize: 11 },
|
axisLabel: { color: axisLabel, fontSize: 11 },
|
||||||
},
|
},
|
||||||
@@ -54,7 +57,7 @@ function drawFinanceTrend() {
|
|||||||
{
|
{
|
||||||
name: 'GMV(万)',
|
name: 'GMV(万)',
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: GMV_TREND.map((d) => d.gmv),
|
data: props.trend.map((d) => d.gmv ?? 0),
|
||||||
barMaxWidth: 14,
|
barMaxWidth: 14,
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: {
|
color: {
|
||||||
@@ -76,18 +79,18 @@ function drawFinanceTrend() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '净利润(万)',
|
name: '毛利(万)',
|
||||||
type: 'line',
|
type: 'line',
|
||||||
smooth: true,
|
smooth: true,
|
||||||
symbolSize: 6,
|
symbolSize: 6,
|
||||||
data: GMV_TREND.map((d) => d.profit),
|
data: props.trend.map((d) => d.profit ?? 0),
|
||||||
lineStyle: { width: 2.5, color: isDark ? '#34d399' : '#059669' },
|
lineStyle: { width: 2.5, color: isDark ? '#34d399' : '#059669' },
|
||||||
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '退款(万)',
|
name: '退款(万)',
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: GMV_TREND.map((d) => d.refund),
|
data: props.trend.map((d) => d.refund ?? 0),
|
||||||
barMaxWidth: 8,
|
barMaxWidth: 8,
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: isDark
|
color: isDark
|
||||||
@@ -108,6 +111,14 @@ onMounted(() => {
|
|||||||
void redraw();
|
void redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.trend,
|
||||||
|
() => {
|
||||||
|
void redraw();
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
|
|
||||||
defineExpose({ redraw });
|
defineExpose({ redraw });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -119,12 +130,12 @@ defineExpose({ redraw });
|
|||||||
<h3
|
<h3
|
||||||
class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||||
>
|
>
|
||||||
GMV 与净利润趋势
|
GMV 与毛利趋势
|
||||||
</h3>
|
</h3>
|
||||||
<p
|
<p
|
||||||
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
柱=GMV,线=净利润,浅柱=退款(示例区间)
|
柱=GMV,线=日毛利(销售额−成本−退款),浅柱=退款;与全店概览订单口径一致
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-6 py-5 md:px-8 md:py-6">
|
<div class="px-6 py-5 md:px-8 md:py-6">
|
||||||
|
|||||||
+28
-29
@@ -2,30 +2,30 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
||||||
|
|
||||||
import { message, Segmented } from 'ant-design-vue';
|
import { message, Segmented } from 'ant-design-vue';
|
||||||
|
|
||||||
import CategoryComparisonTable from '../../../../store-overview/components/CategoryComparisonTable.vue';
|
import CategoryComparisonTable from '../../../../store-overview/components/CategoryComparisonTable.vue';
|
||||||
import PlatformSummaryCard from '../../../../store-overview/components/PlatformSummaryCard.vue';
|
import PlatformSummaryCard from '../../../../store-overview/components/PlatformSummaryCard.vue';
|
||||||
import ShopComparisonTable from '../../../../store-overview/components/ShopComparisonTable.vue';
|
import ShopComparisonTable from '../../../../store-overview/components/ShopComparisonTable.vue';
|
||||||
import {
|
|
||||||
getWorkbenchCategoryOverview,
|
|
||||||
getWorkbenchPlatformOverview,
|
|
||||||
getWorkbenchProductAsCategoryOverview,
|
|
||||||
getWorkbenchShopOverview,
|
|
||||||
} from '../../../overview-mock';
|
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchOverviewTables' });
|
defineOptions({ name: 'WorkbenchOverviewTables' });
|
||||||
|
|
||||||
withDefaults(defineProps<{ taxRate?: number }>(), {
|
withDefaults(
|
||||||
taxRate: 0.04,
|
defineProps<{
|
||||||
});
|
taxRate?: number;
|
||||||
|
shopSummary?: CompanyOverviewVO.ShopOverview | null;
|
||||||
|
platformSummary?: CompanyOverviewVO.PlatformOverview | null;
|
||||||
|
categorySummary?: CompanyOverviewVO.CategoryOverview | null;
|
||||||
|
productSummary?: CompanyOverviewVO.CategoryOverview | null;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
taxRate: 0.04,
|
||||||
|
},
|
||||||
|
);
|
||||||
const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop');
|
const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop');
|
||||||
|
|
||||||
const shopOverview = getWorkbenchShopOverview();
|
|
||||||
const platformOverview = getWorkbenchPlatformOverview();
|
|
||||||
const categoryOverview = getWorkbenchCategoryOverview();
|
|
||||||
const productOverview = getWorkbenchProductAsCategoryOverview();
|
|
||||||
|
|
||||||
const shopExportMode = ref(false);
|
const shopExportMode = ref(false);
|
||||||
const selectedExportShopIds = ref<number[]>([]);
|
const selectedExportShopIds = ref<number[]>([]);
|
||||||
const platformExportMode = ref(false);
|
const platformExportMode = ref(false);
|
||||||
@@ -45,7 +45,7 @@ const modeOptions = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function demoExportHint() {
|
function demoExportHint() {
|
||||||
message.warning('工作台为静态演示,导出请使用「全店概览」页面');
|
message.warning('工作台明细与全店概览同源;批量导出请使用「全店概览」页面');
|
||||||
}
|
}
|
||||||
|
|
||||||
function navigateToShopOverview(shopId: number) {
|
function navigateToShopOverview(shopId: number) {
|
||||||
@@ -60,8 +60,7 @@ function navigateToShopOverview(shopId: number) {
|
|||||||
<p
|
<p
|
||||||
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
下列表格与「全店概览」使用相同组件与列结构(演示数据,可替换为接口返回的
|
下列表格与「全店概览」使用相同组件;四表数据由工作台接口按订单、推广费、刷单与店铺月度目标等口径汇总(与全店概览后端计算一致)。若接口未返回汇总表字段,则回退为按维度行估算(部分列为「-」)。
|
||||||
VO)。
|
|
||||||
</p>
|
</p>
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<Segmented
|
<Segmented
|
||||||
@@ -73,9 +72,9 @@ function navigateToShopOverview(shopId: number) {
|
|||||||
|
|
||||||
<ShopComparisonTable
|
<ShopComparisonTable
|
||||||
v-if="activeMode === 'shop'"
|
v-if="activeMode === 'shop'"
|
||||||
heading-title="各店铺多维度经营明细汇总(演示)"
|
heading-title="各店铺多维度经营明细汇总"
|
||||||
heading-subtitle="与「全店概览」同款表格;对接接口后可替换为实时数据"
|
heading-subtitle="与全店概览同款表格;金额与目标等为后端汇总口径(元)"
|
||||||
:shop-summary="shopOverview"
|
:shop-summary="shopSummary ?? undefined"
|
||||||
:tax-rate="taxRate"
|
:tax-rate="taxRate"
|
||||||
:shop-export-mode="shopExportMode"
|
:shop-export-mode="shopExportMode"
|
||||||
:selected-export-shop-ids="selectedExportShopIds"
|
:selected-export-shop-ids="selectedExportShopIds"
|
||||||
@@ -87,9 +86,9 @@ function navigateToShopOverview(shopId: number) {
|
|||||||
|
|
||||||
<PlatformSummaryCard
|
<PlatformSummaryCard
|
||||||
v-if="activeMode === 'platform'"
|
v-if="activeMode === 'platform'"
|
||||||
heading-title="各平台多维度经营明细汇总(演示)"
|
heading-title="各平台多维度经营明细汇总"
|
||||||
heading-subtitle="与「全店概览」同款表格;对接接口后可替换为实时数据"
|
heading-subtitle="与全店概览同款表格"
|
||||||
:platform-summary="platformOverview"
|
:platform-summary="platformSummary ?? undefined"
|
||||||
:tax-rate="taxRate"
|
:tax-rate="taxRate"
|
||||||
:platform-export-mode="platformExportMode"
|
:platform-export-mode="platformExportMode"
|
||||||
:selected-export-platform-ids="selectedExportPlatformIds"
|
:selected-export-platform-ids="selectedExportPlatformIds"
|
||||||
@@ -100,9 +99,9 @@ function navigateToShopOverview(shopId: number) {
|
|||||||
|
|
||||||
<CategoryComparisonTable
|
<CategoryComparisonTable
|
||||||
v-if="activeMode === 'category'"
|
v-if="activeMode === 'category'"
|
||||||
heading-title="各品类多维度经营明细汇总(演示)"
|
heading-title="各品类多维度经营明细汇总"
|
||||||
heading-subtitle="与「全店概览」同款表格;对接接口后可替换为实时数据"
|
heading-subtitle="与全店概览同款表格"
|
||||||
:category-summary="categoryOverview"
|
:category-summary="categorySummary ?? undefined"
|
||||||
:tax-rate="taxRate"
|
:tax-rate="taxRate"
|
||||||
:category-export-mode="categoryExportMode"
|
:category-export-mode="categoryExportMode"
|
||||||
:selected-export-category-ids="selectedExportCategoryIds"
|
:selected-export-category-ids="selectedExportCategoryIds"
|
||||||
@@ -113,10 +112,10 @@ function navigateToShopOverview(shopId: number) {
|
|||||||
|
|
||||||
<CategoryComparisonTable
|
<CategoryComparisonTable
|
||||||
v-if="activeMode === 'product'"
|
v-if="activeMode === 'product'"
|
||||||
heading-title="各商品多维度经营明细汇总(演示)"
|
heading-title="各商品多维度经营明细汇总"
|
||||||
heading-subtitle="列结构与品类表一致,首列为商品名称;对接接口后可替换为实时数据"
|
heading-subtitle="列结构与品类表一致;数据与全店概览商品维度同源"
|
||||||
first-column-label="商品"
|
first-column-label="商品"
|
||||||
:category-summary="productOverview"
|
:category-summary="productSummary ?? undefined"
|
||||||
:tax-rate="taxRate"
|
:tax-rate="taxRate"
|
||||||
:category-export-mode="productExportMode"
|
:category-export-mode="productExportMode"
|
||||||
:selected-export-category-ids="selectedExportProductIds"
|
:selected-export-category-ids="selectedExportProductIds"
|
||||||
|
|||||||
+12
-2
@@ -1,10 +1,16 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
import { nextTick, ref } from 'vue';
|
import { nextTick, ref } from 'vue';
|
||||||
|
|
||||||
import WorkbenchMultiDimCardsGrid from './components/WorkbenchMultiDimCardsGrid.vue';
|
import WorkbenchMultiDimCardsGrid from './components/WorkbenchMultiDimCardsGrid.vue';
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchMultiTab' });
|
defineOptions({ name: 'WorkbenchMultiTab' });
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
multiAnalysis: WorkbenchVO.MultiPanel;
|
||||||
|
}>();
|
||||||
|
|
||||||
const gridRef = ref<InstanceType<typeof WorkbenchMultiDimCardsGrid> | null>(
|
const gridRef = ref<InstanceType<typeof WorkbenchMultiDimCardsGrid> | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
@@ -22,8 +28,12 @@ defineExpose({ redraw });
|
|||||||
<p
|
<p
|
||||||
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
按平台、店铺、品类、商品各一张卡,分别对比销售额、毛利额、净利额、退款及毛利率/净利率(演示数据)
|
按平台、店铺、品类、商品各一张卡;数据与全店概览订单统计口径一致
|
||||||
</p>
|
</p>
|
||||||
<WorkbenchMultiDimCardsGrid ref="gridRef" />
|
<WorkbenchMultiDimCardsGrid
|
||||||
|
ref="gridRef"
|
||||||
|
:multi-analysis="multiAnalysis"
|
||||||
|
live-data
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
+43
-17
@@ -2,8 +2,9 @@
|
|||||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||||
|
|
||||||
import type { WorkbenchDimKey } from '../../../data';
|
import type { WorkbenchDimKey } from '../../../data';
|
||||||
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||||
|
|
||||||
@@ -15,6 +16,10 @@ const props = defineProps<{
|
|||||||
dimension: WorkbenchDimKey;
|
dimension: WorkbenchDimKey;
|
||||||
title: string;
|
title: string;
|
||||||
variant: 'analysis' | 'rank';
|
variant: 'analysis' | 'rank';
|
||||||
|
/** 接口维度行;未传时使用本地演示数据 */
|
||||||
|
rows?: WorkbenchVO.DimRow[];
|
||||||
|
/** 为 true 时排行图不展示演示环比 */
|
||||||
|
liveData?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
/** 多维分析:不在卡片上 overflow-hidden,避免底部 X 轴类目名被裁掉 */
|
/** 多维分析:不在卡片上 overflow-hidden,避免底部 X 轴类目名被裁掉 */
|
||||||
@@ -38,21 +43,29 @@ function multiChartGridBottomPx(
|
|||||||
return 44;
|
return 44;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rows = computed(() => WORKBENCH_MULTI_BY_DIM[props.dimension]);
|
const rows = computed(() =>
|
||||||
|
props.rows !== undefined
|
||||||
|
? props.rows
|
||||||
|
: WORKBENCH_MULTI_BY_DIM[props.dimension],
|
||||||
|
);
|
||||||
|
|
||||||
const rankMomDemo = [16.2, 11.4, 8.8, -2.1, 6.5, 4.2, 3.8, 2.4];
|
const rankMomDemo = [16.2, 11.4, 8.8, -2.1, 6.5, 4.2, 3.8, 2.4];
|
||||||
|
|
||||||
const rankRows = computed(() => {
|
const rankRows = computed(() => {
|
||||||
const raw = [...rows.value];
|
const raw = [...rows.value];
|
||||||
const sorted = raw.sort((a, b) => b.gmvWan - a.gmvWan);
|
const sorted = raw.sort(
|
||||||
const total = sorted.reduce((s, r) => s + r.gmvWan, 0) || 1;
|
(a, b) => Number(b.gmvWan ?? 0) - Number(a.gmvWan ?? 0),
|
||||||
|
);
|
||||||
|
const total = sorted.reduce((s, r) => s + Number(r.gmvWan ?? 0), 0) || 1;
|
||||||
return sorted.map((r, i) => ({
|
return sorted.map((r, i) => ({
|
||||||
rank: i + 1,
|
rank: i + 1,
|
||||||
key: r.key,
|
key: r.key,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
gmvWan: r.gmvWan,
|
gmvWan: Number(r.gmvWan ?? 0),
|
||||||
sharePct: Number(((r.gmvWan / total) * 100).toFixed(1)),
|
sharePct: Number(((Number(r.gmvWan ?? 0) / total) * 100).toFixed(1)),
|
||||||
momPct: rankMomDemo[i % rankMomDemo.length] ?? 0,
|
momPct: props.liveData
|
||||||
|
? 0
|
||||||
|
: (rankMomDemo[i % rankMomDemo.length] ?? 0),
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -123,28 +136,28 @@ const drawMultiBarChart = () => {
|
|||||||
{
|
{
|
||||||
name: '销售额(万)',
|
name: '销售额(万)',
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: r.map((row) => row.gmvWan),
|
data: r.map((row) => Number(row.gmvWan ?? 0)),
|
||||||
barMaxWidth: 16,
|
barMaxWidth: 16,
|
||||||
itemStyle: { color: isDark ? '#60a5fa' : '#2563eb' },
|
itemStyle: { color: isDark ? '#60a5fa' : '#2563eb' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '毛利额(万)',
|
name: '毛利额(万)',
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: r.map((row) => row.grossProfitWan),
|
data: r.map((row) => Number(row.grossProfitWan ?? 0)),
|
||||||
barMaxWidth: 16,
|
barMaxWidth: 16,
|
||||||
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '净利额(万)',
|
name: '净利额(万)',
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: r.map((row) => row.netProfitWan),
|
data: r.map((row) => Number(row.netProfitWan ?? 0)),
|
||||||
barMaxWidth: 16,
|
barMaxWidth: 16,
|
||||||
itemStyle: { color: isDark ? '#a78bfa' : '#7c3aed' },
|
itemStyle: { color: isDark ? '#a78bfa' : '#7c3aed' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '退款金额(万)',
|
name: '退款金额(万)',
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: r.map((row) => row.refundWan),
|
data: r.map((row) => Number(row.refundWan ?? 0)),
|
||||||
barMaxWidth: 16,
|
barMaxWidth: 16,
|
||||||
itemStyle: { color: isDark ? '#fb7185' : '#e11d48' },
|
itemStyle: { color: isDark ? '#fb7185' : '#e11d48' },
|
||||||
},
|
},
|
||||||
@@ -209,7 +222,7 @@ const drawMultiLineChart = () => {
|
|||||||
type: 'line',
|
type: 'line',
|
||||||
smooth: true,
|
smooth: true,
|
||||||
symbolSize: 6,
|
symbolSize: 6,
|
||||||
data: r.map((row) => row.grossMarginPct),
|
data: r.map((row) => Number(row.grossMarginPct ?? 0)),
|
||||||
lineStyle: { width: 2.5, color: isDark ? '#34d399' : '#059669' },
|
lineStyle: { width: 2.5, color: isDark ? '#34d399' : '#059669' },
|
||||||
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
||||||
},
|
},
|
||||||
@@ -218,7 +231,7 @@ const drawMultiLineChart = () => {
|
|||||||
type: 'line',
|
type: 'line',
|
||||||
smooth: true,
|
smooth: true,
|
||||||
symbolSize: 6,
|
symbolSize: 6,
|
||||||
data: r.map((row) => row.netMarginPct),
|
data: r.map((row) => Number(row.netMarginPct ?? 0)),
|
||||||
lineStyle: { width: 2.5, color: isDark ? '#fbbf24' : '#d97706' },
|
lineStyle: { width: 2.5, color: isDark ? '#fbbf24' : '#d97706' },
|
||||||
itemStyle: { color: isDark ? '#fbbf24' : '#d97706' },
|
itemStyle: { color: isDark ? '#fbbf24' : '#d97706' },
|
||||||
},
|
},
|
||||||
@@ -255,7 +268,10 @@ const drawRankBarChart = () => {
|
|||||||
if (!row) return '';
|
if (!row) return '';
|
||||||
const mom =
|
const mom =
|
||||||
row.momPct >= 0 ? `▲${row.momPct}` : `▼${Math.abs(row.momPct)}`;
|
row.momPct >= 0 ? `▲${row.momPct}` : `▼${Math.abs(row.momPct)}`;
|
||||||
return `${row.name}<br/>${p?.marker ?? ''} 销售额 <b>${row.gmvWan}</b> 万<br/>占合计 <b>${row.sharePct}%</b><br/>环比 <b>${mom}%</b>`;
|
const momLine = props.liveData
|
||||||
|
? ''
|
||||||
|
: `<br/>环比 <b>${mom}%</b>(演示)`;
|
||||||
|
return `${row.name}<br/>${p?.marker ?? ''} 销售额 <b>${row.gmvWan}</b> 万<br/>占合计 <b>${row.sharePct}%</b>${momLine}`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
grid: {
|
grid: {
|
||||||
@@ -284,7 +300,7 @@ const drawRankBarChart = () => {
|
|||||||
{
|
{
|
||||||
name: '销售额(万)',
|
name: '销售额(万)',
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: r.map((row) => row.gmvWan),
|
data: r.map((row) => Number(row.gmvWan ?? 0)),
|
||||||
barMaxWidth: 22,
|
barMaxWidth: 22,
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
borderRadius: [0, 8, 8, 0],
|
borderRadius: [0, 8, 8, 0],
|
||||||
@@ -319,6 +335,14 @@ onMounted(() => {
|
|||||||
void redraw();
|
void redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [props.rows, props.dimension, props.variant, props.liveData],
|
||||||
|
() => {
|
||||||
|
void redraw();
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
|
|
||||||
defineExpose({ redraw });
|
defineExpose({ redraw });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -335,7 +359,8 @@ defineExpose({ redraw });
|
|||||||
<p
|
<p
|
||||||
class="mt-0.5 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="mt-0.5 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
销售/毛利/净利/退款(柱)与毛利率、净利率(线)· 演示数据
|
销售/毛利/净利/退款(柱)与毛利率、净利率(线)·
|
||||||
|
{{ liveData ? '接口数据(与全店概览订单口径一致)' : '演示数据' }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@@ -376,7 +401,8 @@ defineExpose({ redraw });
|
|||||||
<p
|
<p
|
||||||
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
自上而下为第 1 名;悬浮查看占合计与环比(演示数据)
|
自上而下为第 1 名;悬浮查看占合计
|
||||||
|
{{ liveData ? '(接口数据)' : '与环比(演示)' }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4 h-[320px] min-h-0 w-full overflow-hidden md:h-[360px]">
|
<div class="mt-4 h-[320px] min-h-0 w-full overflow-hidden md:h-[360px]">
|
||||||
|
|||||||
+15
@@ -1,10 +1,17 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
import { nextTick, ref } from 'vue';
|
import { nextTick, ref } from 'vue';
|
||||||
|
|
||||||
import WorkbenchDimChartsCard from './WorkbenchDimChartsCard.vue';
|
import WorkbenchDimChartsCard from './WorkbenchDimChartsCard.vue';
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchMultiDimCardsGrid' });
|
defineOptions({ name: 'WorkbenchMultiDimCardsGrid' });
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
multiAnalysis: WorkbenchVO.MultiPanel;
|
||||||
|
liveData?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
const multiPlatformCardRef = ref<InstanceType<
|
const multiPlatformCardRef = ref<InstanceType<
|
||||||
typeof WorkbenchDimChartsCard
|
typeof WorkbenchDimChartsCard
|
||||||
> | null>(null);
|
> | null>(null);
|
||||||
@@ -42,24 +49,32 @@ defineExpose({ redraw });
|
|||||||
dimension="platform"
|
dimension="platform"
|
||||||
variant="analysis"
|
variant="analysis"
|
||||||
title="平台"
|
title="平台"
|
||||||
|
:rows="props.multiAnalysis.platform"
|
||||||
|
:live-data="props.liveData"
|
||||||
/>
|
/>
|
||||||
<WorkbenchDimChartsCard
|
<WorkbenchDimChartsCard
|
||||||
ref="multiShopCardRef"
|
ref="multiShopCardRef"
|
||||||
dimension="shop"
|
dimension="shop"
|
||||||
variant="analysis"
|
variant="analysis"
|
||||||
title="店铺"
|
title="店铺"
|
||||||
|
:rows="props.multiAnalysis.shop"
|
||||||
|
:live-data="props.liveData"
|
||||||
/>
|
/>
|
||||||
<WorkbenchDimChartsCard
|
<WorkbenchDimChartsCard
|
||||||
ref="multiCategoryCardRef"
|
ref="multiCategoryCardRef"
|
||||||
dimension="category"
|
dimension="category"
|
||||||
variant="analysis"
|
variant="analysis"
|
||||||
title="品类"
|
title="品类"
|
||||||
|
:rows="props.multiAnalysis.category"
|
||||||
|
:live-data="props.liveData"
|
||||||
/>
|
/>
|
||||||
<WorkbenchDimChartsCard
|
<WorkbenchDimChartsCard
|
||||||
ref="multiProductCardRef"
|
ref="multiProductCardRef"
|
||||||
dimension="product"
|
dimension="product"
|
||||||
variant="analysis"
|
variant="analysis"
|
||||||
title="商品"
|
title="商品"
|
||||||
|
:rows="props.multiAnalysis.product"
|
||||||
|
:live-data="props.liveData"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
+8
-2
@@ -1,10 +1,16 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
import { nextTick, ref } from 'vue';
|
import { nextTick, ref } from 'vue';
|
||||||
|
|
||||||
import WorkbenchSalesRankCardsGrid from './components/WorkbenchSalesRankCardsGrid.vue';
|
import WorkbenchSalesRankCardsGrid from './components/WorkbenchSalesRankCardsGrid.vue';
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchSalesRankTab' });
|
defineOptions({ name: 'WorkbenchSalesRankTab' });
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
salesRank: WorkbenchVO.MultiPanel;
|
||||||
|
}>();
|
||||||
|
|
||||||
const gridRef = ref<InstanceType<typeof WorkbenchSalesRankCardsGrid> | null>(
|
const gridRef = ref<InstanceType<typeof WorkbenchSalesRankCardsGrid> | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
@@ -22,8 +28,8 @@ defineExpose({ redraw });
|
|||||||
<p
|
<p
|
||||||
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
各维度独立排行:平台、店铺、品类、商品销售额 TOP(演示数据)
|
各维度按销售额排序;接口未返回环比时仅展示占比
|
||||||
</p>
|
</p>
|
||||||
<WorkbenchSalesRankCardsGrid ref="gridRef" />
|
<WorkbenchSalesRankCardsGrid ref="gridRef" :sales-rank="salesRank" live-data />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
+15
@@ -1,10 +1,17 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
import { nextTick, ref } from 'vue';
|
import { nextTick, ref } from 'vue';
|
||||||
|
|
||||||
import WorkbenchDimChartsCard from '../../multi/components/WorkbenchDimChartsCard.vue';
|
import WorkbenchDimChartsCard from '../../multi/components/WorkbenchDimChartsCard.vue';
|
||||||
|
|
||||||
defineOptions({ name: 'WorkbenchSalesRankCardsGrid' });
|
defineOptions({ name: 'WorkbenchSalesRankCardsGrid' });
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
salesRank: WorkbenchVO.MultiPanel;
|
||||||
|
liveData?: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
const rankPlatformCardRef = ref<InstanceType<
|
const rankPlatformCardRef = ref<InstanceType<
|
||||||
typeof WorkbenchDimChartsCard
|
typeof WorkbenchDimChartsCard
|
||||||
> | null>(null);
|
> | null>(null);
|
||||||
@@ -42,24 +49,32 @@ defineExpose({ redraw });
|
|||||||
dimension="platform"
|
dimension="platform"
|
||||||
variant="rank"
|
variant="rank"
|
||||||
title="平台"
|
title="平台"
|
||||||
|
:rows="salesRank.platform"
|
||||||
|
:live-data="liveData"
|
||||||
/>
|
/>
|
||||||
<WorkbenchDimChartsCard
|
<WorkbenchDimChartsCard
|
||||||
ref="rankShopCardRef"
|
ref="rankShopCardRef"
|
||||||
dimension="shop"
|
dimension="shop"
|
||||||
variant="rank"
|
variant="rank"
|
||||||
title="店铺"
|
title="店铺"
|
||||||
|
:rows="salesRank.shop"
|
||||||
|
:live-data="liveData"
|
||||||
/>
|
/>
|
||||||
<WorkbenchDimChartsCard
|
<WorkbenchDimChartsCard
|
||||||
ref="rankCategoryCardRef"
|
ref="rankCategoryCardRef"
|
||||||
dimension="category"
|
dimension="category"
|
||||||
variant="rank"
|
variant="rank"
|
||||||
title="品类"
|
title="品类"
|
||||||
|
:rows="salesRank.category"
|
||||||
|
:live-data="liveData"
|
||||||
/>
|
/>
|
||||||
<WorkbenchDimChartsCard
|
<WorkbenchDimChartsCard
|
||||||
ref="rankProductCardRef"
|
ref="rankProductCardRef"
|
||||||
dimension="product"
|
dimension="product"
|
||||||
variant="rank"
|
variant="rank"
|
||||||
title="商品"
|
title="商品"
|
||||||
|
:rows="salesRank.product"
|
||||||
|
:live-data="liveData"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
+198
@@ -0,0 +1,198 @@
|
|||||||
|
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
||||||
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
|
function wanToYuan(w?: number | null): number {
|
||||||
|
const n = Number(w);
|
||||||
|
if (!Number.isFinite(n)) return 0;
|
||||||
|
return Math.round(n * 10_000 * 100) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
function dimRowToShopSummary(row: WorkbenchVO.DimRow): CompanyOverviewVO.ShopSummary {
|
||||||
|
const salesAmount = wanToYuan(row.gmvWan);
|
||||||
|
const refundAmount = wanToYuan(row.refundWan);
|
||||||
|
const grossYuan = wanToYuan(row.grossProfitWan);
|
||||||
|
const profitAfterTax = wanToYuan(row.netProfitWan);
|
||||||
|
const totalCost = Math.max(0, salesAmount - refundAmount - grossYuan);
|
||||||
|
const shopId = Number(row.key);
|
||||||
|
return {
|
||||||
|
shopId: Number.isFinite(shopId) ? shopId : 0,
|
||||||
|
shopName: row.name,
|
||||||
|
salesAmount,
|
||||||
|
refundAmount,
|
||||||
|
totalCost,
|
||||||
|
productCost: totalCost,
|
||||||
|
shippingCost: 0,
|
||||||
|
otherCost: 0,
|
||||||
|
totalProfitBeforeTax: grossYuan,
|
||||||
|
profitAfterTax,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function aggregateShopTotal(
|
||||||
|
shops: CompanyOverviewVO.ShopSummary[],
|
||||||
|
): CompanyOverviewVO.ShopSummary {
|
||||||
|
const sum = (k: keyof CompanyOverviewVO.ShopSummary) =>
|
||||||
|
shops.reduce((a, x) => a + (Number(x[k]) || 0), 0);
|
||||||
|
const salesAmount = sum('salesAmount');
|
||||||
|
const orderCount = sum('orderCount') || 1;
|
||||||
|
const totalPromotionFee = sum('totalPromotionFee');
|
||||||
|
const averageOrderValue = salesAmount / orderCount;
|
||||||
|
const feeRatio = salesAmount ? (totalPromotionFee / salesAmount) * 100 : 0;
|
||||||
|
return {
|
||||||
|
shopId: 0,
|
||||||
|
shopName: '合计',
|
||||||
|
targetOrderCount: sum('targetOrderCount'),
|
||||||
|
orderCountAchievementRate: sum('orderCountAchievementRate'),
|
||||||
|
targetAmount: sum('targetAmount'),
|
||||||
|
salesAmountAchievementRate: sum('salesAmountAchievementRate'),
|
||||||
|
salesAmount,
|
||||||
|
orderCount: sum('orderCount'),
|
||||||
|
averageOrderValue,
|
||||||
|
productCost: sum('productCost'),
|
||||||
|
shippingCost: sum('shippingCost'),
|
||||||
|
otherCost: sum('otherCost'),
|
||||||
|
totalCost: sum('totalCost'),
|
||||||
|
refundAmount: sum('refundAmount'),
|
||||||
|
totalPromotionFee,
|
||||||
|
brushFee: sum('brushFee'),
|
||||||
|
feeRatio,
|
||||||
|
totalProfitBeforeTax: sum('totalProfitBeforeTax'),
|
||||||
|
salesTaxAmount: sum('salesTaxAmount'),
|
||||||
|
roi: totalPromotionFee ? salesAmount / totalPromotionFee : 0,
|
||||||
|
profitAfterTax: sum('profitAfterTax'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildShopOverviewFromDimRows(
|
||||||
|
rows: WorkbenchVO.DimRow[],
|
||||||
|
): CompanyOverviewVO.ShopOverview {
|
||||||
|
const shops = rows.map(dimRowToShopSummary);
|
||||||
|
return { total: aggregateShopTotal(shops), shops };
|
||||||
|
}
|
||||||
|
|
||||||
|
function dimRowToCategorySummary(
|
||||||
|
row: WorkbenchVO.DimRow,
|
||||||
|
): CompanyOverviewVO.CategorySummary {
|
||||||
|
const salesAmount = wanToYuan(row.gmvWan);
|
||||||
|
const refundAmount = wanToYuan(row.refundWan);
|
||||||
|
const grossYuan = wanToYuan(row.grossProfitWan);
|
||||||
|
const profitAfterTax = wanToYuan(row.netProfitWan);
|
||||||
|
const totalCost = Math.max(0, salesAmount - refundAmount - grossYuan);
|
||||||
|
const rawId = Number(row.key);
|
||||||
|
const categoryId =
|
||||||
|
row.key === '0' || !Number.isFinite(rawId) ? undefined : rawId;
|
||||||
|
return {
|
||||||
|
categoryId,
|
||||||
|
categoryName: row.name,
|
||||||
|
salesAmount,
|
||||||
|
refundAmount,
|
||||||
|
totalCost,
|
||||||
|
productCost: totalCost,
|
||||||
|
shippingCost: 0,
|
||||||
|
otherCost: 0,
|
||||||
|
totalProfitBeforeTax: grossYuan,
|
||||||
|
profitAfterTax,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function aggregateCategoryTotal(
|
||||||
|
rows: CompanyOverviewVO.CategorySummary[],
|
||||||
|
): CompanyOverviewVO.CategorySummary {
|
||||||
|
const sum = (k: keyof CompanyOverviewVO.CategorySummary) =>
|
||||||
|
rows.reduce((a, x) => a + (Number(x[k]) || 0), 0);
|
||||||
|
const salesAmount = sum('salesAmount');
|
||||||
|
const orderCount = sum('orderCount') || 1;
|
||||||
|
const totalPromotionFee = sum('totalPromotionFee');
|
||||||
|
const averageOrderValue = salesAmount / orderCount;
|
||||||
|
const feeRatio = salesAmount ? (totalPromotionFee / salesAmount) * 100 : 0;
|
||||||
|
return {
|
||||||
|
categoryName: '合计',
|
||||||
|
salesAmount,
|
||||||
|
orderCount: sum('orderCount'),
|
||||||
|
averageOrderValue,
|
||||||
|
productCost: sum('productCost'),
|
||||||
|
shippingCost: sum('shippingCost'),
|
||||||
|
otherCost: sum('otherCost'),
|
||||||
|
totalCost: sum('totalCost'),
|
||||||
|
refundAmount: sum('refundAmount'),
|
||||||
|
totalPromotionFee,
|
||||||
|
brushFee: sum('brushFee'),
|
||||||
|
feeRatio,
|
||||||
|
totalProfitBeforeTax: sum('totalProfitBeforeTax'),
|
||||||
|
salesTaxAmount: sum('salesTaxAmount'),
|
||||||
|
roi: totalPromotionFee ? salesAmount / totalPromotionFee : 0,
|
||||||
|
profitAfterTax: sum('profitAfterTax'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildCategoryOverviewFromDimRows(
|
||||||
|
rows: WorkbenchVO.DimRow[],
|
||||||
|
): CompanyOverviewVO.CategoryOverview {
|
||||||
|
const categories = rows.map(dimRowToCategorySummary);
|
||||||
|
return { total: aggregateCategoryTotal(categories), categories };
|
||||||
|
}
|
||||||
|
|
||||||
|
function dimRowToPlatformSummary(
|
||||||
|
row: WorkbenchVO.DimRow,
|
||||||
|
): CompanyOverviewVO.PlatformSummary {
|
||||||
|
const salesAmount = wanToYuan(row.gmvWan);
|
||||||
|
const refundAmount = wanToYuan(row.refundWan);
|
||||||
|
const grossYuan = wanToYuan(row.grossProfitWan);
|
||||||
|
const profitAfterTax = wanToYuan(row.netProfitWan);
|
||||||
|
const totalCost = Math.max(0, salesAmount - refundAmount - grossYuan);
|
||||||
|
const platformId = Number(row.key);
|
||||||
|
return {
|
||||||
|
platformId: Number.isFinite(platformId) ? platformId : 0,
|
||||||
|
platformName: row.name,
|
||||||
|
salesAmount,
|
||||||
|
refundAmount,
|
||||||
|
totalCost,
|
||||||
|
productCost: totalCost,
|
||||||
|
shippingCost: 0,
|
||||||
|
otherCost: 0,
|
||||||
|
totalProfitBeforeTax: grossYuan,
|
||||||
|
profitAfterTax,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function aggregatePlatformTotal(
|
||||||
|
rows: CompanyOverviewVO.PlatformSummary[],
|
||||||
|
): CompanyOverviewVO.PlatformSummary {
|
||||||
|
const sum = (k: keyof CompanyOverviewVO.PlatformSummary) =>
|
||||||
|
rows.reduce((a, x) => a + (Number(x[k]) || 0), 0);
|
||||||
|
const salesAmount = sum('salesAmount');
|
||||||
|
const orderCount = sum('orderCount') || 1;
|
||||||
|
const totalPromotionFee = sum('totalPromotionFee');
|
||||||
|
const averageOrderValue = salesAmount / orderCount;
|
||||||
|
const feeRatio = salesAmount ? (totalPromotionFee / salesAmount) * 100 : 0;
|
||||||
|
return {
|
||||||
|
platformId: 0,
|
||||||
|
platformName: '合计',
|
||||||
|
targetOrderCount: sum('targetOrderCount'),
|
||||||
|
orderCountAchievementRate: sum('orderCountAchievementRate'),
|
||||||
|
targetAmount: sum('targetAmount'),
|
||||||
|
salesAmountAchievementRate: sum('salesAmountAchievementRate'),
|
||||||
|
salesAmount,
|
||||||
|
orderCount: sum('orderCount'),
|
||||||
|
averageOrderValue,
|
||||||
|
productCost: sum('productCost'),
|
||||||
|
shippingCost: sum('shippingCost'),
|
||||||
|
otherCost: sum('otherCost'),
|
||||||
|
totalCost: sum('totalCost'),
|
||||||
|
refundAmount: sum('refundAmount'),
|
||||||
|
totalPromotionFee,
|
||||||
|
brushFee: sum('brushFee'),
|
||||||
|
feeRatio,
|
||||||
|
totalProfitBeforeTax: sum('totalProfitBeforeTax'),
|
||||||
|
salesTaxAmount: sum('salesTaxAmount'),
|
||||||
|
roi: totalPromotionFee ? salesAmount / totalPromotionFee : 0,
|
||||||
|
profitAfterTax: sum('profitAfterTax'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildPlatformOverviewFromDimRows(
|
||||||
|
rows: WorkbenchVO.DimRow[],
|
||||||
|
): CompanyOverviewVO.PlatformOverview {
|
||||||
|
const platforms = rows.map(dimRowToPlatformSummary);
|
||||||
|
return { total: aggregatePlatformTotal(platforms), platforms };
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user