Browse Source

修改店铺的商品分类和商品获取,以及用户删除订单只对用户作用

Yangzw 1 month ago
parent
commit
bba680dbb8

+ 2 - 2
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/controller/app/category/AppCategoryController.java

@@ -33,8 +33,8 @@ public class AppCategoryController {
 
     @GetMapping("/list")
     @Operation(summary = "获得商品分类列表")
-    public CommonResult<List<AppCategoryRespVO>> getProductCategoryList() {
-        List<ProductCategoryDO> list = categoryService.getEnableCategoryList();
+    public CommonResult<List<AppCategoryRespVO>> getProductCategoryList(Long merchantId, Long shopId) {
+        List<ProductCategoryDO> list = categoryService.getEnableCategoryList(merchantId, shopId);
         list.sort(Comparator.comparing(ProductCategoryDO::getSort));
         return success(BeanUtils.toBean(list, AppCategoryRespVO.class));
     }

+ 6 - 0
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/controller/app/spu/vo/AppProductSpuPageReqVO.java

@@ -39,6 +39,12 @@ public class AppProductSpuPageReqVO extends PageParam {
     @Schema(description = "排序方式", example = "true")
     private Boolean sortAsc;
 
+    @Schema(description = "店铺id", example = "true")
+    private Long shopId;
+
+    @Schema(description = "商户id", example = "true")
+    private Long merchantId;
+
     @AssertTrue(message = "排序字段不合法")
     @JsonIgnore
     public boolean isSortFieldValid() {

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

@@ -60,6 +60,8 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
                 .inIfPresent(ProductSpuDO::getCategoryId, categoryIds);
         // 上架状态 且有库存
         query.eq(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus());
+        query.eqIfPresent(ProductSpuDO::getShopId, pageReqVO.getShopId());
+        query.eqIfPresent(ProductSpuDO::getMerchantId, pageReqVO.getMerchantId());
 
         // 排序逻辑
         if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_SALES_COUNT)) {

+ 1 - 1
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/service/category/ProductCategoryService.java

@@ -73,7 +73,7 @@ public interface ProductCategoryService {
      *
      * @return 商品分类列表
      */
-    List<ProductCategoryDO> getEnableCategoryList();
+    List<ProductCategoryDO> getEnableCategoryList(Long merchantId, Long shopId);
 
     /**
      * 获得开启状态的商品分类列表,指定编号

+ 16 - 1
feifan-module-mall/feifan-module-product-biz/src/main/java/cn/newfeifan/mall/module/product/service/category/ProductCategoryServiceImpl.java

@@ -7,8 +7,10 @@ import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
 import cn.newfeifan.mall.module.product.controller.admin.category.vo.ProductCategoryListReqVO;
 import cn.newfeifan.mall.module.product.controller.admin.category.vo.ProductCategorySaveReqVO;
 import cn.newfeifan.mall.module.product.dal.dataobject.category.ProductCategoryDO;
+import cn.newfeifan.mall.module.product.dal.dataobject.spu.ProductSpuDO;
 import cn.newfeifan.mall.module.product.dal.mysql.category.ProductCategoryMapper;
 import cn.newfeifan.mall.module.product.service.spu.ProductSpuService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
@@ -18,6 +20,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.newfeifan.mall.module.product.dal.dataobject.category.ProductCategoryDO.PARENT_ID_NULL;
@@ -165,7 +168,19 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
     }
 
     @Override
-    public List<ProductCategoryDO> getEnableCategoryList() {
+    public List<ProductCategoryDO> getEnableCategoryList(Long merchantId, Long shopId) {
+        if(merchantId != null && shopId != null) {
+            List<ProductSpuDO> spuDOS = productSpuService.getSpuListByMerchantIdAndShopId(merchantId, shopId);
+            List<Long> categoryIds = spuDOS.stream().map(ProductSpuDO::getCategoryId).distinct().collect(Collectors.toList());
+            List<ProductCategoryDO> productCategoryDOS = productCategoryMapper.selectList(new LambdaQueryWrapper<ProductCategoryDO>()
+                    .eq(ProductCategoryDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
+                    .in(ProductCategoryDO::getId, categoryIds));
+            List<ProductCategoryDO> parentCategory = productCategoryMapper.selectList(new LambdaQueryWrapper<ProductCategoryDO>()
+                    .eq(ProductCategoryDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
+                    .in(ProductCategoryDO::getId, productCategoryDOS.stream().map(ProductCategoryDO::getParentId).collect(Collectors.toList())));
+            productCategoryDOS.addAll(parentCategory);
+            return productCategoryDOS;
+        }
         return productCategoryMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus());
     }
 

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

@@ -131,4 +131,11 @@ public interface ProductSpuService {
     @Async
     void updateBrowseCount(Long id, int incrCount);
 
+    /**
+     * 通过商户id和店铺id获取商品列表
+     * @param merchantId 商户id
+     * @param shopId 店铺id
+     * @return 商品列表
+     */
+    List<ProductSpuDO> getSpuListByMerchantIdAndShopId(Long merchantId, Long shopId);
 }

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

@@ -19,6 +19,7 @@ import cn.newfeifan.mall.module.product.enums.spu.ProductSpuStatusEnum;
 import cn.newfeifan.mall.module.product.service.brand.ProductBrandService;
 import cn.newfeifan.mall.module.product.service.category.ProductCategoryService;
 import cn.newfeifan.mall.module.product.service.sku.ProductSkuService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.google.common.collect.Maps;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
@@ -163,6 +164,13 @@ public class ProductSpuServiceImpl implements ProductSpuService {
         productSpuMapper.updateBrowseCount(id , incrCount);
     }
 
+    @Override
+    public List<ProductSpuDO> getSpuListByMerchantIdAndShopId(Long merchantId, Long shopId) {
+        return productSpuMapper.selectList(new LambdaQueryWrapper<ProductSpuDO>()
+                .eq(ProductSpuDO::getMerchantId, merchantId)
+                .eq(ProductSpuDO::getShopId, shopId));
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void deleteSpu(Long id) {

+ 4 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/dataobject/order/TradeOrderDO.java

@@ -342,5 +342,9 @@ public class TradeOrderDO extends BaseDO {
      * 退还的使用的消费分
      */
     private Long refundConsumption;
+    /**
+     * 用户是否删除
+     */
+    private Boolean userDeleted;
 
 }

+ 1 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/mysql/order/TradeOrderMapper.java

@@ -76,6 +76,7 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
                 .eq(TradeOrderDO::getUserId, userId)
                 .eqIfPresent(TradeOrderDO::getStatus, reqVO.getStatus())
                 .eqIfPresent(TradeOrderDO::getCommentStatus, reqVO.getCommentStatus())
+                .eq(TradeOrderDO::getUserDeleted, false)
                 .orderByDesc(TradeOrderDO::getId)); // TODO 非繁人:未来不同的 status,不同的排序
     }
 

+ 3 - 1
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderUpdateServiceImpl.java

@@ -2179,8 +2179,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
         if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus())) {
             throw exception(ORDER_DELETE_FAIL_STATUS_NOT_CANCEL);
         }
+        // 用户删除作为给用户看的订单
+        order.setUserDeleted(true);
         // 2. 删除订单
-        tradeOrderMapper.deleteById(id);
+        tradeOrderMapper.updateById(order);
 
         // 3. 记录日志
         TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus());