Преглед на файлове

Merge remote-tracking branch 'origin/master'

TRX преди 1 година
родител
ревизия
faae4cc4b2

+ 4 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/ChinaumsSenselessPayService.java

@@ -449,6 +449,10 @@ public class ChinaumsSenselessPayService extends SuperService {
 
     @SneakyThrows
     public ResultContent<UnionFrictionlessPayFinishModel> refundQuery(String projectOid, String userId, String oid, String refundOrderNo, Boolean handle) {
+        System.out.println("触发退款查询" + DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyyMMddHHmmssSSS));
+        if (handle){
+            throw new RuntimeException("refundQuery异常");
+        }
         String projectAccountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
         com.github.microservice.pay.client.ret.ResultContent<AccountModel> projectAccountModelResultContent = payProductAccountService.get(projectAccountName);
         if (!projectAccountModelResultContent.getState().equals(ResultState.Success)) {

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

@@ -2,14 +2,18 @@ package com.zhongshu.card.server.core.service.pay;
 
 import com.github.microservice.components.data.base.util.PageEntityUtil;
 import com.github.microservice.core.util.JsonUtil;
+import com.github.microservice.pay.client.model.AccountModel;
+import com.github.microservice.pay.client.model.PayProductChannelConf;
 import com.github.microservice.pay.client.model.PayProductParameter;
 import com.github.microservice.pay.client.model.ledger.GeneralLedgerQueryModel;
 import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
 import com.github.microservice.pay.client.model.ledger.TransferTransactionsModel;
 import com.github.microservice.pay.client.model.ledger.transaction.GeneralLedgerQueryTransactionLogModel;
 import com.github.microservice.pay.client.model.ledger.transaction.TransactionLogAggregateRetModel;
+import com.github.microservice.pay.client.product.senseless.chinaumsSenseless.conf.ChinaumsSenselessConf;
 import com.github.microservice.pay.client.ret.ResultContent;
 import com.github.microservice.pay.client.ret.ResultState;
+import com.github.microservice.pay.client.service.PayProductAccountService;
 import com.github.microservice.pay.client.service.ledger.GeneralLedgerService;
 import com.github.microservice.pay.client.service.ledger.TransactionLogService;
 import com.github.microservice.pay.client.service.product.SenselessPayService;
@@ -83,6 +87,9 @@ public class WithdrawService extends SuperService {
     @Autowired
     OrgPayAccountService orgPayAccountService;
 
+    @Autowired
+    PayProductAccountService payProductAccountService;
+
     /**
      * 查询可提现余额
      */
@@ -113,28 +120,42 @@ public class WithdrawService extends SuperService {
         if (StringUtils.isBlank(oid)){
             oid = getCurrentOid();
         }
-        Long amount = queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
-        if (null == amount){
-            return  com.github.microservice.net.ResultContent.buildFail("查询余额失败");
-        }
-        return com.github.microservice.net.ResultContent.buildContent(amount);
+        return queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
+//        if (null == amount){
+//            return  com.github.microservice.net.ResultContent.buildFail("查询余额失败");
+//        }
+//        return com.github.microservice.net.ResultContent.buildContent(amount);
     }
 
     @SneakyThrows
-    private Long queryWithdrawAmountByPaymentType(String projectOid, String oid, PaymentType paymentType) {
+    private com.github.microservice.net.ResultContent<Long> queryWithdrawAmountByPaymentType(String projectOid, String oid, PaymentType paymentType) {
 
         if (paymentType.equals(PaymentType.UnionFrictionlessPay)){
             String orgAccount = orgPayAccountService.queryOgPayAccount(oid, paymentType);
+            String projectAccount = orgPayAccountService.queryOgPayAccount(projectOid, paymentType);
+
+            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(orgAccount);
-            parameter.setMeta(new HashMap<>());
-            ResultContent<Object> resultContent = senselessPayService.withdrawAmountQuery(parameter);
+            parameter.setAccountName(projectAccount);
+            parameter.setMeta(Map.of("mchntNo", withdrawMchId));
+                ResultContent<Object> resultContent = senselessPayService.withdrawAmountQuery(parameter);
             if (!resultContent.getState().equals(ResultState.Success)){
                 return null;
             }
             String data = JsonUtil.toJson(resultContent.getContent());
             Map map = JsonUtil.toObject(data, Map.class);
-            return Long.parseLong((String) map.get("t0WithdrawAmt"));
+            return com.github.microservice.net.ResultContent.buildContent(Long.parseLong((String) map.get("t0WithdrawAmt")));
         }
 
         PayAccount settleAccount = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.Settle);
@@ -143,9 +164,10 @@ public class WithdrawService extends SuperService {
         queryTransactionLogModel.setGeneralLedgerId(new String[]{settleAccount.getLedgerId()});
         ResultContent<TransactionLogAggregateRetModel> aggregateRetModelResultContent = transactionLogService.aggregateAmount(queryTransactionLogModel);
         if (!aggregateRetModelResultContent.getState().equals(ResultState.Success)){
-            return null;
+            return com.github.microservice.net.ResultContent.buildFail(aggregateRetModelResultContent.getMsg());
         }
-        return aggregateRetModelResultContent.getContent().getStatistics().getCreditCount() - aggregateRetModelResultContent.getContent().getStatistics().getDebitCount();
+        long amount = aggregateRetModelResultContent.getContent().getStatistics().getCreditCount() + aggregateRetModelResultContent.getContent().getStatistics().getDebitCount();
+        return com.github.microservice.net.ResultContent.buildContent(amount);
     }
 
     /**
@@ -176,10 +198,12 @@ public class WithdrawService extends SuperService {
         }
 
         //校验提现金额是否大约可以提现金额
-        Long waitAmount = queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
-        if (null == waitAmount){
-            return com.github.microservice.net.ResultContent.buildFail("当前可提现余额为0");
+        com.github.microservice.net.ResultContent<Long> resultContent = queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
+
+        if (!resultContent.getState().equals(ResultState.Success)){
+            return com.github.microservice.net.ResultContent.buildFail(resultContent.getMsg());
         }
+        Long waitAmount = resultContent.getContent();
         if (amount.compareTo(new BigDecimal(waitAmount))>0){
             return com.github.microservice.net.ResultContent.buildFail("大于可提现金额");
         }
@@ -280,10 +304,24 @@ public class WithdrawService extends SuperService {
             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<>();
-                        String orgAccountName = orgPayAccountService.queryOgPayAccount(withdrawOrder.getOid(), PaymentType.UnionFrictionlessPay);
-                        parameter.setAccountName(orgAccountName);
-                        parameter.setMeta(Map.of("orderNo", withdrawOrder.getOrderNo(), "amount", withdrawOrder.getAmount()));
+                        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)){//银联提现失败
@@ -415,16 +453,40 @@ public class WithdrawService extends SuperService {
         }
         switch (withdrawOrder.getPaymentType()){
             case UnionFrictionlessPay -> {
-                String orgAccount = orgPayAccountService.queryOgPayAccount(withdrawOrder.getOid(), withdrawOrder.getPaymentType());
+
+
+                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(orgAccount);
-                parameter.setMeta(Map.of("orderNo", withdrawOrder.getOrderNo(), "transDate", DateUtils.paresTime(withdrawOrder.getCreateTime(), DateUtils.patternyyyyMMDD)));
+                parameter.setAccountName(projectPayAccount);
+
+                parameter.setMeta(Map.of("mchntNo", withdrawMchId,"orderNo", withdrawOrder.getOrderNo(), "transDate", DateUtils.paresTime(withdrawOrder.getCreateTime(), DateUtils.patternyyyyMMDD)));
+
                 ResultContent<Object> resultContent = senselessPayService.withdrawQuery(parameter);
                 if (!resultContent.getState().equals(ResultState.Success)){
                     return resultContent;
                 }
                 String json = JsonUtil.toJson(resultContent.getContent());
                 Map map = JsonUtil.toObject(json, Map.class);
+                //TODO 有问题,提现时,如果是银联,则不从机构冻结账本- 项目账本+,这里成功再加,这里失败,机构冻结- 机构已结算账本+
+
+                PayAccount orgChildren = payAccountService.getOrgChildren(withdrawOrder.getProjectOid(), withdrawOrder.getOid(), PaymentChannelType.WithdrawFrozen);
+                PayAccount projectChildren = payAccountService.getProjectChildren(withdrawOrder.getProjectOid(), withdrawOrder.getPaymentType().getChannelType());
+
+//                buildTransferModel(projectChildren, orgChildren, withdrawOrder.getOrderNo(), withdrawOrder.getAmount(), TransactionType.Withdrawal, )
                 return ResultContent.buildContent(map.get("desc"));
             }
         }