Prechádzať zdrojové kódy

分类绑定商品处理

fubojin 1 mesiac pred
rodič
commit
4024e6951f

+ 0 - 3
yami-shop-api/src/main/java/com/yami/shop/api/controller/SearchController.java

@@ -82,9 +82,6 @@ public class SearchController {
     @GetMapping("/searchProdPage")
     @ApiOperation(value = "搜索商品")
     public ResponseEntity<IPage<SearchProdDto>> searchProdPage(PageParam page, SearchParam searchParam) {
-//        if(searchParam.getCouponId() != null && searchParam.getCouponId() != 0){
-//            applicationContext.publishEvent(new GetCouponCanProdEvent(searchParam));
-//        }
         searchParam.setProdType(0);
         IPage<SearchProdDto> searchProdDtoPageByProdName = productService.getSearchProdDtoPageByProdName(page, searchParam);
         return ResponseEntity.ok(searchProdDtoPageByProdName);

+ 7 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/app/dto/CategoryDto.java

@@ -10,6 +10,7 @@
 
 package com.yami.shop.bean.app.dto;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.yami.shop.bean.model.Category;
 import com.yami.shop.common.serializer.json.ImgJsonSerializer;
@@ -44,6 +45,12 @@ public class CategoryDto {
 	@ApiModelProperty(value = "标签",required=true)
 	private String label;
 
+	/**
+	 * 是否存在二级
+	 */
+	@ApiModelProperty(value = "是否存在二级",required=true)
+	private boolean hasSecond;
+
 	@ApiModelProperty(value = "子类分类列表",required=true)
 	private List<Category> categories;
 }

+ 1 - 1
yami-shop-bean/src/main/java/com/yami/shop/bean/dto/PointsRechargeTemplateDTO.java

@@ -30,7 +30,7 @@ public class PointsRechargeTemplateDTO {
     @ColumnWidth(20)
     private BigDecimal points;
 
-    @ExcelProperty("过期日期")
+    @ExcelProperty("过期日期(yyyy/MM/dd)")
     @ColumnWidth(20)
     @DateTimeFormat("yyyy/MM/dd") // 可选:指定日期格式
     private Date expiryDate;

+ 3 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/dto/SearchProdDto.java

@@ -34,6 +34,9 @@ public class SearchProdDto {
     @ApiModelProperty(value = "商品名字")
     private String prodName;
 
+    @ApiModelProperty(value = "商品库存")
+    private Integer stocks;
+
     @ApiModelProperty(value = "商品价格")
     private Double price;
 

+ 6 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/model/Category.java

@@ -129,4 +129,10 @@ public class Category implements Serializable {
 
     @TableField(exist=false)
     private String label;
+
+    /**
+     * 是否存在二级
+     */
+    @TableField(exist=false)
+    private boolean hasSecond;
 }

+ 1 - 1
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/ChannelProdExportVO.java

@@ -15,7 +15,7 @@ public class ChannelProdExportVO {
 
     @ExcelProperty(value = "海博商品ID", index = 0)
     @ColumnWidth(20)
-    private String skuId;
+    private Long skuId;
 
     @ExcelProperty(value = "商品名称", index = 1)
     @ColumnWidth(40)

+ 0 - 6
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/CategoryController.java

@@ -131,7 +131,6 @@ public class CategoryController {
 													   @RequestParam(value = "size", required = false, defaultValue = "10") Integer size){
 		IPage<Category> page = categoryService.page(new Page<>(current, size), new LambdaQueryWrapper<Category>()
 				.le(Category::getGrade, maxGrade)
-//				.eq(Category::getShopId, Constant.PLATFORM_SHOP_ID)
 				.eq(Objects.nonNull(shopId), Category::getShopId, shopId)
 				.like(StringUtils.isNotEmpty(categoryName), Category::getCategoryName, categoryName)
 				.orderByDesc(Category::getSeq)
@@ -143,11 +142,6 @@ public class CategoryController {
 				record.setShopName(shopDetail.getShopName());
 			}
 		}
-
-//		return ResponseEntity.ok(categoryService.list(new LambdaQueryWrapper<Category>()
-//														.le(Category::getGrade, maxGrade)
-////														.eq(Category::getShopId, Constant.PLATFORM_SHOP_ID)
-//														.orderByAsc(Category::getSeq)));
 		return R.SUCCESS(page);
 	}
 

+ 8 - 0
yami-shop-service/src/main/java/com/yami/shop/dao/ShopCategoryMapper.java

@@ -42,6 +42,12 @@ public interface ShopCategoryMapper extends BaseMapper<ShopCategory> {
      */
     int  deleteByParentCode(@Param("parentCode") String parentCode);
 
+    /**
+     * 根据名称查询门店对应分类
+     * @param shopId 门店id
+     * @return 门店对应分类
+     */
+    List<ShopCategory> selectAppListAll(@Param("shopId") Long shopId);
     /**
      * 根据名称查询门店对应分类
      * @param shopId 门店id
@@ -49,4 +55,6 @@ public interface ShopCategoryMapper extends BaseMapper<ShopCategory> {
      * @return 门店对应分类
      */
     List<ShopCategory> selectListAll(@Param("shopId") Long shopId, @Param("name") String name);
+
+    Integer selectAppCount(@Param("shopId") Long shopId,@Param("code") String code);
 }

+ 15 - 21
yami-shop-service/src/main/java/com/yami/shop/service/impl/BasketServiceImpl.java

@@ -62,39 +62,33 @@ public class BasketServiceImpl extends ServiceImpl<BasketMapper, Basket> impleme
     private final ProductService productService;
 
     @Override
-    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
+//    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
     public void deleteShopCartItemsByBasketIds(String userId, List<Long> basketIds) {
         basketMapper.deleteShopCartItemsByBasketIds(userId, basketIds);
     }
 
     @Override
+//    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
     public void addShopCartItem(ChangeShopCartParam param, String userId) {
         Basket basket = new Basket();
-        ShopCartItemDto cartItem = basketMapper.getShopCartItemsByShopIdSkuIdUserId(param.getShopId(), param.getSkuId(), userId);
-        if (cartItem!=null){
-            basket.setBasketCount(cartItem.getBasketCount() + param.getCount());
-            basket.setBasketId(cartItem.getBasketId());
-            basketMapper.updateById(basket);
-        }else {
-            basket.setBasketCount(param.getCount());
-            basket.setBasketDate(new Date());
-            basket.setProdId(param.getProdId());
-            basket.setShopId(param.getShopId());
-            basket.setUserId(userId);
-            basket.setSkuId(param.getSkuId());
-            basket.setDistributionCardNo(param.getDistributionCardNo());
-            basketMapper.insert(basket);
-        }
+        basket.setBasketCount(param.getCount());
+        basket.setBasketDate(new Date());
+        basket.setProdId(param.getProdId());
+        basket.setShopId(param.getShopId());
+        basket.setUserId(userId);
+        basket.setSkuId(param.getSkuId());
+        basket.setDistributionCardNo(param.getDistributionCardNo());
+        basketMapper.insert(basket);
     }
 
     @Override
-    @CacheEvict(cacheNames = "ShopCartItems", key = "#basket.userId")
+//    @CacheEvict(cacheNames = "ShopCartItems", key = "#basket.userId")
     public void updateShopCartItem(Basket basket) {
         basketMapper.updateById(basket);
     }
 
     @Override
-    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
+//    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
     public void deleteAllShopCartItems(String userId) {
         basketMapper.deleteAllShopCartItems(userId);
     }
@@ -140,19 +134,19 @@ public class BasketServiceImpl extends ServiceImpl<BasketMapper, Basket> impleme
     }
 
     @Override
-    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
+//    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
     public void cleanExpiryProdList(String userId) {
         basketMapper.cleanExpiryProdList(userId);
     }
 
     @Override
-    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
+//    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
     public void updateBasketByShopCartParam(String userId, List<ShopCartParam> shopCartParams) {
         basketMapper.updateDiscountItemId(userId, shopCartParams);
     }
 
     @Override
-    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
+//    @CacheEvict(cacheNames = "ShopCartItems", key = "#userId")
     public void removeShopCartItemsCacheByUserId(String userId) {
 
     }

+ 9 - 7
yami-shop-service/src/main/java/com/yami/shop/service/impl/CategoryServiceImpl.java

@@ -267,13 +267,15 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
 
     @Override
     public List<ListCategoryForUserVO> listCategoryForUser(Long shopId) {
-        List<ShopCategory> shopCategories = shopCategoryMapper.selectList(new LambdaQueryWrapper<ShopCategory>()
-                .eq(ShopCategory::getShopId, shopId)
-                .eq(ShopCategory::getIsDelete, Boolean.FALSE)
-                .orderByAsc(ShopCategory::getNum));
-        if (CollectionUtil.isEmpty(shopCategories)) {
-            return Collections.emptyList();
-        }
+
+        List<ShopCategory> shopCategories = shopCategoryMapper.selectAppListAll(shopId);
+//        List<ShopCategory> shopCategories = shopCategoryMapper.selectList(new LambdaQueryWrapper<ShopCategory>()
+//                .eq(ShopCategory::getShopId, shopId)
+//                .eq(ShopCategory::getIsDelete, Boolean.FALSE)
+//                .orderByAsc(ShopCategory::getNum));
+//        if (CollectionUtil.isEmpty(shopCategories)) {
+//            return Collections.emptyList();
+//        }
 
         Map<Long, List<ShopCategory>> parentMap = shopCategories.stream()
                 .collect(Collectors.groupingBy(ShopCategory::getPid));

+ 1 - 1
yami-shop-service/src/main/java/com/yami/shop/service/impl/ChannelProdServiceImpl.java

@@ -325,7 +325,7 @@ public class ChannelProdServiceImpl extends ServiceImpl<ChannelProdMapper, Chann
         // 转换为导出VO
         List<ChannelProdExportVO> exportData = dataList.stream().map(item -> {
             ChannelProdExportVO exportVO = new ChannelProdExportVO();
-            exportVO.setSkuId(String.valueOf(item.getSkuId()));
+            exportVO.setSkuId(item.getSkuId());
             exportVO.setChannelName(item.getChannelName());
             exportVO.setShopName(item.getShopName());
             exportVO.setPurchasePrice(item.getPurchasePrice());

+ 72 - 6
yami-shop-service/src/main/java/com/yami/shop/service/impl/ShopCategoryServiceImpl.java

@@ -1,5 +1,6 @@
 package com.yami.shop.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.event.AnalysisEventListener;
@@ -10,6 +11,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yami.shop.bean.dto.ShopCategoryExcelDTO;
 import com.yami.shop.bean.model.*;
 import com.yami.shop.bean.param.CategoryProductDTO;
+import com.yami.shop.bean.vo.ListCategoryForUserVO;
 import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.R;
 import com.yami.shop.dao.*;
@@ -27,9 +29,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.InputStream;
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -57,9 +57,67 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
     public List<ShopCategory> treeShopCategory(Long shopId, String name) {
         // 获取所有未删除的前台类目
         List<ShopCategory> shopCategories = shopCategoryMapper.selectListAll(shopId, name);
-        // 构建树形结构
-        return shopCategories; // 假设根节点的parentCode为"0"
-//        return buildCategoryTree(shopCategories, "0"); // 假设根节点的parentCode为"0"
+//        // 构建树形结构
+//        return shopCategories; // 假设根节点的parentCode为"0"
+////        return buildCategoryTree(shopCategories, "0"); // 假设根节点的parentCode为"0"
+//    }
+//
+//
+//
+//    @Override
+//    public List<ShopCategory> listCategoryForUser(Long shopId) {
+//        List<ShopCategory> shopCategories = shopCategoryMapper.selectList(new LambdaQueryWrapper<ShopCategory>()
+//                .eq(ShopCategory::getShopId, shopId)
+//                .eq(ShopCategory::getIsDelete, Boolean.FALSE)
+//                .orderByAsc(ShopCategory::getNum));
+//        if (CollectionUtil.isEmpty(shopCategories)) {
+//            return Collections.emptyList();
+//        }
+
+        Map<Long, List<ShopCategory>> parentMap = shopCategories.stream()
+                .collect(Collectors.groupingBy(ShopCategory::getPid));
+
+        // 初始层级为一级分类(grade = 1)
+        return buildCategoryTree(parentMap.getOrDefault(0L, Collections.emptyList()), parentMap, 0);
+    }
+    private List<ShopCategory> buildCategoryTree(List<ShopCategory> categories, Map<Long, List<ShopCategory>> parentMap, int currentLevel) {
+        if (CollectionUtil.isEmpty(categories)) return Collections.emptyList();
+        return categories.stream()
+                .map(category -> {
+                    // 直接使用ShopCategory而不是ListCategoryForUserVO
+                    ShopCategory shopCategory = new ShopCategory();
+                    shopCategory.setId(category.getId());
+                    shopCategory.setName(category.getName());
+                    shopCategory.setNum(category.getNum());
+                    shopCategory.setPid(category.getPid());
+                    shopCategory.setIcon(category.getIcon());
+                    shopCategory.setLevel(currentLevel);
+
+                    // 判断是否为二级或三级分类,并设置level字段(原productBeBound)
+                    int level = 0;
+                    if (currentLevel == 1 || currentLevel == 2) {
+                        // 三级分类直接绑定商品
+                        if (currentLevel == 2) {
+                            level = 1;
+                        }
+                        // 二级分类若无子分类(三级分类),则允许绑定商品
+                        else if (currentLevel == 1) {
+                            List<ShopCategory> children = parentMap.getOrDefault(category.getId(), Collections.emptyList());
+                            level = children.isEmpty() ? 1 : 0;
+                        }
+                    }
+                    shopCategory.setLevel(level);
+
+                    // 递归构建子分类树,层级 +1
+                    List<ShopCategory> children = parentMap.getOrDefault(category.getId(), Collections.emptyList());
+
+                    children.sort(Comparator.comparingInt(ShopCategory::getNum));
+
+                    shopCategory.setChildren(buildCategoryTree(children, parentMap, currentLevel + 1));
+
+                    return shopCategory;
+                })
+                .collect(Collectors.toList());
     }
 
     /**
@@ -167,6 +225,14 @@ public class ShopCategoryServiceImpl extends ServiceImpl<ShopCategoryMapper, Sho
         BeanUtils.copyProperties(page, res);
         List<Category> categories = page.getRecords().stream().map((sc) -> {
             Category category = new Category();
+
+            Integer count = shopCategoryMapper.selectAppCount(sc.getShopId(), sc.getCode());
+            if (count == 0){
+                category.setHasSecond(false);
+            }else {
+                category.setHasSecond(true);
+            }
+
             category.setCategoryId(sc.getId());
             category.setShopId(sc.getShopId());
             category.setParentId(sc.getPid());

+ 1 - 1
yami-shop-service/src/main/resources/mapper/OrderMapper.xml

@@ -236,7 +236,7 @@
   </select>
 
     <update id="cancelOrders">
-        update tz_order set `hb_order_status`=60,cancel_time = NOW(),update_time=NOW(),close_type=4  where order_id in
+        update tz_order set `hb_order_status`=60,close_type = 1, cancel_time = NOW(),update_time=NOW(),close_type=4  where order_id in
         <foreach collection="orders" item="order" open="(" close=")" separator=",">
             #{order.orderId}
         </foreach>

+ 4 - 0
yami-shop-service/src/main/resources/mapper/ProductMapper.xml

@@ -593,6 +593,7 @@
 
     <select id="getSearchProdDtoPageByProdNameNew" resultType="com.yami.shop.bean.dto.SearchProdDto">
         select
+        sum(tss.shop_sku_stocks) as stocks,
         any_value(p.prod_id) as prod_id,
         any_value(p.imgs) as pic,
         any_value(p.prod_name) as prod_name,
@@ -677,6 +678,7 @@
         t1.salesVolume
         FROM (
         SELECT
+        sum(tss.shop_sku_stocks)  AS stocks,
         ANY_VALUE(p.prod_id) AS prod_id,
         ANY_VALUE(p.pic) AS pic,
         ANY_VALUE(p.prod_name) AS prod_name,
@@ -686,6 +688,8 @@
         ANY_VALUE(p.update_time) AS update_time
         FROM
         tz_prod p
+        LEFT JOIN tz_sku sku ON p.prod_id = sku.prod_id
+        left join tz_shop_sku tss on sku.sku_id = tss.sku_id
         LEFT JOIN tz_category_prod cp on p.prod_id = cp.prod_id
         LEFT JOIN tz_shop_category sc on cp.code = sc.code
         WHERE

+ 36 - 2
yami-shop-service/src/main/resources/mapper/ShopCategoryMapper.xml

@@ -13,6 +13,39 @@
     </select>
 
 
+    <select id="selectAppListAll" resultType="com.yami.shop.bean.model.ShopCategory">
+        SELECT fc.*, tl.name as labelName
+        FROM tz_shop_category fc
+        left join tz_category_prod cp on fc.code = cp.code  and cp.is_delete = 0 and cp.shop_id = #{shopId}
+        left join tz_prod p on p.prod_id = cp.prod_id and p.is_delete = 0
+        left join tz_label tl on fc.label = tl.id
+        WHERE fc.is_delete = 0 and fc.is_delete = 0
+        and fc.shop_id = #{shopId}
+        AND (
+        fc.level = 1
+        OR (
+        fc.level != 1
+        AND p.prod_id IS NOT NULL
+        AND cp.prod_id IS NOT NULL
+        )
+        )
+        group by fc.id
+    </select>
+
+    <select id="selectAppCount" resultType="java.lang.Integer">
+        SELECT count(fc.id) as prodCount
+        FROM tz_shop_category fc
+                 left join tz_category_prod cp on fc.code = cp.code  and cp.is_delete = 0 and cp.shop_id = #{shopId}
+                 left join tz_prod p on p.prod_id = cp.prod_id and p.is_delete = 0
+        WHERE fc.is_delete = 0 and fc.is_delete = 0
+          AND p.prod_id IS NOT NULL
+          AND cp.prod_id IS NOT NULL
+          and fc.shop_id = #{shopId}
+          and fc.parent_code = #{code}
+    </select>
+
+
+
     <select id="selectListAll" resultType="com.yami.shop.bean.model.ShopCategory">
         SELECT fc.*, count(cp.id) as prodCount,tl.name as labelName
         FROM tz_shop_category fc
@@ -42,14 +75,14 @@
             ) AND is_delete = 0
             )
 
-            OR fc.level = 1 AND  fc.code IN (
+            OR fc.level = 1 AND fc.code IN (
             SELECT parent_code FROM tz_shop_category
             WHERE name like concat('%',#{name},'%')
             AND level = 2
             AND is_delete = 0
             <if test="shopId">AND shop_id = #{shopId}</if>
             )
-            OR fc.level = 3 AND  fc.parent_code IN (
+            OR fc.level = 3 AND fc.parent_code IN (
             SELECT code FROM tz_shop_category
             WHERE name like concat('%',#{name},'%')
             AND level = 2
@@ -79,6 +112,7 @@
         group by fc.id
     </select>
 
+
     <update id="deleteByCode">
         UPDATE tz_front_category
         SET is_delete = 1