mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 03:19:18 +08:00
feat: move
This commit is contained in:
+13
-33
@@ -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<ShopStatisticsVO> 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<ShopStatisticsVO> getShopStatistics(
|
||||
@Operation(summary = "获取店铺总览", description = "获取店铺总览,返回日期范围内每日的销售额、订单数、客单价、成本、退款金额、推广费、费比统计数据,包含时间范围的总值和每日数据数组")
|
||||
@PostMapping("/overview")
|
||||
@RequireRole(description = "查询店铺总览", allowUser = true)
|
||||
public ApiResponse<ShopOverviewVO> 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<PageResultVO<ShopProductDetailVO>> getShopProductPage(
|
||||
@Valid @RequestBody PageQueryDTO<ShopProductFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<ShopProductDetailVO> result = shopService.getShopProductPage(pageQueryDTO);
|
||||
public ApiResponse<PageResultVO<ProductVO>> getShopProductPage(
|
||||
@Valid @RequestBody PageQueryDTO<ShopProductPageFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<ProductVO> result = shopService.getShopProductPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取店铺详情", description = "获取店铺详情,包含统计信息(销售额、订单数、客单价、成本、退款金额、推广费、费比)和所有商品列表,支持按时间范围查询,日期范围参数不传默认为当月1号到今天")
|
||||
@PostMapping("/detail")
|
||||
@RequireRole(description = "查询店铺详情", allowUser = true)
|
||||
public ApiResponse<ShopDetailVO> getShopDetail(
|
||||
@Valid @RequestBody ShopDetailQueryDTO queryDTO) {
|
||||
ShopDetailVO shopDetail = shopService.getShopDetail(queryDTO);
|
||||
return ApiResponse.success(shopDetail);
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -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;
|
||||
}
|
||||
|
||||
+99
@@ -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<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
-26
@@ -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<ShopPO> {
|
||||
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<ShopProductDetailVO> getShopProductPage(PageQueryDTO<ShopProductFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 获取店铺详情(包含统计信息和商品分页列表)
|
||||
*
|
||||
* @param queryDTO 店铺详情查询DTO
|
||||
* @return 店铺详情VO
|
||||
*/
|
||||
ShopDetailVO getShopDetail(ShopDetailQueryDTO queryDTO);
|
||||
PageResultVO<ProductVO> getShopProductPage(PageQueryDTO<ShopProductPageFilterDTO> pageQueryDTO);
|
||||
}
|
||||
|
||||
+345
-266
@@ -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<ShopMapper, ShopPO> 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<ShopMapper, ShopPO> implements
|
||||
this.orderStatusMapper = orderStatusMapper;
|
||||
this.productMapper = productMapper;
|
||||
this.shopProductRelationMapper = shopProductRelationMapper;
|
||||
this.productSpecService = productSpecService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,38 +250,31 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> 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<OrderStatusPO> 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<ShopMapper, ShopPO> 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<ShopMapper, ShopPO> implements
|
||||
// 获取退款状态ID(状态名称为"已退款")
|
||||
Long refundStatusId = getRefundStatusId(companyId);
|
||||
|
||||
// 计算销售额(商家实收金额总和)
|
||||
BigDecimal salesAmount = orders.stream()
|
||||
// 按日期分组订单数据
|
||||
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> order.getOrderDate().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, 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<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);
|
||||
statistics.setSalesAmount(salesAmount);
|
||||
stats.setTotal(total);
|
||||
|
||||
// 计算订单数(按平台订单号去重)
|
||||
long orderCount = orders.stream()
|
||||
// 计算每日销售额
|
||||
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 (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<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;
|
||||
statistics.setAverageOrderValue(averageOrderValue);
|
||||
stats.setTotal(total);
|
||||
|
||||
// 计算成本(成本价*数量总和)
|
||||
BigDecimal costAmount = orders.stream()
|
||||
// 计算每日客单价
|
||||
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 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<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 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<LocalDate, List<OrderPO>> ordersByDate, List<LocalDate> dateList,
|
||||
List<OrderPO> 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<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 (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<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);
|
||||
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<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 statistics;
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取退款状态ID
|
||||
* 计算费比统计
|
||||
*/
|
||||
private Long getRefundStatusId(Long companyId) {
|
||||
LambdaQueryWrapper<OrderStatusPO> 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<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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取店铺商品详细信息
|
||||
* 分页获取店铺商品信息
|
||||
*/
|
||||
@Override
|
||||
public PageResultVO<ShopProductDetailVO> getShopProductPage(PageQueryDTO<ShopProductFilterDTO> pageQueryDTO) {
|
||||
public PageResultVO<ProductVO> getShopProductPage(PageQueryDTO<ShopProductPageFilterDTO> 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<ShopMapper, ShopPO> 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<ShopProductRelationPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
|
||||
@@ -435,33 +655,6 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> 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<ProductPO> 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<ProductPO> products = productMapper.selectList(productWrapper);
|
||||
if (products.isEmpty()) {
|
||||
// 如果没有匹配的商品,返回空结果
|
||||
return PageResultVO.create(List.of(), 0L, pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
List<Long> 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<ShopMapper, ShopPO> implements
|
||||
// 执行分页查询
|
||||
IPage<ShopProductRelationPO> pageResult = shopProductRelationMapper.selectPage(page, wrapper);
|
||||
|
||||
// 转换为VO并填充统计数据
|
||||
List<ShopProductDetailVO> voList = pageResult.getRecords().stream()
|
||||
// 转换为VO并填充商品信息和规格信息
|
||||
List<ProductVO> 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<ShopMapper, ShopPO> implements
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算商品统计数据
|
||||
* 转换商品PO为VO(包含规格信息)
|
||||
*/
|
||||
private void calculateProductStatistics(ShopProductDetailVO vo, Long shopId, Long productId,
|
||||
Long companyId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
|
||||
// 查询该店铺该商品在指定日期的订单
|
||||
LambdaQueryWrapper<OrderPO> 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<OrderPO> orders = orderMapper.selectList(orderWrapper);
|
||||
// 查询商品规格列表
|
||||
LambdaQueryWrapper<ProductSpecPO> 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<ShopProductDetailVO> products = getAllShopProducts(queryDTO.getShopId(), companyId, startDateTime, endDateTime);
|
||||
|
||||
// 组装返回结果
|
||||
ShopDetailVO shopDetailVO = new ShopDetailVO();
|
||||
shopDetailVO.setStatistics(statistics);
|
||||
shopDetailVO.setProducts(products);
|
||||
|
||||
return shopDetailVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺所有商品详细信息
|
||||
*/
|
||||
private List<ShopProductDetailVO> getAllShopProducts(Long shopId, Long companyId,
|
||||
LocalDateTime startDateTime, LocalDateTime endDateTime) {
|
||||
// 构建查询条件(店铺商品关联表)
|
||||
LambdaQueryWrapper<ShopProductRelationPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ShopProductRelationPO::getCompanyId, companyId)
|
||||
.eq(ShopProductRelationPO::getShopId, shopId);
|
||||
|
||||
// 排序
|
||||
wrapper.orderByAsc(ShopProductRelationPO::getSortOrder)
|
||||
.orderByDesc(ShopProductRelationPO::getCreateTime);
|
||||
|
||||
// 查询所有商品关联记录
|
||||
List<ShopProductRelationPO> 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<ProductSpecPO> specPOs = productSpecService.list(specWrapper);
|
||||
List<ProductSpecVO> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ShopVO.Statistics>(
|
||||
`/ec/shop/statistics/current-month/${id}`,
|
||||
);
|
||||
export async function getShopOverviewApi(params: ShopDTO.StatisticsQuery) {
|
||||
return requestClient.post<ShopVO.Overview>('/ec/shop/overview', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺统计信息
|
||||
*/
|
||||
export async function getShopStatisticsApi(params: ShopDTO.StatisticsQuery) {
|
||||
return requestClient.post<ShopVO.Statistics>('/ec/shop/statistics', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取店铺商品详细信息
|
||||
* 分页获取店铺商品信息
|
||||
*/
|
||||
export async function getShopProductPageApi(
|
||||
params: PageQueryDTO<ShopDTO.ProductFilters>,
|
||||
params: PageQueryDTO<ShopDTO.ProductPageFilters>,
|
||||
) {
|
||||
return requestClient.post<PageResultVO<ShopVO.ProductDetail>>(
|
||||
return requestClient.post<PageResultVO<ProductVO.Info>>(
|
||||
'/ec/shop/products/page',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺详情
|
||||
*/
|
||||
export async function getShopDetailApi(params: ShopDTO.DetailQuery) {
|
||||
return requestClient.post<ShopVO.Detail>('/ec/shop/detail', params);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
import { Card, Statistic } from 'ant-design-vue';
|
||||
|
||||
interface Props {
|
||||
/** 标题 */
|
||||
title: string;
|
||||
/** 统计数据 */
|
||||
data: ShopVO.DailyStatistics;
|
||||
/** 格式化函数 */
|
||||
formatter?: (value: number) => string;
|
||||
/** 图表类型 */
|
||||
chartType?: 'bar' | 'line';
|
||||
/** 图表颜色 */
|
||||
color?: string;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'ChartCard' });
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
chartType: 'line',
|
||||
color: '#5ab1ef',
|
||||
formatter: (value: number) => value.toLocaleString('zh-CN'),
|
||||
});
|
||||
|
||||
const chartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts } = useEcharts(chartRef);
|
||||
|
||||
// 图表配置类型(使用 Record 类型,避免直接导入 echarts 类型)
|
||||
type ChartOptions = Record<string, any>;
|
||||
|
||||
// 格式化日期:从 "2025-11-17" 提取日期部分 "17"
|
||||
function formatDateToDay(dateStr: string): string {
|
||||
const date = new Date(dateStr);
|
||||
return date.getDate().toString();
|
||||
}
|
||||
|
||||
// 图表配置
|
||||
const chartOptions = computed<ChartOptions>(() => {
|
||||
const { dailyDataList } = props.data;
|
||||
// 横坐标只显示日期(日)
|
||||
const dateLabels = dailyDataList.map((item) => formatDateToDay(item.date));
|
||||
// 保存完整日期用于 tooltip
|
||||
const fullDates = dailyDataList.map((item) => item.date);
|
||||
const values = dailyDataList.map((item) => item.value);
|
||||
|
||||
const isLine = props.chartType === 'line';
|
||||
|
||||
return {
|
||||
grid: {
|
||||
bottom: 20,
|
||||
containLabel: true,
|
||||
left: '3%',
|
||||
right: '3%',
|
||||
top: '10%',
|
||||
},
|
||||
tooltip: {
|
||||
axisPointer: {
|
||||
lineStyle: {
|
||||
color: props.color,
|
||||
width: 1,
|
||||
},
|
||||
},
|
||||
trigger: 'axis',
|
||||
formatter: (params: any) => {
|
||||
const param = Array.isArray(params) ? params[0] : params;
|
||||
const index = param.dataIndex;
|
||||
const fullDate = fullDates[index];
|
||||
const value = param.value;
|
||||
const formattedValue = props.formatter(value);
|
||||
return `${fullDate}<br/>${props.title}: ${formattedValue}`;
|
||||
},
|
||||
},
|
||||
xAxis: {
|
||||
axisTick: {
|
||||
show: false,
|
||||
},
|
||||
boundaryGap: !isLine,
|
||||
data: dateLabels,
|
||||
type: 'category',
|
||||
},
|
||||
yAxis: {
|
||||
axisTick: {
|
||||
show: false,
|
||||
},
|
||||
splitLine: {
|
||||
lineStyle: {
|
||||
type: 'dashed',
|
||||
},
|
||||
show: true,
|
||||
},
|
||||
type: 'value',
|
||||
},
|
||||
series: [
|
||||
{
|
||||
areaStyle: isLine
|
||||
? {
|
||||
color: {
|
||||
type: 'linear',
|
||||
x: 0,
|
||||
y: 0,
|
||||
x2: 0,
|
||||
y2: 1,
|
||||
colorStops: [
|
||||
{
|
||||
offset: 0,
|
||||
color: props.color,
|
||||
},
|
||||
{
|
||||
offset: 1,
|
||||
color: `${props.color}00`, // 透明
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
data: values,
|
||||
itemStyle: {
|
||||
color: props.color,
|
||||
},
|
||||
smooth: isLine,
|
||||
type: props.chartType,
|
||||
...(props.chartType === 'bar' && { barMaxWidth: 60 }),
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
// 渲染图表
|
||||
function renderChart() {
|
||||
if (chartRef.value && props.data.dailyDataList.length > 0) {
|
||||
renderEcharts(chartOptions.value);
|
||||
}
|
||||
}
|
||||
|
||||
// 监听数据变化
|
||||
watch(
|
||||
() => props.data,
|
||||
() => {
|
||||
renderChart();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
renderChart();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card :title="title" class="h-full">
|
||||
<div class="mb-4">
|
||||
<Statistic
|
||||
:title="`${title}总计`"
|
||||
:value="data.total"
|
||||
:formatter="({ value }) => formatter(value as number)"
|
||||
/>
|
||||
</div>
|
||||
<div class="h-64 min-h-0">
|
||||
<EchartsUI ref="chartRef" />
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { ShopDTO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Image, message, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getShopProductPageApi } from '#/api/ecommerce/shop';
|
||||
|
||||
interface Props {
|
||||
shopId: number;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'ProductsTab' });
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
title: '主图',
|
||||
width: 60,
|
||||
slots: { default: 'mainImage' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '商品名称',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'productCode',
|
||||
title: '商品编码',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '规格数量',
|
||||
minWidth: 100,
|
||||
slots: { default: 'specs' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
highlightHoverRow: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
if (!props.shopId) {
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
}
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ShopDTO.ProductPageFilters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: props.shopId,
|
||||
},
|
||||
};
|
||||
const data = await getShopProductPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取商品列表失败:', error);
|
||||
message.error('获取商品列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品名称',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '商品名称',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品编码',
|
||||
},
|
||||
fieldName: 'productCode',
|
||||
label: '商品编码',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '商品列表',
|
||||
});
|
||||
|
||||
// 监听 shopId 变化,刷新表格
|
||||
watch(
|
||||
() => props.shopId,
|
||||
() => {
|
||||
if (props.shopId && gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height content-class="flex flex-col">
|
||||
<Grid :loading="loading">
|
||||
<!-- 主图列 -->
|
||||
<template #mainImage="{ row }: { row: any }">
|
||||
<Image
|
||||
v-if="row.mainImage"
|
||||
:src="row.mainImage"
|
||||
:alt="row.name"
|
||||
width="60"
|
||||
height="60"
|
||||
style="object-fit: cover; border-radius: 4px"
|
||||
:preview="true"
|
||||
/>
|
||||
<span v-else class="text-xs text-gray-400">暂无图片</span>
|
||||
</template>
|
||||
|
||||
<!-- 规格数量列 -->
|
||||
<template #specs="{ row }: { row: any }">
|
||||
<Tag :color="(row.specs?.length || 0) > 0 ? 'blue' : 'default'">
|
||||
{{ row.specs?.length || 0 }} 个规格
|
||||
</Tag>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
+35
-21
@@ -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<Props>();
|
||||
|
||||
interface Props {
|
||||
shopId: number;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
productListUpdate: [products: ShopVO.ProductDetail[]];
|
||||
}>();
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const customStats = ref<null | ShopVO.Statistics>(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();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -147,4 +162,3 @@ onMounted(() => {
|
||||
</Row>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ColumnsType } from 'ant-design-vue/es/table';
|
||||
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Card, Image, message, Table } from 'ant-design-vue';
|
||||
import { Tabs } from 'ant-design-vue';
|
||||
|
||||
import ShopStatistics from './components/ShopStatistics.vue';
|
||||
import OverviewTab from './tabs/OverviewTab.vue';
|
||||
import ProductsTab from './tabs/ProductsTab.vue';
|
||||
|
||||
defineOptions({ name: 'ShopDetails' });
|
||||
|
||||
@@ -22,162 +19,23 @@ const shopId = computed(() => {
|
||||
return id ? Number(id) : 0;
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const productList = ref<ShopVO.ProductDetail[]>([]);
|
||||
|
||||
// 格式化金额
|
||||
function formatCurrency(value: number): string {
|
||||
return `¥${value.toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}`;
|
||||
}
|
||||
|
||||
// 处理商品列表更新(由 ShopStatistics 组件触发)
|
||||
function handleProductListUpdate(products: ShopVO.ProductDetail[]) {
|
||||
productList.value = products || [];
|
||||
}
|
||||
|
||||
// 表格列配置
|
||||
const columns: ColumnsType<ShopVO.ProductDetail> = [
|
||||
{
|
||||
title: '序号',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
customRender: ({ index }) => index + 1,
|
||||
},
|
||||
{
|
||||
title: '商品主图',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
dataIndex: 'mainImage',
|
||||
key: 'mainImage',
|
||||
},
|
||||
{
|
||||
title: '商品名称',
|
||||
dataIndex: 'productName',
|
||||
key: 'productName',
|
||||
ellipsis: true,
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
title: '商品编码',
|
||||
dataIndex: 'productCode',
|
||||
key: 'productCode',
|
||||
ellipsis: true,
|
||||
minWidth: 150,
|
||||
},
|
||||
{
|
||||
title: '销售额',
|
||||
dataIndex: 'salesAmount',
|
||||
key: 'salesAmount',
|
||||
width: 150,
|
||||
align: 'right',
|
||||
customRender: ({ text }) => formatCurrency(text || 0),
|
||||
},
|
||||
{
|
||||
title: '订单数',
|
||||
dataIndex: 'orderCount',
|
||||
key: 'orderCount',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
},
|
||||
{
|
||||
title: '客单价',
|
||||
dataIndex: 'averageOrderValue',
|
||||
key: 'averageOrderValue',
|
||||
width: 150,
|
||||
align: 'right',
|
||||
customRender: ({ text }) => formatCurrency(text || 0),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
];
|
||||
|
||||
// 初始化数据
|
||||
onMounted(async () => {
|
||||
if (shopId.value) {
|
||||
// 等待 ShopStatistics 组件加载完成后,会自动触发 dateRangeChange 事件
|
||||
// 这里不需要手动调用 fetchShopDetail
|
||||
} else {
|
||||
message.error('店铺ID不存在');
|
||||
}
|
||||
});
|
||||
// 当前激活的 tab
|
||||
const activeKey = ref('overview');
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height content-class="flex flex-col">
|
||||
<!-- 店铺统计信息 -->
|
||||
<ShopStatistics
|
||||
:shop-id="shopId"
|
||||
@product-list-update="handleProductListUpdate"
|
||||
/>
|
||||
|
||||
<!-- 商品列表表格 -->
|
||||
<Card
|
||||
title="商品详细信息"
|
||||
:loading="loading"
|
||||
<Tabs
|
||||
v-model:active-key="activeKey"
|
||||
class="flex min-h-0 flex-1 flex-col"
|
||||
:body-style="{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
overflow: 'hidden',
|
||||
flex: 1,
|
||||
}"
|
||||
:tab-bar-style="{ marginBottom: '16px' }"
|
||||
>
|
||||
<!-- 表格 -->
|
||||
<div class="min-h-0 flex-1 overflow-auto">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="productList"
|
||||
:loading="loading"
|
||||
:pagination="false"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
size="small"
|
||||
bordered
|
||||
row-key="productId"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'mainImage'">
|
||||
<div
|
||||
v-if="record.mainImage"
|
||||
style="
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
"
|
||||
>
|
||||
<Image
|
||||
:src="record.mainImage"
|
||||
:alt="record.productName"
|
||||
:preview="false"
|
||||
style="
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
object-fit: cover;
|
||||
border-radius: 4px;
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
style="
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
"
|
||||
>
|
||||
<span style="color: #999">暂无图片</span>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</Table>
|
||||
</div>
|
||||
</Card>
|
||||
<Tabs.TabPane key="overview" tab="总览">
|
||||
<OverviewTab :shop-id="shopId" />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="products" tab="商品">
|
||||
<ProductsTab :shop-id="shopId" />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { Card, Col, DatePicker, message, Row, Space } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getShopOverviewApi } from '#/api/ecommerce/shop';
|
||||
|
||||
import ChartCard from '../components/ChartCard.vue';
|
||||
|
||||
defineOptions({ name: 'OverviewTab' });
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
interface Props {
|
||||
shopId: number;
|
||||
}
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const overviewData = ref<null | ShopVO.Overview>(null);
|
||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||
dayjs().subtract(30, 'day'),
|
||||
dayjs(),
|
||||
]);
|
||||
|
||||
// 格式化金额
|
||||
function formatCurrency(value: number): string {
|
||||
return `¥${value.toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}`;
|
||||
}
|
||||
|
||||
// 格式化百分比
|
||||
function formatPercent(value: number): string {
|
||||
return `${(value * 100).toFixed(2)}%`;
|
||||
}
|
||||
|
||||
// 获取店铺总览数据
|
||||
async function fetchShopOverview() {
|
||||
if (!props.shopId || !dateRange.value) return;
|
||||
try {
|
||||
loading.value = true;
|
||||
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 getShopOverviewApi(params);
|
||||
overviewData.value = data;
|
||||
} catch (error) {
|
||||
console.error('获取店铺总览失败:', error);
|
||||
message.error('获取店铺总览失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理日期范围变化
|
||||
function handleDateRangeChange() {
|
||||
fetchShopOverview();
|
||||
}
|
||||
|
||||
// 监听 shopId 变化
|
||||
watch(
|
||||
() => props.shopId,
|
||||
(newShopId) => {
|
||||
if (newShopId) {
|
||||
fetchShopOverview();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 初始化数据
|
||||
onMounted(() => {
|
||||
if (props.shopId) {
|
||||
fetchShopOverview();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-full flex-col">
|
||||
<!-- 日期选择器 -->
|
||||
<Card :loading="loading" class="mb-4 flex-shrink-0">
|
||||
<Space>
|
||||
<span>选择日期范围:</span>
|
||||
<DatePicker.RangePicker
|
||||
v-model:value="dateRange"
|
||||
format="YYYY-MM-DD"
|
||||
@change="handleDateRangeChange"
|
||||
/>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
<!-- 图表展示 -->
|
||||
<div v-if="overviewData" class="min-h-0 flex-1 overflow-auto">
|
||||
<Row :gutter="[16, 16]">
|
||||
<!-- 销售额 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.salesAmount"
|
||||
:formatter="formatCurrency"
|
||||
title="销售额"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 订单数 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.orderCount"
|
||||
chart-type="bar"
|
||||
color="#019680"
|
||||
title="订单数"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 客单价 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.averageOrderValue"
|
||||
:formatter="formatCurrency"
|
||||
color="#ff9800"
|
||||
title="客单价"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 成本 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.costAmount"
|
||||
:formatter="formatCurrency"
|
||||
color="#f56c6c"
|
||||
title="成本"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 退款金额 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.refundAmount"
|
||||
:formatter="formatCurrency"
|
||||
color="#e6a23c"
|
||||
title="退款金额"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 推广费 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.promotionFee"
|
||||
:formatter="formatCurrency"
|
||||
color="#909399"
|
||||
title="推广费"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<!-- 费比 -->
|
||||
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
|
||||
<ChartCard
|
||||
:data="overviewData.feeRatio"
|
||||
:formatter="formatPercent"
|
||||
color="#67c23a"
|
||||
title="费比"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div v-else class="flex flex-1 items-center justify-center">
|
||||
<span class="text-gray-400">暂无数据</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { ShopDTO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Image, message, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getShopProductPageApi } from '#/api/ecommerce/shop';
|
||||
|
||||
interface Props {
|
||||
shopId: number;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'ProductsTab' });
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
title: '主图',
|
||||
width: 60,
|
||||
slots: { default: 'mainImage' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '商品名称',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'productCode',
|
||||
title: '商品编码',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '规格数量',
|
||||
minWidth: 100,
|
||||
slots: { default: 'specs' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
highlightHoverRow: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
if (!props.shopId) {
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
}
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ShopDTO.ProductPageFilters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: props.shopId,
|
||||
},
|
||||
};
|
||||
const data = await getShopProductPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取商品列表失败:', error);
|
||||
message.error('获取商品列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品名称',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '商品名称',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品编码',
|
||||
},
|
||||
fieldName: 'productCode',
|
||||
label: '商品编码',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '商品列表',
|
||||
});
|
||||
|
||||
// 监听 shopId 变化,刷新表格
|
||||
watch(
|
||||
() => props.shopId,
|
||||
() => {
|
||||
if (props.shopId && gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height content-class="flex flex-col">
|
||||
<Grid :loading="loading">
|
||||
<!-- 主图列 -->
|
||||
<template #mainImage="{ row }: { row: any }">
|
||||
<Image
|
||||
v-if="row.mainImage"
|
||||
:src="row.mainImage"
|
||||
:alt="row.name"
|
||||
width="60"
|
||||
height="60"
|
||||
style="object-fit: cover; border-radius: 4px"
|
||||
:preview="true"
|
||||
/>
|
||||
<span v-else class="text-xs text-gray-400">暂无图片</span>
|
||||
</template>
|
||||
|
||||
<!-- 规格数量列 -->
|
||||
<template #specs="{ row }: { row: any }">
|
||||
<Tag :color="(row.specs?.length || 0) > 0 ? 'blue' : 'default'">
|
||||
{{ row.specs?.length || 0 }} 个规格
|
||||
</Tag>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user