소스 검색

修改商品订单售后订单的数量显示异常问题

Yangzw 11 달 전
부모
커밋
cbf43d9e55

+ 2 - 2
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/controller/admin/spu/ProductSpuController.java

@@ -120,8 +120,8 @@ public class ProductSpuController {
     @GetMapping("/get-count")
     @Operation(summary = "获得商品 SPU 分页 tab count")
     @PreAuthorize("@ss.hasPermission('product:spu:query')")
-    public CommonResult<Map<Integer, Long>> getSpuCount() {
-        return success(productSpuService.getTabsCount());
+    public CommonResult<Map<Integer, Long>> getSpuCount(@Valid ProductSpuPageReqVO pageVO) {
+        return success(productSpuService.getTabsCount(pageVO));
     }
 
     @GetMapping("/get-count-by-mer")

+ 4 - 0
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/controller/admin/spu/vo/ProductSpuPageReqVO.java

@@ -8,6 +8,7 @@ import lombok.ToString;
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.time.LocalDateTime;
+import java.util.List;
 
 import static cn.newfeifan.mall.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 
@@ -75,4 +76,7 @@ public class ProductSpuPageReqVO extends PageParam {
 
     @Schema(description = "商户id", example = "8240")
     private Long merchantId;
+
+    @Schema(description = "店铺编号集")
+    private List<Long> shopIds;
 }

+ 34 - 1
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/dal/mysql/spu/ProductSpuMapper.java

@@ -9,7 +9,6 @@ import cn.newfeifan.mall.module.product.controller.app.spu.vo.AppProductSpuPageR
 import cn.newfeifan.mall.module.product.dal.dataobject.spu.ProductSpuDO;
 import cn.newfeifan.mall.module.product.enums.ProductConstants;
 import cn.newfeifan.mall.module.product.enums.spu.ProductSpuStatusEnum;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 import org.apache.ibatis.annotations.Mapper;
@@ -76,6 +75,40 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
                 .notIn(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()));
     }
 
+    /**
+     * 查询触发警戒库存的 SPU 数量
+     *
+     * @return 触发警戒库存的 SPU 数量
+     */
+    default Long selectCount(ProductSpuPageReqVO pageVO) {
+        LambdaQueryWrapperX<ProductSpuDO> queryWrapper = new LambdaQueryWrapperX<>();
+        // 库存小于等于警戒库存
+        queryWrapper
+                .likeIfPresent(ProductSpuDO::getName, pageVO.getName())
+                .eqIfPresent(ProductSpuDO::getShopId, pageVO.getShopId())
+                .eqIfPresent(ProductSpuDO::getCategoryId, pageVO.getCategoryId())
+                .eqIfPresent(ProductSpuDO::getMerchantId, pageVO.getMerchantId())
+                .inIfPresent(ProductSpuDO::getShopId, pageVO.getShopIds())
+                .betweenIfPresent(ProductSpuDO::getCreateTime, pageVO.getCreateTime())
+                .le(ProductSpuDO::getStock, ProductConstants.ALERT_STOCK)
+                // 如果库存触发警戒库存且状态为回收站的话则不计入触发警戒库存的个数
+                .notIn(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus())
+        ;
+        return selectCount(queryWrapper);
+    }
+
+    default Long selectCount(SFunction<ProductSpuDO, ?> field, Object value,ProductSpuPageReqVO pageVO) {
+        return selectCount(new LambdaQueryWrapperX<ProductSpuDO>()
+                .eq(field, value)
+                .likeIfPresent(ProductSpuDO::getName, pageVO.getName())
+                .eqIfPresent(ProductSpuDO::getShopId, pageVO.getShopId())
+                .eqIfPresent(ProductSpuDO::getCategoryId, pageVO.getCategoryId())
+                .eqIfPresent(ProductSpuDO::getMerchantId, pageVO.getMerchantId())
+                .inIfPresent(ProductSpuDO::getShopId, pageVO.getShopIds())
+                .betweenIfPresent(ProductSpuDO::getCreateTime, pageVO.getCreateTime())
+        );
+    }
+
     /**
      * 获得商品 SPU 分页,提供给用户 App 使用
      */

+ 2 - 2
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/service/spu/ProductSpuService.java

@@ -98,10 +98,10 @@ public interface ProductSpuService {
 
     /**
      * 获取 SPU 列表标签对应的 Count 数量
-     *
+     * @param pageVO 条件查询
      * @return Count 数量
      */
-    Map<Integer, Long> getTabsCount();
+    Map<Integer, Long> getTabsCount(ProductSpuPageReqVO pageVO);
 
 
     /**

+ 6 - 6
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/service/spu/ProductSpuServiceImpl.java

@@ -270,23 +270,23 @@ public class ProductSpuServiceImpl implements ProductSpuService {
     }
 
     @Override
-    public Map<Integer, Long> getTabsCount() {
+    public Map<Integer, Long> getTabsCount(ProductSpuPageReqVO pageVO) {
         Map<Integer, Long> counts = Maps.newLinkedHashMapWithExpectedSize(5);
         // 查询销售中的商品数量
         counts.put(ProductSpuPageReqVO.FOR_SALE,
-                productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus()));
+                productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus(),pageVO));
         // 查询仓库中的商品数量
         counts.put(ProductSpuPageReqVO.IN_WAREHOUSE,
-                productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus()));
+                productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus(),pageVO));
         // 查询售空的商品数量
         counts.put(ProductSpuPageReqVO.SOLD_OUT,
-                productSpuMapper.selectCount(ProductSpuDO::getStock, 0));
+                productSpuMapper.selectCount(ProductSpuDO::getStock, 0,pageVO));
         // 查询触发警戒库存的商品数量
         counts.put(ProductSpuPageReqVO.ALERT_STOCK,
-                productSpuMapper.selectCount());
+                productSpuMapper.selectCount(pageVO));
         // 查询回收站中的商品数量
         counts.put(ProductSpuPageReqVO.RECYCLE_BIN,
-                productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()));
+                productSpuMapper.selectCount(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus(),pageVO));
         return counts;
     }