Преглед изворни кода

APP下单增加会员等级商品逻辑

FengChaoYu пре 1 месец
родитељ
комит
cdf400120e

+ 12 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/goods/AckGoodsBean.java

@@ -34,5 +34,17 @@ public class AckGoodsBean extends Goods {
     @ApiModelProperty("团购活动id")
     private String promotionGroupId;
 
+    @ApiModelProperty(value = "使用会员等级商品规格id")
+    private String useUserLevelGoodsId;
+
+    @ApiModelProperty(value = "商品规格新价格")
+    private BigDecimal goodsSpecNewPrice;
+
+    @ApiModelProperty(value = "商品规格新首件运费")
+    private BigDecimal goodsSpecNewFirstFee;
+
+    @ApiModelProperty(value = "商品规格新续件运费")
+    private BigDecimal goodsSpecNewContinueFee;
+
 
 }

+ 10 - 1
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/order/BuyGood.java

@@ -2,7 +2,6 @@ package com.gree.mall.miniapp.bean.order;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.gree.mall.miniapp.bean.goods.GoodsBean;
-import com.gree.mall.miniapp.plus.entity.Goods;
 import com.gree.mall.miniapp.plus.entity.GoodsSpec;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -60,5 +59,15 @@ public class BuyGood {
     @JsonIgnore
     private String promotionImgUrl;
 
+    @ApiModelProperty(value = "使用会员等级商品规格id")
+    private String useUserLevelGoodsId;
 
+    @ApiModelProperty(value = "商品规格新价格")
+    private BigDecimal goodsSpecNewPrice;
+
+    @ApiModelProperty(value = "商品规格新首件运费")
+    private BigDecimal goodsSpecNewFirstFee;
+
+    @ApiModelProperty(value = "商品规格新续件运费")
+    private BigDecimal goodsSpecNewContinueFee;
 }

+ 82 - 7
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/order/OrderLogic.java

@@ -1,6 +1,5 @@
 package com.gree.mall.miniapp.logic.order;
 
-import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -15,7 +14,8 @@ import com.gree.mall.miniapp.bean.goods.GoodsMaterialStockDTO;
 import com.gree.mall.miniapp.bean.order.*;
 import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
 import com.gree.mall.miniapp.bean.workorder.PgOrderSettleNormBean;
-import com.gree.mall.miniapp.commonmapper.*;
+import com.gree.mall.miniapp.commonmapper.AppMapper;
+import com.gree.mall.miniapp.commonmapper.CategoryMapper;
 import com.gree.mall.miniapp.constant.Constant;
 import com.gree.mall.miniapp.enums.*;
 import com.gree.mall.miniapp.enums.base.BaseEnum;
@@ -162,6 +162,10 @@ public class OrderLogic {
     UserCompanyCreditLogic userCompanyCreditLogic;
     @Resource
     NoticeLogic noticeLogic;
+    @Resource
+    UserLevelRelaService userLevelRelaService;
+    @Resource
+    UserLevelGoodsService userLevelGoodsService;
 
     /**
      * 立即购买
@@ -286,6 +290,14 @@ public class OrderLogic {
             OrderDetail orderDetail = new OrderDetail();
 
             orderDetail.setPayAmount(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
+            orderDetail.setTotalPrice(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
+
+            // 如果会员等级商品规格价格大于0
+            if (StringUtils.isNotBlank(buyGood.getUseUserLevelGoodsId())
+                    && buyGood.getGoodsSpecNewPrice().compareTo(BigDecimal.ZERO) > 0) {
+                orderDetail.setPayAmount(buyGood.getGoodsSpecNewPrice().multiply(new BigDecimal(buyGood.getNum())));
+                orderDetail.setTotalPrice(buyGood.getGoodsSpecNewPrice().multiply(new BigDecimal(buyGood.getNum())));
+            }
 
             orderDetail.setOrderId(orderId);
             orderDetail.setGoodsId(goodsId);
@@ -308,7 +320,6 @@ public class OrderLogic {
             }
             orderDetail.setPrice(goodsSecPrice);
             orderDetail.setNum(buyGood.getNum());
-            orderDetail.setTotalPrice(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
             orderDetail.setImgUrl(goodsSpec.getImgUrl());
             orderDetail.setCreateTime(curDate);
             orderDetail.setIsVr(goods.getIsVr());
@@ -329,13 +340,28 @@ public class OrderLogic {
             orderDetail.setSmallNumber(goodsSpec.getSmallId());
             orderDetail.setSmallName(goodsSpec.getSmallName());
             orderDetail.setFlag(1);
+            orderDetail.setUseUserLevelGoodsId(buyGood.getUseUserLevelGoodsId());
+            orderDetail.setGoodsSpecNewPrice(buyGood.getGoodsSpecNewPrice());
+            orderDetail.setGoodsSpecNewFirstFee(buyGood.getGoodsSpecNewFirstFee());
+            orderDetail.setGoodsSpecNewContinueFee(buyGood.getGoodsSpecNewContinueFee());
 
 //            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) {
                 int surplusNum = orderDetail.getNum() - 1;
-                BigDecimal continueAmountItem = new BigDecimal(surplusNum).multiply(goodsSpec.getContinueFee());
+                BigDecimal continueFee = goodsSpec.getContinueFee();
+                // 如果有会员等级续件运费
+                if (StringUtils.isNotBlank(orderDetail.getUseUserLevelGoodsId())
+                        && orderDetail.getGoodsSpecNewContinueFee().compareTo(BigDecimal.ZERO) >= 0) {
+                    continueFee = orderDetail.getGoodsSpecNewContinueFee();
+                }
+                BigDecimal continueAmountItem = new BigDecimal(surplusNum).multiply(continueFee);
                 freightAmountItem = freightAmountItem.add(continueAmountItem);
             }
             orderDetail.setFreight(freightAmountItem);
@@ -1019,10 +1045,10 @@ public class OrderLogic {
      * 确认订单内容
      */
     public OrderAckBean ackOrder2(OrderBuyBean orderBuyBean, HttpServletRequest request) throws RemoteServiceException, InterruptedException {
-
         //购买人
         String userId = CommonUtils.getUserId(request);
         User user = userService.getById(userId);
+
         //总的商品金额
         BigDecimal totalAmount = new BigDecimal(0);
         //总的商品数量
@@ -1066,12 +1092,28 @@ public class OrderLogic {
             ackGoodsBean.setOrgPrice(goods.getOrgGoodsPrice());
             ackGoodsBean.setSecKillId(buyGood.getSecKillId());
             ackGoodsBean.setPromotionGroupId(buyGood.getPromotionGroupId());
+            ackGoodsBean.setUseUserLevelGoodsId(buyGood.getUseUserLevelGoodsId());
+            ackGoodsBean.setGoodsSpecNewPrice(buyGood.getGoodsSpecNewPrice());
+            ackGoodsBean.setGoodsSpecNewFirstFee(buyGood.getGoodsSpecNewFirstFee());
+            ackGoodsBean.setGoodsSpecNewContinueFee(buyGood.getGoodsSpecNewContinueFee());
 
             BigDecimal freightAmountItem = goodsSpec.getFirstFee();
+            // 如果有会员等级首件运费
+            if (StringUtils.isNotBlank(ackGoodsBean.getUseUserLevelGoodsId())
+                    && ackGoodsBean.getGoodsSpecNewFirstFee().compareTo(BigDecimal.ZERO) >= 0) {
+                freightAmountItem = ackGoodsBean.getGoodsSpecNewFirstFee();
+            }
             // 邮寄方式计算次件运费金额
             if (buyGood.getNum() > 1) {
                 int surplusNum = buyGood.getNum() - 1;
-                BigDecimal continueAmountItem = new BigDecimal(surplusNum).multiply(goodsSpec.getContinueFee());
+                BigDecimal continueFee = goodsSpec.getContinueFee();
+                // 如果有会员等级续件运费
+                if (StringUtils.isNotBlank(ackGoodsBean.getUseUserLevelGoodsId())
+                        && ackGoodsBean.getGoodsSpecNewContinueFee().compareTo(BigDecimal.ZERO) >= 0) {
+                    continueFee = ackGoodsBean.getGoodsSpecNewContinueFee();
+                }
+
+                BigDecimal continueAmountItem = new BigDecimal(surplusNum).multiply(continueFee);
                 freightAmountItem = freightAmountItem.add(continueAmountItem);
             }
             totalFreight = totalFreight.add(freightAmountItem);
@@ -1114,9 +1156,28 @@ public class OrderLogic {
      * @param user
      * @return
      */
-    public List<BuyGood> supplyBuyBoods(OrderBuyBean orderBuyBean,User user) throws InterruptedException {
+    public List<BuyGood> supplyBuyBoods(OrderBuyBean orderBuyBean,User user) {
+        final CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
         List<BuyGood> buyGoods = orderBuyBean.getBuyGoods();
 
+        // 检查是否有会员等级
+        final UserLevelRela userLevelRela = userLevelRelaService.lambdaQuery()
+                .eq(UserLevelRela::getCompanyWechatId, currentCompanyWechat.getCurrentCompanyWechatId())
+                .eq(UserLevelRela::getUserId, user.getUserId())
+                .one();
+
+        // 获取会员等级商品规格
+        Map<String, UserLevelGoods> userLevelGoodsMap = null;
+        if (Objects.nonNull(userLevelRela)) {
+            List<UserLevelGoods> userLevelGoodsList = userLevelGoodsService.lambdaQuery()
+                    .eq(UserLevelGoods::getUserLevelId, userLevelRela.getUserLevelId())
+                    .list();
+            if (CollectionUtil.isNotEmpty(userLevelGoodsList)) {
+                userLevelGoodsMap = userLevelGoodsList.stream()
+                        .collect(Collectors.toMap(v -> v.getGoodsId() + v.getGoodsSpecId() + v.getGoodsSpecCode(), Function.identity()));
+            }
+        }
+
         for(BuyGood buyGood : buyGoods){
             Goods goods = goodsLogic.getGoodsById(buyGood.getGoodsId());
             final GoodsDetail goodsDetail = goodsLogic.getGoodsDetailById(buyGood.getGoodsId());
@@ -1124,6 +1185,7 @@ public class OrderLogic {
             if (goods == null || goodsSpec == null) {
                 throw new RemoteServiceException("商品不存在,请重新添加");
             }
+
             GoodsBean goodsBean = new GoodsBean();
             BeanUtils.copyProperties(goods, goodsBean);
             goodsBean.setImgUrl(goodsDetail.getImgUrl());
@@ -1134,12 +1196,25 @@ public class OrderLogic {
             buyGood.setGoodsSpec(goodsSpec);
             buyGood.setOrgPrice(goodsSpec.getOrgPrice());
             buyGood.setPrice(goodsSpec.getPrice());
+            // 检查是否有会员等级商品规格
+            if (CollectionUtil.isNotEmpty(userLevelGoodsMap)
+                    && userLevelGoodsMap.containsKey(goods.getGoodsId() + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode())) {
+                final UserLevelGoods userLevelGoods = userLevelGoodsMap.get(goods.getGoodsId() + goodsSpec.getGoodsSpecId() + goodsSpec.getGoodsCode());
+                buyGood.setGoodsSpecNewPrice(userLevelGoods.getGoodsSpecNewPrice());
+                buyGood.setGoodsSpecNewFirstFee(userLevelGoods.getGoodsSpecNewFirstFee());
+                buyGood.setGoodsSpecNewContinueFee(userLevelGoods.getGoodsSpecNewContinueFee());
+                buyGood.setUseUserLevelGoodsId(userLevelGoods.getUserLevelId());
+            }
         }
         return buyGoods;
     }
 
     //获取商品小计金额
     private BigDecimal getChildTotalPrice(AckGoodsBean ackGoodsBean){
+        if (StringUtils.isNotBlank(ackGoodsBean.getUseUserLevelGoodsId())
+                && ackGoodsBean.getGoodsSpecNewPrice().compareTo(BigDecimal.ZERO) > 0) {
+            return ackGoodsBean.getGoodsSpecNewPrice().multiply(new BigDecimal(ackGoodsBean.getNum()));
+        }
         return  ackGoodsBean.getPrice().multiply(new BigDecimal(ackGoodsBean.getNum()));
     }
 

+ 32 - 11
mall-server-api/src/main/java/com/gree/mall/manager/logic/user/UserLevelLogic.java

@@ -1,5 +1,6 @@
 package com.gree.mall.manager.logic.user;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -11,14 +12,8 @@ import com.gree.mall.manager.commonmapper.CommonMapper;
 import com.gree.mall.manager.commonmapper.UserLevelCMapper;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.logic.common.CommonLogic;
-import com.gree.mall.manager.plus.entity.User;
-import com.gree.mall.manager.plus.entity.UserLevel;
-import com.gree.mall.manager.plus.entity.UserLevelGoods;
-import com.gree.mall.manager.plus.entity.UserLevelRela;
-import com.gree.mall.manager.plus.service.UserLevelGoodsService;
-import com.gree.mall.manager.plus.service.UserLevelRelaService;
-import com.gree.mall.manager.plus.service.UserLevelService;
-import com.gree.mall.manager.plus.service.UserService;
+import com.gree.mall.manager.plus.entity.*;
+import com.gree.mall.manager.plus.service.*;
 import com.gree.mall.manager.zfire.bean.ZfireParamBean;
 import com.gree.mall.manager.zfire.util.FieldUtils;
 import lombok.RequiredArgsConstructor;
@@ -46,6 +41,8 @@ public class UserLevelLogic {
     private final UserLevelGoodsService userLevelGoodsService;
     private final UserService userService;
     private final UserLevelCMapper userLevelCMapper;
+    private final UserLevelRelaBakService userLevelRelaBakService;
+    private final UserLevelGoodsBakService userLevelGoodsBakService;
 
     public IPage<UserLevelVO> page(ZfireParamBean zfireParamBean) {
         AdminUserCom adminUser = commonLogic.getAdminUser();
@@ -91,6 +88,11 @@ public class UserLevelLogic {
                 .count() > 0) {
             throw new RemoteServiceException("请清空商品关系后再删除等级");
         }
+        if (userLevelRelaService.lambdaQuery()
+                .eq(UserLevelRela::getUserLevelId, id)
+                .count() > 0) {
+            throw new RemoteServiceException("请清空会员关系后再删除等级");
+        }
         userLevelService.removeById(id);
     }
 
@@ -155,6 +157,15 @@ public class UserLevelLogic {
             throw new RemoteServiceException("会员等级信息不存在");
         }
 
+        final List<UserLevelRela> oldRelaList = userLevelRelaService.lambdaQuery()
+                .eq(UserLevelRela::getUserLevelId, userLevel.getId())
+                .list();
+
+        if (CollectionUtil.isNotEmpty(oldRelaList)) {
+            final List<UserLevelRelaBak> bakList = BeanUtil.copyToList(oldRelaList, UserLevelRelaBak.class);
+            userLevelRelaBakService.saveBatch(bakList);
+        }
+
         // 先清空会员关系
         userLevelRelaService.lambdaUpdate()
                 .eq(UserLevelRela::getUserLevelId, userLevel.getId())
@@ -171,7 +182,8 @@ public class UserLevelLogic {
                     final User user = userService.getById(userLevelRela.getUserId());
                     throw new RemoteServiceException(user.getNickName() + "已在" + existUserLevel.getLevelName() +  "建立关系");
                 }
-                rela.setCompanyWechatId(level.getCompanyWechatId())
+                rela.setId(null)
+                        .setCompanyWechatId(level.getCompanyWechatId())
                         .setUserId(userLevelRela.getUserId())
                         .setUserLevelId(userLevel.getId());
 
@@ -195,7 +207,15 @@ public class UserLevelLogic {
             throw new RemoteServiceException("无添加商品规格关系权限");
         }
 
-        // 先清空会员关系
+        final List<UserLevelGoods> oldGoodsList = userLevelGoodsService.lambdaQuery()
+                .eq(UserLevelGoods::getUserLevelId, userLevel.getId())
+                .list();
+
+        if (CollectionUtil.isNotEmpty(oldGoodsList)) {
+            final List<UserLevelGoodsBak> bakList = BeanUtil.copyToList(oldGoodsList, UserLevelGoodsBak.class);
+            userLevelGoodsBakService.saveBatch(bakList);
+        }
+        // 先清空商品规格关系
         userLevelGoodsService.lambdaUpdate()
                 .eq(UserLevelGoods::getUserLevelId, userLevel.getId())
                 .remove();
@@ -236,7 +256,8 @@ public class UserLevelLogic {
                 if (userLevelGoods.getGoodsSpecNewContinueFee().compareTo(BigDecimal.ZERO) < 0) {
                     throw new RemoteServiceException("第" + index + "行, 商品规格新续件运费不能少于0");
                 }
-                userLevelGoods.setUserLevelId(userLevel.getId());
+                userLevelGoods.setId(null)
+                        .setUserLevelId(userLevel.getId());
                 index++;
             }