mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 11:49:20 +08:00
feat: 按经营概览风格重做商品概览并补齐 KPI 与趋势
This commit is contained in:
+20
-248
@@ -2,351 +2,123 @@ package top.xyquan.ecomdmbbackend.modules.bi.productoverview.model.vo;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品概览响应VO
|
* 商品概览响应:经营 KPI/趋势与工作台经营概览同口径,并附 SKU 明细。
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ProductOverviewVO {
|
public class ProductOverviewVO {
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品ID
|
|
||||||
*/
|
|
||||||
private Long productId;
|
private Long productId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品名称
|
|
||||||
*/
|
|
||||||
private String productName;
|
private String productName;
|
||||||
|
|
||||||
// ========== KPI 汇总指标 ==========
|
/** 与工作台经营概览同结构的 KPI 列表 */
|
||||||
|
private List<WorkbenchKpiItemVO> kpis;
|
||||||
|
|
||||||
/**
|
/** 成交/净销售/利润日趋势(与工作台 dealTrend 同形) */
|
||||||
* 总销售额
|
private List<WorkbenchTrendPointVO> dealTrend;
|
||||||
*/
|
|
||||||
|
/** 各 SKU 净销售额占比(饼图) */
|
||||||
|
private List<WorkbenchCostSliceVO> skuSalesShare;
|
||||||
|
|
||||||
|
private String momCompareDateStart;
|
||||||
|
private String momCompareDateEnd;
|
||||||
|
private String yoyCompareDateStart;
|
||||||
|
private String yoyCompareDateEnd;
|
||||||
|
|
||||||
|
/** 兼容 Agent/旧前端:扁平 KPI 摘要 */
|
||||||
private BigDecimal totalSalesAmount;
|
private BigDecimal totalSalesAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 较上月同期增长百分比
|
|
||||||
*/
|
|
||||||
private BigDecimal monthOverMonthGrowth;
|
private BigDecimal monthOverMonthGrowth;
|
||||||
|
|
||||||
/**
|
|
||||||
* 总订单量
|
|
||||||
*/
|
|
||||||
private Integer totalOrderCount;
|
private Integer totalOrderCount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 平均费比(推广费/销售额)
|
|
||||||
*/
|
|
||||||
private BigDecimal averageFeeRatio;
|
private BigDecimal averageFeeRatio;
|
||||||
|
|
||||||
/**
|
|
||||||
* 总净利润(税后)
|
|
||||||
*/
|
|
||||||
private BigDecimal totalNetProfitAfterTax;
|
private BigDecimal totalNetProfitAfterTax;
|
||||||
|
|
||||||
/**
|
|
||||||
* 扣除总税额
|
|
||||||
*/
|
|
||||||
private BigDecimal totalTaxAmount;
|
private BigDecimal totalTaxAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 销量目标达成率
|
|
||||||
*/
|
|
||||||
private BigDecimal orderCountAchievementRate;
|
private BigDecimal orderCountAchievementRate;
|
||||||
|
|
||||||
/**
|
|
||||||
* 销售额目标达成率
|
|
||||||
*/
|
|
||||||
private BigDecimal salesAmountAchievementRate;
|
private BigDecimal salesAmountAchievementRate;
|
||||||
|
|
||||||
/**
|
|
||||||
* 汇总ROI
|
|
||||||
*/
|
|
||||||
private BigDecimal totalROI;
|
private BigDecimal totalROI;
|
||||||
|
|
||||||
// ========== 各规格销量 Top10 ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 各规格销量 Top10(按单量降序,最多10条)
|
|
||||||
*/
|
|
||||||
private List<SpecSalesRankItem> specSalesTop10;
|
private List<SpecSalesRankItem> specSalesTop10;
|
||||||
|
|
||||||
// ========== 趋势数据 ==========
|
/** @deprecated 使用 dealTrend;保留以免旧客户端空指针 */
|
||||||
|
|
||||||
/**
|
|
||||||
* 销售额趋势分析
|
|
||||||
*/
|
|
||||||
private TrendData salesAmountTrend;
|
private TrendData salesAmountTrend;
|
||||||
|
/** @deprecated 使用 dealTrend */
|
||||||
/**
|
|
||||||
* 单量趋势分析
|
|
||||||
*/
|
|
||||||
private TrendData orderCountTrend;
|
private TrendData orderCountTrend;
|
||||||
|
|
||||||
// ========== 规格销售汇总 ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格销售汇总(含各规格明细列表和合计行)
|
|
||||||
*/
|
|
||||||
private SpecSummary specSummaries;
|
private SpecSummary specSummaries;
|
||||||
|
|
||||||
// ========== 内部类 ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 趋势数据
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public static class TrendData {
|
public static class TrendData {
|
||||||
/**
|
|
||||||
* 时间范围的总值
|
|
||||||
*/
|
|
||||||
private BigDecimal total;
|
private BigDecimal total;
|
||||||
|
|
||||||
/**
|
|
||||||
* 每日数据列表
|
|
||||||
*/
|
|
||||||
private List<TrendDataItem> dailyDataList;
|
private List<TrendDataItem> dailyDataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 趋势数据项
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public static class TrendDataItem {
|
public static class TrendDataItem {
|
||||||
/**
|
|
||||||
* 日期
|
|
||||||
*/
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
|
|
||||||
/**
|
|
||||||
* 对应的值
|
|
||||||
*/
|
|
||||||
private BigDecimal value;
|
private BigDecimal value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格销售汇总
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public static class SpecSummary {
|
public static class SpecSummary {
|
||||||
/**
|
|
||||||
* 各规格明细列表
|
|
||||||
*/
|
|
||||||
private List<SpecSummaryItem> list;
|
private List<SpecSummaryItem> list;
|
||||||
|
|
||||||
/**
|
|
||||||
* 合计行
|
|
||||||
*/
|
|
||||||
private SpecSummaryTotal total;
|
private SpecSummaryTotal total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格销售明细项
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public static class SpecSummaryItem {
|
public static class SpecSummaryItem {
|
||||||
/**
|
|
||||||
* 规格ID
|
|
||||||
*/
|
|
||||||
private Long skuId;
|
private Long skuId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格名称
|
|
||||||
*/
|
|
||||||
private String skuName;
|
private String skuName;
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格编码
|
|
||||||
*/
|
|
||||||
private String skuCode;
|
private String skuCode;
|
||||||
|
|
||||||
/**
|
|
||||||
* 销售额
|
|
||||||
*/
|
|
||||||
private BigDecimal salesAmount;
|
private BigDecimal salesAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单量(按平台订单号去重)
|
|
||||||
*/
|
|
||||||
private Integer orderCount;
|
private Integer orderCount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 总件数
|
|
||||||
*/
|
|
||||||
private Integer quantity;
|
private Integer quantity;
|
||||||
|
|
||||||
/**
|
|
||||||
* 客单价
|
|
||||||
*/
|
|
||||||
private BigDecimal averageOrderValue;
|
private BigDecimal averageOrderValue;
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品成本
|
|
||||||
*/
|
|
||||||
private BigDecimal productCost;
|
private BigDecimal productCost;
|
||||||
|
|
||||||
/**
|
|
||||||
* 运费
|
|
||||||
*/
|
|
||||||
private BigDecimal shippingCost;
|
private BigDecimal shippingCost;
|
||||||
|
|
||||||
/**
|
|
||||||
* 其他成本
|
|
||||||
*/
|
|
||||||
private BigDecimal otherCost;
|
private BigDecimal otherCost;
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单成本(商品成本+运费+其他成本,不含推广费、刷单费)
|
|
||||||
*/
|
|
||||||
private BigDecimal orderCost;
|
private BigDecimal orderCost;
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款金额
|
|
||||||
*/
|
|
||||||
private BigDecimal refundAmount;
|
private BigDecimal refundAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 推广费
|
|
||||||
*/
|
|
||||||
private BigDecimal promotionFee;
|
private BigDecimal promotionFee;
|
||||||
|
|
||||||
/**
|
|
||||||
* 费比(推广费/销售额)
|
|
||||||
*/
|
|
||||||
private BigDecimal feeRatio;
|
private BigDecimal feeRatio;
|
||||||
|
|
||||||
/**
|
|
||||||
* 税前盈亏
|
|
||||||
*/
|
|
||||||
private BigDecimal profitBeforeTax;
|
private BigDecimal profitBeforeTax;
|
||||||
|
|
||||||
/**
|
|
||||||
* 销售额×税率的税额
|
|
||||||
*/
|
|
||||||
private BigDecimal salesTaxAmount;
|
private BigDecimal salesTaxAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* ROI
|
|
||||||
*/
|
|
||||||
private BigDecimal roi;
|
private BigDecimal roi;
|
||||||
|
|
||||||
/**
|
|
||||||
* 税后盈亏
|
|
||||||
*/
|
|
||||||
private BigDecimal profitAfterTax;
|
private BigDecimal profitAfterTax;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格销售汇总合计行
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public static class SpecSummaryTotal {
|
public static class SpecSummaryTotal {
|
||||||
/**
|
|
||||||
* 销售额
|
|
||||||
*/
|
|
||||||
private BigDecimal salesAmount;
|
private BigDecimal salesAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单量
|
|
||||||
*/
|
|
||||||
private Integer orderCount;
|
private Integer orderCount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 总件数
|
|
||||||
*/
|
|
||||||
private Integer quantity;
|
private Integer quantity;
|
||||||
|
|
||||||
/**
|
|
||||||
* 商品成本
|
|
||||||
*/
|
|
||||||
private BigDecimal productCost;
|
private BigDecimal productCost;
|
||||||
|
|
||||||
/**
|
|
||||||
* 运费
|
|
||||||
*/
|
|
||||||
private BigDecimal shippingCost;
|
private BigDecimal shippingCost;
|
||||||
|
|
||||||
/**
|
|
||||||
* 其他成本
|
|
||||||
*/
|
|
||||||
private BigDecimal otherCost;
|
private BigDecimal otherCost;
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单成本(商品成本+运费+其他成本,不含推广费、刷单费)
|
|
||||||
*/
|
|
||||||
private BigDecimal orderCost;
|
private BigDecimal orderCost;
|
||||||
|
|
||||||
/**
|
|
||||||
* 退款金额
|
|
||||||
*/
|
|
||||||
private BigDecimal refundAmount;
|
private BigDecimal refundAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 推广费
|
|
||||||
*/
|
|
||||||
private BigDecimal promotionFee;
|
private BigDecimal promotionFee;
|
||||||
|
|
||||||
/**
|
|
||||||
* 费比
|
|
||||||
*/
|
|
||||||
private BigDecimal feeRatio;
|
private BigDecimal feeRatio;
|
||||||
|
|
||||||
/**
|
|
||||||
* 税前盈亏
|
|
||||||
*/
|
|
||||||
private BigDecimal profitBeforeTax;
|
private BigDecimal profitBeforeTax;
|
||||||
|
|
||||||
/**
|
|
||||||
* 税额
|
|
||||||
*/
|
|
||||||
private BigDecimal salesTaxAmount;
|
private BigDecimal salesTaxAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* ROI
|
|
||||||
*/
|
|
||||||
private BigDecimal roi;
|
private BigDecimal roi;
|
||||||
|
|
||||||
/**
|
|
||||||
* 税后盈亏
|
|
||||||
*/
|
|
||||||
private BigDecimal profitAfterTax;
|
private BigDecimal profitAfterTax;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格销量排名项
|
|
||||||
*/
|
|
||||||
@Data
|
@Data
|
||||||
public static class SpecSalesRankItem {
|
public static class SpecSalesRankItem {
|
||||||
/**
|
|
||||||
* 规格ID
|
|
||||||
*/
|
|
||||||
private Long skuId;
|
private Long skuId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格名称
|
|
||||||
*/
|
|
||||||
private String skuName;
|
private String skuName;
|
||||||
|
|
||||||
/**
|
|
||||||
* 规格编码
|
|
||||||
*/
|
|
||||||
private String skuCode;
|
private String skuCode;
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单量
|
|
||||||
*/
|
|
||||||
private Integer orderCount;
|
private Integer orderCount;
|
||||||
|
|
||||||
/**
|
|
||||||
* 销售额
|
|
||||||
*/
|
|
||||||
private BigDecimal salesAmount;
|
private BigDecimal salesAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+175
-156
@@ -6,17 +6,20 @@ import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
|||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyProductDoc;
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyProductDoc;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailySkuDoc;
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailySkuDoc;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.query.BiOrderStatQueryService;
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.query.BiOrderStatQueryService;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.productoverview.service.BiProductOverviewService;
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.support.BiWorkbenchFeeLoader;
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.agg.OverviewAggRows;
|
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.agg.OverviewAggRows;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.vo.CompanyOverviewVO;
|
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.vo.CompanyOverviewVO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.service.CompanyOverviewService;
|
import top.xyquan.ecomdmbbackend.modules.bi.overview.service.CompanyOverviewService;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.productoverview.model.dto.ProductOverviewQueryDTO;
|
import top.xyquan.ecomdmbbackend.modules.bi.productoverview.model.dto.ProductOverviewQueryDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.bi.productoverview.model.vo.ProductOverviewVO;
|
import top.xyquan.ecomdmbbackend.modules.bi.productoverview.model.vo.ProductOverviewVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.productoverview.service.BiProductOverviewService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.support.BiFinanceKpiAssembler;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.support.BiWorkbenchFeeLoader;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductService;
|
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.monthlytarget.mapper.ShopMonthlyTargetMapper;
|
import top.xyquan.ecomdmbbackend.modules.ec.shop.monthlytarget.mapper.ShopMonthlyTargetMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.monthlytarget.model.po.ShopMonthlyTargetPO;
|
import top.xyquan.ecomdmbbackend.modules.ec.shop.monthlytarget.model.po.ShopMonthlyTargetPO;
|
||||||
@@ -26,7 +29,6 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.temporal.ChronoUnit;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -38,8 +40,7 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品概览:Mongo product/sku 日汇聚 + MySQL 推广/目标。
|
* 商品概览:Mongo product/sku 日汇聚 + 经营 KPI(与工作台同口径)。
|
||||||
* 推广分摊复用工作台四表(按店全量商品行作分母),不再扫订单明细。
|
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
||||||
@@ -87,7 +88,6 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
BigDecimal taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE;
|
BigDecimal taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE;
|
||||||
LocalDate start = queryDTO.getStartDate();
|
LocalDate start = queryDTO.getStartDate();
|
||||||
LocalDate end = queryDTO.getEndDate();
|
LocalDate end = queryDTO.getEndDate();
|
||||||
|
|
||||||
Long filterShopId = queryDTO.getShopId();
|
Long filterShopId = queryDTO.getShopId();
|
||||||
if (filterShopId != null) {
|
if (filterShopId != null) {
|
||||||
ShopPO shop = shopService.getById(filterShopId);
|
ShopPO shop = shopService.getById(filterShopId);
|
||||||
@@ -96,10 +96,53 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先拉本商品日文档,确定涉及店铺
|
|
||||||
List<Long> shopIdFilter = filterShopId != null ? List.of(filterShopId) : null;
|
List<Long> shopIdFilter = filterShopId != null ? List.of(filterShopId) : null;
|
||||||
|
PeriodBundle cur = loadPeriod(companyId, product.getId(), shopIdFilter, filterShopId, start, end, taxRate);
|
||||||
|
|
||||||
|
LocalDate[] mom = BiFinanceKpiAssembler.lastMonthSameSpan(start, end);
|
||||||
|
LocalDate[] yoy = BiFinanceKpiAssembler.yoySameSpan(start, end);
|
||||||
|
PeriodBundle prev = loadPeriod(companyId, product.getId(), shopIdFilter, filterShopId, mom[0], mom[1], taxRate);
|
||||||
|
PeriodBundle yoyBundle = loadPeriod(companyId, product.getId(), shopIdFilter, filterShopId, yoy[0], yoy[1], taxRate);
|
||||||
|
|
||||||
|
BiFinanceKpiAssembler.Totals curT = cur.totals();
|
||||||
|
BiFinanceKpiAssembler.Totals prevT = prev.totals();
|
||||||
|
BiFinanceKpiAssembler.Totals yoyT = yoyBundle.totals();
|
||||||
|
|
||||||
|
List<WorkbenchTrendPointVO> dealTrend = BiFinanceKpiAssembler.buildTrendFromDaily(
|
||||||
|
cur.dailyRows(), start, end, curT);
|
||||||
|
|
||||||
|
List<BiOrderStatDailySkuDoc> skuDocs =
|
||||||
|
orderStatQueryService.listSkuDocs(companyId, product.getId(), shopIdFilter, start, end);
|
||||||
|
List<BiOrderStatQueryService.SkuPeriodMetrics> skuMetrics =
|
||||||
|
orderStatQueryService.sumSkuDocsBySku(skuDocs);
|
||||||
|
ProductOverviewVO.SpecSummary specSummaries =
|
||||||
|
buildSpecSummary(skuMetrics, taxRate, curT.promotion());
|
||||||
|
|
||||||
|
ProductOverviewVO vo = new ProductOverviewVO();
|
||||||
|
vo.setProductId(product.getId());
|
||||||
|
vo.setProductName(product.getName());
|
||||||
|
vo.setKpis(BiFinanceKpiAssembler.buildKpis(curT, prevT, yoyT, start, end, taxRate));
|
||||||
|
vo.setDealTrend(dealTrend);
|
||||||
|
vo.setSkuSalesShare(buildSkuSalesShare(specSummaries, curT.totalSales()));
|
||||||
|
vo.setMomCompareDateStart(mom[0].toString());
|
||||||
|
vo.setMomCompareDateEnd(mom[1].toString());
|
||||||
|
vo.setYoyCompareDateStart(yoy[0].toString());
|
||||||
|
vo.setYoyCompareDateEnd(yoy[1].toString());
|
||||||
|
vo.setSpecSummaries(specSummaries);
|
||||||
|
vo.setSpecSalesTop10(buildSpecTop10(specSummaries));
|
||||||
|
fillLegacyFlatFields(vo, curT, prevT);
|
||||||
|
fillTargets(vo, companyId, cur.shopIds(), start, end, curT.totalSales(), curT.orderCount());
|
||||||
|
fillLegacyTrends(vo, dealTrend);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载单区间:店铺范围 + 商品分摊后的经营 Totals + 日趋势行。
|
||||||
|
*/
|
||||||
|
private PeriodBundle loadPeriod(Long companyId, Long productId, List<Long> shopIdFilter, Long filterShopId,
|
||||||
|
LocalDate start, LocalDate end, BigDecimal taxRate) {
|
||||||
List<BiOrderStatDailyProductDoc> thisProductDocs =
|
List<BiOrderStatDailyProductDoc> thisProductDocs =
|
||||||
orderStatQueryService.listProductDocs(companyId, shopIdFilter, product.getId(), start, end);
|
orderStatQueryService.listProductDocs(companyId, shopIdFilter, productId, start, end);
|
||||||
|
|
||||||
List<Long> shopIds;
|
List<Long> shopIds;
|
||||||
if (filterShopId != null) {
|
if (filterShopId != null) {
|
||||||
@@ -121,83 +164,74 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
s -> s.getPlatformCode() != null ? s.getPlatformCode() : "",
|
s -> s.getPlatformCode() != null ? s.getPlatformCode() : "",
|
||||||
(a, b) -> a));
|
(a, b) -> a));
|
||||||
|
|
||||||
// 店内全量商品行:推广分摊分母(替代 allShopOrdersForPromo)
|
List<OverviewAggRows.DailyRow> dailyRows =
|
||||||
List<BiOrderStatDailyProductDoc> allProductDocs = shopIds.isEmpty()
|
orderStatQueryService.toDailyRowsFromProductDocs(thisProductDocs);
|
||||||
? List.of()
|
|
||||||
: orderStatQueryService.listProductDocs(companyId, shopIds, start, end);
|
|
||||||
BiWorkbenchFeeLoader.FeeBundle fees = shopIds.isEmpty()
|
|
||||||
? new BiWorkbenchFeeLoader.FeeBundle(List.of(), List.of())
|
|
||||||
: feeLoader.load(companyId, shopIds, start, end);
|
|
||||||
|
|
||||||
|
if (shops.isEmpty()) {
|
||||||
|
return new PeriodBundle(List.of(), BiFinanceKpiAssembler.Totals.empty(), dailyRows);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BiOrderStatDailyProductDoc> allProductDocs =
|
||||||
|
orderStatQueryService.listProductDocs(companyId, shopIds, start, end);
|
||||||
|
BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(companyId, shopIds, start, end);
|
||||||
List<OverviewAggRows.ShopProductRow> orderRows =
|
List<OverviewAggRows.ShopProductRow> orderRows =
|
||||||
orderStatQueryService.toShopProductRows(allProductDocs, platformByShopId);
|
orderStatQueryService.toShopProductRows(allProductDocs, platformByShopId);
|
||||||
CompanyOverviewVO.WorkbenchTableBundle tables = shops.isEmpty()
|
CompanyOverviewVO.WorkbenchTableBundle tables =
|
||||||
? emptyTables()
|
companyOverviewService.buildWorkbenchSummaryTablesFromAgg(
|
||||||
: companyOverviewService.buildWorkbenchSummaryTablesFromAgg(
|
|
||||||
taxRate, companyId, shops, orderRows,
|
taxRate, companyId, shops, orderRows,
|
||||||
fees.promotionRows(), fees.brushRows(), start, end);
|
fees.promotionRows(), fees.brushRows(), start, end);
|
||||||
|
CompanyOverviewVO.CategorySummary productRow = findProductRow(tables.getProductTable(), productId);
|
||||||
CompanyOverviewVO.CategorySummary productRow = findProductRow(tables.getProductTable(), product.getId());
|
BiFinanceKpiAssembler.Totals totals = productRow != null
|
||||||
|
? BiFinanceKpiAssembler.fromCategorySummary(productRow, taxRate)
|
||||||
BigDecimal sales = productRow != null ? nz(productRow.getSalesAmount()) : sumSales(thisProductDocs);
|
: BiFinanceKpiAssembler.Totals.empty();
|
||||||
int orderCount = productRow != null && productRow.getSalesOrderCount() != null
|
return new PeriodBundle(shopIds, totals, dailyRows);
|
||||||
? productRow.getSalesOrderCount()
|
|
||||||
: sumOrders(thisProductDocs);
|
|
||||||
BigDecimal promo = productRow != null ? nz(productRow.getTotalPromotionFee()) : BigDecimal.ZERO;
|
|
||||||
BigDecimal orderCost = productRow != null ? nz(productRow.getOrderCost())
|
|
||||||
: sumCost(thisProductDocs);
|
|
||||||
BigDecimal tax = salesTaxOnNet(sales, taxRate);
|
|
||||||
BigDecimal net = sales.subtract(orderCost).subtract(promo).subtract(tax);
|
|
||||||
|
|
||||||
ProductOverviewVO vo = new ProductOverviewVO();
|
|
||||||
vo.setProductId(product.getId());
|
|
||||||
vo.setProductName(product.getName());
|
|
||||||
vo.setTotalSalesAmount(sales.setScale(2, RoundingMode.HALF_UP));
|
|
||||||
vo.setTotalOrderCount(orderCount);
|
|
||||||
vo.setAverageFeeRatio(sales.compareTo(BigDecimal.ZERO) > 0
|
|
||||||
? promo.divide(sales, 4, RoundingMode.HALF_UP)
|
|
||||||
.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
||||||
: BigDecimal.ZERO);
|
|
||||||
vo.setTotalTaxAmount(tax);
|
|
||||||
vo.setTotalNetProfitAfterTax(net.setScale(2, RoundingMode.HALF_UP));
|
|
||||||
vo.setTotalROI(roi(sales, promo));
|
|
||||||
vo.setMonthOverMonthGrowth(calcPrevPeriodGrowth(companyId, product.getId(), shopIdFilter,
|
|
||||||
start, end, sales));
|
|
||||||
|
|
||||||
fillTargets(vo, companyId, shopIds, start, end, sales, orderCount);
|
|
||||||
|
|
||||||
Map<LocalDate, OverviewAggRows.DailyRow> daily =
|
|
||||||
orderStatQueryService.toDailyRowsFromProductDocs(thisProductDocs).stream()
|
|
||||||
.filter(d -> d.getStatDate() != null)
|
|
||||||
.collect(Collectors.toMap(OverviewAggRows.DailyRow::getStatDate, d -> d, (a, b) -> a));
|
|
||||||
vo.setSalesAmountTrend(buildTrend(start, end, daily, true));
|
|
||||||
vo.setOrderCountTrend(buildTrend(start, end, daily, false));
|
|
||||||
|
|
||||||
List<BiOrderStatDailySkuDoc> skuDocs =
|
|
||||||
orderStatQueryService.listSkuDocs(companyId, product.getId(), shopIdFilter, start, end);
|
|
||||||
List<BiOrderStatQueryService.SkuPeriodMetrics> skuMetrics =
|
|
||||||
orderStatQueryService.sumSkuDocsBySku(skuDocs);
|
|
||||||
vo.setSpecSummaries(buildSpecSummary(skuMetrics, taxRate, promo));
|
|
||||||
vo.setSpecSalesTop10(buildSpecTop10(vo.getSpecSummaries()));
|
|
||||||
|
|
||||||
return vo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BigDecimal calcPrevPeriodGrowth(Long companyId, Long productId, List<Long> shopIds,
|
private void fillLegacyFlatFields(ProductOverviewVO vo,
|
||||||
LocalDate start, LocalDate end, BigDecimal curSales) {
|
BiFinanceKpiAssembler.Totals cur,
|
||||||
long dayCount = ChronoUnit.DAYS.between(start, end) + 1;
|
BiFinanceKpiAssembler.Totals prev) {
|
||||||
LocalDate prevStart = start.minusDays(dayCount);
|
vo.setTotalSalesAmount(BiFinanceKpiAssembler.yuan2(cur.totalSales()));
|
||||||
LocalDate prevEnd = start.minusDays(1);
|
vo.setTotalOrderCount(cur.orderCount());
|
||||||
List<BiOrderStatDailyProductDoc> prevDocs =
|
vo.setAverageFeeRatio(cur.totalSales().compareTo(BigDecimal.ZERO) > 0
|
||||||
orderStatQueryService.listProductDocs(companyId, shopIds, productId, prevStart, prevEnd);
|
? cur.promotion().divide(cur.totalSales(), 4, RoundingMode.HALF_UP)
|
||||||
BigDecimal last = sumSales(prevDocs);
|
.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
||||||
if (last.compareTo(BigDecimal.ZERO) > 0) {
|
: BigDecimal.ZERO);
|
||||||
return curSales.subtract(last)
|
vo.setTotalTaxAmount(BiFinanceKpiAssembler.yuan2(cur.tax()));
|
||||||
.divide(last, 4, RoundingMode.HALF_UP)
|
vo.setTotalNetProfitAfterTax(BiFinanceKpiAssembler.yuan2(cur.netProfit()));
|
||||||
.multiply(new BigDecimal("100"))
|
vo.setTotalROI(cur.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||||
.setScale(2, RoundingMode.HALF_UP);
|
? cur.totalSales().divide(cur.promotion(), 4, RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO);
|
||||||
|
vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillLegacyTrends(ProductOverviewVO vo, List<WorkbenchTrendPointVO> dealTrend) {
|
||||||
|
ProductOverviewVO.TrendData sales = new ProductOverviewVO.TrendData();
|
||||||
|
ProductOverviewVO.TrendData orders = new ProductOverviewVO.TrendData();
|
||||||
|
List<ProductOverviewVO.TrendDataItem> salesItems = new ArrayList<>();
|
||||||
|
List<ProductOverviewVO.TrendDataItem> orderItems = new ArrayList<>();
|
||||||
|
BigDecimal salesTotal = BigDecimal.ZERO;
|
||||||
|
BigDecimal orderTotal = BigDecimal.ZERO;
|
||||||
|
if (dealTrend != null) {
|
||||||
|
for (WorkbenchTrendPointVO p : dealTrend) {
|
||||||
|
ProductOverviewVO.TrendDataItem s = new ProductOverviewVO.TrendDataItem();
|
||||||
|
s.setDate(LocalDate.parse(p.getDate()));
|
||||||
|
s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan()));
|
||||||
|
salesItems.add(s);
|
||||||
|
salesTotal = salesTotal.add(s.getValue());
|
||||||
|
|
||||||
|
ProductOverviewVO.TrendDataItem o = new ProductOverviewVO.TrendDataItem();
|
||||||
|
o.setDate(s.getDate());
|
||||||
|
o.setValue(BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0));
|
||||||
|
orderItems.add(o);
|
||||||
|
orderTotal = orderTotal.add(o.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return curSales.compareTo(BigDecimal.ZERO) > 0 ? new BigDecimal("100.00") : BigDecimal.ZERO;
|
sales.setDailyDataList(salesItems);
|
||||||
|
sales.setTotal(salesTotal);
|
||||||
|
orders.setDailyDataList(orderItems);
|
||||||
|
orders.setTotal(orderTotal);
|
||||||
|
vo.setSalesAmountTrend(sales);
|
||||||
|
vo.setOrderCountTrend(orders);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillTargets(ProductOverviewVO vo, Long companyId, List<Long> shopIds,
|
private void fillTargets(ProductOverviewVO vo, Long companyId, List<Long> shopIds,
|
||||||
@@ -233,13 +267,39 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<WorkbenchCostSliceVO> buildSkuSalesShare(ProductOverviewVO.SpecSummary summary,
|
||||||
|
BigDecimal salesTotal) {
|
||||||
|
if (summary == null || summary.getList() == null || summary.getList().isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
BigDecimal base = BiFinanceKpiAssembler.nz(salesTotal);
|
||||||
|
return summary.getList().stream()
|
||||||
|
.filter(i -> BiFinanceKpiAssembler.nz(i.getSalesAmount()).compareTo(BigDecimal.ZERO) > 0)
|
||||||
|
.sorted(Comparator.comparing(ProductOverviewVO.SpecSummaryItem::getSalesAmount,
|
||||||
|
Comparator.nullsFirst(BigDecimal::compareTo)).reversed())
|
||||||
|
.limit(12)
|
||||||
|
.map(i -> {
|
||||||
|
BigDecimal amt = BiFinanceKpiAssembler.nz(i.getSalesAmount());
|
||||||
|
BigDecimal pct = base.compareTo(BigDecimal.ZERO) > 0
|
||||||
|
? amt.multiply(new BigDecimal("100")).divide(base, 2, RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
String name = i.getSkuName() != null ? i.getSkuName() : "SKU";
|
||||||
|
return WorkbenchCostSliceVO.builder()
|
||||||
|
.name(name)
|
||||||
|
.value(BiFinanceKpiAssembler.yuan2(amt))
|
||||||
|
.pct(pct)
|
||||||
|
.build();
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
private ProductOverviewVO.SpecSummary buildSpecSummary(
|
private ProductOverviewVO.SpecSummary buildSpecSummary(
|
||||||
List<BiOrderStatQueryService.SkuPeriodMetrics> metrics,
|
List<BiOrderStatQueryService.SkuPeriodMetrics> metrics,
|
||||||
BigDecimal taxRate,
|
BigDecimal taxRate,
|
||||||
BigDecimal totalPromo) {
|
BigDecimal totalPromo) {
|
||||||
BigDecimal salesPool = metrics.stream()
|
BigDecimal salesPool = metrics.stream()
|
||||||
.map(BiOrderStatQueryService.SkuPeriodMetrics::salesAmount)
|
.map(BiOrderStatQueryService.SkuPeriodMetrics::salesAmount)
|
||||||
.map(BiProductOverviewServiceImpl::nz)
|
.map(BiFinanceKpiAssembler::nz)
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
Set<Long> skuIds = metrics.stream()
|
Set<Long> skuIds = metrics.stream()
|
||||||
@@ -257,11 +317,12 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
|
|
||||||
List<ProductOverviewVO.SpecSummaryItem> list = new ArrayList<>();
|
List<ProductOverviewVO.SpecSummaryItem> list = new ArrayList<>();
|
||||||
for (BiOrderStatQueryService.SkuPeriodMetrics m : metrics) {
|
for (BiOrderStatQueryService.SkuPeriodMetrics m : metrics) {
|
||||||
BigDecimal sales = nz(m.salesAmount());
|
BigDecimal sales = BiFinanceKpiAssembler.nz(m.salesAmount());
|
||||||
BigDecimal sharePromo = salesPool.compareTo(BigDecimal.ZERO) > 0
|
BigDecimal sharePromo = salesPool.compareTo(BigDecimal.ZERO) > 0
|
||||||
? nz(totalPromo).multiply(sales).divide(salesPool, 4, RoundingMode.HALF_UP)
|
? BiFinanceKpiAssembler.nz(totalPromo).multiply(sales)
|
||||||
|
.divide(salesPool, 4, RoundingMode.HALF_UP)
|
||||||
: BigDecimal.ZERO;
|
: BigDecimal.ZERO;
|
||||||
BigDecimal refund = nz(m.refundAmount());
|
BigDecimal refund = BiFinanceKpiAssembler.nz(m.refundAmount());
|
||||||
BigDecimal cost = m.orderCost();
|
BigDecimal cost = m.orderCost();
|
||||||
BigDecimal tax = salesTaxOnNet(sales, taxRate);
|
BigDecimal tax = salesTaxOnNet(sales, taxRate);
|
||||||
BigDecimal pbt = sales.subtract(cost).subtract(sharePromo);
|
BigDecimal pbt = sales.subtract(cost).subtract(sharePromo);
|
||||||
@@ -279,9 +340,9 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
item.setAverageOrderValue(m.salesOrderCount() > 0
|
item.setAverageOrderValue(m.salesOrderCount() > 0
|
||||||
? sales.divide(BigDecimal.valueOf(m.salesOrderCount()), 2, RoundingMode.HALF_UP)
|
? sales.divide(BigDecimal.valueOf(m.salesOrderCount()), 2, RoundingMode.HALF_UP)
|
||||||
: BigDecimal.ZERO);
|
: BigDecimal.ZERO);
|
||||||
item.setProductCost(nz(m.productCost()).setScale(2, RoundingMode.HALF_UP));
|
item.setProductCost(BiFinanceKpiAssembler.nz(m.productCost()).setScale(2, RoundingMode.HALF_UP));
|
||||||
item.setShippingCost(nz(m.freightCost()).setScale(2, RoundingMode.HALF_UP));
|
item.setShippingCost(BiFinanceKpiAssembler.nz(m.freightCost()).setScale(2, RoundingMode.HALF_UP));
|
||||||
item.setOtherCost(nz(m.otherCost()).setScale(2, RoundingMode.HALF_UP));
|
item.setOtherCost(BiFinanceKpiAssembler.nz(m.otherCost()).setScale(2, RoundingMode.HALF_UP));
|
||||||
item.setOrderCost(cost.setScale(2, RoundingMode.HALF_UP));
|
item.setOrderCost(cost.setScale(2, RoundingMode.HALF_UP));
|
||||||
item.setRefundAmount(refund.setScale(2, RoundingMode.HALF_UP));
|
item.setRefundAmount(refund.setScale(2, RoundingMode.HALF_UP));
|
||||||
item.setPromotionFee(sharePromo.setScale(2, RoundingMode.HALF_UP));
|
item.setPromotionFee(sharePromo.setScale(2, RoundingMode.HALF_UP));
|
||||||
@@ -297,22 +358,32 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
Comparator.nullsFirst(BigDecimal::compareTo)).reversed());
|
Comparator.nullsFirst(BigDecimal::compareTo)).reversed());
|
||||||
|
|
||||||
ProductOverviewVO.SpecSummaryTotal total = new ProductOverviewVO.SpecSummaryTotal();
|
ProductOverviewVO.SpecSummaryTotal total = new ProductOverviewVO.SpecSummaryTotal();
|
||||||
total.setSalesAmount(list.stream().map(i -> nz(i.getSalesAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
total.setSalesAmount(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getSalesAmount()))
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
total.setOrderCount(list.stream().mapToInt(i -> i.getOrderCount() != null ? i.getOrderCount() : 0).sum());
|
total.setOrderCount(list.stream().mapToInt(i -> i.getOrderCount() != null ? i.getOrderCount() : 0).sum());
|
||||||
total.setQuantity(list.stream().mapToInt(i -> i.getQuantity() != null ? i.getQuantity() : 0).sum());
|
total.setQuantity(list.stream().mapToInt(i -> i.getQuantity() != null ? i.getQuantity() : 0).sum());
|
||||||
total.setProductCost(list.stream().map(i -> nz(i.getProductCost())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
total.setProductCost(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getProductCost()))
|
||||||
total.setShippingCost(list.stream().map(i -> nz(i.getShippingCost())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
total.setOtherCost(list.stream().map(i -> nz(i.getOtherCost())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
total.setShippingCost(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getShippingCost()))
|
||||||
total.setOrderCost(list.stream().map(i -> nz(i.getOrderCost())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
total.setRefundAmount(list.stream().map(i -> nz(i.getRefundAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
total.setOtherCost(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getOtherCost()))
|
||||||
total.setPromotionFee(list.stream().map(i -> nz(i.getPromotionFee())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
|
total.setOrderCost(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getOrderCost()))
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
|
total.setRefundAmount(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getRefundAmount()))
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
|
total.setPromotionFee(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getPromotionFee()))
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
total.setFeeRatio(total.getSalesAmount().compareTo(BigDecimal.ZERO) > 0
|
total.setFeeRatio(total.getSalesAmount().compareTo(BigDecimal.ZERO) > 0
|
||||||
? total.getPromotionFee().divide(total.getSalesAmount(), 4, RoundingMode.HALF_UP)
|
? total.getPromotionFee().divide(total.getSalesAmount(), 4, RoundingMode.HALF_UP)
|
||||||
: BigDecimal.ZERO);
|
: BigDecimal.ZERO);
|
||||||
total.setProfitBeforeTax(list.stream().map(i -> nz(i.getProfitBeforeTax())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
total.setProfitBeforeTax(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getProfitBeforeTax()))
|
||||||
total.setSalesTaxAmount(list.stream().map(i -> nz(i.getSalesTaxAmount())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
|
total.setSalesTaxAmount(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getSalesTaxAmount()))
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
total.setRoi(roi(total.getSalesAmount(), total.getPromotionFee()));
|
total.setRoi(roi(total.getSalesAmount(), total.getPromotionFee()));
|
||||||
total.setProfitAfterTax(list.stream().map(i -> nz(i.getProfitAfterTax())).reduce(BigDecimal.ZERO, BigDecimal::add));
|
total.setProfitAfterTax(list.stream().map(i -> BiFinanceKpiAssembler.nz(i.getProfitAfterTax()))
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||||
|
|
||||||
ProductOverviewVO.SpecSummary summary = new ProductOverviewVO.SpecSummary();
|
ProductOverviewVO.SpecSummary summary = new ProductOverviewVO.SpecSummary();
|
||||||
summary.setList(list);
|
summary.setList(list);
|
||||||
@@ -343,29 +414,6 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProductOverviewVO.TrendData buildTrend(
|
|
||||||
LocalDate start, LocalDate end,
|
|
||||||
Map<LocalDate, OverviewAggRows.DailyRow> daily,
|
|
||||||
boolean sales) {
|
|
||||||
List<ProductOverviewVO.TrendDataItem> items = new ArrayList<>();
|
|
||||||
BigDecimal total = BigDecimal.ZERO;
|
|
||||||
for (LocalDate d = start; !d.isAfter(end); d = d.plusDays(1)) {
|
|
||||||
OverviewAggRows.DailyRow row = daily.get(d);
|
|
||||||
BigDecimal value = sales
|
|
||||||
? (row != null ? nz(row.getSalesAmount()) : BigDecimal.ZERO)
|
|
||||||
: BigDecimal.valueOf(row != null && row.getOrderCount() != null ? row.getOrderCount() : 0L);
|
|
||||||
ProductOverviewVO.TrendDataItem item = new ProductOverviewVO.TrendDataItem();
|
|
||||||
item.setDate(d);
|
|
||||||
item.setValue(value);
|
|
||||||
items.add(item);
|
|
||||||
total = total.add(value);
|
|
||||||
}
|
|
||||||
ProductOverviewVO.TrendData trend = new ProductOverviewVO.TrendData();
|
|
||||||
trend.setTotal(total);
|
|
||||||
trend.setDailyDataList(items);
|
|
||||||
return trend;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CompanyOverviewVO.CategorySummary findProductRow(
|
private static CompanyOverviewVO.CategorySummary findProductRow(
|
||||||
CompanyOverviewVO.CategoryOverview table, Long productId) {
|
CompanyOverviewVO.CategoryOverview table, Long productId) {
|
||||||
if (table == null || table.getCategories() == null || productId == null) {
|
if (table == null || table.getCategories() == null || productId == null) {
|
||||||
@@ -377,53 +425,24 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CompanyOverviewVO.WorkbenchTableBundle emptyTables() {
|
|
||||||
CompanyOverviewVO.WorkbenchTableBundle b = new CompanyOverviewVO.WorkbenchTableBundle();
|
|
||||||
CompanyOverviewVO.CategoryOverview empty = new CompanyOverviewVO.CategoryOverview();
|
|
||||||
empty.setCategories(List.of());
|
|
||||||
b.setProductTable(empty);
|
|
||||||
b.setCategoryTable(empty);
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BigDecimal sumSales(List<BiOrderStatDailyProductDoc> docs) {
|
|
||||||
return docs.stream()
|
|
||||||
.map(d -> nz(d.getDealAmount()).subtract(nz(d.getRefundAmount())))
|
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static BigDecimal sumCost(List<BiOrderStatDailyProductDoc> docs) {
|
|
||||||
return docs.stream()
|
|
||||||
.map(d -> nz(d.getProductCost()).add(nz(d.getFreightCost())).add(nz(d.getOtherCost())))
|
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int sumOrders(List<BiOrderStatDailyProductDoc> docs) {
|
|
||||||
return docs.stream().mapToInt(d ->
|
|
||||||
nzInt(d.getDealOrderCount()) - nzInt(d.getRefundOrderCount())).sum();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 税额 = 净销售额 × 税率 */
|
|
||||||
private static BigDecimal salesTaxOnNet(BigDecimal sales, BigDecimal taxRate) {
|
private static BigDecimal salesTaxOnNet(BigDecimal sales, BigDecimal taxRate) {
|
||||||
BigDecimal base = nz(sales);
|
BigDecimal base = BiFinanceKpiAssembler.nz(sales);
|
||||||
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
base = BigDecimal.ZERO;
|
base = BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
return base.multiply(taxRate != null ? taxRate : DEFAULT_TAX_RATE).setScale(2, RoundingMode.HALF_UP);
|
return base.multiply(taxRate != null ? taxRate : DEFAULT_TAX_RATE)
|
||||||
}
|
.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
private static int nzInt(Integer v) {
|
|
||||||
return v != null ? v : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BigDecimal roi(BigDecimal netSales, BigDecimal promo) {
|
private static BigDecimal roi(BigDecimal netSales, BigDecimal promo) {
|
||||||
if (promo == null || promo.compareTo(BigDecimal.ZERO) <= 0) {
|
if (promo == null || promo.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
return nz(netSales).divide(promo, 4, RoundingMode.HALF_UP);
|
return BiFinanceKpiAssembler.nz(netSales).divide(promo, 4, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BigDecimal nz(BigDecimal v) {
|
private record PeriodBundle(List<Long> shopIds,
|
||||||
return v != null ? v : BigDecimal.ZERO;
|
BiFinanceKpiAssembler.Totals totals,
|
||||||
|
List<OverviewAggRows.DailyRow> dailyRows) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+319
@@ -0,0 +1,319 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.bi.workbench.support;
|
||||||
|
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.agg.OverviewAggRows;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.vo.CompanyOverviewVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 经营财务 KPI / 趋势组装:工作台与商品概览共用,保证口径一致。
|
||||||
|
*/
|
||||||
|
public final class BiFinanceKpiAssembler {
|
||||||
|
|
||||||
|
private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04");
|
||||||
|
private static final DateTimeFormatter TREND_DATE_FMT = DateTimeFormatter.ISO_LOCAL_DATE;
|
||||||
|
|
||||||
|
private BiFinanceKpiAssembler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单时间段财务 KPI 总量。
|
||||||
|
*/
|
||||||
|
public 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,
|
||||||
|
int salesQuantitySum,
|
||||||
|
BigDecimal totalDealAmount,
|
||||||
|
int dealOrderCount,
|
||||||
|
int dealQuantitySum,
|
||||||
|
BigDecimal averageOrderValue,
|
||||||
|
BigDecimal dealAverageOrderValue,
|
||||||
|
BigDecimal salesPiecePrice,
|
||||||
|
BigDecimal dealPiecePrice) {
|
||||||
|
public static Totals empty() {
|
||||||
|
return buildTotals(BigDecimal.ZERO, BigDecimal.ZERO,
|
||||||
|
BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO,
|
||||||
|
BigDecimal.ZERO, BigDecimal.ZERO, DEFAULT_TAX_RATE,
|
||||||
|
0, 0, BigDecimal.ZERO, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Totals buildTotals(BigDecimal sales, BigDecimal refund,
|
||||||
|
BigDecimal pc, BigDecimal fc, BigDecimal oc,
|
||||||
|
BigDecimal promotion, BigDecimal brush, BigDecimal taxRate,
|
||||||
|
int orderCount, int salesQuantitySum,
|
||||||
|
BigDecimal totalDealAmount, int dealOrderCount, int dealQuantitySum) {
|
||||||
|
BigDecimal s = nz(sales);
|
||||||
|
BigDecimal cost = nz(pc).add(nz(fc)).add(nz(oc));
|
||||||
|
BigDecimal promo = nz(promotion);
|
||||||
|
BigDecimal brushFee = nz(brush);
|
||||||
|
BigDecimal deal = nz(totalDealAmount);
|
||||||
|
BigDecimal gross = s.subtract(cost);
|
||||||
|
BigDecimal pbt = gross.subtract(promo).subtract(brushFee);
|
||||||
|
BigDecimal tax = salesTaxOnSales(s, taxRate);
|
||||||
|
BigDecimal aov = orderCount > 0
|
||||||
|
? s.divide(BigDecimal.valueOf(orderCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
BigDecimal dealAov = dealOrderCount > 0
|
||||||
|
? deal.divide(BigDecimal.valueOf(dealOrderCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
BigDecimal salesPiecePrice = salesQuantitySum > 0
|
||||||
|
? s.divide(BigDecimal.valueOf(salesQuantitySum), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
BigDecimal dealPiecePrice = dealQuantitySum > 0
|
||||||
|
? deal.divide(BigDecimal.valueOf(dealQuantitySum), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
return new Totals(s, nz(refund), cost, nz(pc), nz(fc), nz(oc), promo, brushFee, tax,
|
||||||
|
gross, pbt.subtract(tax),
|
||||||
|
orderCount, salesQuantitySum, deal, dealOrderCount, dealQuantitySum,
|
||||||
|
aov, dealAov, salesPiecePrice, dealPiecePrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 从经营汇总表商品/品类行构造 Totals(税按税率重算,与工作台一致)。 */
|
||||||
|
public static Totals fromCategorySummary(CompanyOverviewVO.CategorySummary row, BigDecimal taxRate) {
|
||||||
|
if (row == null) {
|
||||||
|
return Totals.empty();
|
||||||
|
}
|
||||||
|
return buildTotals(
|
||||||
|
nz(row.getSalesAmount()),
|
||||||
|
nz(row.getRefundAmount()),
|
||||||
|
nz(row.getProductCost()),
|
||||||
|
nz(row.getShippingCost()),
|
||||||
|
nz(row.getOtherCost()),
|
||||||
|
nz(row.getTotalPromotionFee()),
|
||||||
|
nz(row.getBrushFee()),
|
||||||
|
taxRate,
|
||||||
|
row.getSalesOrderCount() != null ? row.getSalesOrderCount() : 0,
|
||||||
|
row.getSalesQuantitySum() != null ? row.getSalesQuantitySum() : 0,
|
||||||
|
nz(row.getDealAmount()),
|
||||||
|
row.getDealOrderCount() != null ? row.getDealOrderCount() : 0,
|
||||||
|
row.getDealQuantitySum() != null ? row.getDealQuantitySum() : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<WorkbenchKpiItemVO> buildKpis(Totals cur, Totals prev, Totals yoy,
|
||||||
|
LocalDate start, LocalDate end, BigDecimal taxRate) {
|
||||||
|
int days = (int) (end.toEpochDay() - start.toEpochDay() + 1);
|
||||||
|
Totals c = cur != null ? cur : Totals.empty();
|
||||||
|
Totals p = prev != null ? prev : Totals.empty();
|
||||||
|
Totals y = yoy != null ? yoy : Totals.empty();
|
||||||
|
|
||||||
|
BigDecimal grossMarginPct = safePct(c.grossOrder(), c.totalSales());
|
||||||
|
BigDecimal netMarginPct = safePct(c.netProfit(), c.totalSales());
|
||||||
|
BigDecimal refundRate = safePct(c.totalRefund(), c.totalSales());
|
||||||
|
BigDecimal costRate = safePct(c.totalCost(), c.totalSales());
|
||||||
|
BigDecimal roi = c.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||||
|
? c.totalSales().divide(c.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
BigDecimal yoyRoi = y.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||||
|
? y.totalSales().divide(y.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
BigDecimal prevRoi = p.promotion().compareTo(BigDecimal.ZERO) > 0
|
||||||
|
? p.totalSales().divide(p.promotion(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||||
|
|
||||||
|
BigDecimal avgDailySalesOrders = days > 0
|
||||||
|
? BigDecimal.valueOf(c.orderCount()).divide(BigDecimal.valueOf(days), 1, RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
BigDecimal avgDailyDealOrders = days > 0
|
||||||
|
? BigDecimal.valueOf(c.dealOrderCount()).divide(BigDecimal.valueOf(days), 1, RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
|
||||||
|
List<WorkbenchKpiItemVO> list = new ArrayList<>();
|
||||||
|
list.add(kpi("成交金额", yuan2(c.totalDealAmount()), "元", c.totalDealAmount(), p.totalDealAmount(), y.totalDealAmount(),
|
||||||
|
"成交状态实收", c.totalDealAmount(), true));
|
||||||
|
list.add(kpiCount("成交单量", c.dealOrderCount(), p.dealOrderCount(), y.dealOrderCount(), "单",
|
||||||
|
"日均 " + avgDailyDealOrders.stripTrailingZeros().toPlainString() + " 单"));
|
||||||
|
list.add(kpiCount("成交销量", c.dealQuantitySum(), p.dealQuantitySum(), y.dealQuantitySum(), "件", "成交状态件数"));
|
||||||
|
list.add(kpi("成交客单价", yuan2(c.dealAverageOrderValue()), "元",
|
||||||
|
c.dealAverageOrderValue(), p.dealAverageOrderValue(), y.dealAverageOrderValue(),
|
||||||
|
"成交金额/成交单量", c.dealAverageOrderValue(), false));
|
||||||
|
|
||||||
|
list.add(kpi("净销售额", yuan2(c.totalSales()), "元", c.totalSales(), p.totalSales(), y.totalSales(),
|
||||||
|
"成交−退款", c.totalSales(), true));
|
||||||
|
list.add(kpiCount("净销售单量", c.orderCount(), p.orderCount(), y.orderCount(), "单",
|
||||||
|
"日均 " + avgDailySalesOrders.stripTrailingZeros().toPlainString() + " 单"));
|
||||||
|
list.add(kpiCount("净销量", c.salesQuantitySum(), p.salesQuantitySum(), y.salesQuantitySum(), "件",
|
||||||
|
"成交件数−退款件数"));
|
||||||
|
list.add(kpi("净销售客单价", yuan2(c.averageOrderValue()), "元",
|
||||||
|
c.averageOrderValue(), p.averageOrderValue(), y.averageOrderValue(),
|
||||||
|
"净销售额/净销售单量", c.averageOrderValue(), false));
|
||||||
|
|
||||||
|
list.add(kpi("退款额", yuan2(c.totalRefund()), "元", c.totalRefund(), p.totalRefund(), y.totalRefund(),
|
||||||
|
"计入退款状态", c.totalRefund(), true));
|
||||||
|
list.add(kpi("退款率", refundRate.setScale(2, RoundingMode.HALF_UP), "%",
|
||||||
|
refundRate, safePct(p.totalRefund(), p.totalSales()), safePct(y.totalRefund(), y.totalSales()),
|
||||||
|
"退款/净销售额", null, null));
|
||||||
|
|
||||||
|
list.add(kpi("订单成本", yuan2(c.totalCost()), "元", c.totalCost(), p.totalCost(), y.totalCost(),
|
||||||
|
"成本率 " + costRate.stripTrailingZeros().toPlainString() + "%", c.totalCost(), true));
|
||||||
|
list.add(kpi("商品成本", yuan2(c.productCost()), "元", c.productCost(), p.productCost(), y.productCost(),
|
||||||
|
null, c.productCost(), true));
|
||||||
|
list.add(kpi("运费成本", yuan2(c.freightCost()), "元", c.freightCost(), p.freightCost(), y.freightCost(),
|
||||||
|
null, c.freightCost(), true));
|
||||||
|
list.add(kpi("其他成本", yuan2(c.otherCost()), "元", c.otherCost(), p.otherCost(), y.otherCost(),
|
||||||
|
null, c.otherCost(), true));
|
||||||
|
|
||||||
|
list.add(kpi("毛利润", yuan2(c.grossOrder()), "元", c.grossOrder(), p.grossOrder(), y.grossOrder(),
|
||||||
|
"毛利率 " + grossMarginPct.stripTrailingZeros().toPlainString() + "%", c.grossOrder(), true));
|
||||||
|
list.add(kpi("推广费", yuan2(c.promotion()), "元", c.promotion(), p.promotion(), y.promotion(),
|
||||||
|
null, c.promotion(), true));
|
||||||
|
list.add(kpi("刷单费", yuan2(c.brush()), "元", c.brush(), p.brush(), y.brush(),
|
||||||
|
null, c.brush(), true));
|
||||||
|
BigDecimal rate = taxRate != null ? taxRate : DEFAULT_TAX_RATE;
|
||||||
|
list.add(kpi("税额", yuan2(c.tax()), "元", c.tax(), p.tax(), y.tax(),
|
||||||
|
"税率 " + rate.multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%",
|
||||||
|
c.tax(), true));
|
||||||
|
list.add(kpi("净利润", yuan2(c.netProfit()), "元", c.netProfit(), p.netProfit(), y.netProfit(),
|
||||||
|
"净利率 " + netMarginPct.stripTrailingZeros().toPlainString() + "%",
|
||||||
|
c.netProfit(), true));
|
||||||
|
|
||||||
|
list.add(kpi("广告ROI", roi.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros(), ":1", roi, prevRoi, yoyRoi,
|
||||||
|
"净销售额/推广费", null, null));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<WorkbenchTrendPointVO> buildTrendFromDaily(
|
||||||
|
List<OverviewAggRows.DailyRow> dailyRows,
|
||||||
|
LocalDate start, LocalDate end, Totals periodTotals) {
|
||||||
|
Map<LocalDate, OverviewAggRows.DailyRow> byDay = new HashMap<>();
|
||||||
|
if (dailyRows != null) {
|
||||||
|
for (OverviewAggRows.DailyRow row : dailyRows) {
|
||||||
|
if (row.getStatDate() != null) {
|
||||||
|
byDay.put(row.getStatDate(), row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Totals totals = periodTotals != null ? periodTotals : Totals.empty();
|
||||||
|
BigDecimal salesTotal = totals.totalSales();
|
||||||
|
List<WorkbenchTrendPointVO> list = new ArrayList<>();
|
||||||
|
for (LocalDate d = start; !d.isAfter(end); d = d.plusDays(1)) {
|
||||||
|
OverviewAggRows.DailyRow row = byDay.get(d);
|
||||||
|
BigDecimal sales = row != null ? nz(row.getSalesAmount()) : BigDecimal.ZERO;
|
||||||
|
BigDecimal deal = row != null ? nz(row.getDealAmount()) : BigDecimal.ZERO;
|
||||||
|
int salesOrders = row != null && row.getOrderCount() != null ? row.getOrderCount().intValue() : 0;
|
||||||
|
int dealOrders = row != null && row.getDealOrderCount() != null ? row.getDealOrderCount().intValue() : 0;
|
||||||
|
BigDecimal refund = row != null ? nz(row.getRefundAmount()) : BigDecimal.ZERO;
|
||||||
|
BigDecimal cost = row != null
|
||||||
|
? nz(row.getProductCost()).add(nz(row.getFreightCost())).add(nz(row.getOtherCost()))
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
BigDecimal gross = sales.subtract(cost);
|
||||||
|
BigDecimal promoB = allocShare(sales, salesTotal, totals.promotion());
|
||||||
|
BigDecimal brushB = allocShare(sales, salesTotal, totals.brush());
|
||||||
|
BigDecimal taxB = salesTotal.compareTo(BigDecimal.ZERO) <= 0
|
||||||
|
? BigDecimal.ZERO
|
||||||
|
: allocShare(sales, salesTotal.max(BigDecimal.ONE), totals.tax());
|
||||||
|
list.add(WorkbenchTrendPointVO.builder()
|
||||||
|
.date(d.format(TREND_DATE_FMT))
|
||||||
|
.dealYuan(yuan2(deal))
|
||||||
|
.dealOrderCount(dealOrders)
|
||||||
|
.salesYuan(yuan2(sales))
|
||||||
|
.salesOrderCount(salesOrders)
|
||||||
|
.profitYuan(yuan2(gross))
|
||||||
|
.netProfitYuan(yuan2(gross.subtract(promoB).subtract(brushB).subtract(taxB)))
|
||||||
|
.refundYuan(yuan2(refund))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDate[] lastMonthSameSpan(LocalDate start, LocalDate end) {
|
||||||
|
return new LocalDate[]{start.minusMonths(1), end.minusMonths(1)};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDate[] yoySameSpan(LocalDate start, LocalDate end) {
|
||||||
|
return new LocalDate[]{start.minusYears(1), end.minusYears(1)};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BigDecimal yuan2(BigDecimal yuan) {
|
||||||
|
if (yuan == null) {
|
||||||
|
return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
return yuan.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BigDecimal nz(BigDecimal v) {
|
||||||
|
return v != null ? v : BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BigDecimal salesTaxOnSales(BigDecimal salesAmount, BigDecimal rate) {
|
||||||
|
BigDecimal sales = salesAmount != null ? salesAmount : BigDecimal.ZERO;
|
||||||
|
if (sales.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
sales = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
BigDecimal r = rate != null ? rate : DEFAULT_TAX_RATE;
|
||||||
|
return sales.multiply(r).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WorkbenchKpiItemVO kpiCount(String label, int cur, int prev, int yoy, String unit, String sub) {
|
||||||
|
return kpi(label, BigDecimal.valueOf(cur), unit,
|
||||||
|
BigDecimal.valueOf(cur), BigDecimal.valueOf(prev), BigDecimal.valueOf(yoy),
|
||||||
|
sub, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WorkbenchKpiItemVO kpi(String label, BigDecimal value, String unit,
|
||||||
|
BigDecimal curAmt, BigDecimal prevAmt, BigDecimal yoyAmt, String sub,
|
||||||
|
BigDecimal amountYuan, Boolean preferWanDisplay) {
|
||||||
|
BigDecimal change = pctChange(curAmt, prevAmt);
|
||||||
|
boolean up = curAmt.compareTo(prevAmt) >= 0;
|
||||||
|
BigDecimal yoyPct = pctChange(curAmt, yoyAmt);
|
||||||
|
boolean yoyUpFlag = curAmt.compareTo(yoyAmt) >= 0;
|
||||||
|
var b = WorkbenchKpiItemVO.builder()
|
||||||
|
.label(label)
|
||||||
|
.value(value)
|
||||||
|
.unit(unit)
|
||||||
|
.changePct(change)
|
||||||
|
.up(up)
|
||||||
|
.yoyChangePct(yoyPct)
|
||||||
|
.yoyUp(yoyUpFlag)
|
||||||
|
.sub(sub);
|
||||||
|
if (amountYuan != null) {
|
||||||
|
b.amountYuan(yuan2(amountYuan));
|
||||||
|
}
|
||||||
|
if (preferWanDisplay != null) {
|
||||||
|
b.preferWanDisplay(preferWanDisplay);
|
||||||
|
}
|
||||||
|
return b.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,155 +1,127 @@
|
|||||||
export namespace ProductOverviewVO {
|
export namespace ProductOverviewVO {
|
||||||
/** 趋势数据项 */
|
/** 与工作台经营 KPI 同形 */
|
||||||
|
export interface KpiItem {
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
unit: string;
|
||||||
|
changePct?: number;
|
||||||
|
up?: boolean;
|
||||||
|
yoyChangePct?: number | null;
|
||||||
|
yoyUp?: boolean | null;
|
||||||
|
sub?: string;
|
||||||
|
amountYuan?: number | null;
|
||||||
|
preferWanDisplay?: boolean | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TrendPoint {
|
||||||
|
date: string;
|
||||||
|
dealYuan?: number;
|
||||||
|
dealOrderCount?: number;
|
||||||
|
salesYuan?: number;
|
||||||
|
salesOrderCount?: number;
|
||||||
|
profitYuan?: number;
|
||||||
|
netProfitYuan?: number;
|
||||||
|
refundYuan?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PieSlice {
|
||||||
|
name: string;
|
||||||
|
value?: number;
|
||||||
|
pct?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated 旧趋势结构,优先用 dealTrend */
|
||||||
export interface TrendDataItem {
|
export interface TrendDataItem {
|
||||||
/** 日期 */
|
|
||||||
date: string;
|
date: string;
|
||||||
/** 对应的值 */
|
|
||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 趋势数据 */
|
/** @deprecated */
|
||||||
export interface TrendData {
|
export interface TrendData {
|
||||||
/** 时间范围的总值 */
|
|
||||||
total: number;
|
total: number;
|
||||||
/** 每日数据列表 */
|
|
||||||
dailyDataList: TrendDataItem[];
|
dailyDataList: TrendDataItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SKU 销量排名项 */
|
|
||||||
export interface SkuSalesRankItem {
|
export interface SkuSalesRankItem {
|
||||||
/** SKU ID */
|
|
||||||
skuId?: number;
|
skuId?: number;
|
||||||
/** SKU 名称 */
|
|
||||||
skuName?: string;
|
skuName?: string;
|
||||||
/** SKU 编码 */
|
|
||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
/** 订单量 */
|
|
||||||
orderCount?: number;
|
orderCount?: number;
|
||||||
/** 销售额 */
|
|
||||||
salesAmount?: number;
|
salesAmount?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SKU 销售明细项 */
|
|
||||||
export interface SkuSummaryItem {
|
export interface SkuSummaryItem {
|
||||||
/** SKU ID */
|
|
||||||
skuId: number;
|
skuId: number;
|
||||||
/** SKU 名称 */
|
|
||||||
skuName: string;
|
skuName: string;
|
||||||
/** SKU 编码 */
|
|
||||||
skuCode: string;
|
skuCode: string;
|
||||||
/** 销售额 */
|
|
||||||
salesAmount: number;
|
salesAmount: number;
|
||||||
/** 订单量 */
|
|
||||||
orderCount: number;
|
orderCount: number;
|
||||||
/** 总件数 */
|
|
||||||
quantity: number;
|
quantity: number;
|
||||||
/** 客单价 */
|
|
||||||
averageOrderValue: number;
|
averageOrderValue: number;
|
||||||
/** 商品成本 */
|
|
||||||
productCost: number;
|
productCost: number;
|
||||||
/** 运费 */
|
|
||||||
shippingCost: number;
|
shippingCost: number;
|
||||||
/** 其他成本 */
|
|
||||||
otherCost: number;
|
otherCost: number;
|
||||||
/** 订单成本(商品成本+运费+其他成本,不含推广费、刷单费) */
|
|
||||||
orderCost?: number;
|
orderCost?: number;
|
||||||
/** 退款金额 */
|
|
||||||
refundAmount: number;
|
refundAmount: number;
|
||||||
/** 推广费 */
|
|
||||||
promotionFee: number;
|
promotionFee: number;
|
||||||
/** 费比 */
|
|
||||||
feeRatio: number;
|
feeRatio: number;
|
||||||
/** 税前盈亏 */
|
|
||||||
profitBeforeTax: number;
|
profitBeforeTax: number;
|
||||||
/** 销售额×税率的税额 */
|
|
||||||
salesTaxAmount: number;
|
salesTaxAmount: number;
|
||||||
/** ROI */
|
|
||||||
roi: number;
|
roi: number;
|
||||||
/** 税后盈亏 */
|
|
||||||
profitAfterTax: number;
|
profitAfterTax: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SKU 销售汇总合计行 */
|
|
||||||
export interface SkuSummaryTotal {
|
export interface SkuSummaryTotal {
|
||||||
/** 销售额 */
|
|
||||||
salesAmount: number;
|
salesAmount: number;
|
||||||
/** 订单量 */
|
|
||||||
orderCount: number;
|
orderCount: number;
|
||||||
/** 总件数 */
|
|
||||||
quantity: number;
|
quantity: number;
|
||||||
/** 客单价(前端汇总或后端可选返回) */
|
|
||||||
averageOrderValue?: number;
|
averageOrderValue?: number;
|
||||||
/** 商品成本 */
|
|
||||||
productCost: number;
|
productCost: number;
|
||||||
/** 运费 */
|
|
||||||
shippingCost: number;
|
shippingCost: number;
|
||||||
/** 其他成本 */
|
|
||||||
otherCost: number;
|
otherCost: number;
|
||||||
/** 订单成本(商品成本+运费+其他成本,不含推广费、刷单费) */
|
|
||||||
orderCost?: number;
|
orderCost?: number;
|
||||||
/** 退款金额 */
|
|
||||||
refundAmount: number;
|
refundAmount: number;
|
||||||
/** 推广费 */
|
|
||||||
promotionFee: number;
|
promotionFee: number;
|
||||||
/** 费比 */
|
|
||||||
feeRatio: number;
|
feeRatio: number;
|
||||||
/** 税前盈亏 */
|
|
||||||
profitBeforeTax: number;
|
profitBeforeTax: number;
|
||||||
/** 税额 */
|
|
||||||
salesTaxAmount: number;
|
salesTaxAmount: number;
|
||||||
/** ROI */
|
|
||||||
roi: number;
|
roi: number;
|
||||||
/** 税后盈亏 */
|
|
||||||
profitAfterTax: number;
|
profitAfterTax: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SKU 销售汇总 */
|
|
||||||
export interface SkuSummary {
|
export interface SkuSummary {
|
||||||
/** 各 SKU 明细列表 */
|
|
||||||
list: SkuSummaryItem[];
|
list: SkuSummaryItem[];
|
||||||
/** 合计行 */
|
|
||||||
total: SkuSummaryTotal;
|
total: SkuSummaryTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 商品概览响应 */
|
|
||||||
export interface Overview {
|
export interface Overview {
|
||||||
/** 商品 ID */
|
|
||||||
productId: number;
|
productId: number;
|
||||||
/** 商品名称 */
|
|
||||||
productName: string;
|
productName: string;
|
||||||
|
|
||||||
// ========== KPI 汇总指标 ==========
|
/** 经营 KPI(与工作台同口径) */
|
||||||
/** 总销售额 */
|
kpis?: KpiItem[];
|
||||||
totalSalesAmount: number;
|
dealTrend?: TrendPoint[];
|
||||||
/** 较上月同期增长百分比 */
|
skuSalesShare?: PieSlice[];
|
||||||
monthOverMonthGrowth: number;
|
momCompareDateStart?: string | null;
|
||||||
/** 总订单量 */
|
momCompareDateEnd?: string | null;
|
||||||
totalOrderCount: number;
|
yoyCompareDateStart?: string | null;
|
||||||
/** 平均费比 */
|
yoyCompareDateEnd?: string | null;
|
||||||
averageFeeRatio: number;
|
|
||||||
/** 总净利润(税后) */
|
|
||||||
totalNetProfitAfterTax: number;
|
|
||||||
/** 扣除总税额 */
|
|
||||||
totalTaxAmount: number;
|
|
||||||
/** 销量目标达成率 */
|
|
||||||
orderCountAchievementRate: number;
|
|
||||||
/** 销售额目标达成率 */
|
|
||||||
salesAmountAchievementRate: number;
|
|
||||||
/** 汇总 ROI */
|
|
||||||
totalROI: number;
|
|
||||||
|
|
||||||
// ========== 各 SKU 销量 Top10 ==========
|
totalSalesAmount?: number;
|
||||||
/** 各 SKU 销量 Top10(后端字段名仍为 specSalesTop10) */
|
monthOverMonthGrowth?: number;
|
||||||
specSalesTop10: SkuSalesRankItem[];
|
totalOrderCount?: number;
|
||||||
|
averageFeeRatio?: number;
|
||||||
|
totalNetProfitAfterTax?: number;
|
||||||
|
totalTaxAmount?: number;
|
||||||
|
orderCountAchievementRate?: number;
|
||||||
|
salesAmountAchievementRate?: number;
|
||||||
|
totalROI?: number;
|
||||||
|
|
||||||
// ========== 趋势数据 ==========
|
specSalesTop10?: SkuSalesRankItem[];
|
||||||
/** 销售额趋势分析 */
|
/** @deprecated */
|
||||||
salesAmountTrend: TrendData;
|
salesAmountTrend?: TrendData;
|
||||||
/** 单量趋势分析 */
|
/** @deprecated */
|
||||||
orderCountTrend: TrendData;
|
orderCountTrend?: TrendData;
|
||||||
|
specSummaries?: SkuSummary;
|
||||||
// ========== SKU 销售汇总 ==========
|
|
||||||
/** SKU 销售汇总(后端字段名仍为 specSummaries) */
|
|
||||||
specSummaries: SkuSummary;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-6
@@ -11,9 +11,23 @@ import { FINANCE_PANEL_SHELL } from '../constants/finance-ui';
|
|||||||
|
|
||||||
defineOptions({ name: 'WorkbenchFinancePlatformSalesPieChart' });
|
defineOptions({ name: 'WorkbenchFinancePlatformSalesPieChart' });
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = withDefaults(
|
||||||
platformSalesShare: WorkbenchVO.PieSlice[];
|
defineProps<{
|
||||||
}>();
|
platformSalesShare: WorkbenchVO.PieSlice[];
|
||||||
|
/** 面板标题,商品概览可改为「各 SKU 净销售额分布」 */
|
||||||
|
title?: string;
|
||||||
|
subtitle?: string;
|
||||||
|
/** 覆盖面板外壳(商品概览等可传入自身主题 class) */
|
||||||
|
panelClass?: string;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
title: '各平台净销售额分布',
|
||||||
|
subtitle: '占当前筛选条件下净销售额合计的比例',
|
||||||
|
panelClass: undefined,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const shellClass = computed(() => props.panelClass || FINANCE_PANEL_SHELL);
|
||||||
|
|
||||||
const PLATFORM_PIE_COLORS = [
|
const PLATFORM_PIE_COLORS = [
|
||||||
'#3b82f6',
|
'#3b82f6',
|
||||||
@@ -164,17 +178,17 @@ defineExpose({ redraw });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="FINANCE_PANEL_SHELL">
|
<div :class="shellClass">
|
||||||
<div
|
<div
|
||||||
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
||||||
>
|
>
|
||||||
<h3
|
<h3
|
||||||
class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||||
>
|
>
|
||||||
各平台净销售额分布
|
{{ title }}
|
||||||
</h3>
|
</h3>
|
||||||
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
占当前筛选条件下净销售额合计的比例
|
{{ subtitle }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-5 py-4 md:px-6 md:py-5">
|
<div class="px-5 py-4 md:px-6 md:py-5">
|
||||||
|
|||||||
+13
-4
@@ -11,9 +11,18 @@ import { FINANCE_PANEL_SHELL } from '../constants/finance-ui';
|
|||||||
|
|
||||||
defineOptions({ name: 'WorkbenchFinanceTrendChart' });
|
defineOptions({ name: 'WorkbenchFinanceTrendChart' });
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = withDefaults(
|
||||||
trend: WorkbenchVO.TrendPoint[];
|
defineProps<{
|
||||||
}>();
|
trend: WorkbenchVO.TrendPoint[];
|
||||||
|
/** 覆盖面板外壳(商品概览等可传入自身主题 class) */
|
||||||
|
panelClass?: string;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
panelClass: undefined,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const shellClass = computed(() => props.panelClass || FINANCE_PANEL_SHELL);
|
||||||
|
|
||||||
const financeChartRef = ref<EchartsUIType>();
|
const financeChartRef = ref<EchartsUIType>();
|
||||||
const { renderEcharts: renderFinanceTrend } = useEcharts(financeChartRef);
|
const { renderEcharts: renderFinanceTrend } = useEcharts(financeChartRef);
|
||||||
@@ -425,7 +434,7 @@ defineExpose({ redraw });
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="FINANCE_PANEL_SHELL">
|
<div :class="shellClass">
|
||||||
<div
|
<div
|
||||||
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
||||||
>
|
>
|
||||||
|
|||||||
+179
@@ -0,0 +1,179 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import type { ProductOverviewVO } from '#/api/ec/product/overview';
|
||||||
|
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
|
import {
|
||||||
|
PRODUCT_HERO_SHELL,
|
||||||
|
PRODUCT_SPOT_CARD,
|
||||||
|
} from '../constants/product-ui';
|
||||||
|
|
||||||
|
defineOptions({ name: 'ProductOverviewHero' });
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
data: ProductOverviewVO.Overview;
|
||||||
|
dateLabel?: string;
|
||||||
|
shopLabel?: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const IconPackage = createIconifyIcon('lucide:package');
|
||||||
|
const IconWallet = createIconifyIcon('lucide:wallet');
|
||||||
|
const IconBag = createIconifyIcon('lucide:shopping-bag');
|
||||||
|
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
|
||||||
|
const IconRoi = createIconifyIcon('lucide:target');
|
||||||
|
|
||||||
|
function pickKpi(label: string) {
|
||||||
|
return props.data.kpis?.find((k) => k.label === label);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatYuan(v: number | undefined | null) {
|
||||||
|
if (v == null || !Number.isFinite(Number(v))) return '—';
|
||||||
|
return `¥${Number(v).toLocaleString('zh-CN', {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
})}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatNum(v: number | undefined | null, digits = 0) {
|
||||||
|
if (v == null || !Number.isFinite(Number(v))) return '—';
|
||||||
|
return Number(v).toLocaleString('zh-CN', {
|
||||||
|
minimumFractionDigits: digits,
|
||||||
|
maximumFractionDigits: digits,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const spots = computed(() => {
|
||||||
|
const sales = pickKpi('净销售额');
|
||||||
|
const orders = pickKpi('净销售单量');
|
||||||
|
const profit = pickKpi('净利润');
|
||||||
|
const roi = pickKpi('广告ROI');
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
key: 'sales',
|
||||||
|
label: '净销售额',
|
||||||
|
value:
|
||||||
|
sales?.amountYuan != null
|
||||||
|
? formatYuan(sales.amountYuan)
|
||||||
|
: formatYuan(props.data.totalSalesAmount),
|
||||||
|
delta: sales?.changePct,
|
||||||
|
icon: IconWallet,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'orders',
|
||||||
|
label: '净销售单量',
|
||||||
|
value:
|
||||||
|
orders != null
|
||||||
|
? `${formatNum(orders.value)} 单`
|
||||||
|
: `${formatNum(props.data.totalOrderCount)} 单`,
|
||||||
|
delta: orders?.changePct,
|
||||||
|
icon: IconBag,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'profit',
|
||||||
|
label: '净利润',
|
||||||
|
value:
|
||||||
|
profit?.amountYuan != null
|
||||||
|
? formatYuan(profit.amountYuan)
|
||||||
|
: formatYuan(props.data.totalNetProfitAfterTax),
|
||||||
|
delta: profit?.changePct,
|
||||||
|
icon: IconNet,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'roi',
|
||||||
|
label: '广告 ROI',
|
||||||
|
value:
|
||||||
|
roi != null
|
||||||
|
? formatNum(Number(roi.value), 2)
|
||||||
|
: formatNum(props.data.totalROI, 2),
|
||||||
|
delta: roi?.changePct,
|
||||||
|
icon: IconRoi,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
function deltaClass(pct: number | undefined | null) {
|
||||||
|
if (pct == null || !Number.isFinite(Number(pct))) return 'text-slate-400';
|
||||||
|
return Number(pct) >= 0
|
||||||
|
? 'text-emerald-600 dark:text-emerald-400'
|
||||||
|
: 'text-rose-500 dark:text-rose-400';
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDelta(pct: number | undefined | null) {
|
||||||
|
if (pct == null || !Number.isFinite(Number(pct))) return '';
|
||||||
|
const n = Number(pct);
|
||||||
|
return `环比 ${n > 0 ? '+' : ''}${n}%`;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section :class="PRODUCT_HERO_SHELL">
|
||||||
|
<div
|
||||||
|
class="pointer-events-none absolute -right-8 -top-10 size-40 rounded-full bg-teal-200/30 blur-2xl dark:bg-teal-500/10"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="pointer-events-none absolute -bottom-12 left-1/3 size-48 rounded-full bg-cyan-200/25 blur-3xl dark:bg-cyan-500/10"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="relative flex flex-wrap items-start justify-between gap-4">
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="grid size-9 shrink-0 place-items-center rounded-[12px] bg-teal-600 text-white shadow-sm shadow-teal-600/25 dark:bg-teal-500"
|
||||||
|
>
|
||||||
|
<component :is="IconPackage" class="size-4" />
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="rounded-full bg-teal-600/10 px-2 py-0.5 text-[11px] font-semibold text-teal-700 dark:bg-teal-400/10 dark:text-teal-300"
|
||||||
|
>
|
||||||
|
单品诊断
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<h2
|
||||||
|
class="mt-3 max-w-3xl text-xl font-bold tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_96%)] sm:text-2xl"
|
||||||
|
:title="data.productName"
|
||||||
|
>
|
||||||
|
{{ data.productName || '未命名商品' }}
|
||||||
|
</h2>
|
||||||
|
<p class="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
|
<span v-if="dateLabel">统计区间 {{ dateLabel }}</span>
|
||||||
|
<span v-if="shopLabel" class="truncate">店铺:{{ shopLabel }}</span>
|
||||||
|
<span v-else>全渠道店铺汇总</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="relative mt-5 grid grid-cols-2 gap-2.5 lg:grid-cols-4"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="spot in spots"
|
||||||
|
:key="spot.key"
|
||||||
|
:class="PRODUCT_SPOT_CARD"
|
||||||
|
>
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<span class="truncate text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
|
{{ spot.label }}
|
||||||
|
</span>
|
||||||
|
<component
|
||||||
|
:is="spot.icon"
|
||||||
|
class="size-3.5 shrink-0 text-teal-600/80 dark:text-teal-400/80"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mt-1.5 truncate text-lg font-bold tabular-nums tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
|
||||||
|
>
|
||||||
|
{{ spot.value }}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="spot.delta != null"
|
||||||
|
class="mt-1 text-[11px] font-medium tabular-nums"
|
||||||
|
:class="deltaClass(spot.delta)"
|
||||||
|
>
|
||||||
|
{{ formatDelta(spot.delta) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
+95
@@ -0,0 +1,95 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import type { ProductOverviewVO } from '#/api/ec/product/overview';
|
||||||
|
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
|
import { PRODUCT_PANEL_SHELL, PRODUCT_SECTION_LABEL } from '../constants/product-ui';
|
||||||
|
|
||||||
|
defineOptions({ name: 'ProductSkuRankStrip' });
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
items?: ProductOverviewVO.SkuSalesRankItem[] | null;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const rows = computed(() => (props.items ?? []).slice(0, 8));
|
||||||
|
|
||||||
|
const maxOrders = computed(() =>
|
||||||
|
Math.max(1, ...rows.value.map((r) => Number(r.orderCount ?? 0))),
|
||||||
|
);
|
||||||
|
|
||||||
|
function formatAmount(amount: number | undefined) {
|
||||||
|
if (amount == null) return '—';
|
||||||
|
return `¥${amount.toLocaleString('zh-CN', {
|
||||||
|
minimumFractionDigits: 0,
|
||||||
|
maximumFractionDigits: 0,
|
||||||
|
})}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function barWidth(orderCount: number | undefined) {
|
||||||
|
const n = Number(orderCount ?? 0);
|
||||||
|
return `${Math.max(8, Math.round((n / maxOrders.value) * 100))}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rankTone(idx: number) {
|
||||||
|
if (idx === 0) return 'bg-teal-600 text-white';
|
||||||
|
if (idx === 1) return 'bg-teal-500/90 text-white';
|
||||||
|
if (idx === 2) return 'bg-cyan-600 text-white';
|
||||||
|
return 'bg-slate-100 text-slate-600 dark:bg-[hsl(200deg_10%_18%)] dark:text-slate-300';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section v-if="rows.length" :class="PRODUCT_PANEL_SHELL">
|
||||||
|
<div
|
||||||
|
class="flex flex-wrap items-end justify-between gap-2 border-b border-teal-100/80 px-5 pb-3.5 pt-5 md:px-6 dark:border-teal-900/35"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<span :class="PRODUCT_SECTION_LABEL">SKU 结构</span>
|
||||||
|
<h3
|
||||||
|
class="mt-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||||
|
>
|
||||||
|
热销规格速览
|
||||||
|
</h3>
|
||||||
|
<p class="mt-1 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
|
按净销售单量排序,突出本商品规格贡献
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="space-y-2.5 px-5 py-4 md:px-6 md:py-5">
|
||||||
|
<div
|
||||||
|
v-for="(row, idx) in rows"
|
||||||
|
:key="row.skuId ?? `sku-${idx}`"
|
||||||
|
class="grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-[11px] font-bold tabular-nums"
|
||||||
|
:class="rankTone(idx)"
|
||||||
|
>
|
||||||
|
{{ idx + 1 }}
|
||||||
|
</span>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<div class="flex items-baseline justify-between gap-2">
|
||||||
|
<span
|
||||||
|
class="truncate text-sm font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||||
|
:title="row.skuName"
|
||||||
|
>
|
||||||
|
{{ row.skuName || '—' }}
|
||||||
|
</span>
|
||||||
|
<span class="shrink-0 text-xs tabular-nums text-slate-500">
|
||||||
|
{{ row.orderCount?.toLocaleString('zh-CN') ?? 0 }} 单 ·
|
||||||
|
{{ formatAmount(row.salesAmount) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-teal-50 dark:bg-teal-950/50"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="h-full rounded-full bg-gradient-to-r from-teal-500 to-cyan-400 transition-all duration-500"
|
||||||
|
:style="{ width: barWidth(row.orderCount) }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
-227
@@ -1,227 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
|
||||||
|
|
||||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
|
|
||||||
|
|
||||||
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
data: {
|
|
||||||
salesAmountTrend?: {
|
|
||||||
dailyDataList: { date: string; value: number }[];
|
|
||||||
};
|
|
||||||
orderCountTrend?: {
|
|
||||||
dailyDataList: { date: string; value: number }[];
|
|
||||||
};
|
|
||||||
} | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
|
||||||
|
|
||||||
const trendChartRef = ref<EchartsUIType>();
|
|
||||||
const { renderEcharts: renderTrendChart } = useEcharts(trendChartRef);
|
|
||||||
let isUnmounted = false;
|
|
||||||
let renderTimer: null | ReturnType<typeof setTimeout> = null;
|
|
||||||
let darkObserver: MutationObserver | null = null;
|
|
||||||
|
|
||||||
const renderChart = () => {
|
|
||||||
if (!trendChartRef.value || !props.data) return;
|
|
||||||
|
|
||||||
const salesTrend = props.data.salesAmountTrend;
|
|
||||||
const orderTrend = props.data.orderCountTrend;
|
|
||||||
|
|
||||||
if (!salesTrend || !orderTrend) return;
|
|
||||||
const salesList = Array.isArray(salesTrend.dailyDataList)
|
|
||||||
? salesTrend.dailyDataList
|
|
||||||
: [];
|
|
||||||
const orderList = Array.isArray(orderTrend.dailyDataList)
|
|
||||||
? orderTrend.dailyDataList
|
|
||||||
: [];
|
|
||||||
|
|
||||||
if (salesList.length === 0 && orderList.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dates = salesList.map((item) =>
|
|
||||||
dayjs(item.date).format('MM-DD'),
|
|
||||||
);
|
|
||||||
const salesData = salesList.map((item) => item.value);
|
|
||||||
const orderData = orderList.map((item) => item.value);
|
|
||||||
|
|
||||||
const isDark = document.documentElement.classList.contains('dark');
|
|
||||||
try {
|
|
||||||
renderTrendChart({
|
|
||||||
grid: {
|
|
||||||
left: '3%',
|
|
||||||
right: '3%',
|
|
||||||
bottom: '3%',
|
|
||||||
top: '5%',
|
|
||||||
containLabel: true,
|
|
||||||
},
|
|
||||||
tooltip: {
|
|
||||||
trigger: 'axis',
|
|
||||||
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
|
|
||||||
textStyle: {
|
|
||||||
color: isDark ? 'hsl(0deg 0% 95%)' : '#000',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
xAxis: {
|
|
||||||
type: 'category',
|
|
||||||
boundaryGap: false,
|
|
||||||
data: dates,
|
|
||||||
axisLine: {
|
|
||||||
lineStyle: {
|
|
||||||
color: isDark ? 'hsl(240deg 3.7% 22%)' : '#e2e8f0',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
yAxis: [
|
|
||||||
{
|
|
||||||
type: 'value',
|
|
||||||
name: '销售额',
|
|
||||||
nameTextStyle: {
|
|
||||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
|
||||||
},
|
|
||||||
axisLabel: {
|
|
||||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
|
||||||
},
|
|
||||||
splitLine: {
|
|
||||||
lineStyle: {
|
|
||||||
type: 'dashed',
|
|
||||||
color: isDark ? 'hsl(240deg 3.7% 22%)' : undefined,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'value',
|
|
||||||
name: '单量',
|
|
||||||
position: 'right',
|
|
||||||
nameTextStyle: {
|
|
||||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
|
||||||
},
|
|
||||||
axisLabel: {
|
|
||||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
|
||||||
},
|
|
||||||
splitLine: { show: false },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
series: [
|
|
||||||
{
|
|
||||||
name: '销售额',
|
|
||||||
type: 'line',
|
|
||||||
smooth: true,
|
|
||||||
symbol: 'none',
|
|
||||||
lineStyle: { width: 3, color: '#3b82f6' },
|
|
||||||
areaStyle: {
|
|
||||||
color: {
|
|
||||||
type: 'linear',
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
x2: 0,
|
|
||||||
y2: 1,
|
|
||||||
colorStops: [
|
|
||||||
{ offset: 0, color: 'rgba(59, 130, 246, 0.4)' },
|
|
||||||
{ offset: 1, color: 'rgba(59, 130, 246, 0)' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data: salesData,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '日单量',
|
|
||||||
type: 'line',
|
|
||||||
yAxisIndex: 1,
|
|
||||||
smooth: true,
|
|
||||||
symbol: 'none',
|
|
||||||
lineStyle: { width: 3, color: '#10b981' },
|
|
||||||
areaStyle: {
|
|
||||||
color: {
|
|
||||||
type: 'linear',
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
x2: 0,
|
|
||||||
y2: 1,
|
|
||||||
colorStops: [
|
|
||||||
{ offset: 0, color: 'rgba(16, 185, 129, 0.2)' },
|
|
||||||
{ offset: 1, color: 'rgba(16, 185, 129, 0)' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data: orderData,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('渲染趋势图失败:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const scheduleRender = async () => {
|
|
||||||
if (renderTimer) {
|
|
||||||
clearTimeout(renderTimer);
|
|
||||||
renderTimer = null;
|
|
||||||
}
|
|
||||||
await nextTick();
|
|
||||||
if (isUnmounted) return;
|
|
||||||
renderTimer = setTimeout(() => {
|
|
||||||
if (isUnmounted) return;
|
|
||||||
renderChart();
|
|
||||||
}, 16);
|
|
||||||
};
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.data,
|
|
||||||
() => {
|
|
||||||
if (props.data) {
|
|
||||||
scheduleRender();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ deep: true, immediate: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
isUnmounted = false;
|
|
||||||
darkObserver = new MutationObserver(() => {
|
|
||||||
if (props.data) scheduleRender();
|
|
||||||
});
|
|
||||||
darkObserver.observe(document.documentElement, {
|
|
||||||
attributes: true,
|
|
||||||
attributeFilter: ['class'],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
isUnmounted = true;
|
|
||||||
if (renderTimer) {
|
|
||||||
clearTimeout(renderTimer);
|
|
||||||
renderTimer = null;
|
|
||||||
}
|
|
||||||
darkObserver?.disconnect();
|
|
||||||
darkObserver = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
defineExpose({ renderChart });
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div :class="[FINANCE_PANEL_SHELL, 'xl:col-span-2']">
|
|
||||||
<div
|
|
||||||
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
|
||||||
>
|
|
||||||
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
|
||||||
销售额与单量趋势
|
|
||||||
</h3>
|
|
||||||
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
|
||||||
双轴展示销售额与订单量,与上方 KPI 同一时间范围
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="px-5 py-4 md:px-6 md:py-5">
|
|
||||||
<div class="h-[320px] w-full">
|
|
||||||
<EchartsUI ref="trendChartRef" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
-97
@@ -1,97 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
|
|
||||||
|
|
||||||
interface SkuSalesRankItem {
|
|
||||||
skuId?: number;
|
|
||||||
skuName?: string;
|
|
||||||
skuCode?: string;
|
|
||||||
orderCount?: number;
|
|
||||||
salesAmount?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
data: SkuSalesRankItem[] | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
defineProps<Props>();
|
|
||||||
|
|
||||||
const formatAmount = (amount: number | undefined) => {
|
|
||||||
if (amount === undefined || amount === null) return '-';
|
|
||||||
return `¥${amount.toLocaleString('zh-CN', {
|
|
||||||
minimumFractionDigits: 2,
|
|
||||||
maximumFractionDigits: 2,
|
|
||||||
})}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
function rankBadgeClass(idx: number) {
|
|
||||||
if (idx === 0) return 'bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300';
|
|
||||||
if (idx === 1) return 'bg-slate-100 text-slate-600 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-slate-300';
|
|
||||||
if (idx === 2) return 'bg-orange-50 text-orange-700 dark:bg-orange-950/40 dark:text-orange-300';
|
|
||||||
return 'bg-slate-50 text-slate-500 dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)]';
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div :class="FINANCE_PANEL_SHELL">
|
|
||||||
<div
|
|
||||||
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
|
||||||
>
|
|
||||||
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
|
||||||
各 SKU 销量 Top10
|
|
||||||
</h3>
|
|
||||||
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
|
||||||
按单量排序,与当前筛选时间范围一致
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="px-5 py-4 md:px-6 md:py-5">
|
|
||||||
<div class="max-h-[320px] space-y-2 overflow-y-auto pr-1">
|
|
||||||
<template v-if="data?.length">
|
|
||||||
<div
|
|
||||||
v-for="(row, idx) in data"
|
|
||||||
:key="row.skuId ?? `rank-${idx}`"
|
|
||||||
class="flex items-center gap-3 rounded-[10px] border border-slate-200/90 bg-white px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg text-xs font-bold tabular-nums"
|
|
||||||
:class="rankBadgeClass(idx)"
|
|
||||||
>
|
|
||||||
{{ idx + 1 }}
|
|
||||||
</span>
|
|
||||||
<div class="min-w-0 flex-1">
|
|
||||||
<div
|
|
||||||
class="truncate text-sm font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
|
||||||
:title="row.skuName"
|
|
||||||
>
|
|
||||||
{{ row.skuName || '-' }}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-if="row.skuCode"
|
|
||||||
class="truncate text-[11px] text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
|
||||||
>
|
|
||||||
{{ row.skuCode }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="shrink-0 text-right">
|
|
||||||
<div class="text-sm font-bold tabular-nums text-blue-600 dark:text-blue-400">
|
|
||||||
{{ row.orderCount != null ? row.orderCount.toLocaleString('zh-CN') : '-' }}
|
|
||||||
<span class="text-[10px] font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
|
||||||
单
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="text-[11px] font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
|
||||||
{{ formatAmount(row.salesAmount) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<div
|
|
||||||
v-else
|
|
||||||
class="flex h-[280px] items-center justify-center text-sm text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
|
||||||
>
|
|
||||||
暂无 SKU 数据
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
+5
-5
@@ -12,7 +12,7 @@ import {
|
|||||||
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
|
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
|
||||||
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
|
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
|
||||||
|
|
||||||
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
|
import { PRODUCT_PANEL_SHELL } from '../constants/product-ui';
|
||||||
|
|
||||||
interface SkuData {
|
interface SkuData {
|
||||||
skuId: number;
|
skuId: number;
|
||||||
@@ -116,16 +116,16 @@ const footerRow = computed(() => props.footerTotal ?? computedFooter.value);
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="FINANCE_PANEL_SHELL">
|
<div :class="PRODUCT_PANEL_SHELL">
|
||||||
<div
|
<div
|
||||||
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 p-5 md:flex-row md:items-center md:px-6 dark:border-b-[hsl(240deg_3.7%_22%)]"
|
class="flex flex-col items-start justify-between gap-4 border-b border-teal-100/80 p-5 md:flex-row md:items-center md:px-6 dark:border-teal-900/35"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||||
商品 SKU 销售汇总
|
规格经营明细
|
||||||
</h3>
|
</h3>
|
||||||
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
各 SKU 经营明细:规模、成本及最终损益(列序与工作台店铺汇总表对齐)
|
本商品各 SKU 的规模、成本与损益(商品概览核心明细)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
-199
@@ -1,199 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { createIconifyIcon } from '@vben/icons';
|
|
||||||
|
|
||||||
import {
|
|
||||||
FINANCE_KPI_CARD_SHELL,
|
|
||||||
FINANCE_TONE_ICON,
|
|
||||||
} from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
|
|
||||||
|
|
||||||
const IconSales = createIconifyIcon('lucide:wallet');
|
|
||||||
const IconOrders = createIconifyIcon('lucide:shopping-bag');
|
|
||||||
const IconRoi = createIconifyIcon('lucide:target');
|
|
||||||
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
|
|
||||||
const IconTax = createIconifyIcon('lucide:landmark');
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
data: {
|
|
||||||
productName?: string;
|
|
||||||
totalSalesAmount?: number;
|
|
||||||
totalOrderCount?: number;
|
|
||||||
monthOverMonthGrowth?: number;
|
|
||||||
salesAmountAchievementRate?: number;
|
|
||||||
orderCountAchievementRate?: number;
|
|
||||||
averageFeeRatio?: number;
|
|
||||||
totalROI?: number;
|
|
||||||
totalNetProfitAfterTax?: number;
|
|
||||||
totalTaxAmount?: number;
|
|
||||||
} | null;
|
|
||||||
loading?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
defineProps<Props>();
|
|
||||||
|
|
||||||
const cards = [
|
|
||||||
{
|
|
||||||
key: 'sales',
|
|
||||||
label: '净销售额',
|
|
||||||
tone: 'blue' as const,
|
|
||||||
icon: IconSales,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'orders',
|
|
||||||
label: '净销售单量',
|
|
||||||
tone: 'blue' as const,
|
|
||||||
icon: IconOrders,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'roi',
|
|
||||||
label: '广告 ROI',
|
|
||||||
tone: 'purple' as const,
|
|
||||||
icon: IconRoi,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'profit',
|
|
||||||
label: '净利润',
|
|
||||||
tone: 'green' as const,
|
|
||||||
icon: IconNet,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function toneClass(tone: string) {
|
|
||||||
return FINANCE_TONE_ICON[tone] ?? FINANCE_TONE_ICON.blue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const formatAmount = (amount: number | undefined) => {
|
|
||||||
if (amount === undefined) return '-';
|
|
||||||
return `¥${amount.toLocaleString('zh-CN', {
|
|
||||||
minimumFractionDigits: 2,
|
|
||||||
maximumFractionDigits: 2,
|
|
||||||
})}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const toNumber = (value: unknown): number | undefined => {
|
|
||||||
if (value === undefined || value === null || value === '') return undefined;
|
|
||||||
const parsed = Number(value);
|
|
||||||
return Number.isFinite(parsed) ? parsed : undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatPercentPlain = (value: number | undefined | null) => {
|
|
||||||
if (value == null) return '-';
|
|
||||||
return `${value.toFixed(1)}%`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatGrowth = (value: number | undefined) => {
|
|
||||||
if (value === undefined) return '';
|
|
||||||
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="grid grid-cols-1 gap-3.5 sm:grid-cols-2 xl:grid-cols-4">
|
|
||||||
<div
|
|
||||||
v-for="meta in cards"
|
|
||||||
:key="meta.key"
|
|
||||||
:class="FINANCE_KPI_CARD_SHELL"
|
|
||||||
>
|
|
||||||
<div class="flex items-start justify-between gap-2">
|
|
||||||
<span
|
|
||||||
class="min-w-0 truncate text-[16px] font-semibold leading-snug text-slate-800 dark:text-[hsl(0deg_0%_90%)]"
|
|
||||||
>
|
|
||||||
{{ meta.label }}
|
|
||||||
</span>
|
|
||||||
<div
|
|
||||||
class="grid size-9 shrink-0 place-items-center rounded-[10px]"
|
|
||||||
:class="toneClass(meta.tone)"
|
|
||||||
>
|
|
||||||
<component :is="meta.icon" class="size-4" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 销售额 -->
|
|
||||||
<template v-if="meta.key === 'sales'">
|
|
||||||
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
|
||||||
{{ data?.totalSalesAmount ? formatAmount(data.totalSalesAmount) : '-' }}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="mt-2.5 flex min-h-[1.25rem] flex-wrap items-center justify-between gap-x-2 gap-y-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
|
||||||
>
|
|
||||||
<span v-if="data?.salesAmountAchievementRate !== undefined">
|
|
||||||
目标达成
|
|
||||||
<span class="ml-1 font-semibold text-blue-600 dark:text-blue-400">
|
|
||||||
{{ formatPercentPlain(data.salesAmountAchievementRate) }}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
v-if="data?.monthOverMonthGrowth !== undefined"
|
|
||||||
:class="
|
|
||||||
data.monthOverMonthGrowth >= 0
|
|
||||||
? 'font-semibold text-emerald-500 dark:text-emerald-400'
|
|
||||||
: 'font-semibold text-rose-500 dark:text-rose-400'
|
|
||||||
"
|
|
||||||
>
|
|
||||||
环比 {{ formatGrowth(data.monthOverMonthGrowth) }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- 单量 -->
|
|
||||||
<template v-else-if="meta.key === 'orders'">
|
|
||||||
<div class="mt-3 inline-flex items-baseline gap-1 tabular-nums">
|
|
||||||
<span class="text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
|
||||||
{{ data?.totalOrderCount?.toLocaleString('zh-CN') || '-' }}
|
|
||||||
</span>
|
|
||||||
<span class="text-sm font-semibold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
|
||||||
单
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-if="data?.orderCountAchievementRate !== undefined"
|
|
||||||
class="mt-2.5 space-y-2"
|
|
||||||
>
|
|
||||||
<div class="flex justify-between text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
|
||||||
<span>目标达成率</span>
|
|
||||||
<span class="font-semibold text-blue-600 dark:text-blue-400">
|
|
||||||
{{ formatPercentPlain(data.orderCountAchievementRate) }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="h-1.5 w-full overflow-hidden rounded-full bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
|
|
||||||
<div
|
|
||||||
class="h-full rounded-full bg-blue-500 transition-all duration-700"
|
|
||||||
:style="{
|
|
||||||
width: `${Math.min(data.orderCountAchievementRate || 0, 100)}%`,
|
|
||||||
}"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- ROI -->
|
|
||||||
<template v-else-if="meta.key === 'roi'">
|
|
||||||
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-indigo-600 dark:text-indigo-400">
|
|
||||||
{{ toNumber(data?.totalROI)?.toFixed(2) ?? '-' }}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-if="data?.averageFeeRatio !== undefined"
|
|
||||||
class="mt-2.5 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
|
||||||
>
|
|
||||||
平均费比
|
|
||||||
<span class="ml-1 font-semibold text-slate-700 dark:text-[hsl(0deg_0%_90%)]">
|
|
||||||
{{ formatPercentPlain(data.averageFeeRatio) }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- 净利润 -->
|
|
||||||
<template v-else-if="meta.key === 'profit'">
|
|
||||||
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-emerald-600 dark:text-emerald-400">
|
|
||||||
{{ data?.totalNetProfitAfterTax ? formatAmount(data.totalNetProfitAfterTax) : '-' }}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-if="data?.totalTaxAmount !== undefined"
|
|
||||||
class="mt-2.5 flex items-center gap-1.5 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
|
||||||
>
|
|
||||||
<IconTax class="size-3.5 shrink-0 opacity-70" />
|
|
||||||
<span>已扣税额 {{ formatAmount(data.totalTaxAmount) }}</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/** 商品概览:青绿强调,与经营概览蓝灰区分 */
|
||||||
|
|
||||||
|
export const PRODUCT_PAGE_BG =
|
||||||
|
'bg-[#f4f9f8] dark:bg-[hsl(200deg_18%_8%)]';
|
||||||
|
|
||||||
|
export const PRODUCT_PANEL_SHELL =
|
||||||
|
'overflow-hidden rounded-[16px] border border-teal-200/70 bg-white shadow-[0_1px_2px_rgba(15,118,110,0.04),0_10px_28px_rgba(15,118,110,0.05)] dark:border-teal-900/40 dark:bg-[hsl(200deg_14%_11%)] dark:shadow-none';
|
||||||
|
|
||||||
|
export const PRODUCT_HERO_SHELL =
|
||||||
|
'relative overflow-hidden rounded-[18px] border border-teal-200/80 bg-gradient-to-br from-teal-50 via-white to-cyan-50/80 p-5 shadow-[0_1px_2px_rgba(15,118,110,0.05),0_12px_32px_rgba(15,118,110,0.07)] md:p-6 dark:border-teal-900/45 dark:from-teal-950/40 dark:via-[hsl(200deg_14%_11%)] dark:to-cyan-950/30 dark:shadow-none';
|
||||||
|
|
||||||
|
export const PRODUCT_SPOT_CARD =
|
||||||
|
'min-w-0 rounded-[14px] border border-teal-100/90 bg-white/80 px-3.5 py-3 backdrop-blur-sm dark:border-teal-900/35 dark:bg-[hsl(200deg_14%_12%/80%)]';
|
||||||
|
|
||||||
|
export const PRODUCT_SECTION_LABEL =
|
||||||
|
'inline-flex items-center gap-1.5 rounded-full border border-teal-200/80 bg-teal-50/80 px-2.5 py-0.5 text-[11px] font-semibold tracking-wide text-teal-700 dark:border-teal-800/50 dark:bg-teal-950/40 dark:text-teal-300';
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { Dayjs } from 'dayjs';
|
import type { Dayjs } from 'dayjs';
|
||||||
|
import type { ProductOverviewVO } from '#/api/ec/product/overview';
|
||||||
|
import type { WorkbenchVO } from '#/api/bi/workbench/types';
|
||||||
|
import type { FinanceKpiCardId } from '#/views/bi/workbench/tabs/finance/constants/kpi-catalog';
|
||||||
|
|
||||||
import { computed, onActivated, onMounted, onUnmounted, ref, watch } from 'vue';
|
import { computed, nextTick, onActivated, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { Spin, message } from 'ant-design-vue';
|
import { Button, Spin, message } from 'ant-design-vue';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import TimeRangeBar from './components/TimeRangeBar.vue';
|
import TimeRangeBar from './components/TimeRangeBar.vue';
|
||||||
import StatCards from './components/StatCards.vue';
|
import ProductHeroBanner from './components/ProductHeroBanner.vue';
|
||||||
import SalesTrendChart from './components/SalesTrendChart.vue';
|
import ProductSkuRankStrip from './components/ProductSkuRankStrip.vue';
|
||||||
import SkuSalesTop10Panel from './components/SkuSalesTop10Panel.vue';
|
|
||||||
import SkuSummaryTable from './components/SkuSummaryTable.vue';
|
import SkuSummaryTable from './components/SkuSummaryTable.vue';
|
||||||
import { getProductPageApi } from '#/api/ec/product/apis';
|
import { getProductPageApi } from '#/api/ec/product/apis';
|
||||||
import type { ProductVO } from '#/api/ec/product/types';
|
import type { ProductVO } from '#/api/ec/product/types';
|
||||||
@@ -26,19 +29,30 @@ import {
|
|||||||
syncOverviewDateRangeToUrl,
|
syncOverviewDateRangeToUrl,
|
||||||
} from '#/utils/overview-date-range';
|
} from '#/utils/overview-date-range';
|
||||||
|
|
||||||
|
import FinanceCostPieChart from '#/views/bi/workbench/tabs/finance/components/FinanceCostPieChart.vue';
|
||||||
|
import FinanceKpiGrid from '#/views/bi/workbench/tabs/finance/components/FinanceKpiGrid.vue';
|
||||||
|
import FinanceKpiSettingsModal from '#/views/bi/workbench/tabs/finance/components/FinanceKpiSettingsModal.vue';
|
||||||
|
import FinanceTrendChart from '#/views/bi/workbench/tabs/finance/components/FinanceTrendChart.vue';
|
||||||
|
import { useFinanceKpiPreferences } from '#/views/bi/workbench/tabs/finance/composables/useFinanceKpiPreferences';
|
||||||
|
|
||||||
|
import {
|
||||||
|
PRODUCT_PAGE_BG,
|
||||||
|
PRODUCT_PANEL_SHELL,
|
||||||
|
PRODUCT_SECTION_LABEL,
|
||||||
|
} from './constants/product-ui';
|
||||||
|
|
||||||
defineOptions({ name: 'ProductOverview' });
|
defineOptions({ name: 'ProductOverview' });
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
|
||||||
|
|
||||||
const PRODUCT_PAGE_SIZE = 20;
|
const PRODUCT_PAGE_SIZE = 20;
|
||||||
const SHOP_PAGE_SIZE = 20;
|
const SHOP_PAGE_SIZE = 20;
|
||||||
|
|
||||||
/** 当前是否为商品概览路由(keep-alive 下勿用其它页的 params.id 请求商品接口) */
|
|
||||||
const isProductOverviewRoute = () =>
|
const isProductOverviewRoute = () =>
|
||||||
/\/ec\/product\/overview\/[^/]+\/?$/.test(route.path);
|
/\/ec\/product\/overview\/[^/]+\/?$/.test(route.path);
|
||||||
|
|
||||||
// 商品ID(从路由参数获取)
|
|
||||||
const productId = computed(() => {
|
const productId = computed(() => {
|
||||||
if (!isProductOverviewRoute()) return 0;
|
if (!isProductOverviewRoute()) return 0;
|
||||||
const id = route.params.id;
|
const id = route.params.id;
|
||||||
@@ -46,7 +60,6 @@ const productId = computed(() => {
|
|||||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 路由 query.shopId:工作台筛选店铺跳转时带入 */
|
|
||||||
const contextShopId = computed(() => {
|
const contextShopId = computed(() => {
|
||||||
if (!isProductOverviewRoute()) return undefined;
|
if (!isProductOverviewRoute()) return undefined;
|
||||||
return parseOverviewShopIdFromQuery(
|
return parseOverviewShopIdFromQuery(
|
||||||
@@ -85,9 +98,8 @@ const shopSelectOptions = computed(() => {
|
|||||||
return opts;
|
return opts;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 响应式数据
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const overviewData = ref<any>(null);
|
const overviewData = ref<ProductOverviewVO.Overview | null>(null);
|
||||||
|
|
||||||
const productSelectOptions = computed(() => {
|
const productSelectOptions = computed(() => {
|
||||||
const opts = products.value.map((p) => ({
|
const opts = products.value.map((p) => ({
|
||||||
@@ -102,43 +114,73 @@ const productSelectOptions = computed(() => {
|
|||||||
return opts;
|
return opts;
|
||||||
});
|
});
|
||||||
|
|
||||||
const normalizeOverview = (raw: any) => {
|
const financeKpis = computed<WorkbenchVO.KpiItem[]>(
|
||||||
if (!raw || typeof raw !== 'object') return null;
|
() => (overviewData.value?.kpis as WorkbenchVO.KpiItem[] | undefined) ?? [],
|
||||||
return {
|
);
|
||||||
// 保留所有 KPI 字段
|
const dealTrend = computed<WorkbenchVO.TrendPoint[]>(
|
||||||
...raw,
|
() => (overviewData.value?.dealTrend as WorkbenchVO.TrendPoint[] | undefined) ?? [],
|
||||||
// 防御性处理嵌套结构
|
);
|
||||||
salesAmountTrend: {
|
const skuSalesShare = computed<WorkbenchVO.PieSlice[]>(
|
||||||
...(raw.salesAmountTrend || {}),
|
() =>
|
||||||
dailyDataList: Array.isArray(raw.salesAmountTrend?.dailyDataList)
|
(overviewData.value?.skuSalesShare as WorkbenchVO.PieSlice[] | undefined) ??
|
||||||
? raw.salesAmountTrend.dailyDataList
|
[],
|
||||||
: [],
|
);
|
||||||
},
|
|
||||||
orderCountTrend: {
|
|
||||||
...(raw.orderCountTrend || {}),
|
|
||||||
dailyDataList: Array.isArray(raw.orderCountTrend?.dailyDataList)
|
|
||||||
? raw.orderCountTrend.dailyDataList
|
|
||||||
: [],
|
|
||||||
},
|
|
||||||
specSummaries: {
|
|
||||||
...(raw.specSummaries || {}),
|
|
||||||
list: Array.isArray(raw.specSummaries?.list) ? raw.specSummaries.list : [],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// 日期范围(默认:本月至今日)
|
const periodDateLabel = computed(() => {
|
||||||
const dateRange = ref<[Dayjs, Dayjs]>([
|
const [start, end] = dateRange.value;
|
||||||
dayjs().startOf('month'),
|
return `${start.format('YYYY-MM-DD')} ~ ${end.format('YYYY-MM-DD')}`;
|
||||||
dayjs(),
|
});
|
||||||
]);
|
|
||||||
|
|
||||||
// 当前选中的时间范围类型
|
const heroShopLabel = computed(() => {
|
||||||
|
const id = contextShopId.value;
|
||||||
|
if (id == null || id <= 0) return undefined;
|
||||||
|
return (
|
||||||
|
shopSelectOptions.value.find((o) => o.value === String(id))?.label ||
|
||||||
|
selectedShopLabelCache.value ||
|
||||||
|
`店铺 #${id}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
visibleCardIds,
|
||||||
|
primaryByCardId,
|
||||||
|
colsPerRow,
|
||||||
|
applySettings,
|
||||||
|
setCardPrimary,
|
||||||
|
} = useFinanceKpiPreferences();
|
||||||
|
const kpiSettingsOpen = ref(false);
|
||||||
|
const visibleKpiCount = computed(() => visibleCardIds.value.length);
|
||||||
|
|
||||||
|
const trendChartRef = ref<InstanceType<typeof FinanceTrendChart> | null>(null);
|
||||||
|
const costPieRef = ref<InstanceType<typeof FinanceCostPieChart> | null>(null);
|
||||||
|
|
||||||
|
async function redrawCharts() {
|
||||||
|
await nextTick();
|
||||||
|
await trendChartRef.value?.redraw();
|
||||||
|
await costPieRef.value?.redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onKpiSettingsSave(payload: {
|
||||||
|
visibleCardIds: string[];
|
||||||
|
primaryByCardId: Record<string, string>;
|
||||||
|
colsPerRow: number;
|
||||||
|
}) {
|
||||||
|
if (payload.visibleCardIds.length === 0) {
|
||||||
|
message.warning('请至少选择一张 KPI 卡片');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
applySettings(payload);
|
||||||
|
message.success('KPI 显示已更新');
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSetPrimary(payload: { cardId: FinanceKpiCardId; metricLabel: string }) {
|
||||||
|
setCardPrimary(payload.cardId, payload.metricLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateRange = ref<[Dayjs, Dayjs]>([dayjs().startOf('month'), dayjs()]);
|
||||||
const activeTimeRange = ref<
|
const activeTimeRange = ref<
|
||||||
'7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
|
'7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
|
||||||
>('thisMonth');
|
>('thisMonth');
|
||||||
|
|
||||||
// 自定义日期范围
|
|
||||||
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
||||||
dateRange.value[0],
|
dateRange.value[0],
|
||||||
dateRange.value[1],
|
dateRange.value[1],
|
||||||
@@ -147,13 +189,12 @@ const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
|||||||
const lastRequestKey = ref('');
|
const lastRequestKey = ref('');
|
||||||
const isRequesting = ref(false);
|
const isRequesting = ref(false);
|
||||||
|
|
||||||
// 税率(持久化,与全店/店铺概览共用 key)
|
|
||||||
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;
|
||||||
|
|
||||||
watch(taxRate, () => {
|
watch(taxRate, () => {
|
||||||
loadOverviewData();
|
void loadOverviewData();
|
||||||
});
|
});
|
||||||
|
|
||||||
const setTimeRangeTypeByDates = (startDate: Dayjs, endDate: Dayjs) => {
|
const setTimeRangeTypeByDates = (startDate: Dayjs, endDate: Dayjs) => {
|
||||||
@@ -174,31 +215,26 @@ const setTimeRangeTypeByDates = (startDate: Dayjs, endDate: Dayjs) => {
|
|||||||
customDateRange.value = [startDate, endDate];
|
customDateRange.value = [startDate, endDate];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (daysDiff === 0 && startDate.isSame(today, 'day')) {
|
if (daysDiff === 0 && startDate.isSame(today, 'day')) {
|
||||||
activeTimeRange.value = 'today';
|
activeTimeRange.value = 'today';
|
||||||
customDateRange.value = [startDate, endDate];
|
customDateRange.value = [startDate, endDate];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (daysDiff === 0 && startDate.isSame(dayjs().subtract(1, 'day'), 'day')) {
|
if (daysDiff === 0 && startDate.isSame(dayjs().subtract(1, 'day'), 'day')) {
|
||||||
activeTimeRange.value = 'yesterday';
|
activeTimeRange.value = 'yesterday';
|
||||||
customDateRange.value = [startDate, endDate];
|
customDateRange.value = [startDate, endDate];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEndDateToday && isStartDate7DaysAgo) {
|
if (isEndDateToday && isStartDate7DaysAgo) {
|
||||||
activeTimeRange.value = '7days';
|
activeTimeRange.value = '7days';
|
||||||
customDateRange.value = [startDate, endDate];
|
customDateRange.value = [startDate, endDate];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEndDateToday && isStartDate30DaysAgo) {
|
if (isEndDateToday && isStartDate30DaysAgo) {
|
||||||
activeTimeRange.value = '30days';
|
activeTimeRange.value = '30days';
|
||||||
customDateRange.value = [startDate, endDate];
|
customDateRange.value = [startDate, endDate];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
activeTimeRange.value = 'custom';
|
activeTimeRange.value = 'custom';
|
||||||
customDateRange.value = [startDate, endDate];
|
customDateRange.value = [startDate, endDate];
|
||||||
};
|
};
|
||||||
@@ -337,7 +373,6 @@ function handleProductChange(nextProductId: number) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 时间范围状态(传递给子组件)
|
|
||||||
const timeRangeState = computed(() => ({
|
const timeRangeState = computed(() => ({
|
||||||
taxRate: taxRate.value,
|
taxRate: taxRate.value,
|
||||||
activeTimeRange: activeTimeRange.value,
|
activeTimeRange: activeTimeRange.value,
|
||||||
@@ -345,7 +380,6 @@ const timeRangeState = computed(() => ({
|
|||||||
dateRange: dateRange.value,
|
dateRange: dateRange.value,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 监听子组件的时间范围变化(与店铺概览一致:写 URL + 按条件刷新)
|
|
||||||
const handleTimeRangeChange = async (val: typeof timeRangeState.value) => {
|
const handleTimeRangeChange = async (val: typeof timeRangeState.value) => {
|
||||||
taxRate.value = val.taxRate;
|
taxRate.value = val.taxRate;
|
||||||
activeTimeRange.value = val.activeTimeRange;
|
activeTimeRange.value = val.activeTimeRange;
|
||||||
@@ -371,7 +405,8 @@ async function loadOverviewData() {
|
|||||||
? { shopId: contextShopId.value }
|
? { shopId: contextShopId.value }
|
||||||
: {}),
|
: {}),
|
||||||
});
|
});
|
||||||
overviewData.value = normalizeOverview(res);
|
overviewData.value = res ?? null;
|
||||||
|
await redrawCharts();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
message.error(err?.message || '加载失败');
|
message.error(err?.message || '加载失败');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -385,7 +420,7 @@ const refreshOverviewByCurrentParams = async (force = false) => {
|
|||||||
applyDateRangeFromRouteQuery();
|
applyDateRangeFromRouteQuery();
|
||||||
if (!productId.value) return;
|
if (!productId.value) return;
|
||||||
|
|
||||||
const requestKey = `${productId.value}_${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}_${contextShopId.value ?? ''}`;
|
const requestKey = `${productId.value}_${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}_${contextShopId.value ?? ''}_${taxRate.value}`;
|
||||||
if (!force && lastRequestKey.value === requestKey) {
|
if (!force && lastRequestKey.value === requestKey) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -394,7 +429,6 @@ const refreshOverviewByCurrentParams = async (force = false) => {
|
|||||||
await loadOverviewData();
|
await loadOverviewData();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 监听路由(与店铺概览一致;日期 query 以 window.location 为准,见 applyOverviewDateRangeFromUrl)
|
|
||||||
watch(
|
watch(
|
||||||
() => [
|
() => [
|
||||||
route.path,
|
route.path,
|
||||||
@@ -436,16 +470,21 @@ onUnmounted(() => {
|
|||||||
<template>
|
<template>
|
||||||
<Page
|
<Page
|
||||||
auto-content-height
|
auto-content-height
|
||||||
class="bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
:class="PRODUCT_PAGE_BG"
|
||||||
content-padding-class="px-4 pb-4"
|
content-padding-class="px-4 pb-4"
|
||||||
header-class="product-overview-page-header"
|
header-class="product-overview-page-header"
|
||||||
>
|
>
|
||||||
<template #title>
|
<template #title>
|
||||||
<div
|
<div
|
||||||
class="text-xl font-black tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_98%)] sm:text-2xl md:text-3xl"
|
class="text-xl font-black tracking-tight text-teal-950 dark:text-teal-50 sm:text-2xl md:text-3xl"
|
||||||
>
|
>
|
||||||
商品概览
|
商品概览
|
||||||
</div>
|
</div>
|
||||||
|
<p
|
||||||
|
class="mt-0.5 text-xs font-normal text-teal-700/70 dark:text-teal-300/70"
|
||||||
|
>
|
||||||
|
单品诊断 · 规格结构优先
|
||||||
|
</p>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #extra>
|
<template #extra>
|
||||||
@@ -474,31 +513,93 @@ onUnmounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<Spin :spinning="loading">
|
<Spin :spinning="loading">
|
||||||
<div v-if="overviewData" class="product-overview-body mx-auto w-full min-w-0 space-y-4 pt-4">
|
<div
|
||||||
<div>
|
v-if="overviewData"
|
||||||
<h2 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
class="product-overview-body mx-auto w-full min-w-0 space-y-4 pt-4"
|
||||||
经营概览
|
>
|
||||||
</h2>
|
<ProductHeroBanner
|
||||||
<p class="mt-0.5 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
:data="overviewData"
|
||||||
商品核心 KPI · 与当前筛选时间范围一致
|
:date-label="periodDateLabel"
|
||||||
</p>
|
:shop-label="heroShopLabel"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- 商品特色:先看趋势与规格占比,再下钻指标 -->
|
||||||
|
<div class="grid grid-cols-1 gap-3.5 xl:grid-cols-5">
|
||||||
|
<FinanceTrendChart
|
||||||
|
ref="trendChartRef"
|
||||||
|
:trend="dealTrend"
|
||||||
|
:panel-class="PRODUCT_PANEL_SHELL"
|
||||||
|
class="xl:col-span-3"
|
||||||
|
/>
|
||||||
|
<FinanceCostPieChart
|
||||||
|
ref="costPieRef"
|
||||||
|
class="xl:col-span-2"
|
||||||
|
:platform-sales-share="skuSalesShare"
|
||||||
|
:panel-class="PRODUCT_PANEL_SHELL"
|
||||||
|
title="规格销售额占比"
|
||||||
|
subtitle="本商品各 SKU 占净销售额的比例"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<StatCards :data="overviewData" :loading="loading" />
|
<ProductSkuRankStrip :items="overviewData.specSalesTop10" />
|
||||||
|
|
||||||
<div class="grid grid-cols-1 gap-3.5 xl:grid-cols-3">
|
<div class="flex flex-wrap items-center justify-between gap-3 pt-1">
|
||||||
<SalesTrendChart :data="overviewData" />
|
<div>
|
||||||
<SkuSalesTop10Panel :data="overviewData?.specSalesTop10 ?? []" />
|
<span :class="PRODUCT_SECTION_LABEL">指标明细</span>
|
||||||
|
<h2
|
||||||
|
class="mt-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||||
|
>
|
||||||
|
单品经营指标
|
||||||
|
</h2>
|
||||||
|
<p class="mt-0.5 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
|
口径与工作台一致,卡片布局可自定义
|
||||||
|
<span v-if="visibleKpiCount > 0">
|
||||||
|
· 已选 {{ visibleKpiCount }} 张 · 最多 {{ colsPerRow }} 列
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="default"
|
||||||
|
class="shrink-0 whitespace-nowrap !rounded-[10px] !border-teal-200 !bg-white !text-teal-800 shadow-[0_1px_2px_rgba(15,118,110,0.05)] hover:!border-teal-400 hover:!text-teal-700 dark:!border-teal-800/50 dark:!bg-[hsl(200deg_14%_12%)] dark:!text-teal-200 dark:hover:!border-teal-500/50 dark:hover:!text-teal-100"
|
||||||
|
@click="kpiSettingsOpen = true"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<component :is="IconSliders" class="size-4 shrink-0" />
|
||||||
|
</template>
|
||||||
|
KPI 显示设置
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 第三层:SKU 销售汇总 -->
|
<FinanceKpiSettingsModal
|
||||||
|
v-model:open="kpiSettingsOpen"
|
||||||
|
:cols-per-row="colsPerRow"
|
||||||
|
:visible-card-ids="visibleCardIds"
|
||||||
|
:primary-by-card-id="primaryByCardId"
|
||||||
|
@save="onKpiSettingsSave"
|
||||||
|
/>
|
||||||
|
<FinanceKpiGrid
|
||||||
|
:kpis="financeKpis"
|
||||||
|
:cols-per-row="colsPerRow"
|
||||||
|
:tax-rate="taxRate"
|
||||||
|
:visible-card-ids="visibleCardIds"
|
||||||
|
:primary-by-card-id="primaryByCardId"
|
||||||
|
:mom-compare-date-start="overviewData.momCompareDateStart"
|
||||||
|
:mom-compare-date-end="overviewData.momCompareDateEnd"
|
||||||
|
:yoy-compare-date-start="overviewData.yoyCompareDateStart"
|
||||||
|
:yoy-compare-date-end="overviewData.yoyCompareDateEnd"
|
||||||
|
@set-primary="onSetPrimary"
|
||||||
|
/>
|
||||||
|
|
||||||
<SkuSummaryTable
|
<SkuSummaryTable
|
||||||
:data="overviewData?.specSummaries?.list ?? []"
|
:data="overviewData?.specSummaries?.list ?? []"
|
||||||
:footer-total="overviewData?.specSummaries?.total"
|
:footer-total="overviewData?.specSummaries?.total"
|
||||||
:tax-rate="taxRate"
|
:tax-rate="taxRate"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="!loading" class="flex items-center justify-center p-8 text-slate-400">
|
<div
|
||||||
|
v-else-if="!loading"
|
||||||
|
class="flex items-center justify-center p-8 text-slate-400"
|
||||||
|
>
|
||||||
暂无数据
|
暂无数据
|
||||||
</div>
|
</div>
|
||||||
</Spin>
|
</Spin>
|
||||||
|
|||||||
Reference in New Issue
Block a user