luodangjia
2025-01-17 b0cc9bd3619e69fa4c8bbdedebb56435cfd74a8f
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 || (null != goodsSeckill.getCashPayment() && null != goodsSeckill.getPointPayment())) || type == 1){
      if((null == goodsSeckill || (null == goodsSeckill.getCashPayment() && null == goodsSeckill.getPointPayment())) || type == 1){
         //没有秒杀价,则判断门店特价
         GetGoodsBargainPrice goodsBargainPrice = new GetGoodsBargainPrice();
         goodsBargainPrice.setGoodsId(goodsId);
@@ -329,6 +330,29 @@
   @Override
   public Long addGoods(ShoppingCart shoppingCart) {
      Long userid = tokenService.getLoginUserApplet().getUserid();
      long goodsSaleNum = orderService.getGoodsSaleNum(shoppingCart.getGoodsId(), null, userid);
      long count = count(new LambdaQueryWrapper<ShoppingCart>()
            .eq(ShoppingCart::getGoodsId, shoppingCart.getGoodsId())
            .eq(ShoppingCart::getStatus,1)
            .eq(ShoppingCart::getAppUserId, userid));
      goodsSaleNum += count;
      Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData();
      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)
            .eq(ShoppingCart::getGoodsId, shoppingCart.getGoodsId()).eq(ShoppingCart::getType, shoppingCart.getType()).eq(ShoppingCart::getStatus, 1));
      if(null != one){
@@ -351,15 +375,18 @@
    */
   @Override
   public R setGoodsNumber(SetGoodsNumber setGoodsNumber) {
      ShoppingCart shoppingCart = this.getById(setGoodsNumber.getId());
      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()
               && setGoodsNumber.getNumber() >= shoppingCart.getNumber()){
            return R.fail("修改数量不能大于限购数量");
         }
@@ -1183,7 +1210,7 @@
               totalDistributionAmount = totalDistributionAmount.subtract(paymentMoney1);
               balance = balance.subtract(paymentMoney1);
               appUser.setTotalRedPacketAmount(totalRedPacketAmount);
               appUser.setTotalDistributionAmount(totalDistributionAmount);
//               appUser.setTotalDistributionAmount(totalDistributionAmount);
               appUser.setBalance(balance);
               distributionAmount = paymentMoney1;
            }else{
@@ -1191,7 +1218,7 @@
               totalDistributionAmount = BigDecimal.ZERO;
               balance = balance.subtract(paymentMoney1);
               appUser.setTotalRedPacketAmount(totalRedPacketAmount);
               appUser.setTotalDistributionAmount(totalDistributionAmount);
//               appUser.setTotalDistributionAmount(totalDistributionAmount);
               appUser.setBalance(balance);
               distributionAmount = totalDistributionAmount;
            }
@@ -1340,7 +1367,7 @@
                     totalDistributionAmount = totalDistributionAmount.subtract(expressFee1);
                     balance = balance.subtract(expressFee1);
                     appUser.setTotalRedPacketAmount(totalRedPacketAmount);
                     appUser.setTotalDistributionAmount(totalDistributionAmount);
//                     appUser.setTotalDistributionAmount(totalDistributionAmount);
                     appUser.setBalance(balance);
                     distributionAmount = expressFee1;
                  }else{
@@ -1348,7 +1375,7 @@
                     totalDistributionAmount = BigDecimal.ZERO;
                     balance = balance.subtract(expressFee1);
                     appUser.setTotalRedPacketAmount(totalRedPacketAmount);
                     appUser.setTotalDistributionAmount(totalDistributionAmount);
//                     appUser.setTotalDistributionAmount(totalDistributionAmount);
                     appUser.setBalance(balance);
                     distributionAmount = totalDistributionAmount;
                  }