wujiefeng пре 1 година
родитељ
комит
8497dc5019

+ 2 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/ProcessWithdrawParam.java

@@ -1,5 +1,6 @@
 package com.zhongshu.card.client.model.pay;
 
+import com.zhongshu.card.client.type.AuditStatus;
 import com.zhongshu.card.client.type.WithdrawStatus;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
@@ -16,7 +17,7 @@ public class ProcessWithdrawParam {
     private String orderNo;
 
     @Schema(description = "审核结果")
-    private WithdrawStatus status;
+    private AuditStatus status;
 
     @Schema(description = "用户id")
     private String userId;

+ 2 - 2
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/WithdrawOrderModel.java

@@ -15,9 +15,9 @@ public class WithdrawOrderModel {
 
     private String id;
 
-    private String createTime;
+    private Long createTime;
 
-    private String updateTime;
+    private Long updateTime;
 
     @Schema(description = "项目oid")
     private String projectOid;

+ 22 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/type/AuditStatus.java

@@ -0,0 +1,22 @@
+package com.zhongshu.card.client.type;
+
+import lombok.Getter;
+
+public enum AuditStatus {
+
+    Wait("待审核", 0),
+    Success("审核成功",1),
+    Fail("审核失败",1)
+    ;
+
+    @Getter
+    private String remark;
+
+    @Getter
+    private Integer sort;
+
+    AuditStatus(String remark, Integer sort) {
+        this.remark = remark;
+        this.sort = sort;
+    }
+}

+ 4 - 8
FullCardClient/src/main/java/com/zhongshu/card/client/type/WithdrawStatus.java

@@ -4,19 +4,15 @@ import lombok.Getter;
 
 public enum WithdrawStatus {
 
-    Processing("提现处理中", 0),
-    Success("提现成功",1),
-    Fail("提现失败",1)
+    Accepted("已受理"),
+    Success("提现成功"),
+    Fail("提现失败")
     ;
 
     @Getter
     private String remark;
 
-    @Getter
-    private Integer sort;
-
-    WithdrawStatus(String remark, Integer sort) {
+    WithdrawStatus(String remark) {
         this.remark = remark;
-        this.sort = sort;
     }
 }

+ 1 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/utils/DateUtils.java

@@ -25,7 +25,7 @@ public class DateUtils {
      */
     public final static String pattern1 = "yyyyMMdd";
 
-    public final static String patternyyyyMMDD = "yyyyMMDD";
+    public final static String patternyyyyMMDD = "yyyyMMdd";
 
     public final static String patternyyyyMMddHHmmssSSS = "yyyyMMddHHmmssSSS";
 

+ 10 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/pay/WithdrawOrder.java

@@ -4,6 +4,7 @@ import com.github.microservice.components.data.mongo.mongo.domain.SuperEntity;
 import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
 import com.github.microservice.types.payment.PaymentType;
 import com.zhongshu.card.client.model.pay.AttachFileModel;
+import com.zhongshu.card.client.type.AuditStatus;
 import com.zhongshu.card.client.type.WithdrawStatus;
 import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
 import com.zhongshu.card.client.type.paySetting.WithdrawType;
@@ -52,6 +53,9 @@ public class WithdrawOrder extends SuperEntity {
     @Schema(description = "附件")
     private List<AttachFileModel> attachFile;
 
+    @Schema(description = "审核状态")
+    private AuditStatus auditStatus;
+
     @Schema(description = "提现状态")
     private WithdrawStatus withdrawStatus;
 
@@ -59,10 +63,14 @@ public class WithdrawOrder extends SuperEntity {
     private String withdrawStatusDesc;
 
     @Schema(description = "发起人")
-    private UserAccount withdrawUser;
+    private String withdrawUser;
+
+    private String withdrawUserId;
 
     @Schema(description = "处理人")
-    private UserAccount processUser;
+    private String processUser;
+
+    private String processUserId;
 
     @Schema(description = "处理时间")
     private Long processTime;

+ 106 - 77
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/WithdrawService.java

@@ -1,6 +1,7 @@
 package com.zhongshu.card.server.core.service.pay;
 
 import com.github.microservice.components.data.base.util.PageEntityUtil;
+import com.github.microservice.components.data.mongo.queue.service.ExecQueueService;
 import com.github.microservice.core.util.JsonUtil;
 import com.github.microservice.pay.client.model.AccountModel;
 import com.github.microservice.pay.client.model.PayProductChannelConf;
@@ -26,6 +27,7 @@ import com.zhongshu.card.client.model.pay.WithdrawOrderModel;
 import com.zhongshu.card.client.model.pay.WithdrawPageParam;
 import com.zhongshu.card.client.model.pay.WithdrawParam;
 import com.zhongshu.card.client.model.paySetting.paySetting.OrgPayConfigModel;
+import com.zhongshu.card.client.type.AuditStatus;
 import com.zhongshu.card.client.type.WithdrawStatus;
 import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
 import com.zhongshu.card.client.utils.DateUtils;
@@ -90,6 +92,9 @@ public class WithdrawService extends SuperService {
     @Autowired
     PayProductAccountService payProductAccountService;
 
+    @Autowired
+    ExecQueueService execQueueService;
+
     /**
      * 查询可提现余额
      */
@@ -149,13 +154,16 @@ public class WithdrawService extends SuperService {
             PayProductParameter<Object> parameter = new PayProductParameter<>();
             parameter.setAccountName(projectAccount);
             parameter.setMeta(Map.of("mchntNo", withdrawMchId));
-                ResultContent<Object> resultContent = senselessPayService.withdrawAmountQuery(parameter);
+            ResultContent<Object> resultContent = senselessPayService.withdrawAmountQuery(parameter);
             if (!resultContent.getState().equals(ResultState.Success)){
-                return null;
+                return com.github.microservice.net.ResultContent.buildFail(resultContent.getMsg());
             }
             String data = JsonUtil.toJson(resultContent.getContent());
             Map map = JsonUtil.toObject(data, Map.class);
-            return com.github.microservice.net.ResultContent.buildContent(Long.parseLong((String) map.get("t0WithdrawAmt")));
+            if (!map.get("respCode").equals("000000")){
+                return com.github.microservice.net.ResultContent.buildFail((String) map.get("respDesc"));
+            }
+            return com.github.microservice.net.ResultContent.buildContent(Long.parseLong((String) map.get("tzWithdrawAmt")));
         }
 
         PayAccount settleAccount = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.Settle);
@@ -200,7 +208,7 @@ public class WithdrawService extends SuperService {
         //校验提现金额是否大约可以提现金额
         com.github.microservice.net.ResultContent<Long> resultContent = queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
 
-        if (!resultContent.getState().equals(ResultState.Success)){
+        if (!resultContent.getState().equals(com.github.microservice.net.ResultState.Success)){
             return com.github.microservice.net.ResultContent.buildFail(resultContent.getMsg());
         }
         Long waitAmount = resultContent.getContent();
@@ -248,9 +256,10 @@ public class WithdrawService extends SuperService {
         withdrawOrder.setBankAccountNumber(orgPayConfig.getBankSubName() + orgPayConfig.getBankName() + orgPayConfig.getBankAccountNumber());
         withdrawOrder.setOrderNo(withdrawOrderNo);
         withdrawOrder.setAmount(amount);
-        withdrawOrder.setWithdrawStatus(WithdrawStatus.Processing);
-        withdrawOrder.setSort(WithdrawStatus.Processing.getSort());
-        withdrawOrder.setWithdrawUser(userAccounts.get(0));
+        withdrawOrder.setAuditStatus(AuditStatus.Wait);
+        withdrawOrder.setSort(AuditStatus.Wait.getSort());
+        withdrawOrder.setWithdrawUser(userAccounts.get(0).getName());
+        withdrawOrder.setWithdrawUserId(userAccounts.get(0).getUserId());
         withdrawOrder.setFrozenTransactionLogs(transfer.getContent());
         withdrawOrder.setProjectOid(projectOid);
         withdrawOrder.setOid(oid);
@@ -262,6 +271,7 @@ public class WithdrawService extends SuperService {
     /**
      * 审核
      */
+    @SneakyThrows
     public com.github.microservice.net.ResultContent withdraw(ProcessWithdrawParam param){
         String userId = param.getUserId();
         if (StringUtils.isBlank(userId)){
@@ -288,7 +298,7 @@ public class WithdrawService extends SuperService {
             return com.github.microservice.net.ResultContent.buildFail("数据不存在");
         }
         //判断状态是否为待审核
-        if (!withdrawOrder.getWithdrawStatus().equals(WithdrawStatus.Processing)){
+        if (!withdrawOrder.getAuditStatus().equals(AuditStatus.Wait)){
             return com.github.microservice.net.ResultContent.buildFail("只能操作处理中的订单");
         }
 
@@ -296,72 +306,30 @@ public class WithdrawService extends SuperService {
         PayAccount projectAccount = payAccountService.getProjectChildren(withdrawOrder.getProjectOid(), PaymentChannelType.SecretFreePayment);
         PayAccount settleAccount = payAccountService.getOrgChildren(withdrawOrder.getProjectOid(), withdrawOrder.getOid(), PaymentChannelType.Settle);
 
-        //TODO 审批通过, 判断当前可提现余额是否大于提现订单金额
-        if (param.getStatus().equals(WithdrawStatus.Success)){//审批通过
-
+        withdrawOrder.setAttachInfo(param.getAttachInfo());
+        withdrawOrder.setAttachFile(param.getAttachFile());
 
-            //TODO 判断是否线上提现,调用支付渠道对应的提现接口
+        //TODO 审批通过, 判断当前可提现余额是否大于提现订单金额
+        if (param.getStatus().equals(AuditStatus.Success)){//审批通过
+            withdrawOrder.setAuditStatus(AuditStatus.Success);
+            withdrawOrder.setSort(AuditStatus.Success.getSort());
+            //判断是否线上提现,调用支付渠道对应的提现接口
             if (withdrawOrder.getWithdrawMethodType().equals(WithdrawMethodType.OnLine)) {
-                switch (withdrawOrder.getPaymentType()){
-                    case UnionFrictionlessPay-> {
-                        String orgAccount = orgPayAccountService.queryOgPayAccount(withdrawOrder.getOid(), PaymentType.UnionFrictionlessPay);
-                        String projectPayAccount = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
-
-                        ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(orgAccount);
-
-                        if (!accountModelResultContent.getState().equals(ResultState.Success)){
-                            return com.github.microservice.net.ResultContent.buildFail(accountModelResultContent.getMsg());
-                        }
-
-                        ChinaumsSenselessConf conf = (ChinaumsSenselessConf)accountModelResultContent.getContent().getConf();
-                        String withdrawMchId = conf.getWithdrawMchId();
-                        if (StringUtils.isEmpty(withdrawMchId)){
-                            return com.github.microservice.net.ResultContent.buildFail("未配置提现商户号");
-                        }
-
-                        PayProductParameter<Object> parameter = new PayProductParameter<>();
-                        parameter.setAccountName(projectPayAccount);
-                        parameter.setMeta(Map.of("mchntNo", withdrawMchId,"orderNo", withdrawOrder.getOrderNo(), "amount", withdrawOrder.getAmount()));
-                        ResultContent<Object> withdrawRet = senselessPayService.withdraw(parameter);
-                        withdrawOrder.setExpand(withdrawRet.getContent());
-                        if (!withdrawRet.getState().equals(ResultState.Success)){//银联提现失败
-                            withdrawOrder.setWithdrawStatusDesc("银行处理失败");
-                            //划账退回金额: 机构已冻结金额- 机构已结算 +
-                            TransferTransactionsModel transferTransactionsModel = buildTransferModel(settleAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
-                                    withdrawOrder.getAmount(), TransactionType.WithdrawRefund,
-                                    Map.of("paymentType", withdrawOrder.getPaymentType(), "paymentChannelType", withdrawOrder.getPaymentType().getChannelType(), "description", "提现退回"));
-                            ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferTransactionsModel);
-                            if (!transfer.getState().equals(ResultState.Success)){
-                                withdrawOrder.setWithdrawStatusDesc("银行处理失败,余额退回失败");
-                                withdrawOrderDao.save(withdrawOrder);
-                                return com.github.microservice.net.ResultContent.buildFail("银行处理失败,余额退回失败");
-                            }
-                            withdrawOrder.setWithdrawTransactionLogs(transfer.getContent());
-                            withdrawOrder.setWithdrawStatus(WithdrawStatus.Fail);
-                            withdrawOrderDao.save(withdrawOrder);
-                            return com.github.microservice.net.ResultContent.buildFail(withdrawRet.getMsg());
-                        }
-
-                    }
+                return onlineWithdraw(withdrawOrder, userAccounts.get(0), settleAccount, withdrawFrozenAccount);
+            }else {
+                //划账,机构已冻结金额- 项目无感支付+
+                TransferTransactionsModel transferTransactionsModel = buildTransferModel(projectAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
+                        withdrawOrder.getAmount(), TransactionType.Withdrawal,
+                        Map.of("paymentType", withdrawOrder.getPaymentType(), "paymentChannelType", withdrawOrder.getPaymentType().getChannelType(), "description", "提现"));
+                ResultContent<List<TransactionLogModel>> transferResult = transactionLogService.transfer(transferTransactionsModel);
+                if (!transferResult.getState().equals(ResultState.Success)){
+                    return com.github.microservice.net.ResultContent.buildFail(transferResult.getMsg());
                 }
+                withdrawOrder.setWithdrawTransactionLogs(transferResult.getContent());
             }
-
-            //划账,机构已冻结金额- 项目无感支付+
-            TransferTransactionsModel transferTransactionsModel = buildTransferModel(projectAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
-                    withdrawOrder.getAmount(), TransactionType.Withdrawal,
-                    Map.of("paymentType", withdrawOrder.getPaymentType(), "paymentChannelType", withdrawOrder.getPaymentType().getChannelType(), "description", "提现"));
-            ResultContent<List<TransactionLogModel>> transferResult = transactionLogService.transfer(transferTransactionsModel);
-            if (!transferResult.getState().equals(ResultState.Success)){
-                return com.github.microservice.net.ResultContent.buildFail(transferResult.getMsg());
-            }
-            withdrawOrder.setWithdrawTransactionLogs(transferResult.getContent());
-
-            withdrawOrder.setWithdrawStatus(WithdrawStatus.Success);
-            withdrawOrder.setSort(WithdrawStatus.Success.getSort());
-//            withdrawOrder.setReceiveAmount(withdrawOrder.getAmount().movePointLeft(2));
-        }else if (param.getStatus().equals(WithdrawStatus.Fail)){ //审批拒绝
-            withdrawOrder.setWithdrawStatus(WithdrawStatus.Fail);
-            withdrawOrder.setSort(WithdrawStatus.Fail.getSort());
+        }else if (param.getStatus().equals(AuditStatus.Fail)){ //审批拒绝
+            withdrawOrder.setAuditStatus(AuditStatus.Fail);
+            withdrawOrder.setSort(AuditStatus.Fail.getSort());
             //划账退回金额: 机构已冻结金额- 机构已结算 +
             TransferTransactionsModel transferTransactionsModel = buildTransferModel(settleAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
                     withdrawOrder.getAmount(), TransactionType.WithdrawRefund,
@@ -374,12 +342,74 @@ public class WithdrawService extends SuperService {
         }
         withdrawOrder.setAttachInfo(param.getAttachInfo());
         withdrawOrder.setAttachFile(param.getAttachFile());
-        withdrawOrder.setProcessUser(userAccounts.get(0));
+        withdrawOrder.setProcessUser(userAccounts.get(0).getName());
+        withdrawOrder.setWithdrawUserId(userAccounts.get(0).getUserId());
         withdrawOrder.setProcessTime(System.currentTimeMillis());
         withdrawOrderDao.save(withdrawOrder);
         return com.github.microservice.net.ResultContent.buildSuccess();
     }
 
+    @SneakyThrows
+    private com.github.microservice.net.ResultContent onlineWithdraw(WithdrawOrder withdrawOrder, UserAccount userAccount, PayAccount settleAccount, PayAccount withdrawFrozenAccount) {
+        switch (withdrawOrder.getPaymentType()){
+            case UnionFrictionlessPay-> {
+                String orgAccount = orgPayAccountService.queryOgPayAccount(withdrawOrder.getOid(), PaymentType.UnionFrictionlessPay);
+                String projectPayAccount = orgPayAccountService.queryOgPayAccount(withdrawOrder.getProjectOid(), PaymentType.UnionFrictionlessPay);
+
+                ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(orgAccount);
+
+                if (!accountModelResultContent.getState().equals(ResultState.Success)){
+                    return com.github.microservice.net.ResultContent.buildFail(accountModelResultContent.getMsg());
+                }
+
+                ChinaumsSenselessConf conf = (ChinaumsSenselessConf)accountModelResultContent.getContent().getConf();
+                String withdrawMchId = conf.getWithdrawMchId();
+                if (StringUtils.isEmpty(withdrawMchId)){
+                    return com.github.microservice.net.ResultContent.buildFail("未配置提现商户号");
+                }
+
+                PayProductParameter<Object> parameter = new PayProductParameter<>();
+                parameter.setAccountName(projectPayAccount);
+                parameter.setMeta(Map.of("mchntNo", withdrawMchId,"orderNo", withdrawOrder.getOrderNo(), "amount", withdrawOrder.getAmount().toString()));
+                ResultContent<Object> withdrawRet = senselessPayService.withdraw(parameter);
+                withdrawOrder.setExpand(withdrawRet.getContent());
+
+                Map bodyMap = JsonUtil.toObject(JsonUtil.toJson(withdrawRet.getContent()), Map.class);
+
+                if (!bodyMap.get("respCode").equals("000000")){//银联提现失败
+                    withdrawOrder.setWithdrawStatusDesc("银行处理失败");
+                    //划账退回金额: 机构已冻结金额- 机构已结算 +
+                    TransferTransactionsModel transferTransactionsModel = buildTransferModel(settleAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
+                            withdrawOrder.getAmount(), TransactionType.WithdrawRefund,
+                            Map.of("paymentType", withdrawOrder.getPaymentType(), "paymentChannelType", withdrawOrder.getPaymentType().getChannelType(), "description", "提现退回"));
+                    ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferTransactionsModel);
+                    if (!transfer.getState().equals(ResultState.Success)){
+                        withdrawOrder.setWithdrawStatusDesc("银行处理失败,余额退回失败");
+                        withdrawOrderDao.save(withdrawOrder);
+                        return com.github.microservice.net.ResultContent.buildFail("银行处理失败,余额退回失败");
+                    }
+                    withdrawOrder.setWithdrawTransactionLogs(transfer.getContent());
+                    withdrawOrder.setWithdrawStatus(WithdrawStatus.Fail);
+                    withdrawOrderDao.save(withdrawOrder);
+                    return com.github.microservice.net.ResultContent.buildFail((String) bodyMap.get("respDesc"));
+                }else {
+                    withdrawOrder.setWithdrawStatus(WithdrawStatus.Accepted);
+                    withdrawOrder.setWithdrawStatusDesc("银行已受理");
+                }
+                withdrawOrder.setProcessUser(userAccount.getName());
+                withdrawOrder.setProcessUserId(userAccount.getUserId());
+                withdrawOrder.setProcessTime(System.currentTimeMillis());
+                withdrawOrderDao.save(withdrawOrder);
+                execQueueService.add(Map.of("withdrawOrderId", withdrawOrder.getId()), 5, data->{
+                    withdrawQuery((String) data.get("withdrawOrderId"));
+                    return false;
+                });
+                return com.github.microservice.net.ResultContent.buildSuccess();
+            }
+        }
+        return com.github.microservice.net.ResultContent.buildFail("该支付产品不支持线上提现方式");
+    }
+
     private TransferTransactionsModel buildTransferModel(PayAccount credit, PayAccount debit, String orderNo, BigDecimal amount, TransactionType type, Map<String, Object> meta){
         TransferTransactionsModel transferModel = new TransferTransactionsModel();
         //构建出账账户
@@ -431,12 +461,6 @@ public class WithdrawService extends SuperService {
         WithdrawOrderModel model = new WithdrawOrderModel();
         if (withdrawOrder!=null){
             BeanUtils.copyProperties(withdrawOrder, model, "withdrawUser", "processUser");
-            if (withdrawOrder.getWithdrawUser()!=null){
-                model.setWithdrawUser(withdrawOrder.getWithdrawUser().getName());
-            }
-            if (withdrawOrder.getProcessUser()!=null){
-                model.setProcessUser(withdrawOrder.getProcessUser().getName());
-            }
         }
         return model;
     }
@@ -451,6 +475,11 @@ public class WithdrawService extends SuperService {
         if (withdrawOrder == null){
             return com.github.microservice.net.ResultContent.buildFail("数据不存在");
         }
+
+        if (!WithdrawStatus.Accepted.equals(withdrawOrder.getWithdrawStatus())){
+//            return ResultContent.buildContent(withdrawOrder.getWithdrawStatus())
+        }
+
         switch (withdrawOrder.getPaymentType()){
             case UnionFrictionlessPay -> {