Parcourir la source

销量排行榜

yangyb il y a 1 semaine
Parent
commit
6c2fd2fcbf

+ 0 - 32
mall-api/src/main/java/com/txz/mall/constants/Constants.java

@@ -170,25 +170,6 @@ public class Constants {
 
     public static final String CONFIG_KEY_LOGISTICS_APP_CODE = "system_express_app_code"; //快递查询密钥
 
-    //云智服 小程序插件
-    public static final String CONFIG_KEY_YZF_H5_URL = "yzf_h5_url"; //云智服H5 url
-    // 客服电话
-    public static final String CONFIG_KEY_CONSUMER_HOTLINE = "consumer_hotline";
-    // 客服电话服务开关
-    public static final String CONFIG_KEY_TELEPHONE_SERVICE_SWITCH = "telephone_service_switch";
-    //商品分类页配置
-    public static final String CONFIG_CATEGORY_CONFIG = "category_page_config"; //商品分类页配置
-    public static final String CONFIG_IS_SHOW_CATEGORY = "is_show_category"; //是否隐藏一级分类
-    public static final String CONFIG_IS_PRODUCT_LIST_STYLE = "homePageSaleListStyle"; //首页商品列表模板配置
-    // app 版本号
-    public static final String CONFIG_APP_VERSION = "app_version";
-    // android版本地址
-    public static final String CONFIG_APP_ANDROID_ADDRESS = "android_address";
-    // ios版本地址
-    public static final String CONFIG_APP_IOS_ADDRESS = "ios_address";
-    // 开放式升级
-    public static final String CONFIG_APP_OPEN_UPGRADE = "open_upgrade";
-
 
     //分销
     public static final String CONFIG_KEY_STORE_BROKERAGE_LEVEL = "store_brokerage_rate_num"; //返佣比例前缀
@@ -279,19 +260,6 @@ public class Constants {
     public static final String SIGN_TYPE_DAY_TITLE = "day";
     public static final String SIGN_TYPE_GOLD_TITLE = "gold";
 
-
-    //会员搜索日期类型
-    public static final String SEARCH_DATE_DAY = "today"; //今天
-    public static final String SEARCH_DATE_YESTERDAY = "yesterday"; //昨天
-    public static final String SEARCH_DATE_LATELY_7 = "lately7"; //最近7天
-    public static final String SEARCH_DATE_LATELY_30 = "lately30"; //最近30天
-    public static final String SEARCH_DATE_WEEK = "week"; //本周
-    public static final String SEARCH_DATE_PRE_WEEK = "preWeek"; //上周
-    public static final String SEARCH_DATE_MONTH = "month"; //本月
-    public static final String SEARCH_DATE_PRE_MONTH = "preMonth"; //上月
-    public static final String SEARCH_DATE_YEAR = "year"; //年
-    public static final String SEARCH_DATE_PRE_YEAR = "preYear"; //上一年
-
     //分类服务类型  类型,1 产品分类,2 附件分类,3 文章分类, 4 设置分类, 5 菜单分类, 6 配置分类, 7 秒杀配置
     public static final int CATEGORY_TYPE_PRODUCT = 1; //产品
     public static final int CATEGORY_TYPE_ATTACHMENT = 2; //附件分类

+ 7 - 1
mall-service/src/main/java/com/txz/mall/business/OrderServiceBusiness.java

@@ -1,7 +1,10 @@
 package com.txz.mall.business;
 
+import vo.StoreCombinationRankVO;
 import vo.StoreOrderVO;
 
+import java.util.List;
+
 
 /**
  * Created by CodeGenerator on 2025/07/15.
@@ -16,5 +19,8 @@ public interface OrderServiceBusiness {
      */
     StoreOrderVO orderDetail(Long id);
 
-
+    /**
+     * 排行榜
+     */
+    List<StoreCombinationRankVO> getRank();
 }

+ 66 - 8
mall-service/src/main/java/com/txz/mall/business/impl/OrderServiceBusinessImpl.java

@@ -1,25 +1,29 @@
 package com.txz.mall.business.impl;
 
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.txz.cif.dto.UserDTO;
 import com.txz.mall.business.OrderServiceBusiness;
+import com.txz.mall.core.RedisUtil;
 import com.txz.mall.dubbo.client.CifUserDubboServiceClient;
-import com.txz.mall.model.StoreOrder;
-import com.txz.mall.model.StoreOrderInfo;
-import com.txz.mall.model.StoreOrderStatus;
-import com.txz.mall.model.UserAddress;
-import com.txz.mall.service.StoreOrderInfoService;
-import com.txz.mall.service.StoreOrderService;
-import com.txz.mall.service.StoreOrderStatusService;
-import com.txz.mall.service.UserAddressService;
+import com.txz.mall.model.*;
+import com.txz.mall.service.*;
 import lombok.AllArgsConstructor;
+import org.apache.commons.lang.time.DateUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import tk.mybatis.mapper.entity.Condition;
 import tk.mybatis.mapper.entity.Example;
+import vo.StoreCombinationRankVO;
 import vo.StoreOrderVO;
 
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 
 /**
@@ -35,6 +39,9 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
     private final UserAddressService userAddressService;
     private final StoreOrderStatusService storeOrderStatusService;
     private final CifUserDubboServiceClient userDubboServiceClient;
+    private final StoreCombinationService storeCombinationService;
+    private final RedisUtil redisUtil;
+
     @Override
     public StoreOrderVO orderDetail(Long id) {
         StoreOrder storeOrder = storeOrderService.findById(id);
@@ -55,4 +62,55 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
         return vo;
     }
 
+
+    @Override
+    public List<StoreCombinationRankVO> getRank() {
+        List<StoreCombinationRankVO> list = new ArrayList<>();
+        String key = "order:rank:";
+        boolean exists = redisUtil.hasKey("order:rank");
+        if (exists) {
+            String orderVoString = redisUtil.get(key).toString();
+            list = JSONObject.parseArray(orderVoString, StoreCombinationRankVO.class);
+            return list;
+        }
+
+        Condition orderCondition = new Condition(StoreOrder.class);
+        Example.Criteria orderCriteria = orderCondition.createCriteria();
+        Date date = new Date();
+        Date startDate = DateUtil.beginOfDay(DateUtils.addDays(date, -7));
+        Date endDate = DateUtil.endOfDay(date);
+        orderCriteria.andEqualTo("isDelete", 0);
+        orderCriteria.andBetween("createTime", startDate, endDate);
+        orderCriteria.andEqualTo("paid", 1);
+        List<StoreOrder> orderList = storeOrderService.findByCondition(orderCondition);
+        Map<Long, Long> combinationCountMap = orderList.stream()
+                .collect(Collectors.groupingBy(
+                        StoreOrder::getCombinationId,
+                        Collectors.counting()
+                ));
+
+        // 获取前10个热门商品组合
+        List<Map.Entry<Long, Long>> topCombinations = combinationCountMap.entrySet()
+                .stream()
+                .sorted(Map.Entry.<Long, Long>comparingByValue().reversed())
+                .collect(Collectors.toList());
+
+        List<StoreCombination> combinationList = storeCombinationService.findByIds(String.join(",", topCombinations.stream().map(Map.Entry::getKey).map(Object::toString).collect(Collectors.toList())));
+        for (StoreCombination storeCombination : combinationList) {
+            List<StoreCombination> collect = combinationList.stream().filter(c -> c.getId().equals(storeCombination.getId())).collect(Collectors.toList());
+            if (CollectionUtils.isNotEmpty(collect)) {
+                StoreCombination combination = collect.get(0);
+                StoreCombinationRankVO rankVO = new StoreCombinationRankVO();
+                rankVO.setProductId(combination.getProductId());
+                rankVO.setProductName(combination.getProductName());
+                rankVO.setSales(combination.getSales());
+                rankVO.setImage(combination.getImage());
+                rankVO.setPrice(combination.getPrice());
+                list.add(rankVO);
+            }
+        }
+        redisUtil.set(key, list);
+        return list;
+    }
+
 }

+ 19 - 0
mall-service/src/main/java/com/txz/mall/controller/CombinationController.java

@@ -3,6 +3,7 @@ package com.txz.mall.controller;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.txz.mall.business.OrderServiceBusiness;
 import com.txz.mall.core.Result;
 import com.txz.mall.core.ResultCode;
 import com.txz.mall.core.ServiceException;
@@ -19,6 +20,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import tk.mybatis.mapper.entity.Condition;
 import tk.mybatis.mapper.entity.Example;
+import vo.StoreCombinationRankVO;
 
 import javax.annotation.Resource;
 import java.util.Date;
@@ -39,6 +41,8 @@ public class CombinationController {
     private StoreCombinationService storeCombinationService;
     @Resource
     private StoreOrderService storeOrderService;
+    @Resource
+    private OrderServiceBusiness orderServiceBusiness;
 
     @PostMapping("/add")
     @ApiOperation(value = "拼团商品表新增")
@@ -234,5 +238,20 @@ public class CombinationController {
         return Result.success(pageInfo);
     }
 
+    @ApiOperation(value = "排行榜")
+    @GetMapping(value = "/rank")
+    public Result<List<StoreCombinationRankVO>> getRank(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
+        PageHelper.startPage(page, size);
+        PageInfo pageInfo = null;
+        try {
+            List<StoreCombinationRankVO> list = orderServiceBusiness.getRank();
+            pageInfo = new PageInfo(list);
+        } catch (Exception e) {
+            log.error("查询对象操作异常e:{}", e);
+            return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
+        }
+        return Result.success(pageInfo);
+    }
+
 
 }

+ 2 - 0
mall-service/src/main/java/com/txz/mall/enums/OrderStatusEnum.java

@@ -18,6 +18,8 @@ public enum OrderStatusEnum {
     WAIT_RECEIVER(8, "待收货"),
     RECEIVED_GOOD(9, "已收货"),
     COMPLETE(10, "已完成"),
+    CANCEL(11, "已取消"),
+    CLOSE(12, "已关闭"),
     ;
 
     private Integer key;

+ 12 - 9
mall-service/src/main/java/com/txz/mall/service/impl/StoreOrderServiceImpl.java

@@ -19,6 +19,7 @@ import com.txz.mall.core.ResultCode;
 import com.txz.mall.core.ServiceException;
 import com.txz.mall.dubbo.client.CifAccountDubboServiceClient;
 import com.txz.mall.dubbo.client.CifUserDubboServiceClient;
+import com.txz.mall.enums.OrderStatusEnum;
 import com.txz.mall.model.*;
 import com.txz.mall.service.*;
 import com.txz.mall.util.OrderUtils;
@@ -30,6 +31,7 @@ import org.apache.commons.lang3.StringEscapeUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import po.StoreProductPO;
 import tk.mybatis.mapper.entity.Condition;
 import tk.mybatis.mapper.entity.Example;
 import vo.*;
@@ -68,13 +70,14 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
         StoreOrderCountItemVO response = new StoreOrderCountItemVO();
         int type = 2;
         // 全部订单
-        response.setAll(getCount(Constants.ORDER_STATUS_ALL, type));
+
+        response.setAll(getCount(OrderStatusEnum.ALL.getKey(), type));
         // 未支付订单
-        response.setUnPaid(getCount(Constants.ORDER_STATUS_UNPAID, type));
+        response.setUnPaid(getCount(OrderStatusEnum.UNPAID.getKey(), type));
         // 待发货订单
-        response.setNotShipped(getCount(Constants.ORDER_STATUS_WAIT_DELIVER, type));
+        response.setNotShipped(getCount(OrderStatusEnum.WAIT_DELIVER.getKey(), type));
         // 待收货订单
-        response.setSpike(getCount(Constants.ORDER_STATUS_WAIT_RECEIVER, type));
+        response.setSpike(getCount(OrderStatusEnum.WAIT_RECEIVER.getKey(), type));
 //        // 待评价订单
 //        response.setBargain(getCount(Constants.ORDER_STATUS_BARGAIN, type));
 //        // 交易完成订单
@@ -243,8 +246,8 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
             String fileName = URLEncoder.encode("导出订单", "UTF-8").replaceAll("\\+", "%20");
             response.setHeader(
                     "Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
-            List<StoreProduct> list = new ArrayList<>();
-            EasyExcel.write(outputStream, StoreOrder.class).sheet("导出订单").doWrite(list);
+            List<StoreProductPO> list = new ArrayList<>();
+            EasyExcel.write(outputStream, StoreProductPO.class).sheet("导出订单").doWrite(list);
         } catch (Exception e) {
             throw new ServiceException("模板下载失败, 请联系管理员");
         }
@@ -1290,7 +1293,7 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
     @Override
     public void refund(Long id) {
         StoreOrder storeOrder = findById(id);
-        if (storeOrder.getPaid().equals(Constants.ORDER_STATUS_UNPAID)) {
+        if (storeOrder.getPaid().equals(OrderStatusEnum.UNPAID.getKey())) {
             throw new ServiceException("当前状态不支持退款");
         }
     }
@@ -1298,7 +1301,7 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
     @Override
     public void close(Long id) {
         StoreOrder storeOrder = findById(id);
-//        storeOrder.setStatus(Constants.ORDER_STATUS_CLOSE);
+//        storeOrder.setStatus(OrderStatusEnum.CLOSE.getKey());
 //        update(storeOrder);
     }
 
@@ -1306,7 +1309,7 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
     public void cancel(Long id) {
         StoreOrder storeOrder = findById(id);
         if (storeOrder.getPaid().equals(0)) {
-            storeOrder.setStatus(Constants.ORDER_STATUS_CANCEL);
+            storeOrder.setStatus(OrderStatusEnum.CANCEL.getKey());
             update(storeOrder);
         } else {
             throw new ServiceException("当前状态不支持取消");

+ 276 - 0
mall-service/src/main/java/po/StoreProductPO.java

@@ -0,0 +1,276 @@
+package po;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class StoreProductPO {
+
+    /**
+     * 商品图片(主图)
+     */
+    @ApiModelProperty(value = "商品主图")
+    @ExcelProperty(value = "商品图片")
+    private String image;
+
+    /**
+     * 商品名称
+     */
+    @ApiModelProperty(value = "商品名称")
+    @ExcelProperty(value = "商品名称")
+    private String storeName;
+
+    /**
+     * 商品简介
+     */
+    @ApiModelProperty(value = "商品简介")
+    @ExcelProperty(value = "商品简介")
+    private String storeInfo;
+
+    /**
+     * 关键字(副标题)
+     */
+    @ApiModelProperty(value = "副标题")
+    @ExcelProperty(value = "副标题")
+    private String keyword;
+
+    /**
+     * 分类id
+     */
+    @ApiModelProperty(value = "分类id")
+    @ExcelProperty(value = "分类id")
+    private String cateId;
+
+    /**
+     * 商品价格
+     */
+    @ApiModelProperty(value = "商品价格")
+    @ExcelProperty(value = "商品价格")
+    private BigDecimal price;
+
+    /**
+     * 会员价格
+     */
+    @ApiModelProperty(value = "会员价格")
+    @ExcelProperty(value = "会员价格")
+    private BigDecimal vipPrice;
+
+    /**
+     * 市场价
+     */
+    @ApiModelProperty(value = "市场价")
+    @ExcelProperty(value = "市场价")
+    private BigDecimal otPrice;
+
+    /**
+     * 邮费
+     */
+    @ApiModelProperty(value = "邮费")
+    @ExcelProperty(value = "邮费")
+    private BigDecimal postage;
+
+    /**
+     * 单位名
+     */
+    @ApiModelProperty(value = "单位名")
+    @ExcelProperty(value = "单位名")
+    private String unitName;
+
+    /**
+     * 排序
+     */
+    @ApiModelProperty(value = "排序")
+    @ExcelProperty(value = "排序")
+    private Integer sort;
+
+    /**
+     * 销量
+     */
+    @ApiModelProperty(value = "销量")
+    @ExcelProperty(value = "销量")
+    private Integer sales;
+
+    /**
+     * 库存
+     */
+    @ApiModelProperty(value = "库存")
+    @ExcelProperty(value = "库存")
+    private Integer stock;
+
+    /**
+     * 状态(0:未上架,1:上架)
+     */
+    @ApiModelProperty(value = "状态 (0:未上架,1:上架)")
+    @ExcelProperty(value = "状态 (0:未上架,1:上架)")
+    private Integer isShow;
+
+    /**
+     * 是否热卖
+     */
+    @ApiModelProperty(value = "是否热卖")
+    @ExcelProperty(value = "是否热卖")
+    private Integer isHot;
+
+    /**
+     * 是否优惠
+     */
+    @ApiModelProperty(value = "是否优惠")
+    @ExcelProperty(value = "是否优惠")
+    private Integer isBenefit;
+
+    /**
+     * 是否精品
+     */
+    @ApiModelProperty(value = "是否精品")
+    @ExcelProperty(value = "是否精品")
+    private Integer isBest;
+
+    /**
+     * 是否新品
+     */
+    @ApiModelProperty(value = "是否新品")
+    @ExcelProperty(value = "是否新品")
+    private Integer isNew;
+
+    /**
+     * 是否包邮
+     */
+    @ApiModelProperty(value = "是否包邮")
+    @ExcelProperty(value = "是否包邮")
+    private Integer isPostage;
+
+    /**
+     * 获得积分
+     */
+    @ApiModelProperty(value = "获得积分")
+    @ExcelProperty(value = "获得积分")
+    private Integer giveIntegral;
+
+    /**
+     * 成本价
+     */
+    @ApiModelProperty(value = "成本价")
+    @ExcelProperty(value = "成本价")
+    private BigDecimal cost;
+
+    @ApiModelProperty(value = "拼团状态  0未开启 1开启")
+    @ExcelProperty(value = "拼团状态  0未开启 1开启")
+    private Integer isPink;
+
+    /**
+     * 是否优品推荐
+     */
+    @ApiModelProperty(value = "是否优品推荐")
+    @ExcelProperty(value = "是否优品推荐")
+    private Integer isGood;
+
+    /**
+     * 是否单独分佣
+     */
+    @ApiModelProperty(value = "是否单独分佣")
+    @ExcelProperty(value = "是否单独分佣")
+    private Integer isSub;
+
+    /**
+     * 虚拟销量
+     */
+    @ApiModelProperty(value = "虚拟销量")
+    @ExcelProperty(value = "虚拟销量")
+    private Integer ficti;
+
+    /**
+     * 浏览量
+     */
+    @ApiModelProperty(value = "浏览量")
+    @ExcelProperty(value = "浏览量")
+    private Integer browse;
+
+    /**
+     * 主图视频链接
+     */
+    @ApiModelProperty(value = "主图视频链接")
+    @ExcelProperty(value = "主图视频链接")
+    private String videoLink;
+
+    /**
+     * 运费模板ID
+     */
+    @ApiModelProperty("运费模板ID")
+    @ExcelProperty("运费模板ID")
+    private Long tempId;
+
+    /**
+     * 规格 0单 1多
+     */
+    @ApiModelProperty("规格 0单 1多")
+    @ExcelProperty("规格 0单 1多")
+    private Integer specType;
+
+    /**
+     * 活动显示排序 0=默认,1=拼团, 2=秒杀,
+     */
+    @ApiModelProperty("活动显示排序0=默认,1=拼团, 2=秒杀,")
+    @ExcelProperty("活动显示排序0=默认,1=拼团, 2=秒杀,")
+    private String activity;
+
+    /**
+     * 是否回收站
+     */
+    @ApiModelProperty("是否回收站")
+    @ExcelProperty("是否回收站")
+    private Integer isRecycle;
+
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty("创建时间")
+    @ExcelProperty("创建时间")
+    private Date createTime;
+
+    /**
+     * 货号
+     */
+    @ApiModelProperty("货号")
+    @ExcelProperty("货号")
+    private String itemNumber;
+
+    /**
+     * 品牌
+     */
+    @ApiModelProperty("品牌")
+    @ExcelProperty("品牌")
+    private String itemBrand;
+
+    /**
+     * 库存预警值
+     */
+    @ApiModelProperty("库存预警值")
+    @ExcelProperty("库存预警值")
+    private Integer stockThreshold;
+
+    /**
+     * 供应商
+     */
+    @ApiModelProperty("供应商")
+    @ExcelProperty("供应商")
+    private String itemSupplier;
+
+    /**
+     * 轮播图(白底图)
+     */
+    @ApiModelProperty("轮播图(白底图)")
+    @ExcelProperty("轮播图(白底图)")
+    private String sliderImage;
+
+    /**
+     * 展示图(详情图)
+     */
+    @ApiModelProperty("展示图(详情图)")
+    @ExcelProperty("展示图(详情图)")
+    private String flatPattern;
+
+}

+ 30 - 0
mall-service/src/main/java/vo/StoreCombinationRankVO.java

@@ -0,0 +1,30 @@
+package vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+
+@Data
+public class StoreCombinationRankVO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "商品id")
+    private Long productId;
+
+    @ApiModelProperty(value = "商品名称")
+    private String productName;
+
+    @ApiModelProperty(value = "推荐图")
+    private String image;
+
+    @ApiModelProperty(value = "价格")
+    private BigDecimal price;
+
+    @ApiModelProperty(value = "销量")
+    private Integer sales;
+
+}