zoujiajian пре 3 година
родитељ
комит
8c27959634

+ 15 - 5
netflix-service/src/main/java/com/cyksj/service/exchange/impl/ExchangeCodeServiceImpl.java

@@ -288,11 +288,12 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 	@Override
 	public GroupsRelation getRelationNoOrder(GoodsDonSku sku, Long userId) {
 		GroupsRelation relation = null;
-		relation = getFinalRelation(sku, userId, relation);
+		Integer retryNum = 1;
+		relation = getFinalRelation(sku, userId, relation, retryNum);
 		return relation;
 	}
 
-	public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, GroupsRelation relation) {
+	public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, GroupsRelation relation, Integer retryNum) {
 		//寻找差不多过期时间规格的车位
 		relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths());
 		if (relation == null) {
@@ -328,9 +329,16 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 			relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
 			groupsRelationMapper.updateById(relation);
 		} catch (Exception e) {
+			Object value = redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
+			if (value != null && userId.equals(Long.parseLong(value.toString()))) {
+				redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
+			}
+			if (retryNum == 10) {
+				log.error("用户:{}获取车票:{}异常", userId, relation.getId());
+				throw BusinessRuntimeException.getInstance("获取车票异常,请联系客服");
+			}
 			//失败重新给他分配车位
-			getFinalRelation(sku, userId, relation);
-			redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
+			getFinalRelation(sku, userId, relation, ++retryNum);
 		}
 		return relation;
 	}
@@ -339,7 +347,9 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 		if (redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId) != null) {
 			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)) {
+				throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
+			}
 			GroupsRelation relation = groupsRelationMapper.selectById(relationId);
 			int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
 			if (count == 0) {

+ 16 - 1
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -615,6 +615,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		if (relationId == null || relationId <= 0 || renewSkuId == null || payRequest.getNum() == null) {
 			throw new BusinessRuntimeException("缺少必填参数");
 		}
+		//是否有其他规格的续费订单 若有请先关闭
+		Integer count = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
+				.eq(OrderDon::getRelationId, payRequest.getRelationId())
+				.eq(OrderDon::getStatus, OrderDon.Status.noPayment).eq(OrderDon::getOrderType, 2));
+		if (count > 0) {
+			throw BusinessRuntimeException.getInstance("您有该车票未支付的续费订单..");
+		}
 
 		GoodsDonSku sku = goodsDonSkuMapper.selectById(renewSkuId);
 
@@ -1027,6 +1034,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			}
 			if (relation != null) {
 				Date expiryTime = relation.getExpiryTime();
+
+				if (orderDon.getIsChangeTicket()) {
+					UserRenewChangeTicketRecord record = userRenewChangeTicketRecordMapper.selectOne(Wrappers.lambdaQuery(UserRenewChangeTicketRecord.class)
+							.eq(UserRenewChangeTicketRecord::getRenewOrderId, orderDon.getId()).last("limit 1"));
+					if (record != null && relationId.equals(record.getPreRelationId())) {
+						relation = groupsRelationMapper.selectById(record.getAfterRelationId());
+					}
+				}
 				if (isFlag) {
 					relation.setUserId(0l);
 					relation.setStatus(GroupsRelation.Status.none);
@@ -1805,7 +1820,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 	 * @param afterSku 续费之后的规格
 	 */
 	private void changeTicketAndRecord(Long preSkuId, Long preRelationId, Long orderId, Integer num, GoodsDonSku afterSku, Long userId) {
-		Long afterSkuId = afterSku.getId();
 		//清理之前的车票
 		GroupsRelation relation = groupsRelationMapper.selectById(preRelationId);
 		if (relation != null) {
@@ -1844,6 +1858,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			Date preExpiryTime = relation.getExpiryTime();
 			DateTime afterExpiryTime = DateUtil.offsetMonth(relationView.getExpiryTime(), num * afterSku.getMonths());
 
+			log.info("用户:{}重复续费,将过期时间累加到新车票:{}上", userId, relationView.getId());
 			relationView.setExpiryTime(afterExpiryTime);
 			groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
 					.set(GroupsRelation::getExpiryTime, relationView.getExpiryTime())