移除店铺总览功能(已迁移至概览模块)

This commit is contained in:
小蟑螂
2026-05-04 22:04:45 +08:00
parent 143cf1b977
commit 17bbae66a1
8 changed files with 1 additions and 610 deletions
@@ -15,12 +15,10 @@ import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.UpdateShopDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopOverviewQueryDTO; import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopOverviewQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopOverviewVO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.ShopOverviewStatisticsVO; import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo.ShopOverviewStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService; import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
@@ -92,15 +90,6 @@ public class ShopController {
return ApiResponse.success("Logo上传成功", fileVO); return ApiResponse.success("Logo上传成功", fileVO);
} }
@Operation(summary = "获取店铺总览", description = "获取店铺总览,返回日期范围内每日的销售额、订单数、客单价、成本、退款金额、推广费、费比统计数据,包含时间范围的总值和每日数据数组")
@PostMapping("/overview")
@RequirePermission(value = "ecom:shop:read", description = "查询店铺总览", allowSuper = true)
public ApiResponse<ShopOverviewVO> getShopOverview(
@Valid @RequestBody ShopStatisticsQueryDTO queryDTO) {
ShopOverviewVO overview = shopService.getShopOverview(queryDTO);
return ApiResponse.success("获取店铺总览成功", overview);
}
@Operation(summary = "分页获取店铺商品信息", description = "通过中间表分页获取店铺商品信息,包含商品基本信息和规格列表") @Operation(summary = "分页获取店铺商品信息", description = "通过中间表分页获取店铺商品信息,包含商品基本信息和规格列表")
@PostMapping("/products/list") @PostMapping("/products/list")
@RequirePermission(value = "ecom:shop:read", description = "查询店铺商品列表", allowSuper = true) @RequirePermission(value = "ecom:shop:read", description = "查询店铺商品列表", allowSuper = true)
@@ -1,37 +0,0 @@
package top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDate;
/**
* 店铺统计查询DTO
*/
@Data
@Schema(description = "店铺统计查询DTO")
public class ShopStatisticsQueryDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
/**
* 开始日期
*/
@Schema(description = "开始日期", example = "2024-01-01", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "开始日期不能为空")
private LocalDate startDate;
/**
* 结束日期
*/
@Schema(description = "结束日期", example = "2024-01-31", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "结束日期不能为空")
private LocalDate endDate;
}
@@ -1,99 +0,0 @@
package top.xyquan.ecomdmbbackend.modules.ecom.shop.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 ShopOverviewVO {
/**
* 销售额统计
*/
@Schema(description = "销售额统计")
private DailyStatistics salesAmount;
/**
* 订单数统计
*/
@Schema(description = "订单数统计")
private DailyStatistics orderCount;
/**
* 客单价统计
*/
@Schema(description = "客单价统计")
private DailyStatistics averageOrderValue;
/**
* 成本统计
*/
@Schema(description = "成本统计")
private DailyStatistics costAmount;
/**
* 退款金额统计
*/
@Schema(description = "退款金额统计")
private DailyStatistics refundAmount;
/**
* 推广费统计
*/
@Schema(description = "推广费统计")
private DailyStatistics promotionFee;
/**
* 费比统计
*/
@Schema(description = "费比统计")
private DailyStatistics feeRatio;
/**
* 每日统计数据
*/
@Data
@Schema(description = "每日统计数据")
public static class DailyStatistics {
/**
* 时间范围的总值
*/
@Schema(description = "时间范围的总值")
private BigDecimal total;
/**
* 每日数据列表
*/
@Schema(description = "每日数据列表")
private List<DailyData> dailyDataList;
}
/**
* 每日数据项
*/
@Data
@Schema(description = "每日数据项")
public static class DailyData {
/**
* 日期
*/
@JsonFormat(pattern = "yyyy-MM-dd")
@Schema(description = "日期", example = "2024-01-01")
private LocalDate date;
/**
* 对应的值
*/
@Schema(description = "对应的值")
private BigDecimal value;
}
}
@@ -8,12 +8,10 @@ import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.UpdateShopDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopOverviewVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO; import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO;
@@ -62,14 +60,6 @@ public interface ShopService extends IService<ShopPO> {
*/ */
SysFileUploadVO uploadLogo(MultipartFile file); SysFileUploadVO uploadLogo(MultipartFile file);
/**
* 获取店铺总览(每日统计数据)
*
* @param queryDTO 统计查询DTO
* @return 店铺总览VO
*/
ShopOverviewVO getShopOverview(ShopStatisticsQueryDTO queryDTO);
/** /**
* 分页获取店铺商品信息 * 分页获取店铺商品信息
* *
@@ -21,16 +21,12 @@ import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopProductRelationMapper; import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopProductRelationMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.mapper.ShopMonthlyTargetMapper; import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.mapper.ShopMonthlyTargetMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.model.po.ShopMonthlyTargetPO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.model.po.ShopMonthlyTargetPO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.model.vo.ShopMonthlyTargetVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.CreateShopDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopProductPageFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.UpdateShopDTO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.dto.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO; import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO; import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO;
@@ -39,7 +35,6 @@ import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopProductRelationP
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSpecVO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSpecVO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopDashboardVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopOverviewVO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO; import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService; import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService; import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
@@ -57,9 +52,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -76,7 +69,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
private final ProductMapper productMapper; private final ProductMapper productMapper;
private final ShopProductRelationMapper shopProductRelationMapper; private final ShopProductRelationMapper shopProductRelationMapper;
private final ProductSpecService productSpecService; private final ProductSpecService productSpecService;
private final OrderStatusService orderStatusService;
private final PlatformMapper platformMapper; private final PlatformMapper platformMapper;
private final BrushOrderMapper brushOrderMapper; private final BrushOrderMapper brushOrderMapper;
private final ShopMonthlyTargetMapper shopMonthlyTargetMapper; private final ShopMonthlyTargetMapper shopMonthlyTargetMapper;
@@ -85,7 +77,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
OrderMapper orderMapper, PromotionFeeMapper promotionFeeMapper, OrderMapper orderMapper, PromotionFeeMapper promotionFeeMapper,
ProductMapper productMapper, ProductMapper productMapper,
ShopProductRelationMapper shopProductRelationMapper, ProductSpecService productSpecService, ShopProductRelationMapper shopProductRelationMapper, ProductSpecService productSpecService,
OrderStatusService orderStatusService, PlatformMapper platformMapper, PlatformMapper platformMapper,
BrushOrderMapper brushOrderMapper, ShopMonthlyTargetMapper shopMonthlyTargetMapper) { BrushOrderMapper brushOrderMapper, ShopMonthlyTargetMapper shopMonthlyTargetMapper) {
this.currentUserContext = currentUserContext; this.currentUserContext = currentUserContext;
this.sysFileMapper = sysFileMapper; this.sysFileMapper = sysFileMapper;
@@ -95,7 +87,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
this.productMapper = productMapper; this.productMapper = productMapper;
this.shopProductRelationMapper = shopProductRelationMapper; this.shopProductRelationMapper = shopProductRelationMapper;
this.productSpecService = productSpecService; this.productSpecService = productSpecService;
this.orderStatusService = orderStatusService;
this.platformMapper = platformMapper; this.platformMapper = platformMapper;
this.brushOrderMapper = brushOrderMapper; this.brushOrderMapper = brushOrderMapper;
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper; this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
@@ -258,19 +249,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
return files.get(0); return files.get(0);
} }
/**
* 获取退款状态ID(根据 is_refund 字段查找)
*/
private List<Long> getRefundStatusIds() {
Long companyId = currentUserContext.getCurrentCompanyId();
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
.eq(OrderStatusPO::getIsRefund, 1)
.select(OrderStatusPO::getId);
List<OrderStatusPO> statusList = orderStatusService.list(wrapper);
return statusList.stream().map(OrderStatusPO::getId).collect(Collectors.toList());
}
/** /**
* 转换为VO * 转换为VO
*/ */
@@ -297,367 +275,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
return shopVO; return shopVO;
} }
/**
* 获取店铺总览(每日统计数据)
*/
@Override
public ShopOverviewVO getShopOverview(ShopStatisticsQueryDTO queryDTO) {
// 从token中获取公司ID
Long companyId = currentUserContext.getCurrentCompanyId();
// 验证店铺是否存在
ShopPO shop = this.getById(queryDTO.getShopId());
if (shop == null || !shop.getCompanyId().equals(companyId)) {
throw new BusinessException("店铺不存在");
}
// 验证日期范围
if (queryDTO.getStartDate().isAfter(queryDTO.getEndDate())) {
throw new BusinessException("开始日期不能晚于结束日期");
}
// 查询时间范围(订单使用orderTime,推广费使用feeDate)
LocalDateTime startDateTime = queryDTO.getStartDate().atStartOfDay();
LocalDateTime endDateTime = queryDTO.getEndDate().atTime(23, 59, 59);
// 查询订单数据
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, queryDTO.getStartDate())
.le(PromotionFeePO::getFeeDate, queryDTO.getEndDate());
List<PromotionFeePO> promotionFees = promotionFeeMapper.selectList(promotionWrapper);
// 获取退款状态ID
List<Long> refundStatusIds = getRefundStatusIds();
// 按日期分组订单数据
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
.collect(Collectors.groupingBy(order -> order.getOrderTime().toLocalDate()));
// 按日期分组推广费数据
Map<LocalDate, List<PromotionFeePO>> promotionFeesByDate = promotionFees.stream()
.collect(Collectors.groupingBy(PromotionFeePO::getFeeDate));
// 生成日期范围内的所有日期列表
List<LocalDate> dateList = new ArrayList<>();
LocalDate currentDate = queryDTO.getStartDate();
while (!currentDate.isAfter(queryDTO.getEndDate())) {
dateList.add(currentDate);
currentDate = currentDate.plusDays(1);
}
// 构建返回对象
ShopOverviewVO overviewVO = new ShopOverviewVO();
// 计算销售额统计
ShopOverviewVO.DailyStatistics salesAmountStats = calculateSalesAmountStatistics(
ordersByDate, dateList, orders);
overviewVO.setSalesAmount(salesAmountStats);
// 计算订单数统计
ShopOverviewVO.DailyStatistics orderCountStats = calculateOrderCountStatistics(
ordersByDate, dateList, orders);
overviewVO.setOrderCount(orderCountStats);
// 计算客单价统计
ShopOverviewVO.DailyStatistics averageOrderValueStats = calculateAverageOrderValueStatistics(
salesAmountStats, orderCountStats);
overviewVO.setAverageOrderValue(averageOrderValueStats);
// 计算成本统计
ShopOverviewVO.DailyStatistics costAmountStats = calculateCostAmountStatistics(
ordersByDate, dateList, orders);
overviewVO.setCostAmount(costAmountStats);
// 计算退款金额统计
ShopOverviewVO.DailyStatistics refundAmountStats = calculateRefundAmountStatistics(
ordersByDate, dateList, orders, refundStatusIds);
overviewVO.setRefundAmount(refundAmountStats);
// 计算推广费统计
ShopOverviewVO.DailyStatistics promotionFeeStats = calculatePromotionFeeStatistics(
promotionFeesByDate, dateList, promotionFees);
overviewVO.setPromotionFee(promotionFeeStats);
// 计算费比统计
ShopOverviewVO.DailyStatistics feeRatioStats = calculateFeeRatioStatistics(
salesAmountStats, promotionFeeStats);
overviewVO.setFeeRatio(feeRatioStats);
return overviewVO;
}
/**
* 计算销售额统计
*/
private ShopOverviewVO.DailyStatistics calculateSalesAmountStatistics(
Map<LocalDate, List<OrderPO>> ordersByDate, List<LocalDate> dateList, List<OrderPO> allOrders) {
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
// 计算总销售额
BigDecimal total = allOrders.stream()
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
stats.setTotal(total);
// 计算每日销售额
List<ShopOverviewVO.DailyData> dailyDataList = dateList.stream()
.map(date -> {
ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData();
dailyData.setDate(date);
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
BigDecimal dayAmount = dayOrders.stream()
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
dailyData.setValue(dayAmount);
return dailyData;
})
.sorted(Comparator.comparing(ShopOverviewVO.DailyData::getDate))
.collect(Collectors.toList());
stats.setDailyDataList(dailyDataList);
return stats;
}
/**
* 计算订单数统计
*/
private ShopOverviewVO.DailyStatistics calculateOrderCountStatistics(
Map<LocalDate, List<OrderPO>> ordersByDate, List<LocalDate> dateList, List<OrderPO> allOrders) {
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
// 计算总订单数(按平台订单号去重)
long totalCount = allOrders.stream()
.map(OrderPO::getPlatformOrderNo)
.filter(no -> no != null && !no.isEmpty())
.distinct()
.count();
if (totalCount == 0) {
totalCount = allOrders.size();
}
stats.setTotal(BigDecimal.valueOf(totalCount));
// 计算每日订单数
List<ShopOverviewVO.DailyData> dailyDataList = dateList.stream()
.map(date -> {
ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData();
dailyData.setDate(date);
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
long dayCount = dayOrders.stream()
.map(OrderPO::getPlatformOrderNo)
.filter(no -> no != null && !no.isEmpty())
.distinct()
.count();
if (dayCount == 0) {
dayCount = dayOrders.size();
}
dailyData.setValue(BigDecimal.valueOf(dayCount));
return dailyData;
})
.sorted(Comparator.comparing(ShopOverviewVO.DailyData::getDate))
.collect(Collectors.toList());
stats.setDailyDataList(dailyDataList);
return stats;
}
/**
* 计算客单价统计
*/
private ShopOverviewVO.DailyStatistics calculateAverageOrderValueStatistics(
ShopOverviewVO.DailyStatistics salesAmountStats, ShopOverviewVO.DailyStatistics orderCountStats) {
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
// 计算总客单价
BigDecimal totalSales = salesAmountStats.getTotal();
BigDecimal totalOrders = orderCountStats.getTotal();
BigDecimal total = totalOrders.compareTo(BigDecimal.ZERO) > 0
? totalSales.divide(totalOrders, 2, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
stats.setTotal(total);
// 计算每日客单价
List<ShopOverviewVO.DailyData> dailyDataList = new ArrayList<>();
for (int i = 0; i < salesAmountStats.getDailyDataList().size(); i++) {
ShopOverviewVO.DailyData salesData = salesAmountStats.getDailyDataList().get(i);
ShopOverviewVO.DailyData orderData = orderCountStats.getDailyDataList().get(i);
ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData();
dailyData.setDate(salesData.getDate());
BigDecimal dayValue = orderData.getValue().compareTo(BigDecimal.ZERO) > 0
? salesData.getValue().divide(orderData.getValue(), 2, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
dailyData.setValue(dayValue);
dailyDataList.add(dailyData);
}
stats.setDailyDataList(dailyDataList);
return stats;
}
/**
* 计算成本统计
*/
private ShopOverviewVO.DailyStatistics calculateCostAmountStatistics(
Map<LocalDate, List<OrderPO>> ordersByDate, List<LocalDate> dateList, List<OrderPO> allOrders) {
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
// 计算总成本(单件商品成本 + 单件运费成本 + 单件其他成本) * 数量
BigDecimal total = allOrders.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;
BigDecimal unitCost = productCost.add(shippingCost).add(otherCost);
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 0;
return unitCost.multiply(BigDecimal.valueOf(quantity));
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
stats.setTotal(total);
// 计算每日成本
List<ShopOverviewVO.DailyData> dailyDataList = dateList.stream()
.map(date -> {
ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData();
dailyData.setDate(date);
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
BigDecimal dayCost = dayOrders.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;
BigDecimal unitCost = productCost.add(shippingCost).add(otherCost);
Integer quantity = order.getQuantity() != null ? order.getQuantity() : 0;
return unitCost.multiply(BigDecimal.valueOf(quantity));
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
dailyData.setValue(dayCost);
return dailyData;
})
.sorted(Comparator.comparing(ShopOverviewVO.DailyData::getDate))
.collect(Collectors.toList());
stats.setDailyDataList(dailyDataList);
return stats;
}
/**
* 计算退款金额统计
*/
private ShopOverviewVO.DailyStatistics calculateRefundAmountStatistics(
Map<LocalDate, List<OrderPO>> ordersByDate, List<LocalDate> dateList,
List<OrderPO> allOrders, List<Long> refundStatusIds) {
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
// 计算总退款金额
BigDecimal total = BigDecimal.ZERO;
if (!refundStatusIds.isEmpty()) {
total = allOrders.stream()
.filter(order -> refundStatusIds.contains(order.getStatusId()))
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
stats.setTotal(total);
// 计算每日退款金额
List<ShopOverviewVO.DailyData> dailyDataList = dateList.stream()
.map(date -> {
ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData();
dailyData.setDate(date);
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
BigDecimal dayRefund = BigDecimal.ZERO;
if (!refundStatusIds.isEmpty()) {
dayRefund = dayOrders.stream()
.filter(order -> refundStatusIds.contains(order.getStatusId()))
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
dailyData.setValue(dayRefund);
return dailyData;
})
.sorted(Comparator.comparing(ShopOverviewVO.DailyData::getDate))
.collect(Collectors.toList());
stats.setDailyDataList(dailyDataList);
return stats;
}
/**
* 计算推广费统计
*/
private ShopOverviewVO.DailyStatistics calculatePromotionFeeStatistics(
Map<LocalDate, List<PromotionFeePO>> promotionFeesByDate, List<LocalDate> dateList,
List<PromotionFeePO> allPromotionFees) {
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
// 计算总推广费
BigDecimal total = allPromotionFees.stream()
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
stats.setTotal(total);
// 计算每日推广费
List<ShopOverviewVO.DailyData> dailyDataList = dateList.stream()
.map(date -> {
ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData();
dailyData.setDate(date);
List<PromotionFeePO> dayFees = promotionFeesByDate.getOrDefault(date, List.of());
BigDecimal dayFee = dayFees.stream()
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
dailyData.setValue(dayFee);
return dailyData;
})
.sorted(Comparator.comparing(ShopOverviewVO.DailyData::getDate))
.collect(Collectors.toList());
stats.setDailyDataList(dailyDataList);
return stats;
}
/**
* 计算费比统计
*/
private ShopOverviewVO.DailyStatistics calculateFeeRatioStatistics(
ShopOverviewVO.DailyStatistics salesAmountStats, ShopOverviewVO.DailyStatistics promotionFeeStats) {
ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics();
// 计算总费比
BigDecimal totalSales = salesAmountStats.getTotal();
BigDecimal totalPromotionFee = promotionFeeStats.getTotal();
BigDecimal total = totalSales.compareTo(BigDecimal.ZERO) > 0
? totalPromotionFee.divide(totalSales, 4, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
stats.setTotal(total);
// 计算每日费比
List<ShopOverviewVO.DailyData> dailyDataList = new ArrayList<>();
for (int i = 0; i < salesAmountStats.getDailyDataList().size(); i++) {
ShopOverviewVO.DailyData salesData = salesAmountStats.getDailyDataList().get(i);
ShopOverviewVO.DailyData promotionData = promotionFeeStats.getDailyDataList().get(i);
ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData();
dailyData.setDate(salesData.getDate());
BigDecimal dayValue = salesData.getValue().compareTo(BigDecimal.ZERO) > 0
? promotionData.getValue().divide(salesData.getValue(), 4, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
dailyData.setValue(dayValue);
dailyDataList.add(dailyData);
}
stats.setDailyDataList(dailyDataList);
return stats;
}
/** /**
* 分页获取店铺商品信息 * 分页获取店铺商品信息
*/ */
@@ -50,13 +50,6 @@ export async function uploadShopLogoApi(file: File) {
}); });
} }
/**
* 获取店铺总览
*/
export async function getShopOverviewApi(params: ShopDTO.StatisticsQuery) {
return requestClient.post<ShopVO.Overview>('/ec/shop/overview', params);
}
/** /**
* 分页获取店铺商品信息 * 分页获取店铺商品信息
*/ */
@@ -31,16 +31,6 @@ export namespace ShopDTO {
platformId?: number; platformId?: number;
} }
/** 店铺统计查询参数 */
export interface StatisticsQuery {
/** 店铺ID */
shopId: number;
/** 开始日期 */
startDate: string;
/** 结束日期 */
endDate: string;
}
/** 店铺商品分页查询过滤条件 */ /** 店铺商品分页查询过滤条件 */
export interface ProductPageFilters { export interface ProductPageFilters {
/** 店铺ID */ /** 店铺ID */
@@ -29,40 +29,6 @@ export namespace ShopVO {
updateBy?: number; updateBy?: number;
} }
/** 店铺统计信息 */
export interface Statistics {
/** 销售额(商家实收金额总和) */
salesAmount: number;
/** 订单数 */
orderCount: number;
/** 客单价(销售额/订单数) */
averageOrderValue: number;
/** 成本(成本价*数量总和) */
costAmount: number;
/** 退款金额(已退款订单的实收金额总和) */
refundAmount: number;
/** 推广费 */
promotionFee: number;
/** 费比(推广费/销售额) */
feeRatio: number;
}
/** 每日数据项 */
export interface DailyData {
/** 日期 */
date: string;
/** 对应的值 */
value: number;
}
/** 每日统计数据 */
export interface DailyStatistics {
/** 时间范围的总值 */
total: number;
/** 每日数据列表 */
dailyDataList: DailyData[];
}
/** 店铺商品详细信息(已废弃,后端接口已删除) */ /** 店铺商品详细信息(已废弃,后端接口已删除) */
export interface ProductDetail { export interface ProductDetail {
/** 商品ID */ /** 商品ID */
@@ -89,24 +55,6 @@ export namespace ShopVO {
averageOrderValue: number; averageOrderValue: number;
} }
/** 店铺总览 */
export interface Overview {
/** 销售额统计 */
salesAmount: DailyStatistics;
/** 订单数统计 */
orderCount: DailyStatistics;
/** 客单价统计 */
averageOrderValue: DailyStatistics;
/** 成本统计 */
costAmount: DailyStatistics;
/** 退款金额统计 */
refundAmount: DailyStatistics;
/** 推广费统计 */
promotionFee: DailyStatistics;
/** 费比统计 */
feeRatio: DailyStatistics;
}
/** 店铺概览统计信息 */ /** 店铺概览统计信息 */
export interface OverviewStatistics { export interface OverviewStatistics {
/** 店铺ID */ /** 店铺ID */