xiongzhu 4 năm trước cách đây
mục cha
commit
02bc1bcd94
1 tập tin đã thay đổi với 22 bổ sung17 xóa
  1. 22 17
      src/main/java/com/izouma/nineth/service/OrderService.java

+ 22 - 17
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -47,6 +47,7 @@ import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.context.event.EventListener;
 import org.springframework.core.env.Environment;
 import org.springframework.data.domain.Page;
+import org.springframework.data.redis.core.BoundSetOperations;
 import org.springframework.data.redis.core.BoundValueOperations;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -423,6 +424,10 @@ public class OrderService {
             response = Payment.create(paymentParams);
             log.info("createOrderResponse {}", JSON.toJSONString(response, SerializerFeature.PrettyFormat));
             AdapayService.checkSuccess(response);
+
+            BoundSetOperations<String, Object> ops = redisTemplate.boundSetOps("orderNotify::" + order.getId());
+            ops.add(MapUtils.getString(response, "id"));
+            ops.expire(7, TimeUnit.DAYS);
         }
 
         switch (payChannel) {
@@ -607,28 +612,28 @@ public class OrderService {
             return;
         }
 
-        Set<Object> transactionIds = redisTemplate.opsForSet().members("orderNotify::" + order.getId());
-        if (transactionIds != null && transactionIds.size() > 0) {
-            if (transactionIds.parallelStream().anyMatch(transactionId -> {
-                try {
-                    Map<String, Object> map = Payment.query(transactionId.toString());
-                    return "succeeded".equalsIgnoreCase(MapUtils.getString(map, "status")) ||
-                            "pending".equalsIgnoreCase(MapUtils.getString(map, "status"));
-                } catch (BaseAdaPayException e) {
-                    e.printStackTrace();
-                }
-                return false;
-            })) {
-                log.info("订单已经支付成功或待支付,不能取消 {}", order.getId());
-                return;
-            }
-        }
-
         try {
             if (order.getStatus() != OrderStatus.NOT_PAID) {
                 throw new BusinessException("已支付订单无法取消");
             }
 
+            Set<Object> transactionIds = redisTemplate.opsForSet().members("orderNotify::" + order.getId());
+            if (transactionIds != null && transactionIds.size() > 0) {
+                if (transactionIds.parallelStream().anyMatch(transactionId -> {
+                    try {
+                        Map<String, Object> map = Payment.query(transactionId.toString());
+                        return "succeeded".equalsIgnoreCase(MapUtils.getString(map, "status")) ||
+                                "pending".equalsIgnoreCase(MapUtils.getString(map, "status"));
+                    } catch (BaseAdaPayException e) {
+                        e.printStackTrace();
+                    }
+                    return false;
+                })) {
+                    log.info("订单已经支付成功或待支付,不能取消 {}", order.getId());
+                    return;
+                }
+            }
+
             CollectionSource source = Optional.ofNullable(order.getSource()).orElseGet(() ->
                     collectionRepo.findById(order.getCollectionId()).map(Collection::getSource).orElse(null));