Procházet zdrojové kódy

Merge remote-tracking branch 'origin/develop/v1.0' into develop/v1.0

tangxiangan před 4 měsíci
rodič
revize
3fd2ea7409

+ 2 - 0
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/service/OrderService.java

@@ -63,6 +63,8 @@ public interface OrderService extends IService<Order> {
      */
     OrderUpdateVO updateOrderSucceeded(OrderSucceededBO orderSucceeded);
 
+    void deleteTheCacheInTheCacheManager(String key);
+
     /**
      * 通过id获取订单信息
      *

+ 12 - 10
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/service/impl/OrderServiceImpl.java

@@ -289,9 +289,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         // 请求支付中台
         log.info("创建订单,请求支付中台,{}", jsonObject);
         OkHttpClient client = new OkHttpClient().newBuilder()
-                .connectTimeout(120, TimeUnit.SECONDS)
-                .readTimeout(120, TimeUnit.SECONDS)
-                .writeTimeout(120, TimeUnit.SECONDS)
+                .connectTimeout(300, TimeUnit.SECONDS)
+                .readTimeout(300, TimeUnit.SECONDS)
+                .writeTimeout(300, TimeUnit.SECONDS)
                 .build();
         okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
         RequestBody body = RequestBody.create(mediaType, jsonObject.toString());
@@ -456,9 +456,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         // 请求支付中台
         log.info("创建订阅,请求支付中台,参数:{}", jsonObject);
         OkHttpClient client = new OkHttpClient().newBuilder()
-                .connectTimeout(120, TimeUnit.SECONDS)
-                .readTimeout(120, TimeUnit.SECONDS)
-                .writeTimeout(120, TimeUnit.SECONDS)
+                .connectTimeout(300, TimeUnit.SECONDS)
+                .readTimeout(300, TimeUnit.SECONDS)
+                .writeTimeout(300, TimeUnit.SECONDS)
                 .build();
         okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
         RequestBody body = RequestBody.create(mediaType, jsonObject.toString());
@@ -554,6 +554,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         }
         //删除缓存中的订单
         deleteTheCacheInTheCacheManager(orders.getEmail() + "-" + orders.getProductId() + "-" + orders.getPayment());
+        deleteTheCacheInTheCacheManager(orders.getUserId() + "-" + orders.getProductId() + "-" + orders.getPayment());
         // 检查订单优惠券
         productApi.refundCouponByOrderId(orderId);
     }
@@ -597,7 +598,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
      *
      * @param key key
      */
-    private void deleteTheCacheInTheCacheManager(String key) {
+    @Override
+    public void deleteTheCacheInTheCacheManager(String key) {
         log.info("删除缓存中的订单 key" + key);
         RedisCache cache = (RedisCache) myRedisCacheManager.getCache(RedisKeyConstant.CACHE_PAYMENT_CREAT_ORDER);
         if (cache != null) {
@@ -631,9 +633,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
             String authorization = rsaUtils.encrypt(String.format("{\"configId\":\"%s\"}", payCenterConfigProperties.getPaypal()));
 
             OkHttpClient client = new OkHttpClient().newBuilder()
-                    .connectTimeout(120, TimeUnit.SECONDS)
-                    .readTimeout(120, TimeUnit.SECONDS)
-                    .writeTimeout(120, TimeUnit.SECONDS)
+                    .connectTimeout(300, TimeUnit.SECONDS)
+                    .readTimeout(300, TimeUnit.SECONDS)
+                    .writeTimeout(300, TimeUnit.SECONDS)
                     .build();
             String url = payCenterConfigProperties.getPayCenterUrl() + payCenterConfigProperties.getCapturePaypalMethod() + "?tradeId=" + order.getThirdOrderNo();
             Request request = new Request.Builder()

+ 6 - 103
pdf-office-payment/src/main/java/cn/kdan/cloud/pdf/office/payment/service/impl/PayCenterWebhookServiceImpl.java

@@ -76,6 +76,7 @@ public class PayCenterWebhookServiceImpl implements PayCenterWebhookService {
      * @return String 支付链接
      */
     @Override
+    @Transactional
     public Boolean webhookMonitor(Map<String, String> body) {
         if (body == null || body.isEmpty()) {
             log.error("支付中台统一回调,请求参数为空");
@@ -284,106 +285,8 @@ public class PayCenterWebhookServiceImpl implements PayCenterWebhookService {
                             userSubscriptionInfoApi.insert(userSubscriptionInfo);
                         }
                     }
-
-                    /*if (ordersVO.getPaymentModel() == 1) {
-                        log.info("订阅订单回调,{}", ordersVO);
-//                        ProductVO productVO = productApi.getProduct(ordersVO.getProductId()).getResult();
-                        // 自动订阅,查询用户有没有订阅信息
-                        List<UserSubscriptionInfoVO> collect = subscriptionInfoList.stream().filter(
-                                userSubscriptionInfoVO -> userSubscriptionInfoVO.getPlatform().equals(productVO.getPlatform())
-                        ).collect(Collectors.toList());
-                        if (CollectionUtils.isNotEmpty(collect)) {
-                            log.info("用户有订阅信息,更新记录");
-                            UserSubscriptionInfoVO userSubscriptionInfoVO = collect.get(0);
-                            BeanUtil.copyProperties(userSubscriptionInfoVO, userSubscriptionInfo);
-                            userSubscriptionInfo.setStatus(PDFOfficeUserSubscriptionStatusEnum.SUBSCRIPTION_IN_PROGRESS.value());
-                            // 获取当前时间
-                            Date currentDate = new Date();
-                            // 根据产品周期添加订阅信息记录的结束时间
-                            if (currentDate.compareTo(userSubscriptionInfoVO.getEndDate()) < 0) {
-                                // 订阅未过期,设置结束时间为当前时间加产品周期
-                                currentDate = userSubscriptionInfoVO.getEndDate();
-                            }
-                            Date endDate = getDateByCycle(currentDate, productVO.getCycle());
-                            userSubscriptionInfo.setEndDate(endDate);
-                            userSubscriptionInfo.setPayType(1);
-                            userSubscriptionInfo.setPlatform(productVO.getPlatform());
-                            if(productVO.getPlatform()==3){
-                                //如果是ai还要加ai点数
-                                userSubscriptionInfo.setPoint(userSubscriptionInfo.getPoint()+Integer.valueOf(productVO.getPoints()));
-                                if(productVO.getCode().contains("trail")){
-                                    UserVO userVO = new UserVO();
-                                    userVO.setId(ordersVO.getUserId());
-                                    userVO.setCanAccessAi("0");
-                                    userApi.updateUser(userVO);
-                                }
-                            }
-                            userSubscriptionInfo.setAppId(ordersVO.getAppId());
-                            userSubscriptionInfo.setProductId(ordersVO.getProductId());
-                            userSubscriptionInfoApi.update(userSubscriptionInfo);
-                        } else {
-                            log.info("用户没有订阅信息,新增记录");
-                            userSubscriptionInfo.setId(CommonUtils.generateId());
-                            userSubscriptionInfo.setUserId(ordersVO.getUserId());
-                            userSubscriptionInfo.setStatus(PDFOfficeUserSubscriptionStatusEnum.SUBSCRIPTION_IN_PROGRESS.value());
-                            // 获取当前时间
-                            Date currentDate = new Date();
-                            Date endDate = getDateByCycle(currentDate, productVO.getCycle());
-                            userSubscriptionInfo.setEndDate(endDate);
-                            userSubscriptionInfo.setPayType(1);
-                            //0免费,1永久版,2订阅,3ai
-                            userSubscriptionInfo.setPlatform(productVO.getPlatform());
-                            if(productVO.getPlatform()==3){
-                                //如果是ai还要加ai点数
-                                userSubscriptionInfo.setPoint(Integer.valueOf(productVO.getPoints()));
-                                if(productVO.getCode().contains("trail")){
-                                    UserVO userVO = new UserVO();
-                                    userVO.setId(ordersVO.getUserId());
-                                    userVO.setCanAccessAi("0");
-                                    userApi.updateUser(userVO);
-                                }
-                            }
-                            userSubscriptionInfo.setAppId(ordersVO.getAppId());
-                            userSubscriptionInfo.setProductId(ordersVO.getProductId());
-                            userSubscriptionInfoApi.insert(userSubscriptionInfo);
-                        }
-                    } else {
-                        log.info("买断订单回调,{}", ordersVO);
-                        // 买断,查询用户买断信息
-                        List<UserSubscriptionInfoVO> collect = subscriptionInfoList.stream().filter(userSubscriptionInfoVO -> userSubscriptionInfoVO.getPlatform().equals(productVO.getPlatform())).collect(Collectors.toList());
-                        if (CollectionUtils.isNotEmpty(collect) || ordersVO.getPayNumber() > 1) {
-                            String info = CollectionUtils.isNotEmpty(collect) ? "用户有买断的订阅信息,新增订单赠送" : String.format("批量购买%s个,新增订单赠送", order.getPayNumber());
-                            log.info(info);
-                            // 批量购买和用户已购买的买断商品,放入 order_gift
-                            List<OrderGift> orderGiftList = new ArrayList<>();
-                            for (Integer i = 0; i < ordersVO.getPayNumber(); i++) {
-                                OrderGift orderGift = new OrderGift();
-                                orderGift.setId(CommonUtils.generateId());
-                                orderGift.setOrderId(ordersVO.getId());
-                                orderGift.setProductId(ordersVO.getProductId());
-                                orderGift.setUserId(ordersVO.getUserId());
-                                orderGift.setValidFlag("1");
-                                orderGiftList.add(orderGift);
-                            }
-                            orderGiftService.saveBatch(orderGiftList);
-                        } else {
-                            log.info("用户没有订阅信息,新增记录");
-                            userSubscriptionInfo.setId(CommonUtils.generateId());
-                            userSubscriptionInfo.setUserId(ordersVO.getUserId());
-                            userSubscriptionInfo.setPlatform(1);
-                            userSubscriptionInfo.setStatus(PDFOfficeUserSubscriptionStatusEnum.SUBSCRIPTION_IN_PROGRESS.value());
-                            // 设置过期时间一百年
-                            // 获取当前时间
-                            Calendar calendar = Calendar.getInstance();
-                            // 向当前时间增加100年
-                            calendar.add(Calendar.YEAR, 100);
-                            userSubscriptionInfo.setEndDate(calendar.getTime());
-                            userSubscriptionInfo.setPayType(0);
-                            userSubscriptionInfo.setAppId(ordersVO.getAppId());
-                            userSubscriptionInfo.setProductId(ordersVO.getProductId());
-                            userSubscriptionInfoApi.insert(userSubscriptionInfo);
-                        }
-                    }*/
+                    //删除缓存中的订单
+                    ordersService.deleteTheCacheInTheCacheManager(ordersVO.getUserId() + "-" + ordersVO.getProductId() + "-" + ordersVO.getPayment());
                     break;
                 case "2":
                     // 支付失败,有延时队列暂不处理
@@ -406,7 +309,7 @@ public class PayCenterWebhookServiceImpl implements PayCenterWebhookService {
                     // 更新user_subscription_info
                     UserSubscriptionInfo userSubscriptionInfo1 = new UserSubscriptionInfo();
                     // 查询用户订阅的信息
-                    List<UserSubscriptionInfoVO> collect = subscriptionInfoList.stream().filter(userSubscriptionInfoVO -> userSubscriptionInfoVO.getPaymentModel().equals("1")).collect(Collectors.toList());
+                    List<UserSubscriptionInfoVO> collect = subscriptionInfoList.stream().filter(userSubscriptionInfoVO -> userSubscriptionInfoVO.getPlatform().equals(productVO.getPlatform())).collect(Collectors.toList());
                     if (CollectionUtils.isNotEmpty(collect)) {
                         log.error("订阅周期付款,用户订阅信息异常,thirdTradeId:{}", thirdTradeId);
                         break;
@@ -431,9 +334,9 @@ public class PayCenterWebhookServiceImpl implements PayCenterWebhookService {
                     // 更新user_subscription_info
                     UserSubscriptionInfo userSubscriptionInfo2 = new UserSubscriptionInfo();
                     // 查询用户订阅的信息
-                    List<UserSubscriptionInfoVO> collect1 = subscriptionInfoList.stream().filter(userSubscriptionInfoVO -> userSubscriptionInfoVO.getPaymentModel().equals("1")).collect(Collectors.toList());
+                    List<UserSubscriptionInfoVO> collect1 = subscriptionInfoList.stream().filter(userSubscriptionInfoVO -> userSubscriptionInfoVO.getPlatform().equals(productVO.getPlatform())).collect(Collectors.toList());
                     if (CollectionUtils.isNotEmpty(collect1)) {
-                        log.error("订阅周期付款,用户订阅信息异常,thirdTradeId:{}", thirdTradeId);
+                        log.error("订阅取消,用户订阅信息异常,thirdTradeId:{}", thirdTradeId);
                         break;
                     }
                     BeanUtil.copyProperties(collect1.get(0), userSubscriptionInfo2);