Forráskód Böngészése

fix 特定价格展示

zoujiajian 3 éve
szülő
commit
fd22838c96

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/GoodsDon.java

@@ -178,6 +178,11 @@ public class GoodsDon extends BaseEntity {
     @DbIgnore
     private Integer accountCount;
 
+    /**
+     * 是否是特定价格 规格平台
+     */
+    private Boolean isSp;
+
     @AllArgsConstructor
     @Getter
     public enum SpecialType {

+ 1 - 4
netflix-dao/src/main/java/com/cyksj/model/views/GoodsFrontListView.java

@@ -101,12 +101,9 @@ public class GoodsFrontListView {
 	@JsonIgnore
 	private Integer virtualSold;
 
-	@DbField("g.specific_price")
+	@DbIgnore
 	private BigDecimal specificPrice;
 
-	@DbField("g.specific_goods_ids")
-	private String specificGoodsIds;
-
 	@DbField("g.pay_desc")
 	private String payDesc;
 

+ 11 - 0
netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsGoodsDonServiceImpl.java

@@ -1,5 +1,6 @@
 package com.cyksj.service.mange.goods;
 
+import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cyksj.mapper.GoodsDonMapper;
@@ -11,6 +12,7 @@ import com.ejlchina.searcher.BeanSearcher;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Optional;
 
@@ -34,7 +36,16 @@ public class CmsGoodsDonServiceImpl extends ServiceImpl<GoodsDonMapper, GoodsDon
 				.eq(GoodsDonSku::getGoodsId, goodsId)
 				.eq(GoodsDonSku::getStatus, true)
 				.orderByAsc(GoodsDonSku::getPrice));
+		//是否有特定价格规格
+		if (goods.getIsSp() && CollUtil.isEmpty(skuViews)) {
+			goods.setIsSp(false);
+			goodsDonMapper.updateById(goods);
+		}
 		if (!skuViews.isEmpty()) {
+			//是否有特定价格规格
+			Optional<GoodsDonSku> specificSkuAny = skuViews.stream().filter(sku -> sku.getSpecificPrice().compareTo(BigDecimal.ZERO) > 0).findAny();
+			goods.setIsSp(specificSkuAny.isPresent() ? true : false);
+
 			GoodsDonSku min = skuViews.get(0);
 			goods.setMinPrice(min.getPrice());
 			if (min.getDays() == null) {

+ 55 - 99
netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java

@@ -172,24 +172,8 @@ public class GoodsDonController {
             try {
                 List<GoodsFrontListView> list = Jsons.parseObject(value, List.class);
                 if (CollUtil.isNotEmpty(list)) {
-                    if (fUid != null) {
-                        list.forEach(data -> {
-                            data.getSkuList().forEach(sku -> {
-                                String specificGoodsIdsStr = sku.getSpecificGoodsIds();
-                                if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
-                                    BigDecimal specificPrice = data.getSpecificPrice();
-                                    BigDecimal skuSpecificPrice = sku.getSpecificPrice();
-                                    if (specificPrice == null) {
-                                        data.setSpecificPrice(skuSpecificPrice);
-                                        data.setMonths(sku.getMonths());
-                                    } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
-                                        data.setSpecificPrice(skuSpecificPrice);
-                                        data.setMonths(sku.getMonths());
-                                    }
-                                }
-                            });
-                        });
-                    }
+                    //设置特定价格
+                    setSpecificPrice(list, fUid);
                     return GatewayResponse.SUCCESS.newBuilder().toResult(list);
                 }
             } catch (Exception e) {
@@ -209,20 +193,6 @@ public class GoodsDonController {
                     List<GoodsDiscountPlusPurchaseRelationFrontView> dpSkuViews = beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelationFrontView.class, MapUtils.builder().field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId()).build());
                     sku.setDpSkuViews(dpSkuViews);
                 }
-                if (fUid != null) {
-                    String specificGoodsIdsStr = sku.getSpecificGoodsIds();
-                    if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
-                        BigDecimal specificPrice = data.getSpecificPrice();
-                        BigDecimal skuSpecificPrice = sku.getSpecificPrice();
-                        if (specificPrice == null) {
-                            data.setSpecificPrice(skuSpecificPrice);
-                            data.setMonths(sku.getMonths());
-                        } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
-                            data.setSpecificPrice(skuSpecificPrice);
-                            data.setMonths(sku.getMonths());
-                        }
-                    }
-                }
             });
             Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
                     .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
@@ -236,6 +206,8 @@ public class GoodsDonController {
             data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
         });
         redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
+        //设置特定价格
+        setSpecificPrice(list, fUid);
         return GatewayResponse.SUCCESS.newBuilder().toResult(list);
     }
 
@@ -259,45 +231,8 @@ public class GoodsDonController {
             try {
                 List<GoodsFrontListView> list = Jsons.parseObject(value, List.class);
                 if (CollUtil.isNotEmpty(list)) {
-                    if (fUid != null) {
-                        list.forEach(data -> {
-                            if (data.getIsSp()) {
-                                //查找所有特定规格最小价格 满足条件
-                                String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId();
-                                Object speciObj = redisService.get(specificGoodsKey);
-                                List<GoodsDonSku> specificSkus = null;
-                                if (speciObj != null) {
-                                    specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
-                                } else {
-                                    specificSkus = goodsDonSkuMapper.selectList(
-                                            Wrappers.lambdaQuery(GoodsDonSku.class)
-                                                    .eq(GoodsDonSku::getGoodsId, data.getId())
-                                                    .eq(GoodsDonSku::getStatus, true)
-                                                    .gt(GoodsDonSku::getSpecificPrice, 0));
-                                    redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
-                                }
-                                specificSkus.forEach(specificSku -> {
-                                    String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
-                                    if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
-                                        BigDecimal specificPrice = data.getSpecificPrice();
-                                        BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
-                                        if (specificPrice == null) {
-                                            data.setSpecificPrice(skuSpecificPrice);
-                                            data.setMonths(specificSku.getMonths());
-                                        } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
-                                            data.setSpecificPrice(skuSpecificPrice);
-                                            data.setMonths(specificSku.getMonths());
-                                        }
-                                    }
-                                });
-                            }
-                            String specificGoodsIdsStr = data.getSpecificGoodsIds();
-                            if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
-                                data.setSpecificGoodsIds(null);
-                                data.setSpecificPrice(null);
-                            }
-                        });
-                    }
+                    //设置特定价格
+                    setSpecificPrice(list, fUid);
                     return GatewayResponse.SUCCESS.newBuilder().toResult(list);
                 }
             } catch (Exception e) {
@@ -314,16 +249,10 @@ public class GoodsDonController {
                     .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
             data.setSold(sold + data.getVirtualSold());
             data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
-
-            if (fUid != null) {
-                String specificGoodsIdsStr = data.getSpecificGoodsIds();
-                if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
-                    data.setSpecificGoodsIds(null);
-                    data.setSpecificPrice(null);
-                }
-            }
         });
         redisService.setNx(h5CacheKey, dataList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
+        //设置特定价格
+        setSpecificPrice(dataList, fUid);
         return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
     }
 
@@ -385,7 +314,7 @@ public class GoodsDonController {
      * 获取商品推荐平台
      */
     @GetMapping("/get/recommend/{id}")
-    public Result<List<GoodsRecommendViews>> getRecommendGoodsByGid(@PathVariable Long id, Boolean isLogin) throws Exception {
+    public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id, Boolean isLogin) throws Exception {
         String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id;
         Object value = redisService.get(key);
         Long userId = null;
@@ -394,16 +323,8 @@ public class GoodsDonController {
         }
         final Long fUid = userId;
         if (value != null) {
-            List<GoodsRecommendViews> goodsRecommendViews = Jsons.parseList(value.toString(), GoodsRecommendViews.class);
-            if (fUid != null) {
-                goodsRecommendViews.forEach(data -> {
-                    String specificGoodsIdsStr = data.getSpecificGoodsIds();
-                    if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
-                        data.setSpecificGoodsIds(null);
-                        data.setSpecificPrice(null);
-                    }
-                });
-            }
+            List<GoodsFrontListView> goodsRecommendViews = Jsons.parseList(value.toString(), GoodsFrontListView.class);
+            setSpecificPrice(goodsRecommendViews, fUid);
             return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
         }
         if (value == null) {
@@ -414,20 +335,15 @@ public class GoodsDonController {
                     .build());
             if (goodsDon != null && StrUtil.isNotEmpty(goodsDon.getRecommendGoods())) {
                 List<Long> recommend_gidList = Jsons.parseList(goodsDon.getRecommendGoods(), Long.class);
-                List<GoodsRecommendViews> goodsRecommendViews = beanSearcher.searchAll(GoodsRecommendViews.class, MapUtils.builder().field(GoodsRecommendViews::getGoodsId, recommend_gidList).op(Operator.InList).build());
+                List<GoodsFrontListView> goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, MapUtils.builder().field(GoodsRecommendViews::getGoodsId, recommend_gidList).op(Operator.InList).build());
                 goodsRecommendViews.forEach(data -> {
                     Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
-                            .eq(RegisterOrderDon::getGoodsId, data.getGoodsId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
+                            .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
                     data.setSold(sold + data.getVirtualSold());
-                    if (fUid != null) {
-                        String specificGoodsIdsStr = data.getSpecificGoodsIds();
-                        if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
-                            data.setSpecificGoodsIds(null);
-                            data.setSpecificPrice(null);
-                        }
-                    }
                 });
                 redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l);
+                //设置特定价格
+                setSpecificPrice(goodsRecommendViews, fUid);
                 return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
             }
         }
@@ -550,4 +466,44 @@ public class GoodsDonController {
         }
         return false;
     }
+
+    /**
+     * 设置平台 特定价格
+     */
+    public void setSpecificPrice(List<GoodsFrontListView> list, Long fUid) {
+        if (fUid != null) {
+            list.forEach(data -> {
+                if (data.getIsSp()) {
+                    //查找所有特定规格最小价格 满足条件
+                    String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId();
+                    Object speciObj = redisService.get(specificGoodsKey);
+                    List<GoodsDonSku> specificSkus = null;
+                    if (speciObj != null) {
+                        specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
+                    } else {
+                        specificSkus = goodsDonSkuMapper.selectList(
+                                Wrappers.lambdaQuery(GoodsDonSku.class)
+                                        .eq(GoodsDonSku::getGoodsId, data.getId())
+                                        .eq(GoodsDonSku::getStatus, true)
+                                        .gt(GoodsDonSku::getSpecificPrice, 0));
+                        redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
+                    }
+                    specificSkus.forEach(specificSku -> {
+                        String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
+                        if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
+                            BigDecimal specificPrice = data.getSpecificPrice();
+                            BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
+                            if (specificPrice == null) {
+                                data.setSpecificPrice(skuSpecificPrice);
+                                data.setMonths(specificSku.getMonths());
+                            } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
+                                data.setSpecificPrice(skuSpecificPrice);
+                                data.setMonths(specificSku.getMonths());
+                            }
+                        }
+                    });
+                }
+            });
+        }
+    }
 }