puzhibing
2025-01-15 9a3055a717c98a27a193e566a8febda4a1dd2413
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java
@@ -11,6 +11,7 @@
import com.ruoyi.account.api.vo.PaymentUserCoupon;
import com.ruoyi.account.api.vo.PaymentUserCouponVo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.mapper.ShoppingCartMapper;
@@ -190,7 +191,7 @@
      info.setVip(appUser.getVipId());
      GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(info).getData();
      //没有秒杀活动或者添加的普通商品则不使用秒杀活动价格
      if(null == goodsSeckill || type == 1){
      if((null == goodsSeckill || (null == goodsSeckill.getCashPayment() && null == goodsSeckill.getPointPayment())) || type == 1){
         //没有秒杀价,则判断门店特价
         GetGoodsBargainPrice goodsBargainPrice = new GetGoodsBargainPrice();
         goodsBargainPrice.setGoodsId(goodsId);
@@ -209,17 +210,17 @@
            area.setVip(appUser.getVipId());
            area.setGoodsId(goodsId);
            GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData();
            if(null == goodsArea){
            if(null == goodsArea || (null == goodsArea.getCashPayment() && null == goodsArea.getPointPayment())){
               //没有地区价格,则使用会员价格
               GoodsVip goodsVip = goodsVipClient.getGoodsVip(goodsId, appUser.getVipId()).getData();
               if(null == goodsVip){
               if(null == goodsVip || (null == goodsVip.getCashPayment() && null == goodsVip.getPointPayment())){
                  //没有配置价格,直接使用原始基础价格
                  return null;
               }else{
                  price.setCash(goodsVip.getSellingPrice());
                  price.setPoint(goodsVip.getIntegral());
                  price.setCashPayment(goodsVip.getCashPayment() == 1);
                  price.setPointPayment(goodsVip.getPointPayment() == 1);
                  price.setCashPayment(null != goodsVip.getCashPayment() && goodsVip.getCashPayment() == 1);
                  price.setPointPayment(null != goodsVip.getPointPayment() && goodsVip.getPointPayment() == 1);
                  price.setEarnSpendingPoints(goodsVip.getEarnSpendingPoints());
                  price.setSuperiorSubcommission(goodsVip.getSuperiorSubcommission());
                  price.setSuperiorRebatePoints(goodsVip.getSuperiorRebatePoints());
@@ -236,8 +237,8 @@
            }else{
               price.setCash(goodsArea.getSellingPrice());
               price.setPoint(goodsArea.getIntegral());
               price.setCashPayment(goodsArea.getCashPayment() == 1);
               price.setPointPayment(goodsArea.getPointPayment() == 1);
               price.setCashPayment(null !=goodsArea.getCashPayment() && goodsArea.getCashPayment() == 1);
               price.setPointPayment(null !=goodsArea.getPointPayment() && goodsArea.getPointPayment() == 1);
               price.setEarnSpendingPoints(goodsArea.getEarnSpendingPoints());
               price.setSuperiorSubcommission(goodsArea.getSuperiorSubcommission());
               price.setSuperiorRebatePoints(goodsArea.getSuperiorRebatePoints());
@@ -304,8 +305,8 @@
         if(goodsSeckill.getCashPayment() == 0 && goodsSeckill.getPointPayment() == 1){
            price.setPoint(goodsSeckill.getIntegral());
         }
         price.setCashPayment(goodsSeckill.getCashPayment() == 1);
         price.setPointPayment(goodsSeckill.getPointPayment() == 1);
         price.setCashPayment(null != goodsSeckill.getCashPayment() && goodsSeckill.getCashPayment() == 1);
         price.setPointPayment(null != goodsSeckill.getPointPayment() && goodsSeckill.getPointPayment() == 1);
         price.setEndTime(goodsSeckill.getEndTime());
         price.setEarnSpendingPoints(goodsSeckill.getEarnSpendingPoints());
         price.setSuperiorSubcommission(goodsSeckill.getSuperiorSubcommission());
@@ -329,6 +330,11 @@
   @Override
   public Long addGoods(ShoppingCart shoppingCart) {
      Long userid = tokenService.getLoginUserApplet().getUserid();
      Integer goodsSaleNum = orderService.getGoodsSaleNum(shoppingCart.getGoodsId(), null, userid);
      Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
      if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && (goodsSaleNum + shoppingCart.getNumber()) > goods.getPurchaseLimit()){
         throw new ServiceException("超出购买数量限制");
      }
      ShoppingCart one = this.getOne(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid)
            .eq(ShoppingCart::getGoodsId, shoppingCart.getGoodsId()).eq(ShoppingCart::getType, shoppingCart.getType()).eq(ShoppingCart::getStatus, 1));
      if(null != one){
@@ -351,15 +357,22 @@
    */
   @Override
   public R setGoodsNumber(SetGoodsNumber setGoodsNumber) {
      Long userid = tokenService.getLoginUserApplet().getUserid();
      ShoppingCart shoppingCart = this.getById(setGoodsNumber.getId());
      Integer goodsSaleNum = orderService.getGoodsSaleNum(shoppingCart.getGoodsId(), null, userid);
      Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
      if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && (goodsSaleNum + shoppingCart.getNumber()) > goods.getPurchaseLimit()){
         throw new ServiceException("超出购买数量限制");
      }
      if(0 >= setGoodsNumber.getNumber()){
         return R.fail("修改数量不能小于等于0");
      }
      ShoppingCart shoppingCart = this.getById(setGoodsNumber.getId());
      if(null != shoppingCart){
         Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
         if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && goods.getPurchaseLimit() < setGoodsNumber.getNumber()){
         Goods goods1 = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
         if(null != goods1.getPurchaseLimit() && -1 != goods1.getPurchaseLimit() && goods1.getPurchaseLimit() < setGoodsNumber.getNumber()){
            return R.fail("修改数量不能大于限购数量");
         }
@@ -418,12 +431,14 @@
         BigDecimal bigDecimal = BigDecimal.ZERO;
         for (MyShoppingCartVo myShoppingCartVo : goodsList) {
            bigDecimal = bigDecimal.add(myShoppingCartVo.getCash().multiply(new BigDecimal(myShoppingCartVo.getNumber())));
            myShoppingCartVo.setEarnSpendingPoints(myShoppingCartVo.getEarnSpendingPoints() * myShoppingCartVo.getNumber());
         }
         confirmOrderVo.setOrderMoney(bigDecimal);
      }else{
         int sum = 0;
         for (MyShoppingCartVo myShoppingCartVo : goodsList) {
            sum += (myShoppingCartVo.getPoint() * myShoppingCartVo.getNumber());
            sum += ((null != myShoppingCartVo.getPoint() ? myShoppingCartVo.getPoint() : 0) * myShoppingCartVo.getNumber());
            myShoppingCartVo.setEarnSpendingPoints((null != myShoppingCartVo.getEarnSpendingPoints() ? myShoppingCartVo.getEarnSpendingPoints() : 0) * myShoppingCartVo.getNumber());
         }
         confirmOrderVo.setOrderPoint(sum);
      }
@@ -569,11 +584,11 @@
                  }
               }else{
                  //部分商品适用
                  BigDecimal goodsMoney = BigDecimal.ZERO;
                   BigDecimal goodsMoney = BigDecimal.ZERO;
                  for (MyShoppingCartVo myShoppingCartVo : goodsList) {
                     Integer goodsId = myShoppingCartVo.getGoodsId();
                     BigDecimal cash = myShoppingCartVo.getCash();
                     if(forGoodIds.contains(goodsId)){
                     if(forGoodIds.contains(String.valueOf(goodsId))){
                        goodsMoney = goodsMoney.add(cash);
                     }
                  }
@@ -721,7 +736,7 @@
         num += num1;
         ShoppingCart shoppingCart = this.getById(id);
         //判断当前数量是否已经超出限购数量(需要计算已经购买的数量)
         Integer goodsSaleNum = orderService.getGoodsSaleNum(shoppingCart.getGoodsId(), type);
         Integer goodsSaleNum = orderService.getGoodsSaleNum(shoppingCart.getGoodsId(), type, userid);
         Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
         if(1 == type){
            if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && (goodsSaleNum + num1) > goods.getPurchaseLimit()){
@@ -984,7 +999,7 @@
      if(null != orderActivityInfo1){
         order.setActivityJson(JSON.toJSONString(orderActivityInfo1));
      }
      if(null != shoppingCartPayment.getUserAddressId()){
      if(2 == shoppingCartPayment.getDistributionMode()){
         UserAddress address = userAddressClient.getUserAddressById(shoppingCartPayment.getUserAddressId()).getData();
         order.setExpressAmount(expressFee);
         order.setAddressJson(JSON.toJSONString(address));
@@ -1005,7 +1020,7 @@
      }
      if(3 == shoppingCartPayment.getPaymentType()){
         Integer availablePoint = appUser.getAvailablePoint();
         if(availablePoint < orderPoint){
         if(availablePoint.compareTo(orderPoint) < 0){
            return R.fail("账户可用积分不足");
         }
      }
@@ -1148,11 +1163,7 @@
                  userCouponClient.editUserCoupon(userCoupon);
               }
            }
            //添加查询快递信息队列
            if(StringUtils.isNotEmpty(order.getExpressJson())){
               //一小时后定时查询快递信息
               redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC));
            }
            //删除购物车数据
            userid = tokenService.getLoginUserApplet().getUserid();
@@ -1265,11 +1276,7 @@
               userCouponClient.editUserCoupon(userCoupon);
            }
         }
         //添加查询快递信息队列
         if(StringUtils.isNotEmpty(order.getExpressJson())){
            //一小时后定时查询快递信息
            redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC));
         }
      }
      //积分支付
      if(3 == shoppingCartPayment.getPaymentType()){
@@ -1392,14 +1399,7 @@
            //删除购物车数据
            this.removeBatchByIds(ids);
         }
         //添加查询快递信息队列
         if(StringUtils.isNotEmpty(order.getExpressJson())){
            //一小时后定时查询快递信息
            SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
            JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
            Integer waitTime = jsonObject.getInteger("waitTime");
            redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(waitTime).toEpochSecond(ZoneOffset.UTC));
         }
      }
      //添加账户余额支付明细
@@ -1491,11 +1491,6 @@
            userCoupon.setUseTime(LocalDateTime.now());
            userCouponClient.editUserCoupon(userCoupon);
         }
      }
      //添加查询快递信息队列
      if(StringUtils.isNotEmpty(order.getExpressJson())){
         //一小时后定时查询快递信息
         redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC));
      }
      //删除购物车数据