Explorar o código

APP下单时增加会员等级商品规格价格逻辑

FengChaoYu hai 4 semanas
pai
achega
5186816228

+ 5 - 2
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/goods/GoodsBean.java

@@ -1,9 +1,9 @@
 package com.gree.mall.miniapp.bean.goods;
 
-import com.gree.mall.miniapp.plus.entity.*;
 import com.gree.mall.miniapp.plus.entity.CommonFile;
+import com.gree.mall.miniapp.plus.entity.CommonTemplate;
 import com.gree.mall.miniapp.plus.entity.Goods;
-import com.gree.mall.miniapp.plus.entity.GoodsSpec;
+import com.gree.mall.miniapp.plus.entity.PubTemplate;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -50,4 +50,7 @@ public class GoodsBean extends Goods {
     private List<String> tags1;
     private List<String> tags2;
 
+    @ApiModelProperty(value = "商品规格新价格")
+    private BigDecimal goodsSpecNewPrice;
+
 }

+ 3 - 1
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/goods/GoodsNewBean.java

@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 @ApiModel
@@ -20,5 +21,6 @@ public class GoodsNewBean extends Goods {
     @ApiModelProperty("下标签")
     private List<String> tags2;
 
-
+    @ApiModelProperty(value = "商品规格新价格")
+    private BigDecimal goodsSpecNewPrice;
 }

+ 3 - 1
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/goods/GoodsSpecSecBean.java

@@ -4,7 +4,6 @@ import com.gree.mall.miniapp.plus.entity.GoodsSpec;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
 
 import java.math.BigDecimal;
 
@@ -46,4 +45,7 @@ public class GoodsSpecSecBean extends GoodsSpec {
     @ApiModelProperty("是否已记录到货通知")
     private boolean adviceNotice = false;
 
+    @ApiModelProperty(value = "商品规格新价格")
+    private BigDecimal goodsSpecNewPrice;
+
 }

+ 3 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/order/BuyGood.java

@@ -59,6 +59,9 @@ public class BuyGood {
     @JsonIgnore
     private String promotionImgUrl;
 
+    @ApiModelProperty(value = "使用会员等级id")
+    private String useUserLevelId;
+
     @ApiModelProperty(value = "使用会员等级商品规格id")
     private String useUserLevelGoodsId;
 

+ 58 - 3
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/goods/GoodsLogic.java

@@ -73,6 +73,10 @@ public class GoodsLogic {
     GoodsDocumentsRelaService goodsDocumentsRelaService;
     @Resource
     AppMapper appMapper;
+    @Resource
+    UserLevelRelaService userLevelRelaService;
+    @Resource
+    UserLevelGoodsService userLevelGoodsService;
 
     /**
      * 商品列表
@@ -101,7 +105,10 @@ public class GoodsLogic {
             }
         }
 
-        //补充标签
+        // 获取会员等级商品规格
+        Map<String, UserLevelGoods> userLevelGoodsMap = this.queryUserLevelGoodsMap(currentCompanyWechat);
+
+        //补充标签和会员等级商品规格价格
         for (GoodsNewBean goodsNewBean : page.getRecords()) {
             //查询上标签
             List<GoodsTagRela> list1 = goodsTagRelaService.lambdaQuery().eq(GoodsTagRela::getGoodsId, goodsNewBean.getGoodsId())
@@ -119,6 +126,20 @@ public class GoodsLogic {
                 List<String> collect1 = list.stream().map(GoodsTagRela::getGoodsTagName).collect(Collectors.toList());
                 goodsNewBean.setTags2(collect1);
             }
+
+            if (CollectionUtil.isNotEmpty(userLevelGoodsMap)) {
+                final GoodsSpec goodsSpec = goodsSpecService.lambdaQuery()
+                        .select(GoodsSpec::getGoodsSpecId, GoodsSpec::getGoodsCode)
+                        .eq(GoodsSpec::getGoodsId, goodsNewBean.getGoodsId())
+                        .orderByAsc(GoodsSpec::getPrice)
+                        .last("limit 1")
+                        .one();
+
+                if (Objects.nonNull(goodsSpec) && userLevelGoodsMap.containsKey(goodsNewBean.getGoodsId() + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode())) {
+                    final UserLevelGoods userLevelGoods = userLevelGoodsMap.get(goodsNewBean.getGoodsId() + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode());
+                    goodsNewBean.setGoodsSpecNewPrice(userLevelGoods.getGoodsSpecNewPrice());
+                }
+            }
         }
     }
 
@@ -130,7 +151,7 @@ public class GoodsLogic {
 
         User user = userService.getById(userId);
 
-        GoodsBean goodsBean = this.commonDetail(goodsId, user, storageId);
+        GoodsBean goodsBean = this.commonDetail(goodsId, user, storageId, currentCompanyWechat);
 
         //补充标签
         //查询上标签
@@ -177,7 +198,7 @@ public class GoodsLogic {
      * @param goodsId
      * @return
      */
-    public GoodsBean commonDetail(String goodsId, User user, String storageId) throws RemoteServiceException {
+    public GoodsBean commonDetail(String goodsId, User user, String storageId, CurrentCompanyWechat currentCompanyWechat) throws RemoteServiceException {
         Goods goods = goodsService.lambdaQuery()
                 .eq(Goods::getGoodsId, goodsId)
                 .eq(Goods::getDel, false)
@@ -190,6 +211,9 @@ public class GoodsLogic {
 
         //商品规格
         List<GoodsSpecSecBean> goodsSpecs = goodsSpecDetailMapper.querySpecSec(goodsId);
+        // 商品规格按价格排升序
+        goodsSpecs = goodsSpecs.stream().sorted(Comparator.comparing(GoodsSpecSecBean::getPrice)).collect(Collectors.toList());
+
         final List<String> goodsMaterialIds = goodsSpecs.stream().map(GoodsSpecSecBean::getGoodsCode).collect(Collectors.toList());
 
         // 获取规格库存
@@ -206,6 +230,9 @@ public class GoodsLogic {
                 .eq(GoodsFavorite::getUserId, user.getUserId())
                 .count();
 
+        // 获取会员等级商品规格
+        Map<String, UserLevelGoods> userLevelGoodsMap = this.queryUserLevelGoodsMap(currentCompanyWechat);
+        BigDecimal goodsSpecNewPrice = null;
         for (GoodsSpecSecBean goodsSpec : goodsSpecs) {
             final Integer stockQty = goodsMaterialStorageMap.get(goodsSpec.getGoodsCode());
             goodsSpec.setStockNum(Objects.isNull(stockQty) ? 0 : stockQty);
@@ -234,6 +261,14 @@ public class GoodsLogic {
                     }
                 }
             }
+
+            if (CollectionUtil.isNotEmpty(userLevelGoodsMap) && userLevelGoodsMap.containsKey(goodsId + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode())) {
+                final UserLevelGoods userLevelGoods = userLevelGoodsMap.get(goodsId + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode());
+                goodsSpec.setGoodsSpecNewPrice(userLevelGoods.getGoodsSpecNewPrice());
+                if (Objects.isNull(goodsSpecNewPrice)) {
+                    goodsSpecNewPrice = userLevelGoods.getGoodsSpecNewPrice();
+                }
+            }
         }
 
         // 总商品库存
@@ -252,10 +287,30 @@ public class GoodsLogic {
         goodsBean.setStock(goodsStock);
         goodsBean.setCommonTemplate(goodsSpecDetailMapper.queryCommonTemplate(goodsId));
         goodsBean.setPubCommonTemplate(pubTemplateService.getById(goods.getCompanyWechatId()));
+        goodsBean.setGoodsSpecNewPrice(goodsSpecNewPrice);
 
         return goodsBean;
     }
 
+    private Map<String, UserLevelGoods> queryUserLevelGoodsMap(CurrentCompanyWechat currentCompanyWechat) {
+        if (Objects.nonNull(currentCompanyWechat.getUser())) {
+            // 检查是否有会员等级
+            UserLevelRela userLevelRela = userLevelRelaService.lambdaQuery()
+                    .eq(UserLevelRela::getCompanyWechatId, currentCompanyWechat.getCurrentCompanyWechatId())
+                    .eq(UserLevelRela::getUserId, currentCompanyWechat.getUserId())
+                    .one();
+
+            List<UserLevelGoods> userLevelGoodsList = userLevelGoodsService.lambdaQuery()
+                    .eq(UserLevelGoods::getUserLevelId, userLevelRela.getUserLevelId())
+                    .list();
+            if (CollectionUtil.isNotEmpty(userLevelGoodsList)) {
+                return userLevelGoodsList.stream()
+                        .collect(Collectors.toMap(v -> v.getGoodsId() + v.getGoodsSpecId() + v.getGoodsSpecCode(), Function.identity()));
+            }
+        }
+        return null;
+    }
+
     /**
      * 获取商品
      *

+ 20 - 6
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/order/OrderLogic.java

@@ -262,6 +262,7 @@ public class OrderLogic {
 
         //订单详情
         List<OrderDetail> orderDetails = new ArrayList<>();
+        String useUserLevelId = null;
         for (BuyGood buyGood : buyGoods) {
             //商品
             Goods goods = buyGood.getGoods();
@@ -347,13 +348,15 @@ public class OrderLogic {
 
 //            BigDecimal freightAmountItem = Objects.nonNull(userAddress) ? this.getFreightAmountItem(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), buyGood, currentCompanyWechat) : BigDecimal.valueOf(0);
             BigDecimal freightAmountItem = orderInfo.getTakeGoodsType().equals(TakeGoodsTypeEnum.Z.getKey()) ? BigDecimal.valueOf(0) : goodsSpec.getFirstFee();
-            // 如果有会员等级首件运费
-            if (StringUtils.isNotBlank(orderDetail.getUseUserLevelGoodsId())
-                    && orderDetail.getGoodsSpecNewFirstFee().compareTo(BigDecimal.ZERO) >= 0) {
-                freightAmountItem = orderDetail.getGoodsSpecNewFirstFee();
-            }
+
             // 邮寄方式计算次件运费金额
             if (orderInfo.getTakeGoodsType().equals(TakeGoodsTypeEnum.Y.getKey()) && orderDetail.getNum() > 1) {
+                // 如果有会员等级首件运费
+                if (StringUtils.isNotBlank(orderDetail.getUseUserLevelGoodsId())
+                        && orderDetail.getGoodsSpecNewFirstFee().compareTo(BigDecimal.ZERO) >= 0) {
+                    freightAmountItem = orderDetail.getGoodsSpecNewFirstFee();
+                }
+
                 int surplusNum = orderDetail.getNum() - 1;
                 BigDecimal continueFee = goodsSpec.getContinueFee();
                 // 如果有会员等级续件运费
@@ -373,6 +376,16 @@ public class OrderLogic {
             totalFreight = totalFreight.add(freightAmountItem);
             orderTitle.append(goods.getGoodsName()).append(",");
             totalNum += buyGood.getNum();
+
+            // 检查使用会员等级id如果为null就一直遍历到注入有值为止
+            if (StringUtils.isBlank(useUserLevelId)) {
+                useUserLevelId = buyGood.getUseUserLevelId();
+            }
+        }
+
+        // 注入使用的会员等级id
+        if (StringUtils.isNotBlank(useUserLevelId)) {
+            orderInfo.setUseUserLevelId(useUserLevelId);
         }
 
         //实际需要支付的金额(包含运费)
@@ -1203,7 +1216,8 @@ public class OrderLogic {
                 buyGood.setGoodsSpecNewPrice(userLevelGoods.getGoodsSpecNewPrice());
                 buyGood.setGoodsSpecNewFirstFee(userLevelGoods.getGoodsSpecNewFirstFee());
                 buyGood.setGoodsSpecNewContinueFee(userLevelGoods.getGoodsSpecNewContinueFee());
-                buyGood.setUseUserLevelGoodsId(userLevelGoods.getUserLevelId());
+                buyGood.setUseUserLevelGoodsId(userLevelGoods.getId());
+                buyGood.setUseUserLevelId(userLevelGoods.getUserLevelId());
             }
         }
         return buyGoods;

+ 3 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsDocumentsRelaBean.java

@@ -11,6 +11,9 @@ import lombok.EqualsAndHashCode;
 @ApiModel
 public class GoodsDocumentsRelaBean extends GoodsDocumentsRela {
 
+    @ApiModelProperty(value = "文件一级分类id")
+    private String parentCategoryId;
+
     @ApiModelProperty(value = "文件一级分类名称")
     private String parentCategoryName;
 

+ 1 - 0
mall-server-api/src/main/resources/mapper/CommonMapper.xml

@@ -1263,6 +1263,7 @@
             resultType="com.gree.mall.manager.bean.goods.GoodsDocumentsRelaBean">
         SELECT
             a.*,
+            c.category_id AS parent_category_id,
             c.name AS parent_category_name
         FROM
             goods_documents_rela a