Pu Zhibing
2025-01-20 41af6f7c9dbd59d945946c805c3f29eeaa8bb261
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java
@@ -337,7 +337,20 @@
            .eq(ShoppingCart::getAppUserId, userid));
      goodsSaleNum += count;
      Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
      if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && (goodsSaleNum + shoppingCart.getNumber()) > goods.getPurchaseLimit()){
      Integer maxNum = 0;
      if(shoppingCart.getType() == 2){
         R<SeckillActivityInfo> r = seckillActivityInfoClient.getSeckillActivityInfoByGoodsId(shoppingCart.getGoodsId());
         if (R.isError(r)){
            throw new ServiceException("获取秒杀商品失败!");
         }
         SeckillActivityInfo seckillActivityInfo = r.getData();
         maxNum = seckillActivityInfo.getMaxNum();
      }else {
         maxNum = goods.getPurchaseLimit();
      }
      if(null != goods.getPurchaseLimit() && -1 != maxNum && (goodsSaleNum + shoppingCart.getNumber()) > maxNum){
         throw new ServiceException("超出购买数量限制");
      }
      ShoppingCart one = this.getOne(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid)
@@ -371,7 +384,9 @@
      if(null != shoppingCart){
         Goods goods1 = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
         if(null != goods1.getPurchaseLimit() && -1 != goods1.getPurchaseLimit() && goods1.getPurchaseLimit() < setGoodsNumber.getNumber()){
         if(null != goods1.getPurchaseLimit() && -1 != goods1.getPurchaseLimit()
               && goods1.getPurchaseLimit() < setGoodsNumber.getNumber()
               && setGoodsNumber.getNumber() >= shoppingCart.getNumber()){
            return R.fail("修改数量不能大于限购数量");
         }