zoujiajian 2 hete
szülő
commit
ae760cf8e3

+ 1 - 18
netflix-service/src/main/java/com/cyksj/service/order/impl/MultiQuantityOrderServiceImpl.java

@@ -425,9 +425,8 @@ public class MultiQuantityOrderServiceImpl implements MultiQuantityOrderService
 		if (!ticketRecordService.markSuccess(recordId, relation.getId(), workerToken)) {
 			throw new IllegalStateException("ticket slot claim expired");
 		}
-        OrderDon oneTicketOrder = copyForOneTicket(order, relation.getId());
         try {
-            expiryRecordService.syncGroupsRelationExpiryRecord(oneTicketOrder, goods, sku);
+			expiryRecordService.syncGroupsRelationExpiryRecord(order, relation.getId(), goods, sku);
         } catch (DuplicateKeyException ignored) {
             // The expiry record is ancillary; slot ownership is already durable.
 		}
@@ -560,22 +559,6 @@ public class MultiQuantityOrderServiceImpl implements MultiQuantityOrderService
                 com.cyksj.model.entity.OrderDonGalaxyCoinRecord.Source.ordinary);
     }
 
-    private OrderDon copyForOneTicket(OrderDon source, Long relationId) {
-        OrderDon copy = new OrderDon();
-        copy.setId(source.getId());
-        copy.setOrderNo(source.getOrderNo());
-        copy.setGoodsId(source.getGoodsId());
-        copy.setSkuId(source.getSkuId());
-        copy.setUserId(source.getUserId());
-        copy.setPayTime(source.getPayTime());
-        copy.setCreatedTime(source.getCreatedTime());
-        copy.setRelationId(relationId);
-        copy.setNum(1);
-        copy.setOrderType(1);
-		copy.setYhsId(source.getYhsId() == null ? 0L : source.getYhsId());
-        return copy;
-    }
-
     private void afterCommit(Runnable action) {
         if (!TransactionSynchronizationManager.isSynchronizationActive()) {
             action.run();

+ 8 - 0
netflix-service/src/main/java/com/cyksj/service/relation/GroupsRelationExpiryRecordService.java

@@ -14,4 +14,12 @@ import com.cyksj.model.entity.OrderDon;
  */
 public interface GroupsRelationExpiryRecordService extends IService<GroupsRelationExpiryRecord> {
 	void syncGroupsRelationExpiryRecord(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku);
+
+	/**
+	 * Sync the renewal-follow record for one ticket of an order without fabricating a
+	 * one-ticket {@link OrderDon}. This overload is used by multi-quantity delivery:
+	 * all tickets still belong to the same order in {@code order_don}.
+	 */
+	void syncGroupsRelationExpiryRecord(OrderDon orderDon, Long relationId,
+			GoodsDon goodsDon, GoodsDonSku sku);
 }

+ 25 - 24
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -398,23 +398,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 					ticket.setRemainDays(remainDays);
 					ticket.setTotal(DateUtil.betweenDay(ticket.getStartTime(), ticket.getExpiryTime(), false) + 1);
 				}
-				OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
-						.eq(OrderDon::getRelationId, ticket.getRelationId())
-						.in(OrderDon::getUserId, userIds)
-						.eq(OrderDon::getOrderType, 1)
-						.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-						.orderByDesc(OrderDon::getId)
-						.last("limit 1"));
-				if (orderDon == null) {
-					OrderDonTicketRecord multiTicket = orderDonTicketRecordService.getActiveByRelationId(ticket.getRelationId());
-					if (multiTicket != null) {
-						orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
-								.eq(OrderDon::getId, multiTicket.getOrderId())
-								.in(OrderDon::getUserId, userIds)
-								.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-								.last("limit 1"));
-					}
-				}
+				OrderDon orderDon = getCurrentTicketOrder(ticket.getRelationId(), userIds);
 				Long zhSkuId = ticket.getSkuId();
 				if (orderDon == null) {
 					if (ticket.getGoodsId() == Constant.NETFLIX_GID) {
@@ -2140,13 +2124,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 				}
 			}
 
-			OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
-					.eq(OrderDon::getRelationId, ticket.getRelationId())
-					.eq(OrderDon::getUserId, ticket.getUserId())
-					.eq(OrderDon::getOrderType, 1)
-					.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-					.orderByDesc(OrderDon::getId)
-					.last("limit 1"));
+			OrderDon orderDon = getCurrentTicketOrder(ticket.getRelationId(), userIds);
 			if (orderDon != null) {
 				ticket.setOrderId(orderDon.getId());
 			}
@@ -2155,6 +2133,29 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		return list;
 	}
 
+	/**
+	 * Resolve the order that currently owns a ticket. A relation id can be reused
+	 * after an old ticket expires or is cleared, so an active multi-quantity slot
+	 * must take precedence over historical order_don.relation_id rows.
+	 */
+	private OrderDon getCurrentTicketOrder(Long relationId, List<Long> userIds) {
+		OrderDonTicketRecord activeTicket = orderDonTicketRecordService.getActiveByRelationId(relationId);
+		if (activeTicket != null) {
+			return orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+					.eq(OrderDon::getId, activeTicket.getOrderId())
+					.in(OrderDon::getUserId, userIds)
+					.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+					.last("limit 1"));
+		}
+		return orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+				.eq(OrderDon::getRelationId, relationId)
+				.in(OrderDon::getUserId, userIds)
+				.eq(OrderDon::getOrderType, 1)
+				.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+				.orderByDesc(OrderDon::getId)
+				.last("limit 1"));
+	}
+
 	@Override
 	public TicketRenewUpgradeView getRenewUpgradeInfo(long userId, Long relationId) {
 		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);

+ 7 - 1
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupsRelationExpiryRecordServiceImpl.java

@@ -29,11 +29,17 @@ public class GroupsRelationExpiryRecordServiceImpl extends ServiceImpl<GroupsRel
 
 	@Override
 	public void syncGroupsRelationExpiryRecord(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) {
+		syncGroupsRelationExpiryRecord(orderDon, orderDon.getRelationId(), goodsDon, sku);
+	}
+
+	@Override
+	public void syncGroupsRelationExpiryRecord(OrderDon orderDon, Long relationId,
+			GoodsDon goodsDon, GoodsDonSku sku) {
 		List<Long> userIdList = userBindRelationService.getRelationUserIdList(orderDon.getUserId(), null);
 		GroupsRelationExpiryRecord groupsRelationExpiryRecord = this.getOne(Wrappers.lambdaQuery(GroupsRelationExpiryRecord.class)
 				.in(GroupsRelationExpiryRecord::getUserId, userIdList)
 				.eq(GroupsRelationExpiryRecord::getIsReBuy, false)
-				.eq(GroupsRelationExpiryRecord::getRelationId, orderDon.getRelationId()).last("limit 1"));
+				.eq(GroupsRelationExpiryRecord::getRelationId, relationId).last("limit 1"));
 		if (groupsRelationExpiryRecord == null) {
 			List<GroupsRelationExpiryRecord> groupsRelationExpiryRecords = this.list(Wrappers.lambdaQuery(GroupsRelationExpiryRecord.class)
 					.in(GroupsRelationExpiryRecord::getUserId, userIdList)