Pārlūkot izejas kodu

Merge branch 'codex/multi-quantity-orders' into pre

zoujiajian 1 nedēļu atpakaļ
vecāks
revīzija
d795452171

+ 15 - 6
netflix-service/src/main/java/com/cyksj/server/recharge/impl/GptProxyRechargeServiceImpl.java

@@ -23,6 +23,7 @@ import com.cyksj.server.recharge.dto.TaskResult;
 import com.cyksj.server.recharge.dto.TaskSubmitResult;
 import com.cyksj.server.recharge.dto.TokenParseResult;
 import com.cyksj.service.chatgpt.GptUserRechargeRecordService;
+import com.cyksj.service.order.MultiQuantityOrderService;
 import com.cyksj.service.recharge.*;
 import com.cyksj.service.user.UserBindRelationService;
 import lombok.RequiredArgsConstructor;
@@ -55,6 +56,8 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
 
     private final OrderDonMapper orderDonMapper;
 
+    private final MultiQuantityOrderService multiQuantityOrderService;
+
 	private final GptUserRechargeRecordService gptUserRechargeRecordService;
 
 	private final RedisService redisService;
@@ -347,12 +350,18 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
 			if (updateRemainNum == 0) {
 				throw BusinessRuntimeException.getInstance("代充异常,请重试");
 			}
-			OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
-					.in(OrderDon::getUserId, userIdList)
-					.eq(OrderDon::getRelationId, relationId)
-					.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-					.orderByDesc(OrderDon::getId)
-					.last("limit 1"));
+			OrderDon orderDon = multiQuantityOrderService.findOrderByRelationId(relationId);
+			if (orderDon != null && !userIdList.contains(orderDon.getUserId())) {
+				orderDon = null;
+			}
+			if (orderDon == null) {
+				orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+						.in(OrderDon::getUserId, userIdList)
+						.eq(OrderDon::getRelationId, relationId)
+						.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+						.orderByDesc(OrderDon::getId)
+						.last("limit 1"));
+			}
 			if (orderDon == null) {
 				throw BusinessRuntimeException.getInstance("代充订单不存在或已退款");
 			}

+ 15 - 6
netflix-service/src/main/java/com/cyksj/service/mange/gpt/impl/GptRechargeServiceImpl.java

@@ -29,6 +29,7 @@ import com.cyksj.server.recharge.dto.TaskSubmitResult;
 import com.cyksj.server.recharge.dto.TokenParseResult;
 import com.cyksj.service.chatgpt.GptUserRechargeRecordService;
 import com.cyksj.service.mange.gpt.GptRechargeService;
+import com.cyksj.service.order.MultiQuantityOrderService;
 import com.cyksj.service.recharge.*;
 import com.cyksj.service.user.UserBindRelationService;
 import lombok.RequiredArgsConstructor;
@@ -64,6 +65,8 @@ public class GptRechargeServiceImpl implements GptRechargeService {
 
 	private final OrderDonMapper orderDonMapper;
 
+	private final MultiQuantityOrderService multiQuantityOrderService;
+
 	private final GptUserRechargeRecordService gptUserRechargeRecordService;
 
 	private final TransactionTemplate transactionTemplate;
@@ -190,12 +193,18 @@ public class GptRechargeServiceImpl implements GptRechargeService {
 			if (updateRemainNum == 0) {
 				throw BusinessRuntimeException.getInstance("剩余可代充次数为0");
 			}
-			OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
-					.eq(OrderDon::getUserId, relation.getUserId())
-					.eq(OrderDon::getRelationId, relationId)
-					.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-					.orderByDesc(OrderDon::getId)
-					.last("limit 1"));
+			OrderDon orderDon = multiQuantityOrderService.findOrderByRelationId(relationId);
+			if (orderDon != null && !relation.getUserId().equals(orderDon.getUserId())) {
+				orderDon = null;
+			}
+			if (orderDon == null) {
+				orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+						.eq(OrderDon::getUserId, relation.getUserId())
+						.eq(OrderDon::getRelationId, relationId)
+						.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+						.orderByDesc(OrderDon::getId)
+						.last("limit 1"));
+			}
 			if (orderDon == null) {
 				throw BusinessRuntimeException.getInstance("代充订单不存在或已退款");
 			}

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/order/MultiQuantityOrderService.java

@@ -22,4 +22,6 @@ public interface MultiQuantityOrderService {
     MultiQuantityRedeliveryResult redeliverManually(Long orderId);
 
     boolean completeIfAllTicketsAvailable(Long orderId);
+
+    OrderDon findOrderByRelationId(Long relationId);
 }

+ 13 - 0
netflix-service/src/main/java/com/cyksj/service/order/impl/MultiQuantityOrderServiceImpl.java

@@ -60,6 +60,19 @@ public class MultiQuantityOrderServiceImpl implements MultiQuantityOrderService
     private static final int DELIVERY_MAX_RETRIES = 5;
     private static final int MANUAL_DELIVERY_LEASE_MINUTES = 5;
 
+    @Override
+    public OrderDon findOrderByRelationId(Long relationId) {
+        if (relationId == null || relationId <= 0) {
+            return null;
+        }
+        OrderDonTicketRecord record = ticketRecordService.getActiveByRelationId(relationId);
+        if (record == null || record.getOrderId() == null) {
+            return null;
+        }
+        OrderDon order = orderDonMapper.selectById(record.getOrderId());
+        return order != null && order.getNum() != null && order.getNum() > 1 ? order : null;
+    }
+
     private final OrderDonMapper orderDonMapper;
     private final GoodsDonMapper goodsDonMapper;
     private final GoodsDonSkuMapper goodsDonSkuMapper;

+ 27 - 6
netflix-web/src/main/java/com/cyksj/web/controller/manage/group/CmsGroupRelationController.java

@@ -124,6 +124,24 @@ public class CmsGroupRelationController {
         return relationIds;
     }
 
+    private OrderDon getMultiQuantityOrderByRelationId(Long relationId) {
+        if (relationId == null || relationId <= 0) {
+            return null;
+        }
+        OrderDonTicketRecord ticketRecord = orderDonTicketRecordMapper.selectOne(
+                Wrappers.lambdaQuery(OrderDonTicketRecord.class)
+                        .eq(OrderDonTicketRecord::getRelationId, relationId)
+                        .eq(OrderDonTicketRecord::getStatus, OrderDonTicketRecord.Status.success)
+                        .orderByDesc(OrderDonTicketRecord::getId)
+                        .last("limit 1"));
+        if (ticketRecord == null) {
+            return null;
+        }
+        OrderDon orderDon = orderDonMapper.selectById(ticketRecord.getOrderId());
+        return orderDon != null && orderDon.getNum() != null && orderDon.getNum() > 1
+                ? orderDon : null;
+    }
+
     @GetMapping("/get")
     public Result<List<GroupsRelationBackView>> get(){
         List<GroupsRelationBackView> search = beanSearcher.searchAll(GroupsRelationBackView.class, MapUtils.flatBuilder(request.getParameterMap())
@@ -289,12 +307,15 @@ public class CmsGroupRelationController {
         OrderDon orderDon = null;
         if (rechargeStatus == GroupsRelation.RechargeStatus.complete) {
             relation.setSendTime(DateTime.now());
-            orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
-                    .eq(OrderDon::getUserId, relation.getUserId())
-                    .eq(OrderDon::getRelationId, relationId)
-                    .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-                    .orderByDesc(OrderDon::getId)
-                    .last("limit 1"));
+            orderDon = getMultiQuantityOrderByRelationId(relationId);
+            if (orderDon == null) {
+                orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+                        .eq(OrderDon::getUserId, relation.getUserId())
+                        .eq(OrderDon::getRelationId, relationId)
+                        .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
+                        .orderByDesc(OrderDon::getId)
+                        .last("limit 1"));
+            }
             if (orderDon == null){
                 orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
                         .eq(OrderDon::getUserId, relation.getUserId())