Răsfoiți Sursa

监听银联签约通知

wujiefeng 1 an în urmă
părinte
comite
3b4e29a35f

+ 1 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/pay/senseless/ChinaumsSenselessPayController.java

@@ -41,4 +41,5 @@ public class ChinaumsSenselessPayController {
     public Object queryUserSignInfo(){
     public Object queryUserSignInfo(){
         return chinaumsSenselessPayService.queryUserSignInfo(null, null);
         return chinaumsSenselessPayService.queryUserSignInfo(null, null);
     }
     }
+
 }
 }

+ 5 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/pay/ChinaumsSenselessUserSignInfo.java

@@ -54,6 +54,11 @@ public class ChinaumsSenselessUserSignInfo extends SuperEntity {
     @Indexed
     @Indexed
     private ContractState contractState;
     private ContractState contractState;
 
 
+    /**
+     * 超时时间
+     */
+    private Long expireTime;
+
     /**
     /**
      * 协议签约时间
      * 协议签约时间
 
 

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

@@ -29,6 +29,7 @@ import com.zhongshu.card.server.core.service.paySetting.OrgPayAccountService;
 import com.zhongshu.card.server.core.util.BeanUtils;
 import com.zhongshu.card.server.core.util.BeanUtils;
 import com.zhongshu.card.server.core.util.CommonUtil;
 import com.zhongshu.card.server.core.util.CommonUtil;
 import io.micrometer.common.util.StringUtils;
 import io.micrometer.common.util.StringUtils;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -93,15 +94,28 @@ public class ChinaumsSenselessPayService extends SuperService {
                 case SIGNED -> {//已签约
                 case SIGNED -> {//已签约
                     return ResultContent.buildFail("签约已完成,请勿重复请求");
                     return ResultContent.buildFail("签约已完成,请勿重复请求");
                 }
                 }
-                case UNSIGNED, RESCISSION -> {//未签约,已解约
+                case UNSIGNED -> {//未签约,已解约
                     return signApply(param, accountName, userId, mid);
                     return signApply(param, accountName, userId, mid);
                 }
                 }
-                case DELETING_CONTRACT, APPLY -> {
-                    return ResultContent.buildFail("正在签约中,请等待银行返回结果");
+                case RESCISSION ->{
+                    chinaumsSenselessUserSignInfoDao.deleteById(userSignInfo.getId());
+                    return signApply(param, accountName, userId, mid);
+                }
+                case APPLY -> {
+                    if (System.currentTimeMillis() >= userSignInfo.getExpireTime()){
+                        chinaumsSenselessUserSignInfoDao.deleteById(userSignInfo.getId());
+                        ChinaumsSenselessUserSignInfo newUserSignInfo = new ChinaumsSenselessUserSignInfo();
+                        newUserSignInfo.setContractState(ContractState.UNSIGNED);
+                        return ResultContent.buildContent(newUserSignInfo);
+                    }
+                    return ResultContent.buildContent(toUserSignModel(userSignInfo));
                 }
                 }
                 case UNKNOWN ->{
                 case UNKNOWN ->{
                     return ResultContent.buildFail("未知状态,请联系管理人员");
                     return ResultContent.buildFail("未知状态,请联系管理人员");
                 }
                 }
+                case DELETING_CONTRACT ->{
+                    return ResultContent.buildFail("解约中,请等待银行返回结果");
+                }
             }
             }
         }else {
         }else {
             return signApply(param, accountName, userId, mid);
             return signApply(param, accountName, userId, mid);
@@ -110,6 +124,7 @@ public class ChinaumsSenselessPayService extends SuperService {
         return ResultContent.buildFail("数据不存在,请联系管理员");
         return ResultContent.buildFail("数据不存在,请联系管理员");
     }
     }
 
 
+    @SneakyThrows
     private Object signApply(UnionApplySignParam param, String accountName, String userId, String mid) {
     private Object signApply(UnionApplySignParam param, String accountName, String userId, String mid) {
         PayProductParameter<Object> payProductParameter = new PayProductParameter<>();
         PayProductParameter<Object> payProductParameter = new PayProductParameter<>();
         payProductParameter.setAccountName(accountName);
         payProductParameter.setAccountName(accountName);
@@ -117,9 +132,10 @@ public class ChinaumsSenselessPayService extends SuperService {
         com.github.microservice.pay.client.ret.ResultContent<Object> signApplyResultContent = senselessPayService.signApply(payProductParameter);
         com.github.microservice.pay.client.ret.ResultContent<Object> signApplyResultContent = senselessPayService.signApply(payProductParameter);
         if (signApplyResultContent.getState().equals(ResultState.Success)){
         if (signApplyResultContent.getState().equals(ResultState.Success)){
             Object content = signApplyResultContent.getContent();
             Object content = signApplyResultContent.getContent();
-            Map<String, Object> resultMap = BeanUtil.bean2Map(content);
-            String errCode = (String) resultMap.get("errCode");
-            if ("SUCCESS".equals(errCode)){
+            String json = JsonUtil.toJson(content);
+            Map resultMap = JsonUtil.toObject(json, Map.class);
+            String errMsg = (String) resultMap.get("errMsg");
+            if ("success".equals(errMsg)){
                 ChinaumsSenselessUserSignInfo userSignInfo = new ChinaumsSenselessUserSignInfo();
                 ChinaumsSenselessUserSignInfo userSignInfo = new ChinaumsSenselessUserSignInfo();
                 userSignInfo.setUserId(userId);
                 userSignInfo.setUserId(userId);
                 userSignInfo.setContractNo(param.getContractNo());
                 userSignInfo.setContractNo(param.getContractNo());
@@ -128,6 +144,7 @@ public class ChinaumsSenselessPayService extends SuperService {
                 userSignInfo.setRelateSsn((String) resultMap.get("relateSsn"));
                 userSignInfo.setRelateSsn((String) resultMap.get("relateSsn"));
                 userSignInfo.setCqpMpAppId((String) resultMap.get("cqpMpAppId"));
                 userSignInfo.setCqpMpAppId((String) resultMap.get("cqpMpAppId"));
                 userSignInfo.setCqpMpPath((String) resultMap.get("cqpMpPath"));
                 userSignInfo.setCqpMpPath((String) resultMap.get("cqpMpPath"));
+                userSignInfo.setExpireTime(System.currentTimeMillis() + 30*60*1000);
                 chinaumsSenselessUserSignInfoDao.save(userSignInfo);
                 chinaumsSenselessUserSignInfoDao.save(userSignInfo);
                 return signApplyResultContent;
                 return signApplyResultContent;
             }else {
             }else {
@@ -140,6 +157,7 @@ public class ChinaumsSenselessPayService extends SuperService {
     /**
     /**
      * 解约
      * 解约
      */
      */
+    @SneakyThrows
     public Object signCancel(String userId, String projectOid) {
     public Object signCancel(String userId, String projectOid) {
         if (StringUtils.isBlank(userId)){
         if (StringUtils.isBlank(userId)){
             userId = getCurrentUserId();
             userId = getCurrentUserId();
@@ -177,9 +195,15 @@ public class ChinaumsSenselessPayService extends SuperService {
             payProductParameter.setMeta(Map.of("contractId", userSignInfo.getContractId()));
             payProductParameter.setMeta(Map.of("contractId", userSignInfo.getContractId()));
             com.github.microservice.pay.client.ret.ResultContent<Object> objectResultContent = senselessPayService.signCancel(payProductParameter);
             com.github.microservice.pay.client.ret.ResultContent<Object> objectResultContent = senselessPayService.signCancel(payProductParameter);
             if (objectResultContent.getState().equals(ResultState.Success)){
             if (objectResultContent.getState().equals(ResultState.Success)){
-                userSignInfo.setContractState(ContractState.DELETING_CONTRACT);
-                chinaumsSenselessUserSignInfoDao.save(userSignInfo);
-                return ResultContent.buildSuccess();
+                String json = JsonUtil.toJson(objectResultContent.getContent());
+                Map resultMap = JsonUtil.toObject(json, Map.class);
+                String errMsg = (String) resultMap.get("errMsg");
+                if ("success".equals(errMsg)){
+                    userSignInfo.setContractState(ContractState.DELETING_CONTRACT);
+                    chinaumsSenselessUserSignInfoDao.save(userSignInfo);
+                    return ResultContent.buildSuccess();
+                }
+               return ResultContent.buildFail((String) resultMap.get("errMsg"));
             }
             }
             return ResultContent.buildFail("解约失败");
             return ResultContent.buildFail("解约失败");
         }
         }
@@ -187,6 +211,8 @@ public class ChinaumsSenselessPayService extends SuperService {
         return ResultContent.buildFail("当前状态不可解约,请稍后再试");
         return ResultContent.buildFail("当前状态不可解约,请稍后再试");
     }
     }
 
 
+
+    //TODO 添加 判断是否在平台外已经签约逻辑
     public Object queryUserSignInfo(String userId, String projectOid){
     public Object queryUserSignInfo(String userId, String projectOid){
         if (StringUtils.isBlank(userId)){
         if (StringUtils.isBlank(userId)){
             userId = getCurrentUserId();
             userId = getCurrentUserId();
@@ -218,13 +244,13 @@ public class ChinaumsSenselessPayService extends SuperService {
     /**
     /**
      * 支付
      * 支付
      */
      */
-    public Object senselessPay(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String remark) {
+    public ResultContent senselessPay(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String remark) {
 
 
         //获取银联支付产品账户及需要签约的商户号
         //获取银联支付产品账户及需要签约的商户号
         String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
         String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
         com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
         com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
         if (!accountModelResultContent.getState().equals(ResultState.Success)){
         if (!accountModelResultContent.getState().equals(ResultState.Success)){
-            return accountModelResultContent;
+            return ResultContent.buildFail(accountModelResultContent.getMsg());
         }
         }
         ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
         ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
         String mid = conf.getMchId();
         String mid = conf.getMchId();
@@ -245,7 +271,7 @@ public class ChinaumsSenselessPayService extends SuperService {
         request.setAttachedData(remark);
         request.setAttachedData(remark);
         payProductParameter.setMeta(BeanUtil.bean2Map(request));
         payProductParameter.setMeta(BeanUtil.bean2Map(request));
         com.github.microservice.pay.client.ret.ResultContent<Object> collectionResultContent = senselessPayService.collection(payProductParameter);
         com.github.microservice.pay.client.ret.ResultContent<Object> collectionResultContent = senselessPayService.collection(payProductParameter);
-        return collectionResultContent;
+        return ResultContent.buildContent(collectionResultContent.getContent());
     }
     }
 
 
     public Object refund(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String refundOrderNo, String remark) {
     public Object refund(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String refundOrderNo, String remark) {

+ 8 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/OrgOverviewService.java

@@ -282,8 +282,14 @@ public class OrgOverviewService extends SuperService {
         //获取已结算账本
         //获取已结算账本
         PayAccount settleAccount = payAccountService.getOrgChildren(projectOid, oidList.get(0), PaymentChannelType.Settle);
         PayAccount settleAccount = payAccountService.getOrgChildren(projectOid, oidList.get(0), PaymentChannelType.Settle);
 
 
-//        transactionLogService.aggregate()
-        return null;
+        GeneralLedgerQueryTransactionLogModel queryModel = new GeneralLedgerQueryTransactionLogModel();
+        queryModel.setGeneralLedgerId(new String[]{settleAccount.getLedgerId()});
+        queryModel.setStartTime(param.getStartTime());
+        queryModel.setEndTime(param.getEndTime());
+        queryModel.setFilter(Map.of("transactionType",new Document("$ne", "Settle")));
+        queryModel.setPage(pageableModel);
+
+        return transactionLogService.settleAggregate(queryModel);
     }
     }
 
 
 
 

+ 8 - 5
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/SettleService.java

@@ -67,8 +67,12 @@ public class SettleService {
         if (aggregateResult.getContent().getPages().getContent().isEmpty()){
         if (aggregateResult.getContent().getPages().getContent().isEmpty()){
             return ResultContent.buildContent(new HashSet<>());
             return ResultContent.buildContent(new HashSet<>());
         }
         }
+        List<TransactionLogModel> transactionLogModelList = aggregateResult.getContent().getPages().getContent();
         Set<String> orderNoSet = new HashSet<>();
         Set<String> orderNoSet = new HashSet<>();
-        Set<String> collect = aggregateResult.getContent().getPages().getContent().stream().map(TransactionLogModel::getOrderNumber).collect(Collectors.toSet());
+        List<String> settleList = transactionLogModelList.stream().map(it -> {
+            orderNoSet.add(it.getOrderNumber());
+            return it.getId();
+        }).toList();
 
 
 
 
         //收入-支出=可提现金额
         //收入-支出=可提现金额
@@ -87,7 +91,7 @@ public class SettleService {
         sourceTransaction.setTransactionStatus(TransactionStatus.Success);
         sourceTransaction.setTransactionStatus(TransactionStatus.Success);
         sourceTransaction.setAmount(-settleAmount);
         sourceTransaction.setAmount(-settleAmount);
         sourceTransaction.setRemark(remark);
         sourceTransaction.setRemark(remark);
-        sourceTransaction.setMeta(Map.of("paymentType", paymentType, "paymentChannelType", paymentType.getChannelType(), "description", "结算"));
+        sourceTransaction.setMeta(Map.of("orderSize", orderNoSet.size(),"transactionLogList", settleList,"paymentType", paymentType, "paymentChannelType", paymentType.getChannelType(), "description", "结算"));
         transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
         transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
         //构建入账账户
         //构建入账账户
         TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
         TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
@@ -97,14 +101,13 @@ public class SettleService {
         destinationTransaction.setTransactionStatus(TransactionStatus.Success);
         destinationTransaction.setTransactionStatus(TransactionStatus.Success);
         destinationTransaction.setAmount(settleAmount);
         destinationTransaction.setAmount(settleAmount);
         destinationTransaction.setRemark(remark);
         destinationTransaction.setRemark(remark);
-        destinationTransaction.setMeta(Map.of("paymentType", paymentType, "paymentChannelType", paymentType.getChannelType(), "description", "结算"));
+        destinationTransaction.setMeta(Map.of("orderSize", orderNoSet.size(),"transactionLogList", settleList,"paymentType", paymentType, "paymentChannelType", paymentType.getChannelType(), "description", "结算"));
         transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
         transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
         ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferModel);
         ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferModel);
 
 
         List<TransactionLogModel> content = aggregateResult.getContent().getPages().getContent();
         List<TransactionLogModel> content = aggregateResult.getContent().getPages().getContent();
 
 
         if (transfer.getState().equals(ResultState.Success)){
         if (transfer.getState().equals(ResultState.Success)){
-
             content.forEach(it -> {
             content.forEach(it -> {
                 UpdateTransactionLogModel updateTransactionLogModel = new UpdateTransactionLogModel();
                 UpdateTransactionLogModel updateTransactionLogModel = new UpdateTransactionLogModel();
                 Map<String, Object> meta = it.getMeta();
                 Map<String, Object> meta = it.getMeta();
@@ -112,7 +115,7 @@ public class SettleService {
                 updateTransactionLogModel.setMeta(meta);
                 updateTransactionLogModel.setMeta(meta);
                 updateTransactionLogModel.setId(it.getId());
                 updateTransactionLogModel.setId(it.getId());
                 transactionLogService.update(updateTransactionLogModel);
                 transactionLogService.update(updateTransactionLogModel);
-                orderNoSet.add(it.getOrderNumber());
+//                orderNoSet.add(it.getOrderNumber());
             });
             });
             return ResultContent.buildContent(orderNoSet);
             return ResultContent.buildContent(orderNoSet);
         }
         }

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

@@ -0,0 +1,123 @@
+package com.zhongshu.card.server.core.service.pay;
+
+import com.github.microservice.pay.client.model.ledger.GeneralLedgerQueryModel;
+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.ret.ResultContent;
+import com.github.microservice.pay.client.ret.ResultState;
+import com.github.microservice.pay.client.service.ledger.GeneralLedgerService;
+import com.github.microservice.pay.client.service.ledger.TransactionLogService;
+import com.github.microservice.types.payment.PaymentChannelType;
+import com.zhongshu.card.server.core.domain.pay.PayAccount;
+import com.zhongshu.card.server.core.service.base.SuperService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.awt.print.Pageable;
+import java.math.BigDecimal;
+import java.util.Map;
+
+@Service
+public class WithdrawService extends SuperService {
+
+    @Autowired
+    PayAccountService payAccountService;
+
+    @Autowired
+    TransactionLogService transactionLogService;
+
+    @Autowired
+    GeneralLedgerService generalLedgerService;
+
+    /**
+     * 查询可提现余额
+     */
+    public Object queryWithdrawAmount(String projectOid, String oid){
+        if (StringUtils.isBlank(projectOid)){
+            projectOid = getCurrentProjectOid();
+        }
+
+        if (StringUtils.isBlank(oid)){
+            oid = getCurrentOid();
+        }
+        PayAccount settleAccount = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.Settle);
+        ResultContent<GeneralLedgerQueryModel> ledgerQueryModelResultContent = generalLedgerService.get(settleAccount.getLedgerId());
+        if (!ledgerQueryModelResultContent.getState().equals(ResultState.Success)){
+            return com.github.microservice.net.ResultContent.buildFail("提现账本数据不存在");
+        }
+        return ResultContent.buildContent(ledgerQueryModelResultContent.getContent().getBalance());
+    }
+
+    /**
+     * 查询当前支付渠道可提现余额
+     */
+    public Object queryWithdrawAmountByPaymentType(String projectOid, String oid, String paymentType){
+        //todo 统计当前支付渠道的收入与支出
+        PayAccount settleAccount = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.Settle);
+        GeneralLedgerQueryTransactionLogModel queryTransactionLogModel = new GeneralLedgerQueryTransactionLogModel();
+        queryTransactionLogModel.setFilter(Map.of("meta.paymentType", paymentType));
+        queryTransactionLogModel.setGeneralLedgerId(new String[]{settleAccount.getLedgerId()});
+        ResultContent<TransactionLogAggregateRetModel> aggregateRetModelResultContent = transactionLogService.aggregateAmount(queryTransactionLogModel);
+        if (!aggregateRetModelResultContent.getState().equals(ResultState.Success)){
+            return aggregateRetModelResultContent;
+        }
+        long amount = aggregateRetModelResultContent.getContent().getStatistics().getCreditCount() - aggregateRetModelResultContent.getContent().getStatistics().getDebitCount();
+        //todo 收入-支出 等于当前可提现余额
+        return ResultContent.buildContent(amount);
+    }
+
+    /**
+     * 发起提现
+     */
+    public Object withdrawApply(String projectOid, String oid, String paymentType, BigDecimal amount){
+        //TODO 校验提现金额是否大约可以提现金额
+
+        //TODO 获取支付配置 为线上或者线下
+
+        //TODO 创建流程
+
+        //TODO 支付中心划账:机构-已结算子账户- 机构-已冻结金额+
+        return null;
+    }
+
+    /**
+     * 审核
+     */
+    public Object withdraw(String id){
+        //TODO 判断权限?
+
+        //TODO 获取提现订单数据
+
+        //TODO 判断状态是否为待审核
+
+        //TODO 审批通过, 判断当前可提现余额是否大于提现订单金额
+
+        //TODO 判断是否线上提现,调用支付渠道对应的提现接口
+
+        //TODO 划账,机构已冻结金额- 项目无感支付+
+
+        //TODO 修改提现订单状态:提现处理中
+
+        //TODO 审批拒绝
+
+        //TODO 划账:机构已冻结金额- 机构已结算金额+
+
+        //TODO 修改提现订单状态:已拒绝
+        return null;
+    }
+
+    /**
+     * 查询机构提现记录
+     */
+    public Object page(Pageable pageable){
+        return null;
+    }
+
+    /**
+     * 处理银联无感支付,提现结果通知回调
+     */
+    public Object handleWithdrawMessage(){
+        return null;
+    }
+}