zoujiajian 11 months ago
parent
commit
2716d1bc65

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/response/NetflixRecoverResp.java

@@ -18,4 +18,9 @@ public class NetflixRecoverResp {
 	 * 剩余天数
 	 */
 	private Long remainDays;
+
+	/**
+	 * 是否设置成功
+	 */
+	private Boolean isReset = false;
 }

+ 50 - 1
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -1514,11 +1514,24 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 	}
 
 	@Override
+	@Transactional(rollbackFor = Throwable.class)
 	public NetflixRecoverResp netflixSubmitRecover(ErrorNetflixChangeReq req) {
+		NetflixRecoverResp recoverResp = new NetflixRecoverResp();
 		Long relationId = req.getRelationId();
 		Long userId = req.getUserId();
 		//校验奈飞账号状态
 		GroupsRelationView netflixRelationView = checkNetflixErrorStatus(relationId, userId);
+		if (netflixRelationView.getIsFrozen()) {
+			//获取同规格的车票
+			Long skuId = netflixRelationView.getSkuId();
+			GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
+			GroupsRelation relation = getRelation(null, userId, sku, null);
+			if (relation != null) {
+				resetUserTicket(netflixRelationView, relation);
+				recoverResp.setIsReset(Boolean.TRUE);
+				return recoverResp;
+			}
+		}
 		Date expiryTime = netflixRelationView.getExpiryTime();
 		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
 		NetflixUserAccountSubmitRecoverRecord recoverRecord = netflixUserAccountSubmitRecoverRecordMapper.selectOne(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
@@ -1545,13 +1558,49 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		Integer selectCount = netflixUserAccountSubmitRecoverRecordMapper.selectCount(Wrappers.lambdaQuery(NetflixUserAccountSubmitRecoverRecord.class)
 				.lt(NetflixUserAccountSubmitRecoverRecord::getCreatedTime, recoverRecord.getCreatedTime())
 				.eq(NetflixUserAccountSubmitRecoverRecord::getStatus, 0));
-		NetflixRecoverResp recoverResp = new NetflixRecoverResp();
 		//往前加100位
 		recoverResp.setIndex(100 + selectCount + 1);
 		recoverResp.setRemainDays(recoverRecord.getRemainDays());
 		return recoverResp;
 	}
 
+	private void resetUserTicket(GroupsRelationView oldRelation, GroupsRelation newRelation) {
+		Long userId = oldRelation.getUserId();
+		Long oldRelationId = oldRelation.getId();
+		//清除车票
+		List<Long> userIdList;
+		try {
+			userIdList = userBindRelationService.getRelationUserIdList(userId, null);
+		} catch (Exception e) {
+			userIdList = List.of(userId);
+		}
+		GroupsRelation clearRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
+				.eq(GroupsRelation::getId, oldRelationId)
+				.in(GroupsRelation::getUserId, userIdList)
+				.last("limit 1"));
+		if (clearRelation != null) {
+			clearRelation.setNewRelationId(newRelation.getId());
+			clearService.clearTicket(clearRelation, UserTicketClearedRecord.Source.ticket_replace);
+		}
+		//恢复状态
+		newRelation.setStartTime(oldRelation.getStartTime());
+		newRelation.setExpiryTime(DateUtil.offsetDay(DateTime.now(), oldRelation.getReservedDays()));
+		newRelation.setStatus(GroupsRelation.Status.validity);
+		groupsRelationMapper.updateById(newRelation);
+
+		//原订单座位id更新
+		OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+				.in(OrderDon::getUserId, userIdList)
+				.eq(OrderDon::getRelationId, oldRelationId)
+				.notIn(OrderDon::getStatus, Constant.noOrderStatus)
+				.orderByDesc(OrderDon::getId)
+				.last("limit 1"));
+		if (orderDon != null) {
+			orderDon.setRelationId(newRelation.getId());
+			orderDonMapper.updateById(orderDon);
+		}
+	}
+
 	@Override
 	@Transactional(rollbackFor = Throwable.class)
 	public void errorNetflixSubmitChangeOtherTicket(ErrorNetflixChangeReq req) throws Exception {