From c27c1f2beb4ca89a94eaa854fce6b4553db8f2f8 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期三, 15 一月 2025 19:58:12 +0800
Subject: [PATCH] 修改

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java
index 5d46a3e..22aae80 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java
+++ b/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);
@@ -209,10 +210,10 @@
 				area.setVip(appUser.getVipId());
 				area.setGoodsId(goodsId);
 				GoodsArea goodsArea = goodsAreaClient.getGoodsArea(area).getData();
-				if(null == goodsArea || (null != goodsArea.getCashPayment() && null != goodsArea.getPointPayment())){
+				if(null == goodsArea || (null == goodsArea.getCashPayment() && null == goodsArea.getPointPayment())){
 					//没有地区价格,则使用会员价格
 					GoodsVip goodsVip = goodsVipClient.getGoodsVip(goodsId, appUser.getVipId()).getData();
-					if(null == goodsVip || (null != goodsVip.getCashPayment() && null != goodsVip.getPointPayment())){
+					if(null == goodsVip || (null == goodsVip.getCashPayment() && null == goodsVip.getPointPayment())){
 						//没有配置价格,直接使用原始基础价格
 						return null;
 					}else{
@@ -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){
@@ -424,8 +430,8 @@
 		}else{
 			int sum = 0;
 			for (MyShoppingCartVo myShoppingCartVo : goodsList) {
-				sum += (myShoppingCartVo.getPoint() * myShoppingCartVo.getNumber());
-				myShoppingCartVo.setEarnSpendingPoints(myShoppingCartVo.getEarnSpendingPoints() * myShoppingCartVo.getNumber());
+				sum += ((null != myShoppingCartVo.getPoint() ? myShoppingCartVo.getPoint() : 0) * myShoppingCartVo.getNumber());
+				myShoppingCartVo.setEarnSpendingPoints((null != myShoppingCartVo.getEarnSpendingPoints() ? myShoppingCartVo.getEarnSpendingPoints() : 0) * myShoppingCartVo.getNumber());
 			}
 			confirmOrderVo.setOrderPoint(sum);
 		}
@@ -723,7 +729,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()){

--
Gitblit v1.7.1