zoujiajian 3 роки тому
батько
коміт
e8f0d97752

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/exchange/impl/ExchangeCodeServiceImpl.java

@@ -345,9 +345,11 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 
 	private void setRelation(Long relationId, Long userId) {
 		if (redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId) != null) {
+			log.info("=====>用户:{}获取了已有人座位:{}", userId, relationId);
 			throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
 		} else {
 			if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
+				log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
 				throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
 			}
 			GroupsRelation relation = groupsRelationMapper.selectById(relationId);

+ 44 - 29
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -83,10 +83,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 
 import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
 import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
@@ -1016,41 +1013,55 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			//清出车队,车位变为已过期
 			Long relationId = orderDon.getRelationId();
 			//更换车票前后的座位id集合
-			List<Long> relationIds = List.of(orderDon.getRelationId());
+			List<Long> relationIds = new ArrayList<>();
+			relationIds.add(relationId);
 			Integer months = sku.getMonths();
 			Integer num = orderDon.getNum();
 			DateTime now = DateTime.now();
-			GroupsRelation relation = groupsRelationMapper.selectById(relationId);
+			GroupsRelation relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
+					.eq(GroupsRelation::getUserId, orderDon.getUserId())
+					.eq(GroupsRelation::getId, relationId)
+					.eq(GroupsRelation::getStatus, GroupsRelation.Status.validity));
 			//车票变更之后
 			if (relation == null || orderDon.getIsChangeTicket()) {
 				UserRenewChangeTicketRecord record = userRenewChangeTicketRecordMapper.selectOne(Wrappers.lambdaQuery(UserRenewChangeTicketRecord.class)
-						.eq(UserRenewChangeTicketRecord::getRenewOrderId, orderDon.getId()).last("limit 1"));
+						.eq(UserRenewChangeTicketRecord::getUserId, orderDon.getUserId())
+						.eq(UserRenewChangeTicketRecord::getPreRelationId, relationId)
+						.orderByDesc(UserRenewChangeTicketRecord::getId).last("limit 1"));
 				if (record != null && relationId.equals(record.getPreRelationId())) {
 					relation = groupsRelationMapper.selectById(record.getAfterRelationId());
-					relationIds.add(relation.getId());
-				}
-			}
-			Boolean isFlag = true;
-			if (orderDon.getOrderType() == 2) {
-				//是否有其他付款订单是否过期
-				OrderDon otherOrder = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
-						.eq(OrderDon::getRelationId, relationIds)
-						.eq(OrderDon::getUserId, orderDon.getUserId())
-						.ne(OrderDon::getId, orderDon.getId())
-						.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-						.orderByDesc(OrderDon::getId)
-						.last("limit 1"));
-				if (otherOrder != null) {
-					Long otherSkuId = otherOrder.getSkuId();
-					GoodsDonSku otherGoodsSku = goodsDonSkuMapper.selectById(otherSkuId);
-					DateTime endTime = DateUtil.offsetMonth(otherOrder.getCreatedTime(), otherGoodsSku.getMonths() * num);
-					if (now.isBefore(endTime)) {
-						isFlag = false;
-					}
+					Optional.ofNullable(relation).ifPresent((re) -> relationIds.add(re.getId()));
 				}
 			}
 			if (relation != null) {
+				Boolean isFlag = true;
 				Date expiryTime = relation.getExpiryTime();
+				if (orderDon.getOrderType() == 2 || relationIds.size() > 1) {
+					//是否有其他付款订单是否过期
+					OrderDon otherOrder = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+							.in(OrderDon::getRelationId, relationIds)
+							.eq(OrderDon::getUserId, orderDon.getUserId())
+							.ne(OrderDon::getId, orderDon.getId())
+							.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+							.orderByDesc(OrderDon::getId)
+							.last("limit 1"));
+					if (otherOrder != null) {
+						Long otherSkuId = otherOrder.getSkuId();
+						GoodsDonSku otherGoodsSku = goodsDonSkuMapper.selectById(otherSkuId);
+						DateTime endTime = DateUtil.offsetMonth(otherOrder.getCreatedTime(), otherGoodsSku.getMonths() * num);
+						if (now.isBefore(endTime)) {
+							isFlag = false;
+						}
+					} else {
+						//续费更换后的座位 过期时间
+						if (expiryTime != null) {
+							DateTime refundExpiryTime = DateUtil.offsetMonth(expiryTime, -sku.getMonths() * num);
+							if (now.isBefore(refundExpiryTime)) {
+								isFlag = false;
+							}
+						}
+					}
+				}
 				if (isFlag) {
 					relation.setUserId(0l);
 					relation.setStatus(GroupsRelation.Status.none);
@@ -1061,7 +1072,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 						relation.setRenewStatus(false);
 						relation.setAccount(null);
 						groupsRelationMapper.updateExpiryTime(relation, expiryTime);
-					}else {
+					} else {
 						groupsRelationMapper.updateById(relation);
 					}
 					delRelation(relation.getId());
@@ -1223,9 +1234,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		}
 
 		if (redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId) != null) {
+			log.info("=====>用户:{}获取了已有人座位:{}", userId, relationId);
 			throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
 		} else {
-			redisService.set(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L);
+			if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
+				log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
+				throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
+			}
 			GroupsRelation relation = groupsRelationMapper.selectById(relationId);
 			int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
 			if (count == 0) {