Browse Source

供应商-我的商品

chao 4 năm trước cách đây
mục cha
commit
8f051d52f5

+ 5 - 6
src/main/java/com/caimei365/commodity/controller/ProductShopApi.java

@@ -2,9 +2,7 @@ package com.caimei365.commodity.controller;
 
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.search.ProductListVo;
-import com.caimei365.commodity.model.vo.ProductShopVO;
 import com.caimei365.commodity.service.ShopService;
-import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -16,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * Description
@@ -61,10 +60,10 @@ public class ProductShopApi {
         @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
     })
     @GetMapping("/products")
-    public ResponseJson<PageInfo<ProductShopVO>> getShopProducts(Integer shopId, String name, String productCode,
-       Integer validFlag, Integer featuredFlag, Integer typeSort, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId,
-                                             @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
-                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+    public ResponseJson<Map<String, Object>> getShopProducts(Integer shopId, String name, String productCode,
+                                                             Integer validFlag, Integer featuredFlag, Integer typeSort, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId,
+                                                             @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
         return shopService.getShopProducts(shopId, name, productCode, validFlag, featuredFlag, typeSort, bigTypeId, smallTypeId, tinyTypeId, pageNum, pageSize);
     }
 

+ 13 - 3
src/main/java/com/caimei365/commodity/mapper/ShopMapper.java

@@ -1,7 +1,7 @@
 package com.caimei365.commodity.mapper;
 
 import com.caimei365.commodity.model.search.ProductListVo;
-import com.caimei365.commodity.model.vo.ProductShopVO;
+import com.caimei365.commodity.model.vo.ProductItemVo;
 import org.apache.ibatis.annotations.Mapper;
 
 import java.util.List;
@@ -19,10 +19,20 @@ public interface ShopMapper {
      */
     List<ProductListVo> getMainProducts(Integer shopId, List<Integer> visibilityList);
 
+    /**
+     * 主推商品数量
+     */
+    int getMainProductsCount(Integer shopId);
     /**
      * 获取供应商-我的商品列表
      */
-    List<ProductShopVO> getShopProductsSelect(Integer shopId, String name, String productCode, Integer validFlag, Integer featuredFlag, Integer typeSort, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId);
-
+    List<ProductItemVo> getShopProductsSelect(Integer shopId, String name, String productCode, Integer validFlag, Integer featuredFlag, Integer typeSort, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId);
+    /**
+     * 列表显示分类
+     */
     String getTypeName(Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId);
+    /**
+     * 根据供应商Id获取userId
+     */
+    Integer getUserIdByshopId(Integer shopId);
 }

+ 36 - 0
src/main/java/com/caimei365/commodity/model/vo/ProductItemVo.java

@@ -83,4 +83,40 @@ public class ProductItemVo implements Serializable {
     private Integer userIdentity;
     /** 是否启用详聊,1不开启,2开启(开启详聊不展示交易价)*/
     private Integer detailTalkFlag;
+    /**
+     * 内部商品名称
+     */
+    private String aliasName;
+    /**
+     * 市场价
+     */
+    private Double normalPrice;
+    /**
+     * 主图
+     */
+    private String mainImage;
+    /**
+     * 所在分类名称
+     */
+    private String typeName;
+    /**
+     * 供应商主推商品标志 0否 1是
+     */
+    private Integer featuredFlag;
+    /**
+     * 分类类型,1产品,2仪器
+     */
+    private Integer typeSort;
+    /**
+     * 一级分类ID
+     */
+    private Integer bigTypeId;
+    /**
+     * 二级分类Id
+     */
+    private Integer smallTypeId;
+    /**
+     * 三级分类Id
+     */
+    private Integer tinyTypeId;
 }

+ 0 - 72
src/main/java/com/caimei365/commodity/model/vo/ProductShopVO.java

@@ -1,72 +0,0 @@
-package com.caimei365.commodity.model.vo;
-
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * Description
- *
- * @author : Charles
- * @date : 2021/4/19
- */
-@Data
-public class ProductShopVO implements Serializable {
-    private static final long serialVersionUID = 1L;
-    /**
-     * 商品id
-     */
-    private Integer productId;
-    /**
-     * 名称name
-     */
-    private String name;
-    /**
-     * 内部商品名称
-     */
-    private String aliasName;
-    /**
-     * 商品价格
-     */
-    private Double price;
-    /**
-     * 市场价
-     */
-    private Double normalPrice;
-    /**
-     * 主图
-     */
-    private String mainImage;
-    /**
-     * 所在分类名称
-     */
-    private String typeName;
-    /**
-     * 商品状态, 0逻辑删除 1待审核 2已上架 3已下架 8审核未通过 9已隐身 10已冻结
-     */
-    private Integer validFlag;
-    /**
-     * 供应商主推商品标志 0否 1是
-     */
-    private Integer featuredFlag;
-    /** 商品货号 */
-    private String productCode;
-    /** 促销活动 */
-    private PromotionsVo promotions;
-    /**
-     * 分类类型,1产品,2仪器
-     */
-    private Integer typeSort;
-    /**
-     * 一级分类ID
-     */
-    private Integer bigTypeId;
-    /**
-     * 二级分类Id
-     */
-    private Integer smallTypeId;
-    /**
-     * 三级分类Id
-     */
-    private Integer tinyTypeId;
-}

+ 2 - 3
src/main/java/com/caimei365/commodity/service/ShopService.java

@@ -2,10 +2,9 @@ package com.caimei365.commodity.service;
 
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.search.ProductListVo;
-import com.caimei365.commodity.model.vo.ProductShopVO;
-import com.github.pagehelper.PageInfo;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * Description
@@ -39,5 +38,5 @@ public interface ShopService {
      * @param pageSize      每页数量
      * @return PageInfo<ProductShopVO>
      */
-    ResponseJson<PageInfo<ProductShopVO>> getShopProducts(Integer shopId, String name, String productCode, Integer validFlag, Integer featuredFlag, Integer typeSort, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, int pageNum, int pageSize);
+    ResponseJson<Map<String, Object>> getShopProducts(Integer shopId, String name, String productCode, Integer validFlag, Integer featuredFlag, Integer typeSort, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, int pageNum, int pageSize);
 }

+ 19 - 61
src/main/java/com/caimei365/commodity/service/impl/ShopServiceImpl.java

@@ -5,7 +5,7 @@ import com.caimei365.commodity.mapper.ShopMapper;
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.PaginationVo;
-import com.caimei365.commodity.model.vo.ProductShopVO;
+import com.caimei365.commodity.model.vo.ProductItemVo;
 import com.caimei365.commodity.model.vo.PromotionsVo;
 import com.caimei365.commodity.service.ShopService;
 import com.caimei365.commodity.utils.ImageUtils;
@@ -82,72 +82,30 @@ public class ShopServiceImpl implements ShopService {
      * @param tinyTypeId    三级级分类Id
      * @param pageNum      页码
      * @param pageSize     每页数量
-     * @return PageInfo<ProductShopVO>
+     * @return Map<String, Object>
      */
     @Override
-    public ResponseJson<PageInfo<ProductShopVO>> getShopProducts(Integer shopId, String name, String productCode, Integer validFlag, Integer featuredFlag, Integer typeSort, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, int pageNum, int pageSize) {
+    public ResponseJson<Map<String, Object>> getShopProducts(Integer shopId, String name, String productCode, Integer validFlag, Integer featuredFlag, Integer typeSort, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, int pageNum, int pageSize) {
         if (null == shopId) {
             return ResponseJson.error("参数异常:缺少供应商Id", null);
         }
         Map<String, Object> map = new HashMap<>();
         PageHelper.startPage(pageNum, pageSize);
-        List<ProductShopVO> productList = shopMapper.getShopProductsSelect(shopId, name, productCode, validFlag, featuredFlag, typeSort, bigTypeId, smallTypeId, tinyTypeId);
-//        if (null != productList && productList.size() > 0) {
-//            for (ProductShopVO product : productList) {
-//                product.setMainImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
-//                String typeName = shopMapper.getTypeName(product.getBigTypeId(), product.getSmallTypeId(), product.getTinyTypeId());
-//                product.setTypeName(typeName);
-//                //店铺促销
-//                PromotionsVo promotions = promotionsDao.getSupplierPromotionsBySupplierId(product.getShopID());
-//                if (promotions == null) {
-//                    promotions = promotionsDao.getProductPromotionsByProductId(product.getProductID());
-//                }
-//                if (null != promotions) {
-//                    List<CartItem> productGifts = null;
-//                    List<CartItem> promotionsProduct = null;
-//                    if (2 == promotions.getMode()) {
-//                        //满减商品
-//                        promotionsProduct = promotionsDao.findPromotionsProduct(promotions.getId());
-//                    } else if (3 == promotions.getMode()) {
-//                        //满赠商品
-//                        promotionsProduct = promotionsDao.findPromotionsProduct(promotions.getId());
-//                        productGifts = promotionsDao.getProductGifts(promotions.getId());
-//                    }
-//                    //促销商品
-//                    if (null != promotionsProduct && promotionsProduct.size() > 0) {
-//                        promotionsProduct.forEach(p -> {
-//                            if (p != null) {
-//                                p.setImage(ImageUtils.getImageURL("product", p.getImage(), 0, domain));
-//                            }
-//                        });
-//                        promotions.setProductList(promotionsProduct);
-//                    }
-//                    //促销赠品
-//                    if (null != productGifts && productGifts.size() > 0) {
-//                        productGifts.forEach(p -> {
-//                            p.setImage(ImageUtils.getImageURL("product", p.getImage(), 0, domain));
-//                        });
-//                        promotions.setGiftList(productGifts);
-//                    }
-//                    product.setPromotions(promotions);
-//                } else if ("1".equals(product.getLadderPriceFlag())) {
-//                    //启用阶梯价格
-//                    sellerProductService.getLadderPrice(product);
-//                }
-//            }
-//        }
-//        PaginationVo<ProductShopVO> productPage = new PaginationVo<>(productList);
-//        map.put("productPage", productPage);
-//        List<ProductShopVO> mainProduct = supplierDao.findMainProduct(product.getShopID());
-//        //主推商品数量
-//        int featuredNum = 0;
-//        if (null != mainProduct) {
-//            featuredNum = mainProduct.size();
-//        }
-//        map.put("featuredNum", featuredNum);
-//        return ResponseJson.success(map);
-
-        return null;
-
+        List<ProductItemVo> productList = shopMapper.getShopProductsSelect(shopId, name, productCode, validFlag, featuredFlag, typeSort, bigTypeId, smallTypeId, tinyTypeId);
+        if (null != productList && productList.size() > 0) {
+            for (ProductItemVo product : productList) {
+                product.setMainImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
+                String typeName = shopMapper.getTypeName(product.getBigTypeId(), product.getSmallTypeId(), product.getTinyTypeId());
+                product.setTypeName(typeName);
+                // 设置商品价格
+                Integer userId = shopMapper.getUserIdByshopId(shopId);
+                priceUtilService.setItemPriceByUserId(product, userId);
+            }
+        }
+        PaginationVo<ProductItemVo> productPage = new PaginationVo<>(productList);
+        map.put("productPage", productPage);
+        int featuredNum = shopMapper.getMainProductsCount(shopId);
+        map.put("featuredNum", featuredNum);
+        return ResponseJson.success(map);
     }
 }

+ 8 - 1
src/main/resources/mapper/ShopMapper.xml

@@ -20,7 +20,7 @@
         and p.validFlag = 2 and p.featuredFlag=1
         order by p.productID desc limit 4
     </select>
-    <select id="getShopProductsSelect" resultType="com.caimei365.commodity.model.vo.ProductShopVO">
+    <select id="getShopProductsSelect" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
         select
             p.productID as productId, p.name, p.aliasName, p.price, p.normalPrice, p.mainImage,
             p.validFlag, p.featuredFlag, p.productCode, p.bigTypeID as bigTypeId,
@@ -67,4 +67,11 @@
         where
           b.bigTypeID = #{bigTypeId};
     </select>
+    <select id="getUserIdByshopId" resultType="java.lang.Integer">
+        select userID from user where shopID = #{shopId}
+    </select>
+    <select id="getMainProductsCount" resultType="java.lang.Integer">
+        select count(*) from  product where shopID = #{shopId}
+        and validFlag = '2' and featuredFlag='1' order by productID desc
+    </select>
 </mapper>