diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ShopController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ShopController.java index 0af463fb..520e9e67 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ShopController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ShopController.java @@ -12,14 +12,12 @@ import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.CreateShopDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO; +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.vo.ShopDetailVO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO; +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.ShopVO; import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService; import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO; @@ -87,39 +85,21 @@ public class ShopController { return ApiResponse.success(mediaImageVO); } - @Operation(summary = "获取店铺当月统计信息", description = "获取当前店铺当月的销售额、订单数、客单价、成本、退款金额、推广费、费比等统计信息") - @GetMapping("/statistics/current-month/{id}") - @RequireRole(description = "查询店铺当月统计", allowUser = true) - public ApiResponse getShopCurrentMonthStatistics( - @Parameter(description = "店铺ID") @PathVariable Long id) { - ShopStatisticsVO statistics = shopService.getShopCurrentMonthStatistics(id); - return ApiResponse.success(statistics); - } - - @Operation(summary = "获取店铺统计信息", description = "通过维度参数和时间范围返回不同维度指定时间的统计信息(销售额、订单数、客单价、成本、退款金额、推广费、费比)") - @PostMapping("/statistics") - @RequireRole(description = "查询店铺统计", allowUser = true) - public ApiResponse getShopStatistics( + @Operation(summary = "获取店铺总览", description = "获取店铺总览,返回日期范围内每日的销售额、订单数、客单价、成本、退款金额、推广费、费比统计数据,包含时间范围的总值和每日数据数组") + @PostMapping("/overview") + @RequireRole(description = "查询店铺总览", allowUser = true) + public ApiResponse getShopOverview( @Valid @RequestBody ShopStatisticsQueryDTO queryDTO) { - ShopStatisticsVO statistics = shopService.getShopStatistics(queryDTO); - return ApiResponse.success(statistics); + ShopOverviewVO overview = shopService.getShopOverview(queryDTO); + return ApiResponse.success(overview); } - @Operation(summary = "分页获取店铺商品详细信息", description = "分页获取店铺商品的详细信息,包含商品基础信息和统计数据(销售额、订单数、客单价),支持按商品名称、商品编码筛选,日期范围参数不传默认为当月1号到今天") + @Operation(summary = "分页获取店铺商品信息", description = "通过中间表分页获取店铺商品信息,包含商品基本信息和规格列表") @PostMapping("/products/page") @RequireRole(description = "查询店铺商品列表", allowUser = true) - public ApiResponse> getShopProductPage( - @Valid @RequestBody PageQueryDTO pageQueryDTO) { - PageResultVO result = shopService.getShopProductPage(pageQueryDTO); + public ApiResponse> getShopProductPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = shopService.getShopProductPage(pageQueryDTO); return ApiResponse.success(result); } - - @Operation(summary = "获取店铺详情", description = "获取店铺详情,包含统计信息(销售额、订单数、客单价、成本、退款金额、推广费、费比)和所有商品列表,支持按时间范围查询,日期范围参数不传默认为当月1号到今天") - @PostMapping("/detail") - @RequireRole(description = "查询店铺详情", allowUser = true) - public ApiResponse getShopDetail( - @Valid @RequestBody ShopDetailQueryDTO queryDTO) { - ShopDetailVO shopDetail = shopService.getShopDetail(queryDTO); - return ApiResponse.success(shopDetail); - } } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/shop/ShopProductPageFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/shop/ShopProductPageFilterDTO.java new file mode 100644 index 00000000..400d1e36 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/shop/ShopProductPageFilterDTO.java @@ -0,0 +1,21 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 店铺商品分页查询过滤DTO + */ +@Data +@Schema(description = "店铺商品分页查询过滤DTO") +public class ShopProductPageFilterDTO { + + /** + * 店铺ID + */ + @Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "店铺ID不能为空") + private Long shopId; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ShopOverviewVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ShopOverviewVO.java new file mode 100644 index 00000000..4e6e775b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ShopOverviewVO.java @@ -0,0 +1,99 @@ +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 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 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; + } +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ShopService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ShopService.java index 16046795..5c91cbeb 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ShopService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ShopService.java @@ -5,15 +5,13 @@ import org.springframework.web.multipart.MultipartFile; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.CreateShopDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO; +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.po.ShopPO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopDetailVO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO; +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.ShopVO; import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO; @@ -63,34 +61,18 @@ public interface ShopService extends IService { MediaImageVO uploadLogo(MultipartFile file); /** - * 获取店铺当月统计信息 - * - * @param shopId 店铺ID - * @return 店铺统计信息 - */ - ShopStatisticsVO getShopCurrentMonthStatistics(Long shopId); - - /** - * 获取店铺指定时间范围的统计信息 + * 获取店铺总览(每日统计数据) * * @param queryDTO 统计查询DTO - * @return 店铺统计信息 + * @return 店铺总览VO */ - ShopStatisticsVO getShopStatistics(ShopStatisticsQueryDTO queryDTO); + ShopOverviewVO getShopOverview(ShopStatisticsQueryDTO queryDTO); /** - * 分页获取店铺商品详细信息 + * 分页获取店铺商品信息 * * @param pageQueryDTO 分页查询DTO * @return 分页结果 */ - PageResultVO getShopProductPage(PageQueryDTO pageQueryDTO); - - /** - * 获取店铺详情(包含统计信息和商品分页列表) - * - * @param queryDTO 店铺详情查询DTO - * @return 店铺详情VO - */ - ShopDetailVO getShopDetail(ShopDetailQueryDTO queryDTO); + PageResultVO getShopProductPage(PageQueryDTO pageQueryDTO); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ShopServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ShopServiceImpl.java index cd908215..42f41fda 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ShopServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ShopServiceImpl.java @@ -17,21 +17,22 @@ import top.xyquan.ecomdmbbackend.modules.ecom.mapper.PromotionFeeMapper; import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopMapper; import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopProductRelationMapper; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.CreateShopDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO; +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.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.ProductSpecPO; import top.xyquan.ecomdmbbackend.modules.ecom.model.po.PromotionFeePO; import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO; import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopProductRelationPO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopDetailVO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ProductSpecVO; +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.ShopVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ProductSpecService; import top.xyquan.ecomdmbbackend.modules.ecom.service.ShopService; import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService; import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO; @@ -42,7 +43,10 @@ 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; /** @@ -58,11 +62,12 @@ public class ShopServiceImpl extends ServiceImpl implements private final OrderStatusMapper orderStatusMapper; private final ProductMapper productMapper; private final ShopProductRelationMapper shopProductRelationMapper; + private final ProductSpecService productSpecService; public ShopServiceImpl(CurrentUserContext currentUserContext, MediaImageService mediaImageService, OrderMapper orderMapper, PromotionFeeMapper promotionFeeMapper, OrderStatusMapper orderStatusMapper, ProductMapper productMapper, - ShopProductRelationMapper shopProductRelationMapper) { + ShopProductRelationMapper shopProductRelationMapper, ProductSpecService productSpecService) { this.currentUserContext = currentUserContext; this.mediaImageService = mediaImageService; this.orderMapper = orderMapper; @@ -70,6 +75,7 @@ public class ShopServiceImpl extends ServiceImpl implements this.orderStatusMapper = orderStatusMapper; this.productMapper = productMapper; this.shopProductRelationMapper = shopProductRelationMapper; + this.productSpecService = productSpecService; } /** @@ -244,38 +250,31 @@ public class ShopServiceImpl extends ServiceImpl implements } /** - * 获取店铺当月统计信息 + * 获取退款状态ID */ - @Override - public ShopStatisticsVO getShopCurrentMonthStatistics(Long shopId) { - // 从token中获取公司ID - Long companyId = currentUserContext.getCurrentCompanyId(); - - // 验证店铺是否存在 - ShopPO shop = this.getById(shopId); - if (shop == null || !shop.getCompanyId().equals(companyId)) { - throw new BusinessException("店铺不存在"); - } - - // 获取当月开始和结束时间 - LocalDate now = LocalDate.now(); - LocalDate startDate = now.withDayOfMonth(1); - LocalDate endDate = now.withDayOfMonth(now.lengthOfMonth()); - - // 构建查询DTO - ShopStatisticsQueryDTO queryDTO = new ShopStatisticsQueryDTO(); - queryDTO.setShopId(shopId); - queryDTO.setStartDate(startDate); - queryDTO.setEndDate(endDate); - - return calculateStatistics(queryDTO, companyId); + private Long getRefundStatusId(Long companyId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(OrderStatusPO::getCompanyId, companyId) + .eq(OrderStatusPO::getStatusName, "已退款") + .eq(OrderStatusPO::getIsActive, 1); + OrderStatusPO status = orderStatusMapper.selectOne(wrapper); + return status != null ? status.getId() : null; } /** - * 获取店铺指定时间范围的统计信息 + * 转换为VO + */ + private ShopVO convertToVO(ShopPO shop) { + ShopVO shopVO = new ShopVO(); + BeanUtils.copyProperties(shop, shopVO); + return shopVO; + } + + /** + * 获取店铺总览(每日统计数据) */ @Override - public ShopStatisticsVO getShopStatistics(ShopStatisticsQueryDTO queryDTO) { + public ShopOverviewVO getShopOverview(ShopStatisticsQueryDTO queryDTO) { // 从token中获取公司ID Long companyId = currentUserContext.getCurrentCompanyId(); @@ -290,15 +289,6 @@ public class ShopServiceImpl extends ServiceImpl implements throw new BusinessException("开始日期不能晚于结束日期"); } - return calculateStatistics(queryDTO, companyId); - } - - /** - * 计算统计信息 - */ - private ShopStatisticsVO calculateStatistics(ShopStatisticsQueryDTO queryDTO, Long companyId) { - ShopStatisticsVO statistics = new ShopStatisticsVO(); - // 查询时间范围(订单使用orderDate,推广费使用feeDate) LocalDateTime startDateTime = queryDTO.getStartDate().atStartOfDay(); LocalDateTime endDateTime = queryDTO.getEndDate().atTime(23, 59, 59); @@ -322,87 +312,329 @@ public class ShopServiceImpl extends ServiceImpl implements // 获取退款状态ID(状态名称为"已退款") Long refundStatusId = getRefundStatusId(companyId); - // 计算销售额(商家实收金额总和) - BigDecimal salesAmount = orders.stream() + // 按日期分组订单数据 + Map> ordersByDate = orders.stream() + .collect(Collectors.groupingBy(order -> order.getOrderDate().toLocalDate())); + + // 按日期分组推广费数据 + Map> promotionFeesByDate = promotionFees.stream() + .collect(Collectors.groupingBy(PromotionFeePO::getFeeDate)); + + // 生成日期范围内的所有日期列表 + List 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, refundStatusId); + 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> ordersByDate, List dateList, List 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); - statistics.setSalesAmount(salesAmount); + stats.setTotal(total); - // 计算订单数(按平台订单号去重) - long orderCount = orders.stream() + // 计算每日销售额 + List dailyDataList = dateList.stream() + .map(date -> { + ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData(); + dailyData.setDate(date); + List 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> ordersByDate, List dateList, List allOrders) { + ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics(); + + // 计算总订单数(按平台订单号去重) + long totalCount = allOrders.stream() .map(OrderPO::getPlatformOrderNo) .filter(no -> no != null && !no.isEmpty()) .distinct() .count(); - // 如果没有平台订单号,则使用订单记录数 - if (orderCount == 0) { - orderCount = orders.size(); + if (totalCount == 0) { + totalCount = allOrders.size(); } - statistics.setOrderCount(orderCount); + stats.setTotal(BigDecimal.valueOf(totalCount)); - // 计算客单价(销售额/订单数) - BigDecimal averageOrderValue = orderCount > 0 - ? salesAmount.divide(BigDecimal.valueOf(orderCount), 2, RoundingMode.HALF_UP) + // 计算每日订单数 + List dailyDataList = dateList.stream() + .map(date -> { + ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData(); + dailyData.setDate(date); + List 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; - statistics.setAverageOrderValue(averageOrderValue); + stats.setTotal(total); - // 计算成本(成本价*数量总和) - BigDecimal costAmount = orders.stream() + // 计算每日客单价 + List 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> ordersByDate, List dateList, List allOrders) { + ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics(); + + // 计算总成本 + BigDecimal total = allOrders.stream() .map(order -> { BigDecimal cost = order.getCostPrice() != null ? order.getCostPrice() : BigDecimal.ZERO; Integer quantity = order.getQuantity() != null ? order.getQuantity() : 0; return cost.multiply(BigDecimal.valueOf(quantity)); }) .reduce(BigDecimal.ZERO, BigDecimal::add); - statistics.setCostAmount(costAmount); + stats.setTotal(total); - // 计算退款金额(已退款订单的实收金额总和) - BigDecimal refundAmount = BigDecimal.ZERO; + // 计算每日成本 + List dailyDataList = dateList.stream() + .map(date -> { + ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData(); + dailyData.setDate(date); + List dayOrders = ordersByDate.getOrDefault(date, List.of()); + BigDecimal dayCost = dayOrders.stream() + .map(order -> { + BigDecimal cost = order.getCostPrice() != null ? order.getCostPrice() : BigDecimal.ZERO; + Integer quantity = order.getQuantity() != null ? order.getQuantity() : 0; + return cost.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> ordersByDate, List dateList, + List allOrders, Long refundStatusId) { + ShopOverviewVO.DailyStatistics stats = new ShopOverviewVO.DailyStatistics(); + + // 计算总退款金额 + BigDecimal total = BigDecimal.ZERO; if (refundStatusId != null) { - refundAmount = orders.stream() + total = allOrders.stream() .filter(order -> refundStatusId.equals(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); } - statistics.setRefundAmount(refundAmount); + stats.setTotal(total); - // 计算推广费 - BigDecimal promotionFee = promotionFees.stream() + // 计算每日退款金额 + List dailyDataList = dateList.stream() + .map(date -> { + ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData(); + dailyData.setDate(date); + List dayOrders = ordersByDate.getOrDefault(date, List.of()); + BigDecimal dayRefund = BigDecimal.ZERO; + if (refundStatusId != null) { + dayRefund = dayOrders.stream() + .filter(order -> refundStatusId.equals(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> promotionFeesByDate, List dateList, + List 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); - statistics.setPromotionFee(promotionFee); + stats.setTotal(total); - // 计算费比(推广费/销售额) - BigDecimal feeRatio = salesAmount.compareTo(BigDecimal.ZERO) > 0 - ? promotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP) - : BigDecimal.ZERO; - statistics.setFeeRatio(feeRatio); + // 计算每日推广费 + List dailyDataList = dateList.stream() + .map(date -> { + ShopOverviewVO.DailyData dailyData = new ShopOverviewVO.DailyData(); + dailyData.setDate(date); + List 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 statistics; + return stats; } /** - * 获取退款状态ID + * 计算费比统计 */ - private Long getRefundStatusId(Long companyId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(OrderStatusPO::getCompanyId, companyId) - .eq(OrderStatusPO::getStatusName, "已退款") - .eq(OrderStatusPO::getIsActive, 1); - OrderStatusPO status = orderStatusMapper.selectOne(wrapper); - return status != null ? status.getId() : null; + 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 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; } /** - * 分页获取店铺商品详细信息 + * 分页获取店铺商品信息 */ @Override - public PageResultVO getShopProductPage(PageQueryDTO pageQueryDTO) { + public PageResultVO getShopProductPage(PageQueryDTO pageQueryDTO) { // 从token中获取公司ID Long companyId = currentUserContext.getCurrentCompanyId(); // 获取过滤条件 - ShopProductFilterDTO filter = pageQueryDTO.getFilters(); + ShopProductPageFilterDTO filter = pageQueryDTO.getFilters(); if (filter == null || filter.getShopId() == null) { throw new BusinessException("店铺ID不能为空"); } @@ -415,18 +647,6 @@ public class ShopServiceImpl extends ServiceImpl implements throw new BusinessException("店铺不存在"); } - // 确定统计日期范围(不传默认为当月1号到今天) - LocalDate startDate = filter.getStartDate() != null ? filter.getStartDate() : LocalDate.now().withDayOfMonth(1); - LocalDate endDate = filter.getEndDate() != null ? filter.getEndDate() : LocalDate.now(); - - // 验证日期范围 - if (startDate.isAfter(endDate)) { - throw new BusinessException("开始日期不能晚于结束日期"); - } - - LocalDateTime startDateTime = startDate.atStartOfDay(); - LocalDateTime endDateTime = endDate.atTime(23, 59, 59); - // 创建分页对象 Page page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); @@ -435,33 +655,6 @@ public class ShopServiceImpl extends ServiceImpl implements wrapper.eq(ShopProductRelationPO::getCompanyId, companyId) .eq(ShopProductRelationPO::getShopId, shopId); - // 添加商品名称和编码过滤(需要关联商品表) - // 如果同时有商品名称和编码过滤,需要取交集 - boolean hasProductFilter = (filter.getProductName() != null && !filter.getProductName().trim().isEmpty()) || - (filter.getProductCode() != null && !filter.getProductCode().trim().isEmpty()); - - if (hasProductFilter) { - LambdaQueryWrapper productWrapper = new LambdaQueryWrapper<>(); - productWrapper.eq(ProductPO::getCompanyId, companyId); - - if (filter.getProductName() != null && !filter.getProductName().trim().isEmpty()) { - productWrapper.like(ProductPO::getName, filter.getProductName().trim()); - } - - if (filter.getProductCode() != null && !filter.getProductCode().trim().isEmpty()) { - productWrapper.like(ProductPO::getProductCode, filter.getProductCode().trim()); - } - - List products = productMapper.selectList(productWrapper); - if (products.isEmpty()) { - // 如果没有匹配的商品,返回空结果 - return PageResultVO.create(List.of(), 0L, pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); - } - - List productIds = products.stream().map(ProductPO::getId).collect(Collectors.toList()); - wrapper.in(ShopProductRelationPO::getProductId, productIds); - } - // 排序 wrapper.orderByAsc(ShopProductRelationPO::getSortOrder) .orderByDesc(ShopProductRelationPO::getCreateTime); @@ -469,29 +662,20 @@ public class ShopServiceImpl extends ServiceImpl implements // 执行分页查询 IPage pageResult = shopProductRelationMapper.selectPage(page, wrapper); - // 转换为VO并填充统计数据 - List voList = pageResult.getRecords().stream() + // 转换为VO并填充商品信息和规格信息 + List voList = pageResult.getRecords().stream() .map(relation -> { - ShopProductDetailVO vo = new ShopProductDetailVO(); - vo.setRelationId(relation.getId()); - vo.setSortOrder(relation.getSortOrder()); - vo.setCreateTime(relation.getCreateTime()); - vo.setUpdateTime(relation.getUpdateTime()); - // 查询商品信息 ProductPO product = productMapper.selectById(relation.getProductId()); - if (product != null) { - vo.setProductId(product.getId()); - vo.setProductName(product.getName()); - vo.setProductCode(product.getProductCode()); - vo.setMainImage(product.getMainImage()); + if (product == null) { + return null; } - // 统计订单数据(按日期) - calculateProductStatistics(vo, shopId, relation.getProductId(), companyId, startDateTime, endDateTime); - - return vo; + // 转换为VO + ProductVO productVO = convertProductToVO(product); + return productVO; }) + .filter(productVO -> productVO != null) .collect(Collectors.toList()); // 构建分页结果 @@ -499,138 +683,33 @@ public class ShopServiceImpl extends ServiceImpl implements } /** - * 计算商品统计数据 + * 转换商品PO为VO(包含规格信息) */ - private void calculateProductStatistics(ShopProductDetailVO vo, Long shopId, Long productId, - Long companyId, LocalDateTime startDateTime, LocalDateTime endDateTime) { - // 查询该店铺该商品在指定日期的订单 - LambdaQueryWrapper orderWrapper = new LambdaQueryWrapper<>(); - orderWrapper.eq(OrderPO::getCompanyId, companyId) - .eq(OrderPO::getShopId, shopId) - .eq(OrderPO::getProductId, productId) - .ge(OrderPO::getOrderDate, startDateTime) - .le(OrderPO::getOrderDate, endDateTime); + private ProductVO convertProductToVO(ProductPO product) { + ProductVO productVO = new ProductVO(); + BeanUtils.copyProperties(product, productVO); - List orders = orderMapper.selectList(orderWrapper); + // 查询商品规格列表 + LambdaQueryWrapper specWrapper = new LambdaQueryWrapper<>(); + specWrapper.eq(ProductSpecPO::getProductId, product.getId()) + .eq(ProductSpecPO::getCompanyId, product.getCompanyId()) + .orderByAsc(ProductSpecPO::getCreateTime); - // 计算销售额(商家实收金额总和) - BigDecimal salesAmount = orders.stream() - .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) - .reduce(BigDecimal.ZERO, BigDecimal::add); - vo.setSalesAmount(salesAmount); - - // 计算订单数(按平台订单号去重) - long orderCount = orders.stream() - .map(OrderPO::getPlatformOrderNo) - .filter(no -> no != null && !no.isEmpty()) - .distinct() - .count(); - // 如果没有平台订单号,则使用订单记录数 - if (orderCount == 0) { - orderCount = orders.size(); - } - vo.setOrderCount(orderCount); - - // 计算客单价(销售额/订单数) - BigDecimal averageOrderValue = orderCount > 0 - ? salesAmount.divide(BigDecimal.valueOf(orderCount), 2, RoundingMode.HALF_UP) - : BigDecimal.ZERO; - vo.setAverageOrderValue(averageOrderValue); - } - - /** - * 转换为VO - */ - private ShopVO convertToVO(ShopPO shop) { - ShopVO shopVO = new ShopVO(); - BeanUtils.copyProperties(shop, shopVO); - return shopVO; - } - - /** - * 获取店铺详情(包含统计信息和商品列表) - */ - @Override - public ShopDetailVO getShopDetail(ShopDetailQueryDTO queryDTO) { - // 从token中获取公司ID - Long companyId = currentUserContext.getCurrentCompanyId(); - - // 验证店铺是否存在 - ShopPO shop = this.getById(queryDTO.getShopId()); - if (shop == null || !shop.getCompanyId().equals(companyId)) { - throw new BusinessException("店铺不存在"); - } - - // 确定统计日期范围(不传默认为当月1号到今天) - LocalDate startDate = queryDTO.getStartDate() != null ? queryDTO.getStartDate() : LocalDate.now().withDayOfMonth(1); - LocalDate endDate = queryDTO.getEndDate() != null ? queryDTO.getEndDate() : LocalDate.now(); - - // 验证日期范围 - if (startDate.isAfter(endDate)) { - throw new BusinessException("开始日期不能晚于结束日期"); - } - - LocalDateTime startDateTime = startDate.atStartOfDay(); - LocalDateTime endDateTime = endDate.atTime(23, 59, 59); - - // 获取店铺统计信息 - ShopStatisticsQueryDTO statisticsQueryDTO = new ShopStatisticsQueryDTO(); - statisticsQueryDTO.setShopId(queryDTO.getShopId()); - statisticsQueryDTO.setStartDate(startDate); - statisticsQueryDTO.setEndDate(endDate); - ShopStatisticsVO statistics = calculateStatistics(statisticsQueryDTO, companyId); - - // 获取所有商品列表 - List products = getAllShopProducts(queryDTO.getShopId(), companyId, startDateTime, endDateTime); - - // 组装返回结果 - ShopDetailVO shopDetailVO = new ShopDetailVO(); - shopDetailVO.setStatistics(statistics); - shopDetailVO.setProducts(products); - - return shopDetailVO; - } - - /** - * 获取店铺所有商品详细信息 - */ - private List getAllShopProducts(Long shopId, Long companyId, - LocalDateTime startDateTime, LocalDateTime endDateTime) { - // 构建查询条件(店铺商品关联表) - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(ShopProductRelationPO::getCompanyId, companyId) - .eq(ShopProductRelationPO::getShopId, shopId); - - // 排序 - wrapper.orderByAsc(ShopProductRelationPO::getSortOrder) - .orderByDesc(ShopProductRelationPO::getCreateTime); - - // 查询所有商品关联记录 - List relations = shopProductRelationMapper.selectList(wrapper); - - // 转换为VO并填充统计数据 - return relations.stream() - .map(relation -> { - ShopProductDetailVO vo = new ShopProductDetailVO(); - vo.setRelationId(relation.getId()); - vo.setSortOrder(relation.getSortOrder()); - vo.setCreateTime(relation.getCreateTime()); - vo.setUpdateTime(relation.getUpdateTime()); - - // 查询商品信息 - ProductPO product = productMapper.selectById(relation.getProductId()); - if (product != null) { - vo.setProductId(product.getId()); - vo.setProductName(product.getName()); - vo.setProductCode(product.getProductCode()); - vo.setMainImage(product.getMainImage()); - } - - // 统计订单数据(按日期范围) - calculateProductStatistics(vo, shopId, relation.getProductId(), companyId, startDateTime, endDateTime); - - return vo; - }) + List specPOs = productSpecService.list(specWrapper); + List specVOs = specPOs.stream() + .map(this::convertSpecToVO) .collect(Collectors.toList()); + + productVO.setSpecs(specVOs); + return productVO; + } + + /** + * 转换规格PO为VO + */ + private ProductSpecVO convertSpecToVO(ProductSpecPO productSpec) { + ProductSpecVO productSpecVO = new ProductSpecVO(); + BeanUtils.copyProperties(productSpec, productSpecVO); + return productSpecVO; } } diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/apis.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/apis.ts index 26770f2c..b4d8a92b 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/apis.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/apis.ts @@ -1,6 +1,7 @@ import type { ShopDTO, ShopVO } from './types'; import type { PageQueryDTO, PageResultVO } from '#/types/common'; +import type { ProductVO } from '#/api/ecommerce/product/types'; import { requestClient } from '#/api/request'; @@ -50,36 +51,20 @@ export async function uploadShopLogoApi(file: File) { } /** - * 获取店铺当月统计信息 + * 获取店铺总览 */ -export async function getShopCurrentMonthStatisticsApi(id: number) { - return requestClient.get( - `/ec/shop/statistics/current-month/${id}`, - ); +export async function getShopOverviewApi(params: ShopDTO.StatisticsQuery) { + return requestClient.post('/ec/shop/overview', params); } /** - * 获取店铺统计信息 - */ -export async function getShopStatisticsApi(params: ShopDTO.StatisticsQuery) { - return requestClient.post('/ec/shop/statistics', params); -} - -/** - * 分页获取店铺商品详细信息 + * 分页获取店铺商品信息 */ export async function getShopProductPageApi( - params: PageQueryDTO, + params: PageQueryDTO, ) { - return requestClient.post>( + return requestClient.post>( '/ec/shop/products/page', params, ); } - -/** - * 获取店铺详情 - */ -export async function getShopDetailApi(params: ShopDTO.DetailQuery) { - return requestClient.post('/ec/shop/detail', params); -} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.dto.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.dto.ts index cdb5bc79..f47df6de 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.dto.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.dto.ts @@ -41,25 +41,9 @@ export namespace ShopDTO { endDate: string; } - /** 店铺商品过滤条件 */ - export interface ProductFilters { + /** 店铺商品分页查询过滤条件 */ + export interface ProductPageFilters { /** 店铺ID */ shopId: number; - /** 商品名称(模糊查询) */ - productName?: string; - /** 商品编码(模糊查询) */ - productCode?: string; - /** 统计日期(不传默认为当日) */ - statDate?: string; - } - - /** 店铺详情查询参数 */ - export interface DetailQuery { - /** 店铺ID */ - shopId: number; - /** 开始日期(不传默认为当月1号) */ - startDate?: string; - /** 结束日期(不传默认为今天) */ - endDate?: string; } } diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts index ec318bdb..3fa1fb46 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/shop/types/types.vo.ts @@ -45,7 +45,23 @@ export namespace ShopVO { feeRatio: number; } - /** 店铺商品详细信息 */ + /** 每日数据项 */ + export interface DailyData { + /** 日期 */ + date: string; + /** 对应的值 */ + value: number; + } + + /** 每日统计数据 */ + export interface DailyStatistics { + /** 时间范围的总值 */ + total: number; + /** 每日数据列表 */ + dailyDataList: DailyData[]; + } + + /** 店铺商品详细信息(已废弃,后端接口已删除) */ export interface ProductDetail { /** 商品ID */ productId: number; @@ -71,11 +87,21 @@ export namespace ShopVO { averageOrderValue: number; } - /** 店铺详情 */ - export interface Detail { - /** 店铺统计信息 */ - statistics: Statistics; - /** 商品列表 */ - products: ProductDetail[]; + /** 店铺总览 */ + export interface Overview { + /** 销售额统计 */ + salesAmount: DailyStatistics; + /** 订单数统计 */ + orderCount: DailyStatistics; + /** 客单价统计 */ + averageOrderValue: DailyStatistics; + /** 成本统计 */ + costAmount: DailyStatistics; + /** 退款金额统计 */ + refundAmount: DailyStatistics; + /** 推广费统计 */ + promotionFee: DailyStatistics; + /** 费比统计 */ + feeRatio: DailyStatistics; } } diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ChartCard.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ChartCard.vue new file mode 100644 index 00000000..cea05b13 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ChartCard.vue @@ -0,0 +1,170 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ProductsTab.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ProductsTab.vue new file mode 100644 index 00000000..8c80e2fb --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ProductsTab.vue @@ -0,0 +1,210 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ShopStatistics.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ShopStatistics.vue index 10c02084..6a0c992b 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ShopStatistics.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/components/ShopStatistics.vue @@ -3,23 +3,27 @@ import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types'; import { onMounted, ref, watch } from 'vue'; -import { Card, Col, DatePicker, message, Row, Space, Statistic } from 'ant-design-vue'; +import { + Card, + Col, + DatePicker, + message, + Row, + Space, + Statistic, +} from 'ant-design-vue'; import dayjs from 'dayjs'; -import { getShopDetailApi } from '#/api/ecommerce/shop'; +import { getShopOverviewApi } from '#/api/ecommerce/shop'; defineOptions({ name: 'ShopStatistics' }); +const props = defineProps(); + interface Props { shopId: number; } -const props = defineProps(); - -const emit = defineEmits<{ - productListUpdate: [products: ShopVO.ProductDetail[]]; -}>(); - // 响应式数据 const loading = ref(false); const customStats = ref(null); @@ -41,23 +45,34 @@ function formatPercent(value: number): string { return `${(value * 100).toFixed(2)}%`; } -// 获取店铺详情(包含统计信息和商品列表) -async function fetchShopDetail() { +// 从 Overview 中提取统计信息 +function extractStatistics(overview: ShopVO.Overview): ShopVO.Statistics { + return { + salesAmount: overview.salesAmount.total, + orderCount: overview.orderCount.total, + averageOrderValue: overview.averageOrderValue.total, + costAmount: overview.costAmount.total, + refundAmount: overview.refundAmount.total, + promotionFee: overview.promotionFee.total, + feeRatio: overview.feeRatio.total, + }; +} + +// 获取店铺总览数据 +async function fetchShopOverview() { if (!props.shopId || !dateRange.value) return; try { loading.value = true; - const params: ShopDTO.DetailQuery = { + const params: ShopDTO.StatisticsQuery = { shopId: props.shopId, startDate: dateRange.value[0].format('YYYY-MM-DD'), endDate: dateRange.value[1].format('YYYY-MM-DD'), }; - const data = await getShopDetailApi(params); - customStats.value = data.statistics; - // 通知父组件更新商品列表 - emit('productListUpdate', data.products || []); + const data = await getShopOverviewApi(params); + customStats.value = extractStatistics(data); } catch (error) { - console.error('获取店铺详情失败:', error); - message.error('获取店铺详情失败'); + console.error('获取店铺总览失败:', error); + message.error('获取店铺总览失败'); } finally { loading.value = false; } @@ -65,7 +80,7 @@ async function fetchShopDetail() { // 处理日期范围变化 function handleDateRangeChange() { - fetchShopDetail(); + fetchShopOverview(); } // 监听 shopId 变化 @@ -73,7 +88,7 @@ watch( () => props.shopId, (newShopId) => { if (newShopId) { - fetchShopDetail(); + fetchShopOverview(); } }, ); @@ -81,7 +96,7 @@ watch( // 初始化数据 onMounted(() => { if (props.shopId) { - fetchShopDetail(); + fetchShopOverview(); } }); @@ -147,4 +162,3 @@ onMounted(() => { - diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/index.vue index faeaf857..f00fef4a 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/index.vue @@ -1,16 +1,13 @@ diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/tabs/OverviewTab.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/tabs/OverviewTab.vue new file mode 100644 index 00000000..b9b4d0f4 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/tabs/OverviewTab.vue @@ -0,0 +1,178 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/tabs/ProductsTab.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/tabs/ProductsTab.vue new file mode 100644 index 00000000..8c80e2fb --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/details/tabs/ProductsTab.vue @@ -0,0 +1,210 @@ + + +