|
|
@@ -1,31 +1,39 @@
|
|
|
package com.zhongshu.card.server.core.service.pay;
|
|
|
|
|
|
+import com.github.microservice.core.util.JsonUtil;
|
|
|
import com.github.microservice.core.util.bean.BeanUtil;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.pay.client.model.AccountModel;
|
|
|
import com.github.microservice.pay.client.model.PayProductParameter;
|
|
|
+import com.github.microservice.pay.client.model.chinaSenseless.ChinaSenselessPayRequest;
|
|
|
+import com.github.microservice.pay.client.model.chinaSenseless.ChinaSenselessRefundRequest;
|
|
|
import com.github.microservice.pay.client.model.chinaSenseless.ChinaSenselessSignRet;
|
|
|
+import com.github.microservice.pay.client.model.ledger.TransferTransactionsModel;
|
|
|
import com.github.microservice.pay.client.product.senseless.chinaumsSenseless.conf.ChinaumsSenselessConf;
|
|
|
import com.github.microservice.pay.client.ret.ResultState;
|
|
|
import com.github.microservice.pay.client.service.PayProductAccountService;
|
|
|
+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;
|
|
|
import com.github.microservice.types.payment.PaymentType;
|
|
|
import com.zhongshu.card.client.model.pay.ChinaumsSenselessUserSignInfoModel;
|
|
|
import com.zhongshu.card.client.model.pay.UnionApplySignParam;
|
|
|
import com.zhongshu.card.client.type.ContractState;
|
|
|
import com.zhongshu.card.server.core.dao.pay.ChinaumsSenselessUserSignInfoDao;
|
|
|
import com.zhongshu.card.server.core.domain.pay.ChinaumsSenselessUserSignInfo;
|
|
|
+import com.zhongshu.card.server.core.domain.pay.PayAccount;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.paySetting.OrgPayAccountService;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
import io.micrometer.common.util.StringUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.poi.util.StringUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import picocli.CommandLine;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -44,6 +52,12 @@ public class ChinaumsSenselessPayService extends SuperService {
|
|
|
@Autowired
|
|
|
PayProductAccountService payProductAccountService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ PayAccountService payAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ TransactionLogService transactionLogService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 银联申请签约
|
|
|
@@ -201,6 +215,124 @@ public class ChinaumsSenselessPayService extends SuperService {
|
|
|
return ResultContent.buildContent(toUserSignModel(userSignInfo));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 支付
|
|
|
+ */
|
|
|
+ public Object senselessPay(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String remark) {
|
|
|
+
|
|
|
+ //获取银联支付产品账户及需要签约的商户号
|
|
|
+ String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
|
|
|
+ if (!accountModelResultContent.getState().equals(ResultState.Success)){
|
|
|
+ return accountModelResultContent;
|
|
|
+ }
|
|
|
+ ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
|
|
|
+ String mid = conf.getMchId();
|
|
|
+
|
|
|
+ //获取用户签约协议号
|
|
|
+ ChinaumsSenselessUserSignInfo userSignInfo = chinaumsSenselessUserSignInfoDao.findTopByUserIdAndMid(userId, mid);
|
|
|
+ if (userSignInfo==null || !userSignInfo.getContractState().equals(ContractState.SIGNED)){
|
|
|
+ return ResultContent.buildFail("用户未签约或状态未知");
|
|
|
+ }
|
|
|
+
|
|
|
+ PayProductParameter<Object> payProductParameter = new PayProductParameter<>();
|
|
|
+ payProductParameter.setAccountName(accountName);
|
|
|
+ ChinaSenselessPayRequest request = new ChinaSenselessPayRequest();
|
|
|
+ request.setMchntOrderId(orderNo);
|
|
|
+ request.setSrcReserve(JsonUtil.toJson(Map.of("userId", userId, "oid", oid, "projectOid", projectOid)));
|
|
|
+ request.setContractId(userSignInfo.getContractId());
|
|
|
+ request.setTotalAmount(total.toString());
|
|
|
+ request.setAttachedData(remark);
|
|
|
+ payProductParameter.setMeta(BeanUtil.bean2Map(request));
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<Object> collectionResultContent = senselessPayService.collection(payProductParameter);
|
|
|
+ return collectionResultContent;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object refund(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String refundOrderNo, String remark) {
|
|
|
+
|
|
|
+ String accountName = orgPayAccountService.queryOgPayAccount(projectOid, PaymentType.UnionFrictionlessPay);
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<AccountModel> accountModelResultContent = payProductAccountService.get(accountName);
|
|
|
+ if (!accountModelResultContent.getState().equals(ResultState.Success)){
|
|
|
+ return accountModelResultContent;
|
|
|
+ }
|
|
|
+ ChinaumsSenselessConf conf = (ChinaumsSenselessConf) accountModelResultContent.getContent().getConf();
|
|
|
+ String mid = conf.getMchId();
|
|
|
+
|
|
|
+ PayProductParameter<Object> payProductParameter = new PayProductParameter<>();
|
|
|
+ payProductParameter.setAccountName(accountName);
|
|
|
+ ChinaSenselessRefundRequest request = new ChinaSenselessRefundRequest();
|
|
|
+ request.setMchntOrderId(orderNo);
|
|
|
+ request.setVaMchntNo(mid);
|
|
|
+ request.setRefundAmount(total.toString());
|
|
|
+ request.setRefundOrderId(refundOrderNo);
|
|
|
+ request.setSysSource(JsonUtil.toJson(Map.of("userId", userId, "oid", oid, "projectOid", projectOid)));
|
|
|
+ payProductParameter.setMeta(BeanUtil.bean2Map(request));
|
|
|
+ return senselessPayService.refund(payProductParameter);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Object handlePay(String projectOid, String oid, String userId, BigDecimal total, String orderNo, String remark) {
|
|
|
+ //TODO 判断支付状态
|
|
|
+
|
|
|
+ //获取项目总账
|
|
|
+ PayAccount projectParent = payAccountService.getProjectParent(projectOid);
|
|
|
+ //获取用户余额支付子账户
|
|
|
+ PayAccount userBalancePayment = payAccountService.getUserChildren(projectOid, userId, PaymentChannelType.SecretFreePayment);
|
|
|
+ //获取机构待结算账户
|
|
|
+ PayAccount orgWaitSettle = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.WaitSettle);
|
|
|
+ //支付:项目余额子账- 用户无感支付子账+
|
|
|
+ //构建转账参数
|
|
|
+ TransferTransactionsModel transferModel = new TransferTransactionsModel();
|
|
|
+ //构建出账账户
|
|
|
+ TransferTransactionsModel.GeneralLedgerTransaction sourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
|
|
|
+ sourceTransaction.setGeneralLedgerId(projectParent.getLedgerId());
|
|
|
+ sourceTransaction.setOrderNumber(orderNo);
|
|
|
+ sourceTransaction.setTransactionType(TransactionType.Pay);
|
|
|
+ sourceTransaction.setTransactionStatus(TransactionStatus.Success);
|
|
|
+ sourceTransaction.setAmount(total.negate().longValue());
|
|
|
+ sourceTransaction.setRemark(remark);
|
|
|
+ sourceTransaction.setMeta(Map.of("paymentType",PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
|
|
|
+ transferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
|
|
|
+
|
|
|
+ //构建入账账户
|
|
|
+ TransferTransactionsModel.GeneralLedgerTransaction destinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
|
|
|
+ destinationTransaction.setGeneralLedgerId(userBalancePayment.getLedgerId());
|
|
|
+ destinationTransaction.setOrderNumber(orderNo);
|
|
|
+ destinationTransaction.setTransactionType(TransactionType.Pay);
|
|
|
+ destinationTransaction.setTransactionStatus(TransactionStatus.Success);
|
|
|
+ destinationTransaction.setAmount(total.longValue());
|
|
|
+ destinationTransaction.setRemark(remark);
|
|
|
+ destinationTransaction.setMeta(Map.of("paymentType",PaymentType.UnionFrictionlessPay, "description", "用户余额支付"));
|
|
|
+ transferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
|
|
|
+ transactionLogService.transfer(transferModel);
|
|
|
+
|
|
|
+ //支付:项目余额子账- 用户无感支付子账+
|
|
|
+ //构建转账参数
|
|
|
+ TransferTransactionsModel payTransferModel = new TransferTransactionsModel();
|
|
|
+ //构建出账账户
|
|
|
+ TransferTransactionsModel.GeneralLedgerTransaction userSourceTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
|
|
|
+ userSourceTransaction.setGeneralLedgerId(userBalancePayment.getLedgerId());
|
|
|
+ userSourceTransaction.setOrderNumber(orderNo);
|
|
|
+ userSourceTransaction.setTransactionType(TransactionType.Pay);
|
|
|
+ userSourceTransaction.setTransactionStatus(TransactionStatus.Success);
|
|
|
+ userSourceTransaction.setAmount(total.negate().longValue());
|
|
|
+ userSourceTransaction.setRemark(remark);
|
|
|
+ userSourceTransaction.setMeta(Map.of("paymentType",PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
|
|
|
+ payTransferModel.setSource(new TransferTransactionsModel.GeneralLedgerTransaction[]{sourceTransaction});
|
|
|
+
|
|
|
+ //构建入账账户
|
|
|
+ TransferTransactionsModel.GeneralLedgerTransaction orgDestinationTransaction = new TransferTransactionsModel.GeneralLedgerTransaction();
|
|
|
+ destinationTransaction.setGeneralLedgerId(orgWaitSettle.getLedgerId());
|
|
|
+ destinationTransaction.setOrderNumber(orderNo);
|
|
|
+ destinationTransaction.setTransactionType(TransactionType.Pay);
|
|
|
+ destinationTransaction.setTransactionStatus(TransactionStatus.Success);
|
|
|
+ destinationTransaction.setAmount(total.longValue());
|
|
|
+ destinationTransaction.setRemark(remark);
|
|
|
+ destinationTransaction.setMeta(Map.of("paymentType",PaymentType.UnionFrictionlessPay, "description", "银联无感支付"));
|
|
|
+ payTransferModel.setDestinations(new TransferTransactionsModel.GeneralLedgerTransaction[]{destinationTransaction});
|
|
|
+ transactionLogService.transfer(payTransferModel);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private ChinaumsSenselessUserSignInfoModel toUserSignModel(ChinaumsSenselessUserSignInfo userSignInfo){
|
|
|
ChinaumsSenselessUserSignInfoModel model = new ChinaumsSenselessUserSignInfoModel();
|