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

Merge remote-tracking branch 'origin/master'

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

+ 11 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/AttachFileModel.java

@@ -0,0 +1,11 @@
+package com.zhongshu.card.client.model.pay;
+
+import lombok.Data;
+
+@Data
+public class AttachFileModel {
+
+    private String fileName;
+
+    private String fileUrl;
+}

+ 29 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/ProcessWithdrawParam.java

@@ -0,0 +1,29 @@
+package com.zhongshu.card.client.model.pay;
+
+import com.zhongshu.card.client.type.WithdrawStatus;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class ProcessWithdrawParam {
+
+    @Schema(description = "数据id")
+    private String id;
+
+    @Schema(description = "订单编号")
+    private String orderNo;
+
+    @Schema(description = "审核结果")
+    private WithdrawStatus status;
+
+    @Schema(description = "用户id")
+    private String userId;
+
+    @Schema(description = "附加信息")
+    private String attachInfo;
+
+    @Schema(description = "附件")
+    private List<AttachFileModel> attachFile;
+}

+ 3 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/WithdrawParam.java

@@ -15,6 +15,9 @@ public class WithdrawParam {
     @Schema(description = "机构oid")
     private String oid;
 
+    @Schema(description = "用户id")
+    private String userId;
+
     @Schema(description = "支付渠道")
     private PaymentType paymentType;
 

+ 18 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/type/WithdrawStatus.java

@@ -0,0 +1,18 @@
+package com.zhongshu.card.client.type;
+
+import lombok.Getter;
+
+public enum WithdrawStatus {
+
+    Processing("提现处理中"),
+    Success("提现成功"),
+    Fail("提现失败")
+    ;
+
+    @Getter
+    private String remark;
+
+    WithdrawStatus(String remark) {
+        this.remark = remark;
+    }
+}

+ 10 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/WithdrawOrderDao.java

@@ -0,0 +1,10 @@
+package com.zhongshu.card.server.core.dao.pay;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.server.core.dao.pay.extend.WithdrawOrderDaoExtend;
+import com.zhongshu.card.server.core.domain.pay.WithdrawOrder;
+
+public interface WithdrawOrderDao extends MongoDao<WithdrawOrder>, WithdrawOrderDaoExtend {
+
+    WithdrawOrder findTop1ById(String id);
+}

+ 4 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/extend/WithdrawOrderDaoExtend.java

@@ -0,0 +1,4 @@
+package com.zhongshu.card.server.core.dao.pay.extend;
+
+public interface WithdrawOrderDaoExtend {
+}

+ 7 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/impl/WithdrawOrderDaoImpl.java

@@ -0,0 +1,7 @@
+package com.zhongshu.card.server.core.dao.pay.impl;
+
+import com.zhongshu.card.server.core.dao.pay.WithdrawOrderDao;
+import com.zhongshu.card.server.core.dao.pay.extend.WithdrawOrderDaoExtend;
+
+public class WithdrawOrderDaoImpl implements WithdrawOrderDaoExtend {
+}

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

@@ -1,12 +1,75 @@
 package com.zhongshu.card.server.core.domain.pay;
 
 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.WithdrawStatus;
+import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
+import com.zhongshu.card.client.type.paySetting.WithdrawType;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import org.springframework.data.mongodb.core.mapping.Document;
 
+import java.math.BigDecimal;
+import java.util.List;
+
 @Data
 @Document
 public class WithdrawOrder extends SuperEntity {
 
+    @Schema(description = "项目oid")
+    private String projectOid;
+
+    @Schema(description = "机构oid")
+    private String oid;
+
+    @Schema(description = "支付渠道")
+    private PaymentType paymentType;
+
+    @Schema(description = "订单编号")
+    private String orderNo;
+
+    @Schema(description = "提现金额")
+    private BigDecimal amount;
+
+    @Schema(description = "实际到账")
+    private BigDecimal receiveAmount;
+
+    @Schema(description = "提现方式")
+    private WithdrawMethodType withdrawMethodType;
+
+    @Schema(description = "提现规则")
+    private WithdrawType withdrawType;
+
+    @Schema(description = "银行卡号")
+    private String bankAccountNumber;
+
+    @Schema(description = "附加信息")
+    private String attachInfo;
+
+    @Schema(description = "附件")
+    private List<AttachFileModel> attachFile;
+
+    @Schema(description = "提现状态")
+    private WithdrawStatus withdrawStatus;
+
+    @Schema(description = "提现状态说明")
+    private String withdrawStatusDesc;
+
+    @Schema(description = "发起人")
+    private UserAccount withdrawUser;
+
+    @Schema(description = "处理人")
+    private UserAccount processUser;
+
+    @Schema(description = "处理时间")
+    private Long processTime;
+
+    @Schema(description = "冻结账单")
+    private List<TransactionLogModel> frozenTransactionLogs;
 
+    @Schema(description = "提现账单")
+    private List<TransactionLogModel> withdrawTransactionLogs;
 }

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

@@ -319,8 +319,8 @@ public class ChinaumsSenselessPayService extends SuperService {
         //TODO 判断支付状态
 
         //获取项目总账
-        PayAccount projectParent = payAccountService.getProjectParent(projectOid);
-        //获取用户余额支付子账户
+        PayAccount projectAccount = payAccountService.getProjectChildren(projectOid, PaymentChannelType.SecretFreePayment);
+        //获取用户无感支付子账户
         PayAccount userBalancePayment = payAccountService.getUserChildren(projectOid, userId, PaymentChannelType.SecretFreePayment);
         //获取机构待结算账户
         PayAccount orgWaitSettle = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.WaitSettle);
@@ -329,7 +329,7 @@ public class ChinaumsSenselessPayService extends SuperService {
         TransferTransactionsModel transferModel = new TransferTransactionsModel();
         //构建出账账户
         TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
-        sourceTransaction.setGeneralLedgerId(projectParent.getLedgerId());
+        sourceTransaction.setGeneralLedgerId(projectAccount.getLedgerId());
         sourceTransaction.setOrderNumber(orderNo);
         sourceTransaction.setTransactionType(TransactionType.Pay);
         sourceTransaction.setTransactionStatus(TransactionStatus.Success);

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

@@ -1,22 +1,42 @@
 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.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.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.pay.client.type.ledger.TransactionStatus;
+import com.github.microservice.pay.client.type.ledger.TransactionType;
 import com.github.microservice.types.payment.PaymentChannelType;
 import com.github.microservice.types.payment.PaymentType;
+import com.zhongshu.card.client.model.pay.ProcessWithdrawParam;
+import com.zhongshu.card.client.model.pay.WithdrawParam;
+import com.zhongshu.card.client.model.paySetting.paySetting.OrgPayConfigModel;
+import com.zhongshu.card.client.service.org.UserAccountService;
+import com.zhongshu.card.client.type.WithdrawStatus;
+import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
+import com.zhongshu.card.server.core.dao.pay.WithdrawOrderDao;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.server.core.domain.pay.PayAccount;
+import com.zhongshu.card.server.core.domain.pay.WithdrawOrder;
+import com.zhongshu.card.server.core.domain.paySetting.ProjectMainPaySetting;
 import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.service.paySetting.ProjectMainPaySettingService;
+import com.zhongshu.card.server.core.service.paySetting.ProjectPaySettingServiceImpl;
+import com.zhongshu.card.server.core.service.user.UserAccountServiceImpl;
+import com.zhongshu.card.server.core.util.CommonUtil;
 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.math.RoundingMode;
+import java.util.List;
 import java.util.Map;
 
 @Service
@@ -31,6 +51,18 @@ public class WithdrawService extends SuperService {
     @Autowired
     GeneralLedgerService generalLedgerService;
 
+    @Autowired
+    ProjectMainPaySettingService projectMainPaySettingService;
+
+    @Autowired
+    ProjectPaySettingServiceImpl projectPaySettingService;
+
+    @Autowired
+    UserAccountServiceImpl userAccountService;
+
+    @Autowired
+    WithdrawOrderDao withdrawOrderDao;
+
     /**
      * 查询可提现余额
      */
@@ -54,12 +86,10 @@ public class WithdrawService extends SuperService {
      * 查询当前支付渠道可提现余额
      */
     public com.github.microservice.net.ResultContent queryWithdrawAmount(String projectOid, String oid, PaymentType paymentType){
-        //todo 统计当前支付渠道的收入与支出
         Long amount = queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
         if (null == amount){
             return  com.github.microservice.net.ResultContent.buildFail("查询余额失败");
         }
-        //todo 收入-支出 等于当前可提现余额
         return com.github.microservice.net.ResultContent.buildContent(amount);
     }
 
@@ -72,48 +102,183 @@ public class WithdrawService extends SuperService {
         if (!aggregateRetModelResultContent.getState().equals(ResultState.Success)){
             return null;
         }
-        long amount = aggregateRetModelResultContent.getContent().getStatistics().getCreditCount() - aggregateRetModelResultContent.getContent().getStatistics().getDebitCount();
-        return amount;
+        return aggregateRetModelResultContent.getContent().getStatistics().getCreditCount() - aggregateRetModelResultContent.getContent().getStatistics().getDebitCount();
     }
 
     /**
      * 发起提现
      */
-    public Object withdrawApply(String projectOid, String oid, PaymentType paymentType, BigDecimal amount){
-        //TODO 校验提现金额是否大约可以提现金额
-        Long waitAmount = queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
-        //TODO 获取支付配置 为线上或者线下
+    public Object withdrawApply(WithdrawParam param){
+        String projectOid = param.getProjectOid();
+        String oid = param.getOid();
+        String userId = param.getUserId();
+        PaymentType paymentType = param.getPaymentType();
+        BigDecimal amount = param.getAmount();
+
+        if (StringUtils.isBlank(projectOid)){
+            projectOid = getCurrentProjectOid();
+        }
 
-        //TODO 创建流程
+        if (StringUtils.isBlank(oid)){
+            oid = getCurrentOid();
+        }
 
-        //TODO 支付中心划账:机构-已结算子账户- 机构-已冻结金额+
-        return null;
+        if (StringUtils.isBlank(userId)){
+            userId = getCurrentUserId();
+        }
+
+        List<UserAccount> userAccounts = userAccountService.getUserAccounts(List.of(userId));
+        if (userAccounts==null || userAccounts.isEmpty()){
+            return com.github.microservice.net.ResultContent.buildFail("用户信息不存在");
+        }
+
+        //校验提现金额是否大约可以提现金额
+        Long waitAmount = queryWithdrawAmountByPaymentType(projectOid, oid, paymentType);
+        if (null == waitAmount){
+            return com.github.microservice.net.ResultContent.buildFail("当前可提现余额为0");
+        }
+        if (amount.compareTo(new BigDecimal(waitAmount))>0){
+            return com.github.microservice.net.ResultContent.buildFail("大于可提现金额");
+        }
+        //获取支付配置 为线上或者线下
+        ProjectMainPaySetting projectMainPaySetting = projectMainPaySettingService.getProjectMainPaySetting(projectOid, paymentType);
+        OrgPayConfigModel orgPayConfig = projectPaySettingService.getOrgPayConfig(projectOid, oid, paymentType);
+        if (null == orgPayConfig || null == projectMainPaySetting){
+            return com.github.microservice.net.ResultContent.buildFail("支付产品未配置完成");
+        }
+        //支付中心划账:机构-已结算子账户- 机构-已冻结金额+
+        PayAccount settleAccount = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.Settle);
+        PayAccount frozenAccount = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.WithdrawFrozen);
+        //构建转账参数
+        TransferTransactionsModel transferModel = new TransferTransactionsModel();
+        String withdrawOrderNo = CommonUtil.UUID();
+        //构建出账账户
+        TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
+        sourceTransaction.setGeneralLedgerId(settleAccount.getLedgerId());
+        sourceTransaction.setOrderNumber(withdrawOrderNo);
+        sourceTransaction.setTransactionType(TransactionType.WithdrawFrozen);
+        sourceTransaction.setTransactionStatus(TransactionStatus.Success);
+        sourceTransaction.setAmount(amount.negate().longValue());
+        sourceTransaction.setMeta(Map.of("paymentType", paymentType, "paymentChannelType", paymentType.getChannelType(), "description", "提现冻结"));
+        transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
+        //构建入账账户
+        TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
+        destinationTransaction.setGeneralLedgerId(frozenAccount.getLedgerId());
+        destinationTransaction.setOrderNumber(withdrawOrderNo);
+        destinationTransaction.setTransactionType(TransactionType.WithdrawFrozen);
+        destinationTransaction.setTransactionStatus(TransactionStatus.Success);
+        destinationTransaction.setAmount(amount.longValue());
+        destinationTransaction.setMeta(Map.of("paymentType", paymentType, "paymentChannelType", paymentType.getChannelType(), "description", "提现冻结"));
+        transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
+        ResultContent<List<TransactionLogModel>> transfer = transactionLogService.transfer(transferModel);
+        if (!transfer.getState().equals(ResultState.Success)){
+            return com.github.microservice.net.ResultContent.buildFail(transfer.getMsg());
+        }
+        //创建流程
+        WithdrawOrder withdrawOrder = new WithdrawOrder();
+        withdrawOrder.setWithdrawType(projectMainPaySetting.getWithdrawType());
+        withdrawOrder.setWithdrawMethodType(projectMainPaySetting.getWithdrawMethodType());
+        withdrawOrder.setBankAccountNumber(orgPayConfig.getBankSubName() + orgPayConfig.getBankName() + orgPayConfig.getBankAccountNumber());
+        withdrawOrder.setOrderNo(withdrawOrderNo);
+        withdrawOrder.setAmount(amount);
+        withdrawOrder.setWithdrawStatus(WithdrawStatus.Processing);
+        withdrawOrder.setWithdrawUser(userAccounts.get(0));
+        withdrawOrder.setFrozenTransactionLogs(transfer.getContent());
+        withdrawOrder.setProjectOid(projectOid);
+        withdrawOrder.setOid(oid);
+        withdrawOrder.setPaymentType(paymentType);
+        withdrawOrderDao.save(withdrawOrder);
+        return com.github.microservice.net.ResultContent.buildSuccess();
     }
 
     /**
      * 审核
      */
-    public Object withdraw(String id){
+    public com.github.microservice.net.ResultContent withdraw(ProcessWithdrawParam param){
+        String userId = param.getUserId();
+        if (StringUtils.isBlank(userId)){
+            userId = getCurrentUserId();
+        }
+        List<UserAccount> userAccounts = userAccountService.getUserAccounts(List.of(userId));
+        if (userAccounts==null || userAccounts.isEmpty()){
+            return com.github.microservice.net.ResultContent.buildFail("用户信息不存在");
+        }
         //TODO 判断权限?
 
-        //TODO 获取提现订单数据
+        //获取提现订单数据
+        WithdrawOrder withdrawOrder = withdrawOrderDao.findTop1ById(param.getId());
+        if (withdrawOrder == null){
+            return com.github.microservice.net.ResultContent.buildFail("数据不存在");
+        }
+        //判断状态是否为待审核
+        if (!withdrawOrder.getWithdrawStatus().equals(WithdrawStatus.Processing)){
+            return com.github.microservice.net.ResultContent.buildFail("只能操作处理中的订单");
+        }
 
-        //TODO 判断状态是否为待审核
+        PayAccount withdrawFrozenAccount = payAccountService.getOrgChildren(withdrawOrder.getProjectOid(), withdrawOrder.getOid(), PaymentChannelType.WithdrawFrozen);
+        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)){//审批通过
 
-        //TODO 判断是否线上提现,调用支付渠道对应的提现接口
-
-        //TODO 划账,机构已冻结金额- 项目无感支付+
-
-        //TODO 修改提现订单状态:提现处理中
+            //划账,机构已冻结金额- 项目无感支付+
+            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());
+            //TODO 判断是否线上提现,调用支付渠道对应的提现接口
+            if (withdrawOrder.getWithdrawMethodType().equals(WithdrawMethodType.OnLine)) {
 
-        //TODO 审批拒绝
+            }
 
-        //TODO 划账:机构已冻结金额- 机构已结算金额+
+            withdrawOrder.setWithdrawStatus(WithdrawStatus.Success);
+            withdrawOrder.setReceiveAmount(withdrawOrder.getAmount().movePointLeft(2));
+        }else if (param.getStatus().equals(WithdrawStatus.Fail)){ //审批拒绝
+            withdrawOrder.setWithdrawStatus(WithdrawStatus.Fail);
+            //划账退回金额: 机构已冻结金额- 机构已结算 +
+            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)){
+                return com.github.microservice.net.ResultContent.buildFail("余额退回失败");
+            }
+            withdrawOrder.setWithdrawTransactionLogs(transfer.getContent());
+        }
+        withdrawOrder.setAttachInfo(param.getAttachInfo());
+        withdrawOrder.setAttachFile(param.getAttachFile());
+        withdrawOrder.setProcessUser(userAccounts.get(0));
+        withdrawOrder.setProcessTime(System.currentTimeMillis());
+        withdrawOrderDao.save(withdrawOrder);
+        return com.github.microservice.net.ResultContent.buildSuccess();
+    }
 
-        //TODO 修改提现订单状态:已拒绝
-        return null;
+    private TransferTransactionsModel buildTransferModel(PayAccount credit, PayAccount debit, String orderNo, BigDecimal amount, TransactionType type, Map<String, Object> meta){
+        TransferTransactionsModel transferModel = new TransferTransactionsModel();
+        //构建出账账户
+        TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
+        sourceTransaction.setGeneralLedgerId(debit.getLedgerId());
+        sourceTransaction.setOrderNumber(orderNo);
+        sourceTransaction.setTransactionType(type);
+        sourceTransaction.setTransactionStatus(TransactionStatus.Success);
+        sourceTransaction.setAmount(amount.negate().longValue());
+        sourceTransaction.setMeta(meta);
+        transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
+        //构建入账账户
+        TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
+        destinationTransaction.setGeneralLedgerId(credit.getLedgerId());
+        destinationTransaction.setOrderNumber(orderNo);
+        destinationTransaction.setTransactionType(type);
+        destinationTransaction.setTransactionStatus(TransactionStatus.Success);
+        destinationTransaction.setAmount(amount.longValue());
+        destinationTransaction.setMeta(meta);
+        transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
+        return transferModel;
     }
 
     /**
@@ -123,6 +288,17 @@ public class WithdrawService extends SuperService {
         return null;
     }
 
+    /**
+     * 查询详情
+     */
+    public Object queryDetailById(String id){
+        return null;
+    }
+
+    public Object queryDetailByOrderNo(String orderNo){
+        return null;
+    }
+
     /**
      * 处理银联无感支付,提现结果通知回调
      */