|
|
@@ -0,0 +1,101 @@
|
|
|
+package com.zhongshu.card.server.core.service.payment;
|
|
|
+
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.pay.client.model.ledger.TransactionLogModel;
|
|
|
+import com.github.microservice.pay.client.ret.ResultState;
|
|
|
+import com.github.microservice.types.OrderState;
|
|
|
+import com.github.microservice.types.payment.PaymentType;
|
|
|
+import com.zhongshu.card.client.model.operLogs.OperationLogsAddParam;
|
|
|
+import com.zhongshu.card.client.type.LogsLevel;
|
|
|
+import com.zhongshu.card.client.type.MessageType;
|
|
|
+import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
|
|
|
+import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import com.zhongshu.card.server.core.service.pay.BalancePayService;
|
|
|
+import com.zhongshu.card.server.core.service.user.OperationLogsService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/10/24
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class PayCallService extends SuperService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OperationLogsService operationLogsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BalancePayService balancePayService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统一调用支付服务
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent pay(ExpenseFlow entity) {
|
|
|
+ PaymentType paymentType = entity.getPaymentType();
|
|
|
+ if (paymentType == PaymentType.UserWallet) {
|
|
|
+ return balancePay(entity);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 钱包支付
|
|
|
+ *
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent balancePay(ExpenseFlow entity) {
|
|
|
+ String desc = "消费";
|
|
|
+ OperationLogsAddParam logsAddParam = initLog(entity.getUserId());
|
|
|
+ logsAddParam.setTitle(desc);
|
|
|
+ logsAddParam.setDataId(entity.getPaymentNo());
|
|
|
+ entity.setPayStartTime(System.currentTimeMillis());
|
|
|
+
|
|
|
+ com.github.microservice.pay.client.ret.ResultContent<List<TransactionLogModel>> resultContent = balancePayService.balancePay(
|
|
|
+ entity.getProjectOid(), entity.getShopOid(), entity.getUserId(),
|
|
|
+ entity.getPayAmount(), entity.getPaymentNo(), entity.getRemark()
|
|
|
+ );
|
|
|
+ if (resultContent.getState() == ResultState.Success) {
|
|
|
+ // 关联参数
|
|
|
+ String msg = "支付成功";
|
|
|
+ List<TransactionLogModel> list = resultContent.getContent();
|
|
|
+ entity.setTransactionIds(list.stream().map(it -> it.getId()).collect(Collectors.toUnmodifiableList()));
|
|
|
+ entity.setPaymentStatus(msg);
|
|
|
+ entity.setIsPaySuccess(Boolean.TRUE);
|
|
|
+ entity.setPayRemark(msg);
|
|
|
+ entity.setOrderType(OrderState.HAVE_PAID);
|
|
|
+ logsAddParam.setMessageType(MessageType.Info);
|
|
|
+ logsAddParam.setLevel(LogsLevel.Low);
|
|
|
+ logsAddParam.setContent(msg);
|
|
|
+ } else {
|
|
|
+ String msg = resultContent.getMsg();
|
|
|
+ if (StringUtils.isNotEmpty(msg) && msg.contains("Connection reset")) {
|
|
|
+ msg = "调用支付中心失败";
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(msg)) {
|
|
|
+ msg = "支付失败";
|
|
|
+ }
|
|
|
+ entity.setPaymentStatus(msg);
|
|
|
+ entity.setIsPaySuccess(Boolean.FALSE);
|
|
|
+ entity.setPayRemark(msg);
|
|
|
+ entity.setOrderType(OrderState.PAID_ERROR);
|
|
|
+ logsAddParam.setMessageType(MessageType.Warn);
|
|
|
+ logsAddParam.setLevel(LogsLevel.Low);
|
|
|
+ logsAddParam.setContent(msg);
|
|
|
+ }
|
|
|
+ operationLogsService.addLog(logsAddParam);
|
|
|
+ entity.setPayEndTime(System.currentTimeMillis());
|
|
|
+ entity.setPayMillis(entity.getPayEndTime() - entity.getPayStartTime());
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+}
|