Browse Source

在微信回调的时候修改再次查询订单的状态

Yangzw 9 months ago
parent
commit
90a17f657b

+ 4 - 0
feifan-framework/feifan-spring-boot-starter-web/src/main/java/cn/newfeifan/mall/framework/banner/core/BannerApplicationRunner.java

@@ -18,6 +18,10 @@ public class BannerApplicationRunner implements ApplicationRunner {
 
     @Override
     public void run(ApplicationArguments args) {
+        ThreadUtil.execute(() -> {
+            ThreadUtil.sleep(1, TimeUnit.SECONDS); // 延迟 1 秒,保证输出到结尾
+            log.info("\n----------------------------------------------------------\n\t" + "项目启动成功!\n\t" + "----------------------------------------------------------");
+        });
        /* ThreadUtil.execute(() -> {
             ThreadUtil.sleep(1, TimeUnit.SECONDS); // 延迟 1 秒,保证输出到结尾
             log.info("\n----------------------------------------------------------\n\t" +

+ 13 - 1
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/order/TradeOrderUpdateServiceImpl.java

@@ -25,8 +25,11 @@ import cn.newfeifan.mall.module.pay.api.order.PayOrderApi;
 import cn.newfeifan.mall.module.pay.api.order.dto.PayOrderCreateReqDTO;
 import cn.newfeifan.mall.module.pay.api.order.dto.PayOrderRespDTO;
 import cn.newfeifan.mall.module.pay.dal.dataobject.order.PayOrderDO;
+import cn.newfeifan.mall.module.pay.dal.dataobject.order.PayOrderExtensionDO;
+import cn.newfeifan.mall.module.pay.dal.mysql.order.PayOrderExtensionMapper;
 import cn.newfeifan.mall.module.pay.dal.mysql.order.PayOrderMapper;
 import cn.newfeifan.mall.module.pay.enums.order.PayOrderStatusEnum;
+import cn.newfeifan.mall.module.pay.service.order.PayOrderService;
 import cn.newfeifan.mall.module.product.api.comment.ProductCommentApi;
 import cn.newfeifan.mall.module.product.api.comment.dto.ProductCommentCreateReqDTO;
 import cn.newfeifan.mall.module.product.dal.dataobject.sku.ProductSkuDO;
@@ -163,6 +166,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
 
     // =================== Order ===================
 
+    @Resource
+    private PayOrderExtensionMapper orderExtensionMapper;
+
+    @Resource
+    private PayOrderService payOrderService;
+
 
     /**
      * add by Ben
@@ -867,7 +876,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
     //下面的参数中的id1为交易订单TradeOrder表的id,已经没用了,因为一个支付订单对应多个订单。
     //只有支付订单id参数payOrderId是有用的。
     public void updateOrderPaid(Long id1, Long payOrderId) {
-        log.error("========调用当前时间:{}==========",LocalDateTime.now());
+        //修改程序,当微信支付回调的时候再次向微信请求查询pay订单的支付状态
+        PayOrderDO payOrderDO = payOrderMapper.selectById(payOrderId);
+        PayOrderExtensionDO payOrderExtensionDO = orderExtensionMapper.selectByNo(payOrderDO.getNo());
+        payOrderService.syncOrder(payOrderExtensionDO);
 
 
 //        System.out.println("#########updateOrderPaid####payOrderId:"+payOrderId);

+ 8 - 0
feifan-module-pay/feifan-module-pay-biz/src/main/java/cn/newfeifan/mall/module/pay/service/order/PayOrderService.java

@@ -139,6 +139,14 @@ public interface PayOrderService {
      */
     int syncOrder(LocalDateTime minCreateTime);
 
+    /**
+     * 同步单个支付拓展单
+     *
+     * @param orderExtension 支付拓展单
+     * @return 是否已支付
+     */
+    boolean syncOrder(PayOrderExtensionDO orderExtension);
+
     /**
      * 将已过期的订单,状态修改为已关闭
      *

+ 8 - 8
feifan-module-pay/feifan-module-pay-biz/src/main/java/cn/newfeifan/mall/module/pay/service/order/PayOrderServiceImpl.java

@@ -142,7 +142,7 @@ public class PayOrderServiceImpl implements PayOrderService {
     @Override // 注意,这里不能添加事务注解,避免调用支付渠道失败时,将 PayOrderExtensionDO 回滚了
     public PayOrderSubmitRespVO submitOrder(PayOrderSubmitReqVO reqVO, String userIp) {
 
-        log.error("[submitOrder--------->unifiedOrderResp][订单id({})000000支付开始]", reqVO.getId());
+        log.warn("[submitOrder--------->unifiedOrderResp][订单id({})000000支付开始]", reqVO.getId());
 
 
         // 1.1 获得 PayOrderDO ,并校验其是否存在
@@ -151,7 +151,7 @@ public class PayOrderServiceImpl implements PayOrderService {
         PayChannelDO channel = validateChannelCanSubmit(order.getAppId(), reqVO.getChannelCode());
         PayClient client = channelService.getPayClient(channel.getId());
 
-        log.error("[submitOrder--------->unifiedOrderResp][订单id({})1111111支付渠道校验通过]", order.getId());
+        log.warn("[submitOrder--------->unifiedOrderResp][订单id({})1111111支付渠道校验通过]", order.getId());
 
         // 2. 插入 PayOrderExtensionDO
         String no = noRedisDAO.generate(payProperties.getOrderNoPrefix());
@@ -161,7 +161,7 @@ public class PayOrderServiceImpl implements PayOrderService {
                 .setStatus(PayOrderStatusEnum.WAITING.getStatus());
         orderExtensionMapper.insert(orderExtension);
 
-        log.error("[submitOrder--------->unifiedOrderResp][订单id({})2222222支付渠道校验通过]", order.getId());
+        log.warn("[submitOrder--------->unifiedOrderResp][订单id({})2222222支付渠道校验通过]", order.getId());
 
         // 3. 调用三方接口
         PayOrderUnifiedReqDTO unifiedOrderReqDTO = PayOrderConvert.INSTANCE.convert2(reqVO, userIp)
@@ -174,7 +174,7 @@ public class PayOrderServiceImpl implements PayOrderService {
                 .setPrice(order.getPrice()).setExpireTime(order.getExpireTime());
         PayOrderRespDTO unifiedOrderResp = client.unifiedOrder(unifiedOrderReqDTO);
 
-        log.error("[submitOrder--------->unifiedOrderResp][订单id({})333333支付完成,支付状态({})]", order.getId(), unifiedOrderResp.getStatus());
+        log.warn("[submitOrder--------->unifiedOrderResp][订单id({})333333支付完成,支付状态({})]", order.getId(), unifiedOrderResp.getStatus());
 
         // 4. 如果调用直接支付成功,则直接更新支付单状态为成功。例如说:付款码支付,免密支付时,就直接验证支付成功
         if (unifiedOrderResp != null) {
@@ -187,7 +187,7 @@ public class PayOrderServiceImpl implements PayOrderService {
             // 此处需要读取最新的状态
             order = orderMapper.selectById(order.getId());
         }
-        log.error("如果调用直接支付成功,则直接更新支付单状态为成功。例如说:付款码支付,免密支付时,就直接验证支付成功:{}", unifiedOrderResp.toString());
+        log.warn("如果调用直接支付成功,则直接更新支付单状态为成功。例如说:付款码支付,免密支付时,就直接验证支付成功:{}", unifiedOrderResp);
         return PayOrderConvert.INSTANCE.convert(order, unifiedOrderResp);
     }
 
@@ -281,8 +281,8 @@ public class PayOrderServiceImpl implements PayOrderService {
     @Transactional(rollbackFor = Exception.class)
     // 注意,如果是方法内调用该方法,需要通过 getSelf().notifyPayOrder(channel, notify) 调用,否则事务不生效
     public void notifyOrder(PayChannelDO channel, PayOrderRespDTO notify) {
-        log.error("public void notifyOrder(PayChannelDO channel, PayOrderRespDTO notify)");
-        log.error("===========支付订单的状态:{}====", notify.getStatus());
+        log.warn("public void notifyOrder(PayChannelDO channel, PayOrderRespDTO notify)");
+        log.warn("===========支付订单的状态:{}====", notify.getStatus());
         // 情况一:支付成功的回调
         if (PayOrderStatusRespEnum.isSuccess(notify.getStatus())) {
             notifyOrderSuccess(channel, notify);
@@ -486,7 +486,7 @@ public class PayOrderServiceImpl implements PayOrderService {
      * @param orderExtension 支付拓展单
      * @return 是否已支付
      */
-    private boolean syncOrder(PayOrderExtensionDO orderExtension) {
+    public boolean syncOrder(PayOrderExtensionDO orderExtension) {
         try {
             // 1.1 查询支付订单信息
             PayClient payClient = channelService.getPayClient(orderExtension.getChannelId());