Sfoglia il codice sorgente

运费计算封装

xdd 2 mesi fa
parent
commit
604411a500

+ 1 - 1
fs-service-system/src/main/java/com/fs/store/mapper/FsStorePaymentMapper.java

@@ -69,7 +69,7 @@ public interface FsStorePaymentMapper
      */
     public int deleteFsStorePaymentByIds(Long[] paymentIds);
 
-    @Select("select * from fs_store_payment where pay_code=#{payCode}")
+    @Select("select * from fs_store_payment where pay_code=#{payCode} limit 1")
     FsStorePayment selectFsStorePaymentByCode(String payCode);
 
     @Select({"<script> " +

+ 5 - 0
fs-service-system/src/main/java/com/fs/store/service/IFsStorePaymentService.java

@@ -11,6 +11,7 @@ import com.fs.store.param.FsStorePaymentParam;
 import com.fs.store.param.FsStoreStatisticsParam;
 import com.fs.store.vo.FsStorePaymentStatisticsVO;
 import com.fs.store.vo.FsStorePaymentVO;
+import org.springframework.scheduling.annotation.Async;
 
 /**
  * 支付明细Service接口
@@ -102,4 +103,8 @@ public interface IFsStorePaymentService
      * 补偿机制
      */
     void paymentSync();
+
+    void delayQueryTzbk(FsStorePayment fsStorePayment);
+
+    void queryTzbk(FsStorePayment fsStorePayment);
 }

+ 51 - 34
fs-service-system/src/main/java/com/fs/store/service/impl/FsStorePaymentServiceImpl.java

@@ -4,13 +4,13 @@ import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fs.common.annotation.DataScope;
-import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.R;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
@@ -38,6 +38,7 @@ import com.fs.store.vo.FsStorePaymentVO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import com.fs.store.mapper.FsStorePaymentMapper;
 import com.fs.store.domain.FsStorePayment;
@@ -296,42 +297,58 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService
     public void paymentSync() {
         List<FsStorePayment> fsStorePayments = fsStorePaymentMapper.queryPendingDelayState();
         for (FsStorePayment fsStorePayment : fsStorePayments) {
-            RequestDTO<QueryOrderRestDTO> requestDTO = new RequestDTO<>();
-
-            QueryOrderRestDTO queryOrderRestDTO = new QueryOrderRestDTO();
-
-            queryOrderRestDTO.setOrderFlowNo(fsStorePayment.getTradeNo());
-            TzConfigInfoDTO tzConfigInfoDTO = TzConfigUtils.getConfig();
-
-            queryOrderRestDTO.setPlatMerCstNo(tzConfigInfoDTO.getPlatMerCstNo());
-
-            requestDTO.setReqBody(queryOrderRestDTO);
-            requestDTO.setReqHeader(TzReqHeaderDTO.getInstance(fsStorePayment.getPayCode()));
-
-            TzReqResultDTO<QueryOrderInfoDTO> resultDTO = null;
-            try {
-                resultDTO = tzBankService.payQueryOrder(requestDTO);
-                String retCode = resultDTO.getRetCode();
-                // 如果查询支付成功
-                if(retCode.equals("00000000")){
-                    QueryOrderInfoDTO body = resultDTO.getBody();
-                    String status = body.getStatus();
-                    Long orderId = fsStorePayment.getOrderId();
-                    String payCode = fsStorePayment.getPayCode();
-                    if("90".equals(status)){
-                        // 如果查询支付成功 更新订单状态
-                        orderService.payConfirm(1,orderId,fsStorePayment.getPayCode(),
-                                fsStorePayment.getTradeNo(),body.getChlTrxId(),fsStorePayment.getTradeNo());
-
-                    } else if("70".equals(status) || "80".equals(status)) {
-                        fsStorePayment.setStatus(-2);
-                        this.updateFsStorePayment(fsStorePayment);
-                    }
+            queryTzbk(fsStorePayment);
+        }
+    }
+
+    @Override
+    @Async
+    public void delayQueryTzbk(FsStorePayment fsStorePayment){
+        try {
+            TimeUnit.SECONDS.sleep(30);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        this.queryTzbk(fsStorePayment);
+    }
 
+    @Override
+    public void queryTzbk(FsStorePayment fsStorePayment) {
+        RequestDTO<QueryOrderRestDTO> requestDTO = new RequestDTO<>();
+
+        QueryOrderRestDTO queryOrderRestDTO = new QueryOrderRestDTO();
+
+        queryOrderRestDTO.setOrderFlowNo(fsStorePayment.getTradeNo());
+        TzConfigInfoDTO tzConfigInfoDTO = TzConfigUtils.getConfig();
+
+        queryOrderRestDTO.setPlatMerCstNo(tzConfigInfoDTO.getPlatMerCstNo());
+
+        requestDTO.setReqBody(queryOrderRestDTO);
+        requestDTO.setReqHeader(TzReqHeaderDTO.getInstance(fsStorePayment.getPayCode()));
+
+        TzReqResultDTO<QueryOrderInfoDTO> resultDTO = null;
+        try {
+            resultDTO = tzBankService.payQueryOrder(requestDTO);
+            String retCode = resultDTO.getRetCode();
+            // 如果查询支付成功
+            if(retCode.equals("00000000")){
+                QueryOrderInfoDTO body = resultDTO.getBody();
+                String status = body.getStatus();
+                Long orderId = fsStorePayment.getOrderId();
+                String payCode = fsStorePayment.getPayCode();
+                if("90".equals(status)){
+                    // 如果查询支付成功 更新订单状态
+                    orderService.payConfirm(1,orderId, fsStorePayment.getPayCode(),
+                            fsStorePayment.getTradeNo(),body.getChlTrxId(), fsStorePayment.getTradeNo());
+
+                } else if("70".equals(status) || "80".equals(status)) {
+                    fsStorePayment.setStatus(-2);
+                    this.updateFsStorePayment(fsStorePayment);
                 }
-            } catch (Exception e) {
-                logger.error("台州银行支付回调查询失败:",e);
+
             }
+        } catch (Exception e) {
+            logger.error("台州银行支付回调查询失败:",e);
         }
     }
 }

+ 2 - 1
fs-service-system/src/main/java/com/fs/store/vo/FsStoreOrderExportVO.java

@@ -96,7 +96,8 @@ public class FsStoreOrderExportVO implements Serializable
 
 
 //    /** 支付邮费 */
-//    private BigDecimal payPostage;
+    @Excel(name = "支付邮费", cellType= Excel.ColumnType.NUMERIC)
+    private BigDecimal payPostage;
 
     /** 抵扣金额 */
     @Excel(name = "抵扣金额",cellType= Excel.ColumnType.NUMERIC)

+ 19 - 2
fs-user-app/src/main/java/com/fs/app/controller/PaymentController.java

@@ -3,9 +3,12 @@ package com.fs.app.controller;
 
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
+import cn.hutool.core.util.ObjectUtil;
 import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.R;
 import com.fs.common.utils.IpUtil;
+import com.fs.huifuPay.dto.TzMiniProgramCodeRespDTO;
+import com.fs.store.domain.FsStorePayment;
 import com.fs.wx.miniapp.config.WxMaConfiguration;
 import com.fs.wx.miniapp.config.WxMaProperties;
 import com.fs.store.domain.FsUser;
@@ -25,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
+import java.util.concurrent.CompletableFuture;
 
 @Api("支付接口")
 @RestController
@@ -62,12 +66,25 @@ public class PaymentController extends AppBaseController {
                 userService.insertFsUser(user);
             }
             payment.setUserId(user.getUserId());
-            return paymentService.payment(payment);
+
+            R payment1 = paymentService.payment(payment);
+            // 台州银行销售收款延迟回查兼容,30秒后查询,防止回调失败的情况
+            if(payment1 != null) {
+                Object o = payment1.get("result");
+                if(o != null) {
+                    TzMiniProgramCodeRespDTO tzMiniProgramCodeRespDTO = (TzMiniProgramCodeRespDTO) payment1.get("result");
+                    FsStorePayment fsStorePayment = paymentService.selectFsStorePaymentByCode(tzMiniProgramCodeRespDTO.getPayCode());
+                    if(ObjectUtil.equal(fsStorePayment.getStatus(),0)){
+                        paymentService.delayQueryTzbk(fsStorePayment);
+                    }
+                }
+            }
+            return payment1;
         } catch (WxErrorException e) {
             e.printStackTrace();
             return R.error(e.getMessage());
         }
-
     }
 
+
 }