Browse Source

sku相关

zhijiezhao 2 years ago
parent
commit
e4cd37fbf2

+ 7 - 0
src/main/java/com/caimei365/commodity/components/PriceUtilService.java

@@ -134,6 +134,7 @@ public class PriceUtilService {
             }
             //给一个默认的最低价和最低起订量
             price.setPrice(skus.get(0).getPrice());
+            price.setSkuId(skus.get(0).getSkuId());
             price.setMinBuyNumber(skus.get(0).getMinBuyNumber());
             skus.forEach(s -> {
                 // 设置划线价
@@ -264,12 +265,18 @@ public class PriceUtilService {
         //设置展示的默认最低价和展示最低价的规格
         if (lowPrice.get()) {
             ProductItemVo showProduct = priceMapper.findLowPrice(product.getProductId());
+            product.setSkuId(showProduct.getSkuId());
             product.setPrice(showProduct.getPrice());
             product.setUnit(showProduct.getUnit());
+            product.setMinBuyNumber(showProduct.getMinBuyNumber());
+            product.setPriceGrade(getPriceGrade(showProduct.getPrice()));
         } else {
             List<Sku> collect = skus.stream().sorted(Comparator.comparing(Sku::getPrice)).collect(Collectors.toList());
+            product.setSkuId(collect.get(0).getSkuId());
             product.setPrice(collect.get(0).getPrice());
             product.setUnit(collect.get(0).getUnit());
+            product.setMinBuyNumber(collect.get(0).getMinBuyNumber());
+            product.setPriceGrade(getPriceGrade(collect.get(0).getPrice()));
         }
         product.setSkus(skus);
         // 数据库获取基本价格信息

+ 4 - 0
src/main/java/com/caimei365/commodity/model/vo/PriceVo.java

@@ -18,6 +18,10 @@ public class PriceVo implements Serializable {
     private static final long serialVersionUID = 1L;
 
     private List<Sku> skus;
+    /**
+     * 展示的sku的skuId
+     */
+    private Integer skuId;
     /**
      * 展示的阶梯价格标识 0否 1是
      */

+ 4 - 1
src/main/java/com/caimei365/commodity/model/vo/ProductDetailVo.java

@@ -23,7 +23,10 @@ import java.util.List;
 @Data
 public class ProductDetailVo implements Serializable {
     private static final long serialVersionUID = 1L;
-
+    /**
+     * 展示的sku的skuId
+     */
+    private Integer skuId;
     /**
      * skus
      */

+ 11 - 3
src/main/java/com/caimei365/commodity/model/vo/ProductItemVo.java

@@ -17,7 +17,15 @@ import java.util.List;
 public class ProductItemVo implements Serializable {
     private static final long serialVersionUID = 1L;
     /**
-     * 再次购买的skuId
+     * 展示的sku的价格等级
+     */
+    private Integer priceGrade;
+    /**
+     * 组合商品列表默认的起订量
+     */
+    private Integer minBuyNumber;
+    /**
+     * 展示的sku的skuId
      */
     private Integer skuId;
     /**
@@ -41,11 +49,11 @@ public class ProductItemVo implements Serializable {
      */
     private Integer id;
     /**
-     * 展示的最低价的规格(再次购买的unit)
+     * 展示的最低价的规格
      */
     private String unit;
     /**
-     * 默认的最低价(再次购买的价格)
+     * 展示的最低价
      */
     private Double price;
     /**

+ 2 - 0
src/main/java/com/caimei365/commodity/service/impl/PageServiceImpl.java

@@ -648,6 +648,7 @@ public class PageServiceImpl implements PageService {
             //设置展示的默认最低价
             if (lowPrice.get()) {
                 ProductItemVo showProduct = priceMapper.findLowPrice(productId);
+                product.setSkuId(showProduct.getSkuId());
                 product.setPrice(showProduct.getPrice());
                 product.setUnit(showProduct.getUnit());
                 product.setLadderPriceFlag(1);
@@ -656,6 +657,7 @@ public class PageServiceImpl implements PageService {
                 List<Sku> collect = skus.stream().sorted(Comparator.comparing(Sku::getPrice)).collect(Collectors.toList());
                 product.setPrice(collect.get(0).getPrice());
                 product.setUnit(collect.get(0).getUnit());
+                product.setSkuId(collect.get(0).getSkuId());
             }
             //查询商品收藏情况,1未收藏,0未收藏,未收藏过该商品用户是null
             Integer like = likeMapper.findLike(userId, productId);

+ 8 - 10
src/main/java/com/caimei365/commodity/service/impl/SellerServiceImpl.java

@@ -18,6 +18,7 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * Description
@@ -108,18 +109,8 @@ public class SellerServiceImpl implements SellerService {
         PaginationVo<ProductItemVo> productItemVoPaginationVo = new PaginationVo<>(productList);
         if (combinationId != null) {
             List<Integer> productIdList = sellerMapper.findProductList(combinationId);
-            List<Integer> p = new ArrayList<>();
-            p.add(productId);
-            List<ProductItemVo> pd = sellerMapper.getProductList(p);
-            ProductItemVo productItemVo = new ProductItemVo();
-            if (pd != null && pd.size() > 0) {
-                productItemVo = pd.get(0);
-            }
             PageHelper.startPage(pageNum, pageSize);
             productList = sellerMapper.getProductList(productIdList);
-            //本商品设置首位
-            productList.remove(productItemVo);
-            productList.add(0, productItemVo);
             Integer userIdentity = shopMapper.getUserIdentityById(userId);
             // 如果非会员身份剔除会员可见商品
             if (userIdentity != null) {
@@ -127,13 +118,20 @@ public class SellerServiceImpl implements SellerService {
                     productList.removeIf(c -> "1".equals(c.getVisibility()));
                 }
             }
+            AtomicReference<ProductItemVo> item = new AtomicReference<>(new ProductItemVo());
             productList.forEach(product -> {
                 // 设置商品主图及价格
                 priceUtilService.setProductDetails(userId, product);
                 //优惠券标识
                 Boolean couponsLogo = pageService.setCouponsLogo(userId, product.getProductId(), source);
                 product.setCouponsLogo(couponsLogo);
+                if (productId.equals(product.getProductId())) {
+                    item.set(product);
+                }
             });
+            //本商品设置首位
+            productList.removeIf(productItemVo -> productItemVo.getProductId().equals(productId));
+            productList.add(0, item.get());
             productItemVoPaginationVo = new PaginationVo<>(productList);
         }
         return ResponseJson.success(productItemVoPaginationVo);

+ 3 - 3
src/main/resources/mapper/PriceMapper.xml

@@ -166,7 +166,7 @@
                price,
                normalPrice,
                costPrice,
-               ifnull(ladderPriceFlag,0) as ladderPriceFlag,
+               ifnull(ladderPriceFlag, 0) as ladderPriceFlag,
                costCheckFlag,
                costProportional,
                stock,
@@ -177,9 +177,9 @@
         ORDER BY price ASC
     </select>
     <select id="findLowPrice" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
-        select plp.buyPrice,cs.unit
+        select plp.buyPrice as price, cs.unit as unit, cs.minBuyNumber as minBuyNumber, cs.skuId as skuId
         from product_ladder_price plp
-        left join cm_sku cs on plp.skuId=cs.skuId
+                 left join cm_sku cs on plp.skuId = cs.skuId
         where plp.productId = #{productId}
         order by buyPrice asc
         limit 1