|
|
@@ -1,6 +1,8 @@
|
|
|
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.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;
|
|
|
@@ -10,6 +12,7 @@ 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.service.product.SenselessPayService;
|
|
|
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;
|
|
|
@@ -21,6 +24,7 @@ import com.zhongshu.card.client.model.pay.WithdrawParam;
|
|
|
import com.zhongshu.card.client.model.paySetting.paySetting.OrgPayConfigModel;
|
|
|
import com.zhongshu.card.client.type.WithdrawStatus;
|
|
|
import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
|
|
|
+import com.zhongshu.card.client.utils.DateUtils;
|
|
|
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;
|
|
|
@@ -28,11 +32,13 @@ 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.org.UserOrgPermissService;
|
|
|
+import com.zhongshu.card.server.core.service.paySetting.OrgPayAccountService;
|
|
|
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.BeanUtils;
|
|
|
import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
@@ -40,6 +46,7 @@ import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -70,6 +77,12 @@ public class WithdrawService extends SuperService {
|
|
|
@Autowired
|
|
|
UserOrgPermissService userOrgPermissService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ SenselessPayService senselessPayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgPayAccountService orgPayAccountService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询可提现余额
|
|
|
*/
|
|
|
@@ -107,7 +120,23 @@ public class WithdrawService extends SuperService {
|
|
|
return com.github.microservice.net.ResultContent.buildContent(amount);
|
|
|
}
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
private Long queryWithdrawAmountByPaymentType(String projectOid, String oid, PaymentType paymentType) {
|
|
|
+
|
|
|
+ if (paymentType.equals(PaymentType.UnionFrictionlessPay)){
|
|
|
+ String orgAccount = orgPayAccountService.queryOgPayAccount(oid, paymentType);
|
|
|
+ PayProductParameter<Object> parameter = new PayProductParameter<>();
|
|
|
+ parameter.setAccountName(orgAccount);
|
|
|
+ parameter.setMeta(new HashMap<>());
|
|
|
+ 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"));
|
|
|
+ }
|
|
|
+
|
|
|
PayAccount settleAccount = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.Settle);
|
|
|
GeneralLedgerQueryTransactionLogModel queryTransactionLogModel = new GeneralLedgerQueryTransactionLogModel();
|
|
|
queryTransactionLogModel.setFilter(Map.of("meta.paymentType", paymentType));
|
|
|
@@ -246,6 +275,39 @@ public class WithdrawService extends SuperService {
|
|
|
//TODO 审批通过, 判断当前可提现余额是否大于提现订单金额
|
|
|
if (param.getStatus().equals(WithdrawStatus.Success)){//审批通过
|
|
|
|
|
|
+
|
|
|
+ //TODO 判断是否线上提现,调用支付渠道对应的提现接口
|
|
|
+ if (withdrawOrder.getWithdrawMethodType().equals(WithdrawMethodType.OnLine)) {
|
|
|
+ switch (withdrawOrder.getPaymentType()){
|
|
|
+ case UnionFrictionlessPay-> {
|
|
|
+ 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()));
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//划账,机构已冻结金额- 项目无感支付+
|
|
|
TransferTransactionsModel transferTransactionsModel = buildTransferModel(projectAccount, withdrawFrozenAccount, withdrawOrder.getOrderNo(),
|
|
|
withdrawOrder.getAmount(), TransactionType.Withdrawal,
|
|
|
@@ -255,14 +317,10 @@ public class WithdrawService extends SuperService {
|
|
|
return com.github.microservice.net.ResultContent.buildFail(transferResult.getMsg());
|
|
|
}
|
|
|
withdrawOrder.setWithdrawTransactionLogs(transferResult.getContent());
|
|
|
- //TODO 判断是否线上提现,调用支付渠道对应的提现接口
|
|
|
- if (withdrawOrder.getWithdrawMethodType().equals(WithdrawMethodType.OnLine)) {
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
withdrawOrder.setWithdrawStatus(WithdrawStatus.Success);
|
|
|
withdrawOrder.setSort(WithdrawStatus.Success.getSort());
|
|
|
- withdrawOrder.setReceiveAmount(withdrawOrder.getAmount().movePointLeft(2));
|
|
|
+// withdrawOrder.setReceiveAmount(withdrawOrder.getAmount().movePointLeft(2));
|
|
|
}else if (param.getStatus().equals(WithdrawStatus.Fail)){ //审批拒绝
|
|
|
withdrawOrder.setWithdrawStatus(WithdrawStatus.Fail);
|
|
|
withdrawOrder.setSort(WithdrawStatus.Fail.getSort());
|
|
|
@@ -345,6 +403,34 @@ public class WithdrawService extends SuperService {
|
|
|
return model;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询提现状态
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ public Object withdrawQuery(String id){
|
|
|
+ //获取提现订单数据
|
|
|
+ WithdrawOrder withdrawOrder = withdrawOrderDao.findTop1ById(id);
|
|
|
+ if (withdrawOrder == null){
|
|
|
+ return com.github.microservice.net.ResultContent.buildFail("数据不存在");
|
|
|
+ }
|
|
|
+ switch (withdrawOrder.getPaymentType()){
|
|
|
+ case UnionFrictionlessPay -> {
|
|
|
+ String orgAccount = orgPayAccountService.queryOgPayAccount(withdrawOrder.getOid(), withdrawOrder.getPaymentType());
|
|
|
+ PayProductParameter<Object> parameter = new PayProductParameter<>();
|
|
|
+ parameter.setAccountName(orgAccount);
|
|
|
+ parameter.setMeta(Map.of("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);
|
|
|
+ return ResultContent.buildContent(map.get("desc"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultContent.buildContent(withdrawOrder.getWithdrawStatus().getRemark());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询详情
|
|
|
*/
|