mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
feat: 添加店铺概览统计功能及退款状态支持
This commit is contained in:
+14
-1
@@ -16,10 +16,13 @@ import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductPageFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopStatisticsQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.UpdateShopDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview.ShopOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopOverviewStatisticsVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopOverviewStatisticsService;
|
||||
import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO;
|
||||
import top.xyquan.ecomdmbbackend.utils.FileUploadUtils;
|
||||
|
||||
@@ -32,9 +35,11 @@ import top.xyquan.ecomdmbbackend.utils.FileUploadUtils;
|
||||
public class ShopController {
|
||||
|
||||
private final ShopService shopService;
|
||||
private final ShopOverviewStatisticsService shopOverviewStatisticsService;
|
||||
|
||||
public ShopController(ShopService shopService) {
|
||||
public ShopController(ShopService shopService, ShopOverviewStatisticsService shopOverviewStatisticsService) {
|
||||
this.shopService = shopService;
|
||||
this.shopOverviewStatisticsService = shopOverviewStatisticsService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建店铺", description = "创建新的店铺")
|
||||
@@ -102,4 +107,12 @@ public class ShopController {
|
||||
PageResultVO<ProductVO> result = shopService.getShopProductPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取店铺概览统计数据", description = "获取指定店铺的概览统计数据,包括销售额、单量、推广费、利润、ROI等,以及多商品数据横向对比")
|
||||
@PostMapping("/overview-statistics")
|
||||
@RequireRole(description = "查询店铺概览统计", allowUser = true)
|
||||
public ApiResponse<ShopOverviewStatisticsVO> getShopOverviewStatistics(@Valid @RequestBody ShopOverviewQueryDTO queryDTO) {
|
||||
ShopOverviewStatisticsVO overviewVO = shopOverviewStatisticsService.getShopOverviewStatistics(queryDTO);
|
||||
return ApiResponse.success(overviewVO);
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -37,5 +37,11 @@ public class CreateOrderStatusDTO {
|
||||
@Schema(description = "是否自动参与统计", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否自动参与统计不能为空")
|
||||
private Integer autoStatistics;
|
||||
|
||||
/**
|
||||
* 是否为退款状态 0否 1是
|
||||
*/
|
||||
@Schema(description = "是否为退款状态", example = "0")
|
||||
private Integer isRefund;
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -37,5 +37,11 @@ public class UpdateOrderStatusDTO {
|
||||
@Schema(description = "是否自动参与统计", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否自动参与统计不能为空")
|
||||
private Integer autoStatistics;
|
||||
|
||||
/**
|
||||
* 是否为退款状态 0否 1是
|
||||
*/
|
||||
@Schema(description = "是否为退款状态", example = "0")
|
||||
private Integer isRefund;
|
||||
}
|
||||
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 单店铺概览查询DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "单店铺概览查询DTO")
|
||||
public class ShopOverviewQueryDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据)
|
||||
*/
|
||||
@Schema(description = "日期范围数组", example = "[\"2024-01-01\", \"2024-01-31\"]", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "日期范围不能为空")
|
||||
@Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期")
|
||||
private List<LocalDate> dateRange;
|
||||
}
|
||||
|
||||
+6
@@ -50,6 +50,12 @@ public class OrderStatusPO {
|
||||
@TableField("auto_statistics")
|
||||
private Integer autoStatistics;
|
||||
|
||||
/**
|
||||
* 是否为退款状态 0否 1是
|
||||
*/
|
||||
@TableField("is_refund")
|
||||
private Integer isRefund;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
+6
@@ -48,6 +48,12 @@ public class OrderStatusVO {
|
||||
@Schema(description = "是否自动参与统计", example = "1")
|
||||
private Integer autoStatistics;
|
||||
|
||||
/**
|
||||
* 是否为退款状态 0否 1是
|
||||
*/
|
||||
@Schema(description = "是否为退款状态", example = "0")
|
||||
private Integer isRefund;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 单店铺概览统计VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "单店铺概览统计VO")
|
||||
public class ShopOverviewStatisticsVO {
|
||||
|
||||
/**
|
||||
* 店铺总销售额
|
||||
*/
|
||||
@Schema(description = "店铺总销售额", example = "100000.00")
|
||||
private BigDecimal totalSalesAmount;
|
||||
|
||||
/**
|
||||
* 较上月同期增长百分比
|
||||
*/
|
||||
@Schema(description = "较上月同期增长百分比", example = "15.50")
|
||||
private BigDecimal monthOverMonthGrowth;
|
||||
|
||||
/**
|
||||
* 店铺总单量
|
||||
*/
|
||||
@Schema(description = "店铺总单量", example = "1000")
|
||||
private Integer totalOrderCount;
|
||||
|
||||
/**
|
||||
* 总推广费支出
|
||||
*/
|
||||
@Schema(description = "总推广费支出", example = "5000.00")
|
||||
private BigDecimal totalPromotionFee;
|
||||
|
||||
/**
|
||||
* 平均费比(推广费/销售额)
|
||||
*/
|
||||
@Schema(description = "平均费比", example = "0.05")
|
||||
private BigDecimal averageFeeRatio;
|
||||
|
||||
/**
|
||||
* 店铺总净利(税后)
|
||||
*/
|
||||
@Schema(description = "店铺总净利(税后)", example = "80000.00")
|
||||
private BigDecimal totalNetProfitAfterTax;
|
||||
|
||||
/**
|
||||
* 扣除总税额
|
||||
*/
|
||||
@Schema(description = "扣除总税额", example = "6000.00")
|
||||
private BigDecimal totalTaxAmount;
|
||||
|
||||
/**
|
||||
* 店铺总销量目标(目标订单数)
|
||||
*/
|
||||
@Schema(description = "店铺总销量目标(目标订单数)", example = "1200")
|
||||
private Integer totalTargetOrderCount;
|
||||
|
||||
/**
|
||||
* 店铺总销售额目标
|
||||
*/
|
||||
@Schema(description = "店铺总销售额目标", example = "120000.00")
|
||||
private BigDecimal totalTargetAmount;
|
||||
|
||||
/**
|
||||
* 销量目标达成率
|
||||
*/
|
||||
@Schema(description = "销量目标达成率", example = "83.33")
|
||||
private BigDecimal orderCountAchievementRate;
|
||||
|
||||
/**
|
||||
* 销售额目标达成率
|
||||
*/
|
||||
@Schema(description = "销售额目标达成率", example = "83.33")
|
||||
private BigDecimal salesAmountAchievementRate;
|
||||
|
||||
/**
|
||||
* 汇总ROI
|
||||
*/
|
||||
@Schema(description = "汇总ROI", example = "1.5")
|
||||
private BigDecimal totalROI;
|
||||
|
||||
/**
|
||||
* 总税后盈亏
|
||||
*/
|
||||
@Schema(description = "总税后盈亏", example = "80000.00")
|
||||
private BigDecimal totalProfitAfterTax;
|
||||
|
||||
/**
|
||||
* 销售额趋势分析
|
||||
*/
|
||||
@Schema(description = "销售额趋势分析")
|
||||
private TrendData salesAmountTrend;
|
||||
|
||||
/**
|
||||
* 单量趋势分析
|
||||
*/
|
||||
@Schema(description = "单量趋势分析")
|
||||
private TrendData orderCountTrend;
|
||||
|
||||
/**
|
||||
* 多商品数据横向对比
|
||||
*/
|
||||
@Schema(description = "多商品数据横向对比")
|
||||
private List<ProductComparison> productComparisons;
|
||||
|
||||
/**
|
||||
* 商品对比数据
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "商品对比数据")
|
||||
public static class ProductComparison {
|
||||
@Schema(description = "商品ID", example = "1")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "商品名称", example = "iPhone 15 Pro")
|
||||
private String productName;
|
||||
|
||||
@Schema(description = "商品编码", example = "IPHONE15PRO")
|
||||
private String productCode;
|
||||
|
||||
@Schema(description = "销售额", example = "50000.00")
|
||||
private BigDecimal salesAmount;
|
||||
|
||||
@Schema(description = "单量", example = "500")
|
||||
private Integer orderCount;
|
||||
|
||||
@Schema(description = "客单价", example = "100.00")
|
||||
private BigDecimal averageOrderValue;
|
||||
|
||||
@Schema(description = "成本运费", example = "5000.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
@Schema(description = "退款金额", example = "1000.00")
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
@Schema(description = "推广费", example = "5000.00")
|
||||
private BigDecimal totalPromotionFee;
|
||||
|
||||
@Schema(description = "刷单费用", example = "2000.00")
|
||||
private BigDecimal brushFee;
|
||||
|
||||
@Schema(description = "费比", example = "0.10")
|
||||
private BigDecimal feeRatio;
|
||||
|
||||
@Schema(description = "税前盈亏", example = "35000.00")
|
||||
private BigDecimal totalProfitBeforeTax;
|
||||
|
||||
@Schema(description = "销售额4%税额", example = "2000.00")
|
||||
private BigDecimal salesTaxAmount;
|
||||
|
||||
@Schema(description = "税后盈亏", example = "30000.00")
|
||||
private BigDecimal profitAfterTax;
|
||||
|
||||
@Schema(description = "ROI", example = "1.5")
|
||||
private BigDecimal roi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 趋势数据
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "趋势数据")
|
||||
public static class TrendData {
|
||||
/**
|
||||
* 时间范围的总值
|
||||
*/
|
||||
@Schema(description = "时间范围的总值")
|
||||
private BigDecimal total;
|
||||
|
||||
/**
|
||||
* 每日数据列表
|
||||
*/
|
||||
@Schema(description = "每日数据列表")
|
||||
private List<TrendDataItem> dailyDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 趋势数据项
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "趋势数据项")
|
||||
public static class TrendDataItem {
|
||||
/**
|
||||
* 日期
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Schema(description = "日期", example = "2024-01-01")
|
||||
private LocalDate date;
|
||||
|
||||
/**
|
||||
* 对应的值
|
||||
*/
|
||||
@Schema(description = "对应的值")
|
||||
private BigDecimal value;
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview.ShopOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopOverviewStatisticsVO;
|
||||
|
||||
/**
|
||||
* 单店铺概览统计服务接口
|
||||
*/
|
||||
public interface ShopOverviewStatisticsService {
|
||||
|
||||
/**
|
||||
* 获取单店铺概览统计数据
|
||||
*
|
||||
* @param queryDTO 查询DTO
|
||||
* @return 单店铺概览统计VO
|
||||
*/
|
||||
ShopOverviewStatisticsVO getShopOverviewStatistics(ShopOverviewQueryDTO queryDTO);
|
||||
}
|
||||
|
||||
+2
-2
@@ -624,13 +624,13 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取退款状态ID
|
||||
* 获取退款状态ID(通过 is_refund 字段查询)
|
||||
*/
|
||||
private Long getRefundStatusId() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
|
||||
.eq(OrderStatusPO::getStatusName, "已退款")
|
||||
.eq(OrderStatusPO::getIsRefund, 1)
|
||||
.last("LIMIT 1");
|
||||
OrderStatusPO status = orderStatusService.getOne(wrapper);
|
||||
return status != null ? status.getId() : null;
|
||||
|
||||
+3
@@ -61,6 +61,9 @@ public class OrderStatusServiceImpl extends ServiceImpl<OrderStatusMapper, Order
|
||||
if (orderStatus.getAutoStatistics() == null) {
|
||||
orderStatus.setAutoStatistics(1);
|
||||
}
|
||||
if (orderStatus.getIsRefund() == null) {
|
||||
orderStatus.setIsRefund(0);
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
orderStatus.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
+527
@@ -0,0 +1,527 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.BrushOrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopMonthlyTargetMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.overview.ShopOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.OrderStatusPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.PromotionFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopMonthlyTargetPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopOverviewStatisticsVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.OrderStatusService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopOverviewStatisticsService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 单店铺概览统计服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatisticsService {
|
||||
|
||||
private static final BigDecimal SALES_TAX_RATE = new BigDecimal("0.04"); // 销售额4%税额
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final OrderMapper orderMapper;
|
||||
private final PromotionFeeMapper promotionFeeMapper;
|
||||
private final BrushOrderMapper brushOrderMapper;
|
||||
private final ShopMonthlyTargetMapper shopMonthlyTargetMapper;
|
||||
private final ShopService shopService;
|
||||
private final ProductService productService;
|
||||
private final OrderStatusService orderStatusService;
|
||||
|
||||
public ShopOverviewStatisticsServiceImpl(CurrentUserContext currentUserContext,
|
||||
OrderMapper orderMapper,
|
||||
PromotionFeeMapper promotionFeeMapper,
|
||||
BrushOrderMapper brushOrderMapper,
|
||||
ShopMonthlyTargetMapper shopMonthlyTargetMapper,
|
||||
ShopService shopService,
|
||||
ProductService productService,
|
||||
OrderStatusService orderStatusService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.orderMapper = orderMapper;
|
||||
this.promotionFeeMapper = promotionFeeMapper;
|
||||
this.brushOrderMapper = brushOrderMapper;
|
||||
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
|
||||
this.shopService = shopService;
|
||||
this.productService = productService;
|
||||
this.orderStatusService = orderStatusService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopOverviewStatisticsVO getShopOverviewStatistics(ShopOverviewQueryDTO queryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 解析日期范围
|
||||
LocalDate startDate;
|
||||
LocalDate endDate;
|
||||
if (queryDTO.getDateRange().size() == 1) {
|
||||
startDate = queryDTO.getDateRange().get(0);
|
||||
endDate = startDate;
|
||||
} else {
|
||||
startDate = queryDTO.getDateRange().get(0);
|
||||
endDate = queryDTO.getDateRange().get(1);
|
||||
if (startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
}
|
||||
|
||||
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
|
||||
|
||||
// 验证店铺是否存在
|
||||
ShopPO shop = shopService.getById(queryDTO.getShopId());
|
||||
if (shop == null || !shop.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
|
||||
// 查询订单数据(该店铺)
|
||||
LambdaQueryWrapper<OrderPO> orderWrapper = new LambdaQueryWrapper<>();
|
||||
orderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.eq(OrderPO::getShopId, queryDTO.getShopId())
|
||||
.ge(OrderPO::getOrderTime, startDateTime)
|
||||
.le(OrderPO::getOrderTime, endDateTime);
|
||||
List<OrderPO> orders = orderMapper.selectList(orderWrapper);
|
||||
|
||||
// 查询推广费数据(该店铺)
|
||||
LambdaQueryWrapper<PromotionFeePO> promotionWrapper = new LambdaQueryWrapper<>();
|
||||
promotionWrapper.eq(PromotionFeePO::getCompanyId, companyId)
|
||||
.eq(PromotionFeePO::getShopId, queryDTO.getShopId())
|
||||
.ge(PromotionFeePO::getFeeDate, startDate)
|
||||
.le(PromotionFeePO::getFeeDate, endDate);
|
||||
List<PromotionFeePO> promotionFees = promotionFeeMapper.selectList(promotionWrapper);
|
||||
|
||||
// 查询刷单费数据(该店铺)
|
||||
LambdaQueryWrapper<BrushOrderPO> brushWrapper = new LambdaQueryWrapper<>();
|
||||
brushWrapper.eq(BrushOrderPO::getCompanyId, companyId)
|
||||
.eq(BrushOrderPO::getShopId, queryDTO.getShopId())
|
||||
.ge(BrushOrderPO::getBrushTime, startDateTime)
|
||||
.le(BrushOrderPO::getBrushTime, endDateTime);
|
||||
List<BrushOrderPO> brushOrders = brushOrderMapper.selectList(brushWrapper);
|
||||
|
||||
// 获取退款状态ID
|
||||
Long refundStatusId = getRefundStatusId();
|
||||
|
||||
// 计算上月同期数据(用于增长百分比)
|
||||
LocalDate lastMonthStartDate = startDate.minusMonths(1);
|
||||
LocalDate lastMonthEndDate = endDate.minusMonths(1);
|
||||
LocalDateTime lastMonthStartDateTime = lastMonthStartDate.atStartOfDay();
|
||||
LocalDateTime lastMonthEndDateTime = lastMonthEndDate.atTime(23, 59, 59);
|
||||
|
||||
LambdaQueryWrapper<OrderPO> lastMonthOrderWrapper = new LambdaQueryWrapper<>();
|
||||
lastMonthOrderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.eq(OrderPO::getShopId, queryDTO.getShopId())
|
||||
.ge(OrderPO::getOrderTime, lastMonthStartDateTime)
|
||||
.le(OrderPO::getOrderTime, lastMonthEndDateTime);
|
||||
List<OrderPO> lastMonthOrders = orderMapper.selectList(lastMonthOrderWrapper);
|
||||
|
||||
// 构建返回对象
|
||||
ShopOverviewStatisticsVO overviewVO = new ShopOverviewStatisticsVO();
|
||||
|
||||
// 1. 计算店铺总销售额
|
||||
BigDecimal totalSalesAmount = orders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
overviewVO.setTotalSalesAmount(totalSalesAmount);
|
||||
|
||||
// 2. 计算较上月同期增长百分比
|
||||
BigDecimal lastMonthSalesAmount = lastMonthOrders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal monthOverMonthGrowth = BigDecimal.ZERO;
|
||||
if (lastMonthSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
monthOverMonthGrowth = totalSalesAmount.subtract(lastMonthSalesAmount)
|
||||
.divide(lastMonthSalesAmount, 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"));
|
||||
} else if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
monthOverMonthGrowth = new BigDecimal("100");
|
||||
}
|
||||
overviewVO.setMonthOverMonthGrowth(monthOverMonthGrowth);
|
||||
|
||||
// 3. 计算店铺总单量
|
||||
int totalOrderCount = orders.size();
|
||||
overviewVO.setTotalOrderCount(totalOrderCount);
|
||||
|
||||
// 4. 计算总推广费支出
|
||||
BigDecimal totalPromotionFee = promotionFees.stream()
|
||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
overviewVO.setTotalPromotionFee(totalPromotionFee);
|
||||
|
||||
// 5. 计算平均费比
|
||||
BigDecimal averageFeeRatio = BigDecimal.ZERO;
|
||||
if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
averageFeeRatio = totalPromotionFee.divide(totalSalesAmount, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
overviewVO.setAverageFeeRatio(averageFeeRatio);
|
||||
|
||||
// 6. 计算店铺总净利(税后)和总税额
|
||||
BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders);
|
||||
BigDecimal totalSalesTaxAmount = totalSalesAmount.multiply(SALES_TAX_RATE);
|
||||
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalSalesTaxAmount);
|
||||
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax);
|
||||
overviewVO.setTotalTaxAmount(totalSalesTaxAmount);
|
||||
|
||||
// 7. 计算目标维度的数据
|
||||
calculateTargetData(overviewVO, companyId, queryDTO.getShopId(), startDate, endDate, totalSalesAmount, totalOrderCount);
|
||||
|
||||
// 8. 汇总ROI和总税后盈亏
|
||||
BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders);
|
||||
overviewVO.setTotalROI(totalROI);
|
||||
overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax);
|
||||
|
||||
// 9. 计算趋势分析数据
|
||||
ShopOverviewStatisticsVO.TrendData salesAmountTrend = calculateSalesAmountTrend(orders, startDate, endDate);
|
||||
ShopOverviewStatisticsVO.TrendData orderCountTrend = calculateOrderCountTrend(orders, startDate, endDate);
|
||||
overviewVO.setSalesAmountTrend(salesAmountTrend);
|
||||
overviewVO.setOrderCountTrend(orderCountTrend);
|
||||
|
||||
// 10. 多商品数据横向对比
|
||||
List<ShopOverviewStatisticsVO.ProductComparison> productComparisons = calculateProductComparisons(
|
||||
orders, promotionFees, brushOrders, refundStatusId);
|
||||
overviewVO.setProductComparisons(productComparisons);
|
||||
|
||||
return overviewVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算总利润(税前)
|
||||
*/
|
||||
private BigDecimal calculateTotalProfit(List<OrderPO> orders) {
|
||||
return orders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal receivedAmount = order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO;
|
||||
BigDecimal productCost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
|
||||
BigDecimal shippingCost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
|
||||
BigDecimal otherCost = order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO;
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
|
||||
BigDecimal totalCost = productCost.add(shippingCost).add(otherCost).multiply(new BigDecimal(quantity));
|
||||
return receivedAmount.subtract(totalCost);
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算目标维度的数据
|
||||
*/
|
||||
private void calculateTargetData(ShopOverviewStatisticsVO overviewVO, Long companyId, Long shopId,
|
||||
LocalDate startDate, LocalDate endDate,
|
||||
BigDecimal totalSalesAmount, Integer totalOrderCount) {
|
||||
// 生成日期范围内所有月份的第一天列表
|
||||
List<LocalDate> targetMonths = new ArrayList<>();
|
||||
LocalDate currentMonth = startDate.withDayOfMonth(1);
|
||||
LocalDate endMonth = endDate.withDayOfMonth(1);
|
||||
while (!currentMonth.isAfter(endMonth)) {
|
||||
targetMonths.add(currentMonth);
|
||||
currentMonth = currentMonth.plusMonths(1);
|
||||
}
|
||||
|
||||
// 查询该店铺在这些月份的目标数据
|
||||
LambdaQueryWrapper<ShopMonthlyTargetPO> targetWrapper = new LambdaQueryWrapper<>();
|
||||
targetWrapper.eq(ShopMonthlyTargetPO::getCompanyId, companyId)
|
||||
.eq(ShopMonthlyTargetPO::getShopId, shopId)
|
||||
.in(ShopMonthlyTargetPO::getTargetMonth, targetMonths);
|
||||
List<ShopMonthlyTargetPO> targets = shopMonthlyTargetMapper.selectList(targetWrapper);
|
||||
|
||||
// 汇总目标数据
|
||||
BigDecimal totalTargetAmount = targets.stream()
|
||||
.map(target -> target.getTargetAmount() != null ? target.getTargetAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
Integer totalTargetOrderCount = targets.stream()
|
||||
.mapToInt(target -> target.getTargetOrderCount() != null ? target.getTargetOrderCount() : 0)
|
||||
.sum();
|
||||
|
||||
overviewVO.setTotalTargetAmount(totalTargetAmount);
|
||||
overviewVO.setTotalTargetOrderCount(totalTargetOrderCount);
|
||||
|
||||
// 计算达成率
|
||||
BigDecimal salesAmountAchievementRate = BigDecimal.ZERO;
|
||||
if (totalTargetAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
salesAmountAchievementRate = totalSalesAmount.divide(totalTargetAmount, 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"));
|
||||
} else if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
salesAmountAchievementRate = new BigDecimal("100");
|
||||
}
|
||||
overviewVO.setSalesAmountAchievementRate(salesAmountAchievementRate);
|
||||
|
||||
BigDecimal orderCountAchievementRate = BigDecimal.ZERO;
|
||||
if (totalTargetOrderCount > 0) {
|
||||
orderCountAchievementRate = new BigDecimal(totalOrderCount)
|
||||
.divide(new BigDecimal(totalTargetOrderCount), 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"));
|
||||
} else if (totalOrderCount > 0) {
|
||||
orderCountAchievementRate = new BigDecimal("100");
|
||||
}
|
||||
overviewVO.setOrderCountAchievementRate(orderCountAchievementRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算汇总ROI
|
||||
*/
|
||||
private BigDecimal calculateTotalROI(List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders) {
|
||||
BigDecimal totalProfit = calculateTotalProfit(orders);
|
||||
BigDecimal totalPromotionFee = promotionFees.stream()
|
||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalBrushFee = brushOrders.stream()
|
||||
.map(brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalCost = totalPromotionFee.add(totalBrushFee);
|
||||
return calculateROI(totalProfit, totalCost);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算ROI
|
||||
*/
|
||||
private BigDecimal calculateROI(BigDecimal profit, BigDecimal totalCost) {
|
||||
if (totalCost.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return profit.divide(totalCost, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算多商品数据横向对比
|
||||
*/
|
||||
private List<ShopOverviewStatisticsVO.ProductComparison> calculateProductComparisons(
|
||||
List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders, Long refundStatusId) {
|
||||
List<ShopOverviewStatisticsVO.ProductComparison> comparisons = new ArrayList<>();
|
||||
|
||||
// 按商品分组订单数据
|
||||
Map<Long, List<OrderPO>> ordersByProduct = orders.stream()
|
||||
.collect(Collectors.groupingBy(OrderPO::getProductId));
|
||||
|
||||
// 按商品分组刷单费数据(如果有商品ID)
|
||||
Map<Long, List<BrushOrderPO>> brushOrdersByProduct = brushOrders.stream()
|
||||
.filter(brush -> brush.getProductId() != null)
|
||||
.collect(Collectors.groupingBy(BrushOrderPO::getProductId));
|
||||
|
||||
// 推广费无法按商品分组(推广费只有店铺级别),所以每个商品使用相同的推广费比例
|
||||
BigDecimal totalPromotionFee = promotionFees.stream()
|
||||
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalSalesAmount = orders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
for (Map.Entry<Long, List<OrderPO>> entry : ordersByProduct.entrySet()) {
|
||||
Long productId = entry.getKey();
|
||||
List<OrderPO> productOrders = entry.getValue();
|
||||
|
||||
// 获取商品信息
|
||||
ProductPO product = productService.getById(productId);
|
||||
if (product == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 计算各项指标
|
||||
BigDecimal salesAmount = productOrders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
int orderCount = productOrders.size();
|
||||
|
||||
BigDecimal refundAmount = productOrders.stream()
|
||||
.filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId()))
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal brushFee = brushOrdersByProduct.getOrDefault(productId, new ArrayList<>()).stream()
|
||||
.map(brush -> brush.getBrushAmount() != null ? brush.getBrushAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
// 推广费按销售额比例分配
|
||||
BigDecimal productPromotionFee = BigDecimal.ZERO;
|
||||
if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal ratio = salesAmount.divide(totalSalesAmount, 4, RoundingMode.HALF_UP);
|
||||
productPromotionFee = totalPromotionFee.multiply(ratio);
|
||||
}
|
||||
|
||||
// 计算成本运费(单独计算运费成本)
|
||||
BigDecimal shippingCost = productOrders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal cost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
|
||||
return cost.multiply(new BigDecimal(quantity));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal totalCost = calculateProductTotalCost(productOrders);
|
||||
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount);
|
||||
|
||||
// 销售额4%税额
|
||||
BigDecimal salesTaxAmount = salesAmount.multiply(SALES_TAX_RATE);
|
||||
|
||||
// 税后盈亏(扣除销售额4%税额)
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
|
||||
|
||||
BigDecimal totalCostForROI = productPromotionFee.add(brushFee);
|
||||
BigDecimal roi = calculateROI(profitBeforeTax, totalCostForROI);
|
||||
|
||||
BigDecimal feeRatio = BigDecimal.ZERO;
|
||||
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
feeRatio = productPromotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
BigDecimal averageOrderValue = BigDecimal.ZERO;
|
||||
if (orderCount > 0) {
|
||||
averageOrderValue = salesAmount.divide(new BigDecimal(orderCount), 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
ShopOverviewStatisticsVO.ProductComparison comparison = new ShopOverviewStatisticsVO.ProductComparison();
|
||||
comparison.setProductId(productId);
|
||||
comparison.setProductName(product.getName());
|
||||
comparison.setProductCode(product.getProductCode());
|
||||
comparison.setSalesAmount(salesAmount);
|
||||
comparison.setOrderCount(orderCount);
|
||||
comparison.setAverageOrderValue(averageOrderValue);
|
||||
comparison.setShippingCost(shippingCost);
|
||||
comparison.setRefundAmount(refundAmount);
|
||||
comparison.setTotalPromotionFee(productPromotionFee);
|
||||
comparison.setBrushFee(brushFee);
|
||||
comparison.setFeeRatio(feeRatio);
|
||||
comparison.setTotalProfitBeforeTax(profitBeforeTax);
|
||||
comparison.setSalesTaxAmount(salesTaxAmount);
|
||||
comparison.setProfitAfterTax(profitAfterTax);
|
||||
comparison.setRoi(roi);
|
||||
comparisons.add(comparison);
|
||||
}
|
||||
|
||||
// 按销售额降序排序
|
||||
comparisons.sort(Comparator.comparing(ShopOverviewStatisticsVO.ProductComparison::getSalesAmount).reversed());
|
||||
return comparisons;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算商品总成本(订单成本)
|
||||
*/
|
||||
private BigDecimal calculateProductTotalCost(List<OrderPO> orders) {
|
||||
return orders.stream()
|
||||
.map(order -> {
|
||||
BigDecimal productCost = order.getProductCost() != null ? order.getProductCost() : BigDecimal.ZERO;
|
||||
BigDecimal shippingCost = order.getShippingCost() != null ? order.getShippingCost() : BigDecimal.ZERO;
|
||||
BigDecimal otherCost = order.getOtherCost() != null ? order.getOtherCost() : BigDecimal.ZERO;
|
||||
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 1;
|
||||
return productCost.add(shippingCost).add(otherCost).multiply(new BigDecimal(quantity));
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算销售额趋势分析
|
||||
*/
|
||||
private ShopOverviewStatisticsVO.TrendData calculateSalesAmountTrend(List<OrderPO> orders, LocalDate startDate, LocalDate endDate) {
|
||||
ShopOverviewStatisticsVO.TrendData trendData = new ShopOverviewStatisticsVO.TrendData();
|
||||
|
||||
// 按日期分组订单数据
|
||||
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> order.getOrderTime().toLocalDate()));
|
||||
|
||||
// 计算总销售额
|
||||
BigDecimal total = orders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
trendData.setTotal(total);
|
||||
|
||||
// 生成日期范围内的所有日期列表
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
LocalDate currentDate = startDate;
|
||||
while (!currentDate.isAfter(endDate)) {
|
||||
dateList.add(currentDate);
|
||||
currentDate = currentDate.plusDays(1);
|
||||
}
|
||||
|
||||
// 计算每日销售额
|
||||
List<ShopOverviewStatisticsVO.TrendDataItem> dailyDataList = dateList.stream()
|
||||
.map(date -> {
|
||||
ShopOverviewStatisticsVO.TrendDataItem item = new ShopOverviewStatisticsVO.TrendDataItem();
|
||||
item.setDate(date);
|
||||
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, new ArrayList<>());
|
||||
BigDecimal dayAmount = dayOrders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
item.setValue(dayAmount);
|
||||
return item;
|
||||
})
|
||||
.sorted(Comparator.comparing(ShopOverviewStatisticsVO.TrendDataItem::getDate))
|
||||
.collect(Collectors.toList());
|
||||
trendData.setDailyDataList(dailyDataList);
|
||||
|
||||
return trendData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算单量趋势分析
|
||||
*/
|
||||
private ShopOverviewStatisticsVO.TrendData calculateOrderCountTrend(List<OrderPO> orders, LocalDate startDate, LocalDate endDate) {
|
||||
ShopOverviewStatisticsVO.TrendData trendData = new ShopOverviewStatisticsVO.TrendData();
|
||||
|
||||
// 按日期分组订单数据
|
||||
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> order.getOrderTime().toLocalDate()));
|
||||
|
||||
// 计算总单量
|
||||
int totalCount = orders.size();
|
||||
trendData.setTotal(new BigDecimal(totalCount));
|
||||
|
||||
// 生成日期范围内的所有日期列表
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
LocalDate currentDate = startDate;
|
||||
while (!currentDate.isAfter(endDate)) {
|
||||
dateList.add(currentDate);
|
||||
currentDate = currentDate.plusDays(1);
|
||||
}
|
||||
|
||||
// 计算每日单量
|
||||
List<ShopOverviewStatisticsVO.TrendDataItem> dailyDataList = dateList.stream()
|
||||
.map(date -> {
|
||||
ShopOverviewStatisticsVO.TrendDataItem item = new ShopOverviewStatisticsVO.TrendDataItem();
|
||||
item.setDate(date);
|
||||
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, new ArrayList<>());
|
||||
int dayCount = dayOrders.size();
|
||||
item.setValue(new BigDecimal(dayCount));
|
||||
return item;
|
||||
})
|
||||
.sorted(Comparator.comparing(ShopOverviewStatisticsVO.TrendDataItem::getDate))
|
||||
.collect(Collectors.toList());
|
||||
trendData.setDailyDataList(dailyDataList);
|
||||
|
||||
return trendData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取退款状态ID(通过 is_refund 字段查询)
|
||||
*/
|
||||
private Long getRefundStatusId() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
|
||||
.eq(OrderStatusPO::getIsRefund, 1)
|
||||
.last("LIMIT 1");
|
||||
OrderStatusPO status = orderStatusService.getOne(wrapper);
|
||||
return status != null ? status.getId() : null;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -251,13 +251,14 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取退款状态ID(根据状态名称"已退款"查找)
|
||||
* 获取退款状态ID(根据 is_refund 字段查找)
|
||||
*/
|
||||
private Long getRefundStatusId() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
|
||||
.eq(OrderStatusPO::getStatusName, "已退款");
|
||||
.eq(OrderStatusPO::getIsRefund, 1)
|
||||
.last("LIMIT 1");
|
||||
OrderStatusPO status = orderStatusService.getOne(wrapper);
|
||||
return status != null ? status.getId() : null;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ CREATE TABLE `ec_order_status` (
|
||||
`description` VARCHAR(200) DEFAULT NULL COMMENT '状态描述',
|
||||
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`auto_statistics` TINYINT NOT NULL DEFAULT 1 COMMENT '是否自动参与统计 0不参与 1参与',
|
||||
`is_refund` TINYINT NOT NULL DEFAULT 0 COMMENT '是否为退款状态 0否 1是',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
@@ -89,6 +90,7 @@ CREATE TABLE `ec_order_status` (
|
||||
UNIQUE KEY `uk_company_status_name` (`company_id`, `status_name`),
|
||||
KEY `idx_sort_order` (`sort_order`),
|
||||
KEY `idx_auto_statistics` (`auto_statistics`),
|
||||
KEY `idx_is_refund` (`is_refund`),
|
||||
KEY `fk_ec_order_status_creator` (`create_by`),
|
||||
KEY `fk_ec_order_status_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_order_status_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
|
||||
@@ -13,6 +13,8 @@ export namespace OrderStatusDTO {
|
||||
sortOrder?: number;
|
||||
/** 自动统计 0不参与 1参与 */
|
||||
autoStatistics: number;
|
||||
/** 是否为退款状态 0否 1是 */
|
||||
isRefund?: number;
|
||||
}
|
||||
|
||||
/** 更新订单状态参数 */
|
||||
@@ -25,5 +27,7 @@ export namespace OrderStatusDTO {
|
||||
sortOrder?: number;
|
||||
/** 自动统计 0不参与 1参与 */
|
||||
autoStatistics: number;
|
||||
/** 是否为退款状态 0否 1是 */
|
||||
isRefund?: number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ export namespace OrderStatusVO {
|
||||
sortOrder?: number;
|
||||
/** 自动统计 0不参与 1参与 */
|
||||
autoStatistics: number;
|
||||
/** 是否为退款状态 0否 1是 */
|
||||
isRefund?: number;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { ShopDTO, ShopVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { ProductVO } from '#/api/ecommerce/product/types';
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
@@ -68,3 +68,15 @@ export async function getShopProductPageApi(
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺概览统计数据
|
||||
*/
|
||||
export async function getShopOverviewStatisticsApi(
|
||||
params: ShopDTO.OverviewQuery,
|
||||
) {
|
||||
return requestClient.post<ShopVO.OverviewStatistics>(
|
||||
'/ec/shop/overview-statistics',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,4 +46,12 @@ export namespace ShopDTO {
|
||||
/** 店铺ID */
|
||||
shopId: number;
|
||||
}
|
||||
|
||||
/** 店铺概览查询参数 */
|
||||
export interface OverviewQuery {
|
||||
/** 店铺ID */
|
||||
shopId: number;
|
||||
/** 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据) */
|
||||
dateRange: string[];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,4 +104,90 @@ export namespace ShopVO {
|
||||
/** 费比统计 */
|
||||
feeRatio: DailyStatistics;
|
||||
}
|
||||
|
||||
/** 店铺概览统计信息 */
|
||||
export interface OverviewStatistics {
|
||||
/** 店铺总销售额 */
|
||||
totalSalesAmount: number;
|
||||
/** 较上月同期增长百分比 */
|
||||
monthOverMonthGrowth?: number;
|
||||
/** 店铺总单量 */
|
||||
totalOrderCount: number;
|
||||
/** 总推广费支出 */
|
||||
totalPromotionFee: number;
|
||||
/** 平均费比(推广费/销售额) */
|
||||
averageFeeRatio?: number;
|
||||
/** 店铺总净利(税后) */
|
||||
totalNetProfitAfterTax: number;
|
||||
/** 扣除总税额 */
|
||||
totalTaxAmount?: number;
|
||||
/** 店铺总销量目标(目标订单数) */
|
||||
totalTargetOrderCount?: number;
|
||||
/** 店铺总销售额目标 */
|
||||
totalTargetAmount?: number;
|
||||
/** 销量目标达成率 */
|
||||
orderCountAchievementRate?: number;
|
||||
/** 销售额目标达成率 */
|
||||
salesAmountAchievementRate?: number;
|
||||
/** 汇总ROI */
|
||||
totalROI?: number;
|
||||
/** 总税后盈亏 */
|
||||
totalProfitAfterTax?: number;
|
||||
/** 销售额趋势分析 */
|
||||
salesAmountTrend?: TrendData;
|
||||
/** 单量趋势分析 */
|
||||
orderCountTrend?: TrendData;
|
||||
/** 多商品数据横向对比 */
|
||||
productComparisons?: ProductComparison[];
|
||||
}
|
||||
|
||||
/** 商品对比数据 */
|
||||
export interface ProductComparison {
|
||||
/** 商品ID */
|
||||
productId: number;
|
||||
/** 商品名称 */
|
||||
productName: string;
|
||||
/** 商品编码 */
|
||||
productCode?: string;
|
||||
/** 销售额 */
|
||||
salesAmount: number;
|
||||
/** 单量 */
|
||||
orderCount?: number;
|
||||
/** 客单价 */
|
||||
averageOrderValue?: number;
|
||||
/** 成本运费 */
|
||||
shippingCost?: number;
|
||||
/** 退款金额 */
|
||||
refundAmount?: number;
|
||||
/** 推广费 */
|
||||
totalPromotionFee?: number;
|
||||
/** 刷单费用 */
|
||||
brushFee?: number;
|
||||
/** 费比 */
|
||||
feeRatio?: number;
|
||||
/** 税前盈亏 */
|
||||
totalProfitBeforeTax?: number;
|
||||
/** 销售额4%税额 */
|
||||
salesTaxAmount?: number;
|
||||
/** 税后盈亏 */
|
||||
profitAfterTax?: number;
|
||||
/** ROI */
|
||||
roi?: number;
|
||||
}
|
||||
|
||||
/** 趋势数据 */
|
||||
export interface TrendData {
|
||||
/** 时间范围的总值 */
|
||||
total: number;
|
||||
/** 每日数据列表 */
|
||||
dailyDataList: TrendDataItem[];
|
||||
}
|
||||
|
||||
/** 趋势数据项 */
|
||||
export interface TrendDataItem {
|
||||
/** 日期 */
|
||||
date: string;
|
||||
/** 对应的值 */
|
||||
value: number;
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -43,6 +43,7 @@ const formData = ref<Partial<OrderStatusDTO.Create>>({
|
||||
description: '',
|
||||
autoStatistics: 1,
|
||||
sortOrder: 0,
|
||||
isRefund: 0,
|
||||
});
|
||||
|
||||
// 表单验证规则
|
||||
@@ -68,12 +69,14 @@ function open(edit: boolean, record?: OrderStatusVO.Info) {
|
||||
description: record.description || '',
|
||||
autoStatistics: record.autoStatistics,
|
||||
sortOrder: record.sortOrder || 0,
|
||||
isRefund: record.isRefund || 0,
|
||||
}
|
||||
: {
|
||||
statusName: '',
|
||||
description: '',
|
||||
autoStatistics: 1,
|
||||
sortOrder: 0,
|
||||
isRefund: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -97,6 +100,7 @@ async function handleSubmit() {
|
||||
description: formData.value.description,
|
||||
autoStatistics: formData.value.autoStatistics!,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
isRefund: formData.value.isRefund,
|
||||
};
|
||||
await updateOrderStatusApi(currentRecord.value.id, updateData);
|
||||
message.success('更新订单状态成功');
|
||||
@@ -107,6 +111,7 @@ async function handleSubmit() {
|
||||
description: formData.value.description,
|
||||
autoStatistics: formData.value.autoStatistics!,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
isRefund: formData.value.isRefund,
|
||||
};
|
||||
await createOrderStatusApi(createData);
|
||||
message.success('创建订单状态成功');
|
||||
@@ -186,6 +191,16 @@ defineExpose({
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<Form.Item label="是否为退款状态" name="isRefund">
|
||||
<Switch
|
||||
v-model:checked="formData.isRefund"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="是"
|
||||
un-checked-children="否"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,807 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
import { Button, DatePicker, message, Spin } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getShopOverviewStatisticsApi } from '#/api/ecommerce/shop';
|
||||
|
||||
defineOptions({ name: 'ShopOverview' });
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
// 店铺ID(从路由参数获取)
|
||||
const shopId = computed(() => {
|
||||
const id = route.params.id;
|
||||
return id ? Number(id) : 0;
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const overviewData = ref<null | ShopVO.OverviewStatistics>(null);
|
||||
|
||||
// 日期范围
|
||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||
dayjs().subtract(7, 'day'),
|
||||
dayjs(),
|
||||
]);
|
||||
|
||||
// 当前选中的时间范围类型
|
||||
const activeTimeRange = ref<
|
||||
'7days' | '30days' | 'custom' | 'today' | 'yesterday'
|
||||
>('7days');
|
||||
|
||||
// 自定义日期范围
|
||||
const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>(undefined);
|
||||
|
||||
// 切换时间范围
|
||||
const switchTimeRange = (
|
||||
type: '7days' | '30days' | 'custom' | 'today' | 'yesterday',
|
||||
) => {
|
||||
activeTimeRange.value = type;
|
||||
let startDate: dayjs.Dayjs;
|
||||
let endDate: dayjs.Dayjs = dayjs();
|
||||
|
||||
switch (type) {
|
||||
case '7days': {
|
||||
startDate = dayjs().subtract(7, 'day');
|
||||
break;
|
||||
}
|
||||
case '30days': {
|
||||
startDate = dayjs().subtract(30, 'day');
|
||||
break;
|
||||
}
|
||||
case 'custom': {
|
||||
if (customDateRange.value) {
|
||||
dateRange.value = customDateRange.value;
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'today': {
|
||||
startDate = dayjs();
|
||||
endDate = dayjs();
|
||||
break;
|
||||
}
|
||||
case 'yesterday': {
|
||||
startDate = dayjs().subtract(1, 'day');
|
||||
endDate = dayjs().subtract(1, 'day');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dateRange.value = [startDate, endDate];
|
||||
};
|
||||
|
||||
// 自定义日期范围变化
|
||||
const handleCustomDateRangeChange = (
|
||||
value: [dayjs.Dayjs, dayjs.Dayjs] | [string, string] | null,
|
||||
_dateString?: [string, string],
|
||||
) => {
|
||||
if (value && Array.isArray(value) && value.length === 2) {
|
||||
const dates = [
|
||||
dayjs.isDayjs(value[0]) ? value[0] : dayjs(value[0]),
|
||||
dayjs.isDayjs(value[1]) ? value[1] : dayjs(value[1]),
|
||||
] as [dayjs.Dayjs, dayjs.Dayjs];
|
||||
customDateRange.value = dates;
|
||||
activeTimeRange.value = 'custom';
|
||||
dateRange.value = dates;
|
||||
}
|
||||
};
|
||||
|
||||
// 图表引用
|
||||
const trendChartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts: renderTrendChart } = useEcharts(trendChartRef);
|
||||
|
||||
// 格式化金额
|
||||
const formatAmount = (amount: number) => {
|
||||
return `¥${amount.toLocaleString('zh-CN')}`;
|
||||
};
|
||||
|
||||
// 格式化百分比
|
||||
const formatPercent = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
|
||||
};
|
||||
|
||||
// 格式化百分比(不带符号)
|
||||
const formatPercentPlain = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value.toFixed(1)}%`;
|
||||
};
|
||||
|
||||
// 加载概览数据
|
||||
const loadOverviewData = async () => {
|
||||
if (!shopId.value) return;
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: ShopDTO.OverviewQuery = {
|
||||
shopId: shopId.value,
|
||||
dateRange: [
|
||||
dateRange.value[0].format('YYYY-MM-DD'),
|
||||
dateRange.value[1].format('YYYY-MM-DD'),
|
||||
],
|
||||
};
|
||||
const data = await getShopOverviewStatisticsApi(params);
|
||||
overviewData.value = data;
|
||||
} catch (error) {
|
||||
console.error('获取店铺概览数据失败:', error);
|
||||
message.error('获取店铺概览数据失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 渲染趋势图表
|
||||
const renderTrendChartData = () => {
|
||||
if (!trendChartRef.value || !overviewData.value) return;
|
||||
|
||||
const salesTrend = overviewData.value.salesAmountTrend;
|
||||
const orderTrend = overviewData.value.orderCountTrend;
|
||||
|
||||
if (!salesTrend || !orderTrend) return;
|
||||
|
||||
const dates = salesTrend.dailyDataList.map((item) =>
|
||||
dayjs(item.date).format('MM-DD'),
|
||||
);
|
||||
const salesData = salesTrend.dailyDataList.map((item) => item.value);
|
||||
const orderData = orderTrend.dailyDataList.map((item) => item.value);
|
||||
|
||||
renderTrendChart({
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '3%',
|
||||
bottom: '3%',
|
||||
top: '5%',
|
||||
containLabel: true,
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: '#fff',
|
||||
textStyle: { color: '#000' },
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: dates,
|
||||
axisLine: { lineStyle: { color: '#e2e8f0' } },
|
||||
},
|
||||
yAxis: [
|
||||
{
|
||||
type: 'value',
|
||||
name: '销售额',
|
||||
splitLine: { lineStyle: { type: 'dashed' } },
|
||||
},
|
||||
{
|
||||
type: 'value',
|
||||
name: '单量',
|
||||
position: 'right',
|
||||
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,
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
// 监听数据变化,重新渲染图表
|
||||
watch(
|
||||
() => overviewData.value,
|
||||
() => {
|
||||
if (overviewData.value) {
|
||||
setTimeout(() => {
|
||||
renderTrendChartData();
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// 监听日期范围变化
|
||||
watch(
|
||||
() => dateRange.value,
|
||||
() => {
|
||||
loadOverviewData();
|
||||
},
|
||||
);
|
||||
|
||||
// 监听 shopId 变化
|
||||
watch(
|
||||
() => shopId.value,
|
||||
() => {
|
||||
if (shopId.value) {
|
||||
loadOverviewData();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
if (shopId.value) {
|
||||
loadOverviewData();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="店铺经营概览" auto-content-height class="bg-[#f8fafc]">
|
||||
<template #description>
|
||||
<div class="mt-1 text-sm font-bold italic text-slate-500">
|
||||
数据更新于:{{ dayjs().format('今日 HH:mm:ss') }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<!-- 时间选择器 -->
|
||||
<div
|
||||
class="flex items-center gap-1.5 rounded-2xl border border-slate-200 bg-slate-200/50 p-1"
|
||||
>
|
||||
<!-- 快速选择按钮组 -->
|
||||
<div class="flex rounded-xl bg-white/40 p-1 shadow-inner">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-lg !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-all"
|
||||
:class="
|
||||
activeTimeRange === 'today'
|
||||
? '!bg-white !font-black !text-blue-600 !shadow-sm'
|
||||
: '!bg-transparent !text-slate-500 hover:!text-slate-800'
|
||||
"
|
||||
@click="switchTimeRange('today')"
|
||||
>
|
||||
今日
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-lg !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-all"
|
||||
:class="
|
||||
activeTimeRange === 'yesterday'
|
||||
? '!bg-white !font-black !text-blue-600 !shadow-sm'
|
||||
: '!bg-transparent !text-slate-500 hover:!text-slate-800'
|
||||
"
|
||||
@click="switchTimeRange('yesterday')"
|
||||
>
|
||||
昨日
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-lg !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-all"
|
||||
:class="
|
||||
activeTimeRange === '7days'
|
||||
? '!bg-white !font-black !text-blue-600 !shadow-sm'
|
||||
: '!bg-transparent !text-slate-500 hover:!text-slate-800'
|
||||
"
|
||||
@click="switchTimeRange('7days')"
|
||||
>
|
||||
近7日
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-lg !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-all"
|
||||
:class="
|
||||
activeTimeRange === '30days'
|
||||
? '!bg-white !font-black !text-blue-600 !shadow-sm'
|
||||
: '!bg-transparent !text-slate-500 hover:!text-slate-800'
|
||||
"
|
||||
@click="switchTimeRange('30days')"
|
||||
>
|
||||
近30日
|
||||
</Button>
|
||||
</div>
|
||||
<!-- 分隔线 -->
|
||||
<div class="mx-2 h-6 w-px bg-slate-300"></div>
|
||||
<!-- 自定义日期选择器 -->
|
||||
<div class="flex items-center gap-2 px-3">
|
||||
<span class="text-xs font-bold text-slate-400">自定义日期</span>
|
||||
<DatePicker.RangePicker
|
||||
v-model:value="customDateRange"
|
||||
size="small"
|
||||
format="YYYY-MM-DD"
|
||||
:allow-clear="false"
|
||||
:placeholder="['开始日期', '结束日期']"
|
||||
class="!cursor-pointer !border-none !bg-transparent !text-sm !font-bold"
|
||||
@change="handleCustomDateRangeChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<Spin :spinning="loading">
|
||||
<div class="mx-auto w-full space-y-6 p-4 md:p-8">
|
||||
<!-- 第一层:核心统计卡片 -->
|
||||
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<!-- 销售大盘 -->
|
||||
<div
|
||||
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 bg-white/85 p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] backdrop-blur-[12px]"
|
||||
>
|
||||
<div class="mb-4 flex items-start justify-between">
|
||||
<span
|
||||
class="text-xs font-black uppercase tracking-widest text-slate-400"
|
||||
>
|
||||
店铺销售总额
|
||||
</span>
|
||||
<span
|
||||
v-if="overviewData?.monthOverMonthGrowth !== undefined"
|
||||
class="rounded bg-emerald-50 px-2 py-1 text-xs font-bold text-emerald-600"
|
||||
>
|
||||
增长率 {{ formatPercent(overviewData.monthOverMonthGrowth) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-4xl font-black leading-none text-slate-900">
|
||||
{{
|
||||
overviewData?.totalSalesAmount
|
||||
? formatAmount(overviewData.totalSalesAmount)
|
||||
: '-'
|
||||
}}
|
||||
</div>
|
||||
<div
|
||||
v-if="overviewData?.salesAmountAchievementRate !== undefined"
|
||||
class="mt-6 flex items-center justify-between border-t border-slate-100 pt-4 text-xs font-bold"
|
||||
>
|
||||
<span class="text-slate-400">销售额目标达成</span>
|
||||
<span class="font-black text-blue-600">
|
||||
{{
|
||||
formatPercentPlain(overviewData.salesAmountAchievementRate)
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 订单达成 -->
|
||||
<div
|
||||
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 bg-white/85 p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] backdrop-blur-[12px]"
|
||||
>
|
||||
<div
|
||||
class="mb-4 text-xs font-black uppercase tracking-widest text-slate-400"
|
||||
>
|
||||
订单总量与达成
|
||||
</div>
|
||||
<div class="text-4xl font-black leading-none text-slate-900">
|
||||
{{
|
||||
overviewData?.totalOrderCount?.toLocaleString('zh-CN') || '-'
|
||||
}}
|
||||
<span class="ml-1 text-sm font-normal text-slate-400">单</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="overviewData?.orderCountAchievementRate !== undefined"
|
||||
class="mt-6"
|
||||
>
|
||||
<div
|
||||
class="mb-2 flex justify-between text-[10px] font-black text-slate-400"
|
||||
>
|
||||
<span>
|
||||
目标:
|
||||
{{
|
||||
overviewData.totalTargetOrderCount?.toLocaleString(
|
||||
'zh-CN',
|
||||
) || '-'
|
||||
}}
|
||||
单
|
||||
</span>
|
||||
<span>
|
||||
达成率:
|
||||
{{
|
||||
formatPercentPlain(overviewData.orderCountAchievementRate)
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="h-2 w-full overflow-hidden rounded-full bg-slate-100">
|
||||
<div
|
||||
class="h-full bg-indigo-500 transition-all duration-1000"
|
||||
:style="{
|
||||
width: `${Math.min(overviewData.orderCountAchievementRate || 0, 100)}%`,
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 推广效率 -->
|
||||
<div
|
||||
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 bg-white/85 p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] backdrop-blur-[12px]"
|
||||
>
|
||||
<div
|
||||
class="mb-4 text-xs font-black uppercase tracking-widest text-slate-400"
|
||||
>
|
||||
投资回报率 (ROI)
|
||||
</div>
|
||||
<div class="text-4xl font-black leading-none text-indigo-600">
|
||||
{{ overviewData?.totalROI?.toFixed(2) || '-' }}
|
||||
</div>
|
||||
<div
|
||||
v-if="overviewData?.averageFeeRatio !== undefined"
|
||||
class="mt-6 space-y-2 border-t border-slate-100 pt-4"
|
||||
>
|
||||
<div class="flex justify-between text-xs font-bold">
|
||||
<span class="text-slate-400">平均费比</span>
|
||||
<span class="text-slate-800">
|
||||
{{ formatPercentPlain(overviewData.averageFeeRatio) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 利润汇总 -->
|
||||
<div
|
||||
class="flex flex-col justify-between rounded-[20px] border-l-4 border-slate-200/80 border-l-emerald-500 bg-white/85 p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] backdrop-blur-[12px]"
|
||||
>
|
||||
<div
|
||||
class="mb-4 text-xs font-black uppercase tracking-widest text-emerald-600"
|
||||
>
|
||||
店铺总净利润 (税后)
|
||||
</div>
|
||||
<div class="text-4xl font-black leading-none text-emerald-600">
|
||||
{{
|
||||
overviewData?.totalNetProfitAfterTax
|
||||
? formatAmount(overviewData.totalNetProfitAfterTax)
|
||||
: '-'
|
||||
}}
|
||||
</div>
|
||||
<div
|
||||
v-if="overviewData?.totalTaxAmount !== undefined"
|
||||
class="mt-6 flex justify-between border-t border-slate-100 pt-4 text-[11px] font-bold text-slate-400"
|
||||
>
|
||||
<span>已扣除 4% 税额</span>
|
||||
<span>-{{ formatAmount(overviewData.totalTaxAmount) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第二层:趋势与财务拆解 -->
|
||||
<div class="grid grid-cols-1 gap-6 xl:grid-cols-3">
|
||||
<!-- 销售额趋势图 -->
|
||||
<div
|
||||
class="rounded-[20px] border border-slate-200/80 bg-white/85 p-8 shadow-[0_4px_20px_rgba(0,0,0,0.02)] backdrop-blur-[12px] xl:col-span-2"
|
||||
>
|
||||
<h3 class="mb-6 text-lg font-black text-slate-800">
|
||||
销售额与单量趋势分析
|
||||
</h3>
|
||||
<div class="h-[380px] w-full">
|
||||
<EchartsUI ref="trendChartRef" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 财务全维度损益清单 -->
|
||||
<div
|
||||
class="flex flex-col rounded-[20px] border border-slate-200/80 bg-white/85 p-8 shadow-[0_4px_20px_rgba(0,0,0,0.02)] backdrop-blur-[12px]"
|
||||
>
|
||||
<h3 class="mb-6 text-lg font-black text-slate-800">
|
||||
财务损益全维度 (P&L)
|
||||
</h3>
|
||||
<div class="flex flex-1 flex-col space-y-4 text-sm">
|
||||
<div class="flex justify-between border-b border-slate-100 pb-2">
|
||||
<span class="text-slate-500">推广费总支出</span>
|
||||
<span class="font-bold">
|
||||
{{
|
||||
overviewData?.totalPromotionFee
|
||||
? `-${formatAmount(overviewData.totalPromotionFee)}`
|
||||
: '-'
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between border-b border-slate-100 pb-2">
|
||||
<span class="text-slate-500">客单价 (AOV)</span>
|
||||
<span class="font-bold">
|
||||
{{
|
||||
overviewData?.totalSalesAmount &&
|
||||
overviewData?.totalOrderCount
|
||||
? formatAmount(
|
||||
overviewData.totalSalesAmount /
|
||||
overviewData.totalOrderCount,
|
||||
)
|
||||
: '-'
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between border-b border-slate-100 pb-2">
|
||||
<span class="text-slate-500">总税后盈亏 (Profit)</span>
|
||||
<span class="font-bold text-indigo-600">
|
||||
{{
|
||||
overviewData?.totalProfitAfterTax
|
||||
? formatAmount(overviewData.totalProfitAfterTax)
|
||||
: '-'
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
<!-- 扣除项 -->
|
||||
<div class="mt-4 space-y-3 rounded-2xl bg-slate-50/80 p-4">
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-slate-400">销售额 4% 税额</span>
|
||||
<span class="font-bold text-rose-500">
|
||||
{{
|
||||
overviewData?.totalTaxAmount
|
||||
? formatAmount(overviewData.totalTaxAmount)
|
||||
: '-'
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-slate-400">较上月同期增长</span>
|
||||
<span class="font-black text-emerald-500">
|
||||
{{ formatPercent(overviewData?.monthOverMonthGrowth) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 最终结果 -->
|
||||
<div
|
||||
class="mt-auto flex items-center justify-between rounded-2xl bg-slate-900 p-5 text-white shadow-2xl"
|
||||
>
|
||||
<div>
|
||||
<p class="text-[10px] font-black uppercase opacity-60">
|
||||
Final Net Profit
|
||||
</p>
|
||||
<p class="text-xs font-bold">税后最终净利</p>
|
||||
</div>
|
||||
<div class="text-3xl font-black">
|
||||
{{
|
||||
overviewData?.totalNetProfitAfterTax
|
||||
? formatAmount(overviewData.totalNetProfitAfterTax)
|
||||
: '-'
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第三层:多商品 16 维度横向对比表 -->
|
||||
<div
|
||||
class="overflow-hidden rounded-[20px] border border-slate-200/80 bg-white/85 shadow-[0_4px_20px_rgba(0,0,0,0.02)] backdrop-blur-[12px]"
|
||||
>
|
||||
<div
|
||||
class="flex items-center justify-between border-b border-slate-100 bg-white/40 p-8"
|
||||
>
|
||||
<div>
|
||||
<h3 class="text-xl font-black text-slate-800">
|
||||
核心商品多维度损益对比表
|
||||
</h3>
|
||||
<p class="mt-1 text-xs font-bold text-slate-400">
|
||||
横向对比各商品规模、成本及 ROI 效率
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="primary"
|
||||
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-black !shadow-xl !shadow-slate-200 !transition-all hover:!scale-105 active:!scale-95"
|
||||
>
|
||||
导出商品明细报表
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div class="table-container overflow-x-auto">
|
||||
<table class="w-full whitespace-nowrap text-left text-sm">
|
||||
<!-- 分类复合表头 -->
|
||||
<thead
|
||||
class="bg-slate-50 text-[10px] font-black uppercase tracking-tighter text-slate-500"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
rowspan="2"
|
||||
class="sticky-col border-b px-6 py-6 text-sm text-slate-900"
|
||||
>
|
||||
商品详情
|
||||
</th>
|
||||
<th
|
||||
colspan="3"
|
||||
class="border-b border-l border-slate-200 bg-slate-100/50 px-3 py-3 text-center"
|
||||
>
|
||||
商品规模 (Scale)
|
||||
</th>
|
||||
<th
|
||||
colspan="4"
|
||||
class="border-b border-l border-slate-200 bg-orange-50/50 px-3 py-3 text-center italic text-orange-700"
|
||||
>
|
||||
费用成本 (Costs)
|
||||
</th>
|
||||
<th
|
||||
colspan="5"
|
||||
class="border-b border-l border-slate-200 bg-emerald-50/50 px-3 py-3 text-center italic text-emerald-700"
|
||||
>
|
||||
单品损益 (Profitability)
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="bg-slate-50/80">
|
||||
<!-- 规模 -->
|
||||
<th class="border-b border-l px-6 py-4">销售额</th>
|
||||
<th class="border-b px-6 py-4">单量</th>
|
||||
<th class="border-b px-6 py-4">客单价</th>
|
||||
<!-- 成本 -->
|
||||
<th class="border-b border-l px-6 py-4">成本运费</th>
|
||||
<th class="border-b px-6 py-4 text-rose-600">退款金额</th>
|
||||
<th class="border-b px-6 py-4">推广费</th>
|
||||
<th class="border-b px-6 py-4">刷单费用</th>
|
||||
<!-- 损益 -->
|
||||
<th class="border-b border-l px-6 py-4">费比 %</th>
|
||||
<th class="border-b px-6 py-4 text-indigo-700">单品 ROI</th>
|
||||
<th class="border-b px-6 py-4">税前盈亏</th>
|
||||
<th class="border-b px-6 py-4 italic text-rose-500">
|
||||
4%税额
|
||||
</th>
|
||||
<th
|
||||
class="border-b bg-emerald-600 px-6 py-4 font-black text-white"
|
||||
>
|
||||
税后净利
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100">
|
||||
<tr
|
||||
v-for="product in overviewData?.productComparisons"
|
||||
:key="product.productId"
|
||||
class="transition-colors hover:bg-blue-50/30"
|
||||
>
|
||||
<td
|
||||
class="sticky-col border-r-2 border-slate-100 bg-white px-6 py-6 font-bold text-slate-900"
|
||||
>
|
||||
<div>{{ product.productName }}</div>
|
||||
<div
|
||||
v-if="product.productCode"
|
||||
class="text-[10px] font-normal text-slate-300"
|
||||
>
|
||||
编码: {{ product.productCode }}
|
||||
</div>
|
||||
</td>
|
||||
<!-- 规模 -->
|
||||
<td class="px-6 py-4 font-black">
|
||||
{{ formatAmount(product.salesAmount) }}
|
||||
</td>
|
||||
<td class="px-6 py-4 font-medium">
|
||||
{{ product.orderCount?.toLocaleString('zh-CN') || '-' }}
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
{{
|
||||
product.averageOrderValue
|
||||
? formatAmount(product.averageOrderValue)
|
||||
: '-'
|
||||
}}
|
||||
</td>
|
||||
<!-- 成本 -->
|
||||
<td class="px-6 py-4">
|
||||
{{
|
||||
product.shippingCost
|
||||
? formatAmount(product.shippingCost)
|
||||
: '-'
|
||||
}}
|
||||
</td>
|
||||
<td class="px-6 py-4 font-bold text-rose-500">
|
||||
{{
|
||||
product.refundAmount
|
||||
? formatAmount(product.refundAmount)
|
||||
: '-'
|
||||
}}
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
{{
|
||||
product.totalPromotionFee
|
||||
? formatAmount(product.totalPromotionFee)
|
||||
: '-'
|
||||
}}
|
||||
</td>
|
||||
<td class="px-6 py-4 text-amber-500">
|
||||
{{
|
||||
product.brushFee ? formatAmount(product.brushFee) : '-'
|
||||
}}
|
||||
</td>
|
||||
<!-- 损益 -->
|
||||
<td class="px-6 py-4 text-slate-400">
|
||||
{{
|
||||
product.feeRatio !== undefined
|
||||
? formatPercentPlain(product.feeRatio)
|
||||
: '-'
|
||||
}}
|
||||
</td>
|
||||
<td class="px-6 py-4 font-black text-indigo-700">
|
||||
{{ product.roi?.toFixed(2) || '-' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 font-bold text-slate-600">
|
||||
{{
|
||||
product.totalProfitBeforeTax
|
||||
? formatAmount(product.totalProfitBeforeTax)
|
||||
: '-'
|
||||
}}
|
||||
</td>
|
||||
<td class="px-6 py-4 italic text-slate-400">
|
||||
{{
|
||||
product.salesTaxAmount
|
||||
? formatAmount(product.salesTaxAmount)
|
||||
: '-'
|
||||
}}
|
||||
</td>
|
||||
<td
|
||||
class="bg-emerald-50/30 px-6 py-4 text-base font-black"
|
||||
:class="
|
||||
product.profitAfterTax && product.profitAfterTax < 0
|
||||
? 'text-rose-500'
|
||||
: 'text-emerald-600'
|
||||
"
|
||||
>
|
||||
{{
|
||||
product.profitAfterTax
|
||||
? formatAmount(product.profitAfterTax)
|
||||
: '-'
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!overviewData?.productComparisons?.length">
|
||||
<td colspan="13" class="p-8 text-center text-gray-400">
|
||||
暂无数据
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Spin>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 表格滚动条优化 */
|
||||
.table-container::-webkit-scrollbar {
|
||||
height: 6px;
|
||||
}
|
||||
.table-container::-webkit-scrollbar-thumb {
|
||||
background: #e2e8f0;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
/* 固定商品名称列 */
|
||||
.sticky-col {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,284 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>店铺经营概览 - 极简毛玻璃版</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700;800&family=Noto+Sans+SC:wght@400;700;900&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Noto Sans SC', 'Plus Jakarta Sans', sans-serif;
|
||||
background-color: #f8fafc; /* 您要求的背景色 */
|
||||
color: #0f172a;
|
||||
}
|
||||
.glass-card {
|
||||
background: rgba(255, 255, 255, 0.85);
|
||||
backdrop-filter: blur(12px);
|
||||
border: 1px solid rgba(226, 232, 240, 0.8);
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
|
||||
border-radius: 20px;
|
||||
}
|
||||
/* 时间选择器激活状态 */
|
||||
.time-btn.active { background: white; box-shadow: 0 4px 10px rgba(0,0,0,0.05); color: #3b82f6; }
|
||||
|
||||
/* 表格滚动条优化 */
|
||||
.table-container::-webkit-scrollbar { height: 6px; }
|
||||
.table-container::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 10px; }
|
||||
|
||||
/* 固定商品名称列 */
|
||||
.sticky-col { position: sticky; left: 0; background: white; z-index: 10; border-right: 2px solid #f1f5f9; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="p-4 md:p-8">
|
||||
|
||||
<div class="w-full mx-auto space-y-6">
|
||||
|
||||
<!-- 头部:标题与时间筛选器 -->
|
||||
<header class="flex flex-col lg:flex-row justify-between items-start lg:items-center gap-6">
|
||||
<div>
|
||||
<h1 class="text-3xl font-black text-slate-900 tracking-tight">店铺经营概览</h1>
|
||||
<p class="text-slate-500 font-bold mt-1 text-sm italic">数据更新于:今日 20:45:12</p>
|
||||
</div>
|
||||
|
||||
<!-- 时间选择组件 (优化后的 UI) -->
|
||||
<div class="flex items-center gap-1.5 bg-slate-200/50 p-1 rounded-2xl border border-slate-200">
|
||||
<div class="flex bg-white/40 rounded-xl p-1 shadow-inner">
|
||||
<button class="px-5 py-2 text-sm font-bold text-slate-500 hover:text-slate-800 transition">今日</button>
|
||||
<button class="px-5 py-2 text-sm font-bold text-slate-500 hover:text-slate-800 transition">昨日</button>
|
||||
<button class="bg-white px-5 py-2 text-sm font-black rounded-lg shadow-sm text-blue-600">近7日</button>
|
||||
<button class="px-5 py-2 text-sm font-bold text-slate-500 hover:text-slate-800 transition">近30日</button>
|
||||
</div>
|
||||
<div class="w-px h-6 bg-slate-300 mx-2"></div>
|
||||
<div class="flex items-center gap-2 px-3">
|
||||
<span class="text-xs font-bold text-slate-400">自定义日期</span>
|
||||
<input type="date" class="bg-transparent text-sm font-bold outline-none cursor-pointer">
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 第一层:核心统计卡片 (基于 OverviewStatistics) -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-6">
|
||||
<!-- 销售大盘 -->
|
||||
<div class="glass-card p-6 flex flex-col justify-between">
|
||||
<div class="flex justify-between items-start mb-4">
|
||||
<span class="text-xs font-black text-slate-400 uppercase tracking-widest">店铺销售总额</span>
|
||||
<span class="text-xs font-bold text-emerald-600 bg-emerald-50 px-2 py-1 rounded">增长率 +12.4%</span>
|
||||
</div>
|
||||
<div class="text-4xl font-black text-slate-900 leading-none">¥1,284,000</div>
|
||||
<div class="mt-6 pt-4 border-t border-slate-100 flex justify-between items-center text-xs font-bold">
|
||||
<span class="text-slate-400">销售额目标达成</span>
|
||||
<span class="text-blue-600 font-black">96.5%</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 订单达成 -->
|
||||
<div class="glass-card p-6 flex flex-col justify-between">
|
||||
<div class="text-xs font-black text-slate-400 mb-4 uppercase tracking-widest">订单总量与达成</div>
|
||||
<div class="text-4xl font-black text-slate-900 leading-none">8,412 <span class="text-sm font-normal text-slate-400 ml-1">单</span></div>
|
||||
<div class="mt-6">
|
||||
<div class="flex justify-between text-[10px] font-black text-slate-400 mb-2">
|
||||
<span>目标: 10,000 单</span>
|
||||
<span>达成率: 84.1%</span>
|
||||
</div>
|
||||
<div class="w-full bg-slate-100 h-2 rounded-full overflow-hidden">
|
||||
<div class="bg-indigo-500 h-full transition-all duration-1000" style="width: 84.1%"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 推广效率 -->
|
||||
<div class="glass-card p-6 flex flex-col justify-between">
|
||||
<div class="text-xs font-black text-slate-400 mb-4 uppercase tracking-widest">投资回报率 (ROI)</div>
|
||||
<div class="text-4xl font-black text-indigo-600 leading-none">4.21</div>
|
||||
<div class="mt-6 pt-4 border-t border-slate-100 space-y-2">
|
||||
<div class="flex justify-between text-xs font-bold">
|
||||
<span class="text-slate-400">平均费比</span>
|
||||
<span class="text-slate-800">23.7%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 利润汇总 -->
|
||||
<div class="glass-card p-6 border-l-4 border-l-emerald-500 flex flex-col justify-between">
|
||||
<div class="text-xs font-black text-emerald-600 mb-4 uppercase tracking-widest">店铺总净利润 (税后)</div>
|
||||
<div class="text-4xl font-black text-emerald-600 leading-none">¥124,500</div>
|
||||
<div class="mt-6 pt-4 border-t border-slate-100 flex justify-between text-[11px] font-bold text-slate-400">
|
||||
<span>已扣除 4% 税额</span>
|
||||
<span>-¥51,360</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第二层:趋势与财务拆解 -->
|
||||
<div class="grid grid-cols-1 xl:grid-cols-3 gap-6">
|
||||
<!-- 销售额趋势图 -->
|
||||
<div class="xl:col-span-2 glass-card p-8">
|
||||
<h3 class="text-lg font-black text-slate-800 mb-6">销售额与单量趋势分析</h3>
|
||||
<div id="mainTrendChart" style="height: 380px;" class="w-full"></div>
|
||||
</div>
|
||||
|
||||
<!-- 财务全维度损益清单 -->
|
||||
<div class="glass-card p-8 flex flex-col">
|
||||
<h3 class="text-lg font-black text-slate-800 mb-6">财务损益全维度 (P&L)</h3>
|
||||
<div class="space-y-4 text-sm flex-1">
|
||||
<div class="flex justify-between border-b border-slate-100 pb-2"><span class="text-slate-500">推广费总支出</span><span class="font-bold">-¥305,000</span></div>
|
||||
<div class="flex justify-between border-b border-slate-100 pb-2"><span class="text-slate-500">客单价 (AOV)</span><span class="font-bold">¥152.80</span></div>
|
||||
<div class="flex justify-between border-b border-slate-100 pb-2"><span class="text-slate-500">总税后盈亏 (Profit)</span><span class="font-bold text-indigo-600">¥175,860</span></div>
|
||||
<!-- 扣除项 -->
|
||||
<div class="bg-slate-50/80 p-4 rounded-2xl space-y-3 mt-4">
|
||||
<div class="flex justify-between text-xs"><span class="text-slate-400">销售额 4% 税额</span><span class="text-rose-500 font-bold">¥51,360</span></div>
|
||||
<div class="flex justify-between text-xs"><span class="text-slate-400">较上月同期增长</span><span class="text-emerald-500 font-black">+14.2%</span></div>
|
||||
</div>
|
||||
<!-- 最终结果 -->
|
||||
<div class="mt-auto p-5 rounded-2xl bg-slate-900 text-white flex justify-between items-center shadow-2xl">
|
||||
<div>
|
||||
<p class="text-[10px] font-black uppercase opacity-60">Final Net Profit</p>
|
||||
<p class="text-xs font-bold">税后最终净利</p>
|
||||
</div>
|
||||
<div class="text-3xl font-black">¥124,500</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第三层:多商品 16 维度横向对比表 (基于 ProductComparison) -->
|
||||
<div class="glass-card overflow-hidden">
|
||||
<div class="p-8 border-b border-slate-100 flex justify-between items-center bg-white/40">
|
||||
<div>
|
||||
<h3 class="text-xl font-black text-slate-800">核心商品多维度损益对比表</h3>
|
||||
<p class="text-xs text-slate-400 font-bold mt-1">横向对比各商品规模、成本及 ROI 效率</p>
|
||||
</div>
|
||||
<button class="bg-slate-900 text-white px-8 py-3 rounded-2xl text-sm font-black shadow-xl shadow-slate-200 hover:scale-105 active:scale-95 transition-all">导出商品明细报表</button>
|
||||
</div>
|
||||
|
||||
<div class="table-container overflow-x-auto">
|
||||
<table class="w-full text-left text-sm whitespace-nowrap">
|
||||
<!-- 分类复合表头 -->
|
||||
<thead class="bg-slate-50 text-[10px] font-black text-slate-500 uppercase tracking-tighter">
|
||||
<tr>
|
||||
<th rowspan="2" class="px-6 py-6 border-b sticky-col text-slate-900 text-sm">商品详情</th>
|
||||
<th colspan="3" class="px-3 py-3 border-b border-l border-slate-200 text-center bg-slate-100/50">商品规模 (Scale)</th>
|
||||
<th colspan="4" class="px-3 py-3 border-b border-l border-slate-200 text-center bg-orange-50/50 text-orange-700 italic">费用成本 (Costs)</th>
|
||||
<th colspan="5" class="px-3 py-3 border-b border-l border-slate-200 text-center bg-emerald-50/50 text-emerald-700 italic">单品损益 (Profitability)</th>
|
||||
</tr>
|
||||
<tr class="bg-slate-50/80">
|
||||
<!-- 规模 -->
|
||||
<th class="px-6 py-4 border-b border-l">销售额</th>
|
||||
<th class="px-6 py-4 border-b">单量</th>
|
||||
<th class="px-6 py-4 border-b">客单价</th>
|
||||
<!-- 成本 -->
|
||||
<th class="px-6 py-4 border-b border-l">成本运费</th>
|
||||
<th class="px-6 py-4 border-b text-rose-600">退款金额</th>
|
||||
<th class="px-6 py-4 border-b">推广费</th>
|
||||
<th class="px-6 py-4 border-b">刷单费用</th>
|
||||
<!-- 损益 -->
|
||||
<th class="px-6 py-4 border-b border-l">费比 %</th>
|
||||
<th class="px-6 py-4 border-b text-indigo-700">单品 ROI</th>
|
||||
<th class="px-6 py-4 border-b">税前盈亏</th>
|
||||
<th class="px-6 py-4 border-b text-rose-500 italic">4%税额</th>
|
||||
<th class="px-6 py-4 border-b bg-emerald-600 text-white font-black">税后净利</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100">
|
||||
<!-- 演示数据:智能降噪耳机 -->
|
||||
<tr class="hover:bg-blue-50/30 transition-colors">
|
||||
<td class="px-6 py-6 font-bold text-slate-900 sticky-col">
|
||||
<div>智能降噪耳机 G200</div>
|
||||
<div class="text-[10px] text-slate-300 font-normal">编码: ITEM-99201</div>
|
||||
</td>
|
||||
<!-- 规模 -->
|
||||
<td class="px-6 py-4 font-black">¥428,000</td>
|
||||
<td class="px-6 py-4 font-medium">1,240</td>
|
||||
<td class="px-6 py-4">¥345.1</td>
|
||||
<!-- 成本 -->
|
||||
<td class="px-6 py-4">¥42,400</td>
|
||||
<td class="px-6 py-4 text-rose-500 font-bold">¥12,400</td>
|
||||
<td class="px-6 py-4">¥65,000</td>
|
||||
<td class="px-6 py-4 text-amber-500">¥4,500</td>
|
||||
<!-- 损益 -->
|
||||
<td class="px-6 py-4 text-slate-400">15.1%</td>
|
||||
<td class="px-6 py-4 font-black text-indigo-700">6.58</td>
|
||||
<td class="px-6 py-4 font-bold text-slate-600">¥102,500</td>
|
||||
<td class="px-6 py-4 text-slate-400 italic">¥17,120</td>
|
||||
<td class="px-6 py-4 font-black text-emerald-600 text-base bg-emerald-50/30">¥85,380</td>
|
||||
</tr>
|
||||
<!-- 演示数据:复古相机 -->
|
||||
<tr class="hover:bg-blue-50/30 transition-colors">
|
||||
<td class="px-6 py-6 font-bold text-slate-900 sticky-col">
|
||||
<div>复古数码相机 RX-X</div>
|
||||
<div class="text-[10px] text-slate-300 font-normal">编码: ITEM-00821</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 font-black">¥215,000</td>
|
||||
<td class="px-6 py-4 font-medium">890</td>
|
||||
<td class="px-6 py-4">¥241.5</td>
|
||||
<td class="px-6 py-4">¥28,000</td>
|
||||
<td class="px-6 py-4 text-rose-500 font-bold">¥32,000</td>
|
||||
<td class="px-6 py-4">¥82,000</td>
|
||||
<td class="px-6 py-4 text-amber-500">¥8,500</td>
|
||||
<td class="px-6 py-4 text-slate-400">38.1%</td>
|
||||
<td class="px-6 py-4 font-black text-indigo-700">2.62</td>
|
||||
<td class="px-6 py-4 font-bold text-slate-600">¥12,400</td>
|
||||
<td class="px-6 py-4 text-slate-400 italic">¥8,600</td>
|
||||
<td class="px-6 py-4 font-black text-rose-500 text-base bg-rose-50/30">¥3,800</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 销售趋势与单量图 (复刻参考图中的顺滑面积图)
|
||||
const trendChart = echarts.init(document.getElementById('mainTrendChart'));
|
||||
trendChart.setOption({
|
||||
grid: { left: '3%', right: '3%', bottom: '3%', top: '5%', containLabel: true },
|
||||
tooltip: { trigger: 'axis', backgroundColor: '#fff', textStyle: { color: '#000' } },
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: ['10-01', '10-02', '10-03', '10-04', '10-05', '10-06', '10-07'],
|
||||
axisLine: { lineStyle: { color: '#e2e8f0' } }
|
||||
},
|
||||
yAxis: [
|
||||
{ type: 'value', name: '销售额', splitLine: { lineStyle: { type: 'dashed' } } },
|
||||
{ type: 'value', name: '单量', position: 'right', splitLine: { show: false } }
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: '销售额',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
lineStyle: { width: 3, color: '#3b82f6' },
|
||||
areaStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: 'rgba(59, 130, 246, 0.4)' },
|
||||
{ offset: 1, color: 'rgba(59, 130, 246, 0)' }
|
||||
])
|
||||
},
|
||||
data: [82000, 93000, 90000, 120000, 129000, 133000, 128400]
|
||||
},
|
||||
{
|
||||
name: '日单量',
|
||||
type: 'line',
|
||||
yAxisIndex: 1,
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
lineStyle: { width: 3, color: '#10b981' },
|
||||
areaStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: 'rgba(16, 185, 129, 0.2)' },
|
||||
{ offset: 1, color: 'rgba(16, 185, 129, 0)' }
|
||||
])
|
||||
},
|
||||
data: [520, 610, 580, 720, 850, 890, 812]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
window.onresize = () => trendChart.resize();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user