TRX 1 år sedan
förälder
incheckning
f7e9387a66

+ 3 - 0
PaymentClient/src/main/java/com/zhongshu/payment/client/payModel/cooperator/ShopIdParam.java

@@ -1,5 +1,6 @@
 package com.zhongshu.payment.client.payModel.cooperator;
 
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -12,5 +13,7 @@ import lombok.NoArgsConstructor;
 @AllArgsConstructor
 @NoArgsConstructor
 public class ShopIdParam {
+
+    @Schema(description = "商户oid", defaultValue = "66d7c48f75f8672c05508f98")
     private String shopId;
 }

+ 2 - 2
PaymentClient/src/main/java/com/zhongshu/payment/client/payModel/cooperator/WithDrawOpenParam.java

@@ -13,6 +13,6 @@ import lombok.NoArgsConstructor;
 @AllArgsConstructor
 @NoArgsConstructor
 public class WithDrawOpenParam {
-    @Schema(description = "商户oid")
-    private String shopOid;
+    @Schema(description = "商户oid", defaultValue = "66d7c48f75f8672c05508f98")
+    private String shopOid = "";
 }

+ 13 - 20
PaymentServer/src/main/java/com/zhongshu/payment/server/core/controller/unionFrictionlessPay/CooperatorController.java

@@ -85,13 +85,6 @@ public class CooperatorController {
         return unionFrictionlessPayMainService.processWithdraw(param);
     }
 
-    @Operation(summary = "提现状态查询")
-    @ResourceAuth(value = "user", type = AuthType.User)
-    @PostMapping(value = "queryOrderStatus", consumes = MediaType.APPLICATION_JSON_VALUE)
-    public ResultContent queryOrderStatus(@RequestBody @Valid WithQueryParam param) {
-        return unionFrictionlessPayMainService.queryOrderStatus(param);
-    }
-
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "提现记录-分页列表", description = "提现记录-分页列表")
     @RequestMapping(value = {"pageWithDraw"}, method = {RequestMethod.POST})
@@ -107,19 +100,19 @@ public class CooperatorController {
         return cooperatorService.getWithDrawById(id);
     }
 
-    @Operation(summary = "根据订单号查询提现记录详情", description = "根据订单号查询记录详情")
-    @GetMapping(value = "getWithDrawBySysOrderId")
-    public ResultContent<ShopWithDrawRecordModel> getWithDrawBySysOrderId(
-            @RequestParam("sysOrderId") String sysOrderId) {
-        return cooperatorService.getWithDrawBySysOrderId(sysOrderId);
-    }
-
-    @Operation(summary = "根据流水号查询提现记录详情", description = "根据流水号查询记录详情")
-    @GetMapping(value = "getWithDrawBySsn")
-    public ResultContent<ShopWithDrawRecordModel> getWithDrawBySsn(
-            @RequestParam("ssn") String ssn) {
-        return cooperatorService.getWithDrawBySsn(ssn);
-    }
+//    @Operation(summary = "根据订单号查询提现记录详情", description = "根据订单号查询记录详情")
+//    @GetMapping(value = "getWithDrawBySysOrderId")
+//    public ResultContent<ShopWithDrawRecordModel> getWithDrawBySysOrderId(
+//            @RequestParam("sysOrderId") String sysOrderId) {
+//        return cooperatorService.getWithDrawBySysOrderId(sysOrderId);
+//    }
+//
+//    @Operation(summary = "根据流水号查询提现记录详情", description = "根据流水号查询记录详情")
+//    @GetMapping(value = "getWithDrawBySsn")
+//    public ResultContent<ShopWithDrawRecordModel> getWithDrawBySsn(
+//            @RequestParam("ssn") String ssn) {
+//        return cooperatorService.getWithDrawBySsn(ssn);
+//    }
 
     //---------------------------通知 start-----------------------------
     @Operation(summary = "提现结果通知回调")

+ 3 - 0
PaymentServer/src/main/java/com/zhongshu/payment/server/core/domain/unionFrictionlessPay/ShopWithDrawRecord.java

@@ -46,6 +46,9 @@ public class ShopWithDrawRecord extends SuperMain {
     @Schema(description = "提现金额 单位分")
     private BigDecimal withdrawAmt;
 
+    @Schema(description = "检查状态的次数")
+    private Integer checkStateTimes = 0;
+
     @Schema(description = "流水号")
     private String ssn;
 

+ 25 - 0
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/unionFrictionlessPay/CooperatorService.java

@@ -3,6 +3,7 @@ package com.zhongshu.payment.server.core.service.pay.impl.unionFrictionlessPay;
 import com.github.microservice.components.data.base.util.PageEntityUtil;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.net.ResultState;
+import com.github.microservice.types.unionFrictionlessPayType.WithDrawState;
 import com.zhongshu.card.client.service.feign.OrganizationFeignService;
 import com.zhongshu.payment.client.payModel.cooperator.platmatModel.ShopOpenWithDrawModel;
 import com.zhongshu.payment.client.payModel.cooperator.platmatModel.ShopWithDrawRecordModel;
@@ -15,6 +16,7 @@ import com.zhongshu.payment.server.core.domain.unionFrictionlessPay.UnionUserOpe
 import com.zhongshu.payment.server.core.service.base.SuperService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -40,6 +42,9 @@ public class CooperatorService extends SuperService {
     @Autowired
     OrganizationFeignService organizationFeignService;
 
+    @Autowired
+    UnionFrictionlessPayMainService unionFrictionlessPayMainService;
+
     /**
      * 提现记录列表
      *
@@ -63,6 +68,7 @@ public class CooperatorService extends SuperService {
         if (ObjectUtils.isEmpty(record)) {
             return ResultContent.buildFail(String.format("数据不存在:%s", id));
         }
+        record = checkDrawState(record);
         return ResultContent.buildSuccess(toModel(record));
     }
 
@@ -77,6 +83,7 @@ public class CooperatorService extends SuperService {
         if (ObjectUtils.isEmpty(record)) {
             return ResultContent.buildFail(String.format("订单号不存在:%s", sysOrderId));
         }
+        record = checkDrawState(record);
         return ResultContent.buildSuccess(toModel(record));
     }
 
@@ -91,9 +98,27 @@ public class CooperatorService extends SuperService {
         if (ObjectUtils.isEmpty(record)) {
             return ResultContent.buildFail(String.format("流水号不存在:%s", ssn));
         }
+        record = checkDrawState(record);
         return ResultContent.buildSuccess(toModel(record));
     }
 
+    private ShopWithDrawRecord checkDrawState(ShopWithDrawRecord record) {
+        if (record != null && record.getWithDrawState() != WithDrawState.Success) {
+            if (StringUtils.isEmpty(record.getStatus()) || !"-1".equals(record.getStatus())) {
+                // 银联未返回状态, 或 返回的状态不等于 -1 (数据问题)再次查询提现状态结果
+                // 不等于成功 (支付到账 才是成功) 再次请求检查状态
+                ResultContent<ShopWithDrawRecord> resultContent = unionFrictionlessPayMainService.updateState(record);
+                if (resultContent.isSuccess()) {
+                    ShopWithDrawRecord shopWithDrawRecord = resultContent.getContent();
+                    if (shopWithDrawRecord != null) {
+                        return shopWithDrawRecord;
+                    }
+                }
+            }
+        }
+        return record;
+    }
+
     public ShopOpenWithDrawModel toModel(ShopOpenWithDraw entity) {
         ShopOpenWithDrawModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {

+ 54 - 7
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/unionFrictionlessPay/UnionFrictionlessPayMainService.java

@@ -807,6 +807,7 @@ public class UnionFrictionlessPayMainService extends SuperPayService {
         drawRecord.setResponse(requestAPI);
         if (requestAPI.isFailed()) {
             drawRecord.setWithDrawState(WithDrawState.Fail);
+            drawRecord.setStatus("-1");
             drawRecord.setDesc(String.format("提现失败,%s", requestAPI.getMsg()));
             shopWithDrawRecordDao.save(drawRecord);
             return ResultContent.buildFail(requestAPI.getMsg());
@@ -820,14 +821,14 @@ public class UnionFrictionlessPayMainService extends SuperPayService {
     /**
      * 提现状态查询
      *
-     * @param param
+     * @param drawRecord
      * @return
      */
-    public ResultContent<QueryOrderStatusResponse> queryOrderStatus(WithQueryParam param) {
-        ShopWithDrawRecord drawRecord = shopWithDrawRecordDao.findTopBySysOrderId(param.getSysOrderId());
+    public ResultContent<QueryOrderStatusResponse> queryOrderStatus(ShopWithDrawRecord drawRecord) {
         if (ObjectUtils.isEmpty(drawRecord)) {
-            return ResultContent.buildFail(String.format("订单不存在:%s", param.getSysOrderId()));
+            return ResultContent.buildFail(String.format("订单不存在"));
         }
+
         QueryOrderStatusParam requestParam = new QueryOrderStatusParam();
         requestParam.setMchntNo(drawRecord.getMchntNo());
         requestParam.setSysOrderId(drawRecord.getSysOrderId());
@@ -840,7 +841,6 @@ public class UnionFrictionlessPayMainService extends SuperPayService {
             return ResultContent.buildFail(requestAPI.getMsg());
         }
         QueryOrderStatusResponse response = (QueryOrderStatusResponse) requestAPI;
-
         return ResultContent.buildSuccess(response);
     }
 
@@ -944,6 +944,8 @@ public class UnionFrictionlessPayMainService extends SuperPayService {
      */
     public ResultContent<OpenWithdrawResponse> openWithdraw(WithDrawOpenParam param) {
         OpenWithdrawParam requestParam = new OpenWithdrawParam();
+        requestParam.setSysId(withdrawConfig.getSysid());
+        requestParam.setMchntNo(getMchntNo(param.getShopOid()));
         String url = payApiConfig.getUrl(UnionFrictionlessPayApiConfig.openWithdraw);
         SuperCooperatorResponseModel requestAPI = unionRequestService.requestCooperatorAPI
                 (url, requestParam, OpenWithdrawResponse.class);
@@ -951,7 +953,7 @@ public class UnionFrictionlessPayMainService extends SuperPayService {
             return ResultContent.buildFail(requestAPI.getMsg());
         }
         OpenWithdrawResponse response = (OpenWithdrawResponse) requestAPI;
-        return ResultContent.buildSuccess();
+        return ResultContent.buildSuccess(response);
     }
 
     /**
@@ -1006,10 +1008,55 @@ public class UnionFrictionlessPayMainService extends SuperPayService {
         });
         JSONObject jsonObject = new JSONObject(paramMap);
         QueryOrderStatusResponse orderStatusResponse = JSONUtil.toBean(jsonObject, QueryOrderStatusResponse.class);
-
+        ShopWithDrawRecord record = shopWithDrawRecordDao.findTopBySysOrderId(orderStatusResponse.getSysOrderId());
+        updateWithDrawResult(orderStatusResponse, record);
         return ResultContent.buildSuccess();
     }
 
+    public ResultContent<ShopWithDrawRecord> updateState(ShopWithDrawRecord record) {
+        // 查询收钱吧 提现状态
+        ResultContent<QueryOrderStatusResponse> resultContent = queryOrderStatus(record);
+        if (resultContent.isSuccess()) {
+            // 更加收钱吧状态更新本地记录的状态
+            ResultContent<ShopWithDrawRecord> resultContent1 = updateWithDrawResult(resultContent.getContent(), record);
+            if (resultContent1.isSuccess()) {
+                record = resultContent1.getContent();
+            }
+        }
+        return ResultContent.buildSuccess(record);
+    }
+
+    /**
+     * 提现结果
+     *
+     * @param orderStatusResponse
+     * @return
+     */
+    private ResultContent<ShopWithDrawRecord> updateWithDrawResult(
+            QueryOrderStatusResponse orderStatusResponse,
+            ShopWithDrawRecord record) {
+        log.info("提现结果 updateWithDrawResult: {}", orderStatusResponse);
+        if (orderStatusResponse != null && record != null) {
+            String status = orderStatusResponse.getStatus();
+            record.setStatus(status);
+            record.setWithResponse(orderStatusResponse);
+            record.setDesc(orderStatusResponse.getDesc());
+
+            WithDrawState withDrawState = WithDrawState.WithDrawing;
+            //  提现结果 -1:数据问题 0:处理中  1:已记账未支付;2:已支付,状态未知;3:处理成功;
+            //  4:支付失败;5:支付失败,余额已退回 6:已手工重新发起支付
+            if ("0".equals(status) || "4".equals(status) || "5".equals(status)) {
+                withDrawState = WithDrawState.Fail;
+            } else if ("3".equals(status)) {
+                withDrawState = WithDrawState.Success;
+            }
+            record.setWithDrawState(withDrawState);
+            shopWithDrawRecordDao.save(record);
+        }
+        return ResultContent.buildSuccess(record);
+    }
+
+
     //------------------------提现 end-- ------------------------
 
 

+ 11 - 0
PaymentServer/src/main/java/com/zhongshu/payment/server/core/timer/ShopWithDrawTimer.java

@@ -0,0 +1,11 @@
+package com.zhongshu.payment.server.core.timer;
+
+/**
+ * 检查 提现状态的 定时器
+ *
+ * @author TRX
+ * @date 2024/9/6
+ */
+public class ShopWithDrawTimer {
+
+}