From 9a3055a717c98a27a193e566a8febda4a1dd2413 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 15 一月 2025 20:08:04 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/ShoppingCartServiceImpl.java |  117 ++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 72 insertions(+), 45 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 d96c6e6..64920fb 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;
@@ -144,8 +145,31 @@
 		//查询符合商品类型的商品数据
 		List<ShoppingCart> list = this.list(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid)
 				.in(ShoppingCart::getGoodsId, goodsIds).eq(ShoppingCart::getStatus, 1));
+		//删除过期的秒杀活动商品
+		List<ShoppingCart> list1 = new ArrayList<>();
+		for (ShoppingCart shoppingCart : list) {
+			if(shoppingCart.getType() == 2){
+				GetSeckillActivityInfo info = new GetSeckillActivityInfo();
+				info.setGoodsId(shoppingCart.getGoodsId());
+				info.setVip(appUser.getVipId());
+				GoodsSeckill data1 = seckillActivityInfoClient.getSeckillActivityInfo(info).getData();
+				if(null != data1){
+					SeckillActivityInfo seckillActivityInfo = seckillActivityInfoClient.getSeckillActivityInfoById(data1.getSeckillActivityInfoId()).getData();
+					if(null != seckillActivityInfo && (seckillActivityInfo.getIsShelves() == 1 &&
+							seckillActivityInfo.getStartTime().isBefore(LocalDateTime.now()) && seckillActivityInfo.getEndTime().isAfter(LocalDateTime.now()))){
+						
+						list1.add(shoppingCart);
+						continue;
+					}
+				}
+				this.removeById(shoppingCart.getId());
+			}else{
+				list1.add(shoppingCart);
+			}
+		}
+		
 		//构建返回数据
-		List<MyShoppingCartVo> page = buildDetail(appUser, shopId, list, null);
+		List<MyShoppingCartVo> page = buildDetail(appUser, shopId, list1, null);
 		return page;
 	}
 
@@ -167,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);
@@ -186,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());
@@ -213,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());
@@ -281,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());
@@ -306,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){
@@ -328,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("修改数量不能大于限购数量");
 			}
 
@@ -395,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);
 		}
@@ -509,7 +547,7 @@
 		confirmOrderVo.setDiscountAmount(activityAmount);
 		int earnPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getEarnSpendingPoints).sum();
 		confirmOrderVo.setEarnPoint(earnPoint);
-		if(BigDecimal.ZERO.compareTo(paymentMoney) > 0){
+		if(null != paymentMoney && BigDecimal.ZERO.compareTo(paymentMoney) > 0){
 			paymentMoney = BigDecimal.ZERO;
 		}
 
@@ -520,6 +558,7 @@
 		UserAddress userAddress = userAddressClient.getDefaultUserAddress(userid).getData();
 		if(null != userAddress){
 			userAddress.setIdStr(userAddress.getId().toString());
+			userAddress.setRecieveAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getRecieveAddress());
 			confirmOrderVo.setUserAddress(userAddress);
 		}
 		confirmOrderVo.setPaymentType(confirmOrder.getPaymentType());
@@ -545,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);
 							}
 						}
@@ -697,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()){
@@ -938,7 +977,7 @@
 		order.setGoodName(goodName.substring(0, goodName.length() - 1));
 		Goods goods = goodsClient.getGoodsById(goodsList.get(0).getGoodsId()).getData();
 		order.setOrderType(goods.getType());
-		order.setOrderStatus(goods.getType() == 1 ? 3 : 1);
+		order.setOrderStatus(goods.getType() == 1 ? 3 : (shoppingCartPayment.getDistributionMode() == 2 ? 1 : 2));
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
 		order.setOrderNumber("QJS" + getNumber(3) + sdf.format(new Date()));
 		order.setTotalAmount(orderMoney.setScale(2, RoundingMode.HALF_EVEN));
@@ -960,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));
@@ -971,6 +1010,7 @@
 		order.setDelFlag(0);
 		order.setCreateTime(LocalDateTime.now());
 		order.setExpressPayMethod(shoppingCartPayment.getFreightPaymentType());
+		order.setDistributionMode(shoppingCartPayment.getDistributionMode());
 
 		if(2 == shoppingCartPayment.getPaymentType()){
 			BigDecimal balance = appUser.getBalance();
@@ -980,7 +1020,7 @@
 		}
 		if(3 == shoppingCartPayment.getPaymentType()){
 			Integer availablePoint = appUser.getAvailablePoint();
-			if(availablePoint < orderPoint){
+			if(availablePoint.compareTo(orderPoint) < 0){
 				return R.fail("账户可用积分不足");
 			}
 		}
@@ -1123,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();
@@ -1215,6 +1251,7 @@
 			//构建余额明细变动记录
 			BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
 			balanceChangeRecord.setAppUserId(appUser.getId());
+			balanceChangeRecord.setVipId(appUser.getVipId());
 			balanceChangeRecord.setOrderId(order.getId());
 			balanceChangeRecord.setChangeType(5);
 			balanceChangeRecord.setBeforeAmount(balance.add(paymentMoney));
@@ -1239,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()){
@@ -1338,6 +1371,7 @@
 					//构建余额明细变动记录
 					BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
 					balanceChangeRecord.setAppUserId(appUser.getId());
+					balanceChangeRecord.setVipId(appUser.getVipId());
 					balanceChangeRecord.setOrderId(order.getId());
 					balanceChangeRecord.setChangeType(5);
 					balanceChangeRecord.setBeforeAmount(balance.add(expressFee));
@@ -1365,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));
-			}
+			
 		}
 
 		//添加账户余额支付明细
@@ -1465,17 +1492,17 @@
 				userCouponClient.editUserCoupon(userCoupon);
 			}
 		}
-		//添加查询快递信息队列
-		if(StringUtils.isNotEmpty(order.getExpressJson())){
-			//一小时后定时查询快递信息
-			redisTemplate.opsForZSet().add("order_express", order.getId(), LocalDateTime.now().plusHours(1).toEpochSecond(ZoneOffset.UTC));
-		}
 
 		//删除购物车数据
-		Long userid = tokenService.getLoginUserApplet().getUserid();
+		Long userid = order.getAppUserId();
 		List<OrderGood> list = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().eq(OrderGood::getOrderId, order.getId()));
 		List<Integer> goodsIds = list.stream().map(OrderGood::getGoodsId).collect(Collectors.toList());
 		this.remove(new LambdaQueryWrapper<ShoppingCart>().eq(ShoppingCart::getAppUserId, userid).in(ShoppingCart::getGoodsId, goodsIds));
+
+		//商品销量增加
+		for (Integer goodsId : goodsIds) {
+			goodsClient.editGoodsNum(goodsId, 1);
+		}
 		return R.ok();
 	}
 	

--
Gitblit v1.7.1