|
|
@@ -2,21 +2,33 @@ package com.sckw.freight.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.sckw.freight.entity.freight.KwpSettlementLogistics;
|
|
|
+import com.sckw.freight.entity.payment.PayMemberWalletAp;
|
|
|
+import com.sckw.freight.entity.payment.PayOrder;
|
|
|
+import com.sckw.freight.entity.payment.PayOrderSub;
|
|
|
+import com.sckw.freight.entity.payment.PayWalletWithdrawOrder;
|
|
|
import com.sckw.freight.mapper.freight.KwpLedgerLogisticsMapper;
|
|
|
import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
|
|
|
+import com.sckw.freight.mapper.payment.PayMemberWalletApMapper;
|
|
|
+import com.sckw.freight.mapper.payment.PayOrderMapper;
|
|
|
+import com.sckw.freight.mapper.payment.PayOrderSubMapper;
|
|
|
+import com.sckw.freight.mapper.payment.PayWalletWithdrawOrderMapper;
|
|
|
+import com.sckw.freight.model.dto.BusinessNo;
|
|
|
+import com.sckw.freight.model.dto.Order;
|
|
|
import com.sckw.freight.model.dto.PatchPay;
|
|
|
-import com.sckw.freight.model.dto.PayOrderDetail;
|
|
|
import com.sckw.freight.model.enums.ChannelEnum;
|
|
|
import com.sckw.freight.model.enums.KwpSettlementLogisticsStatusEnum;
|
|
|
+import com.sckw.freight.model.po.CheckResult;
|
|
|
import com.sckw.freight.model.po.LedgerLogisticsAndBuySellInfo;
|
|
|
import com.sckw.freight.service.freight.IKwpLedgerLogisticsService;
|
|
|
import com.sckw.freight.service.freight.IKwpSettlementLogisticsService;
|
|
|
import com.sckw.freight.util.MoneyChange;
|
|
|
import com.sckw.freight.util.R;
|
|
|
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.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -41,6 +53,14 @@ public class JobService {
|
|
|
KwpLedgerLogisticsMapper kwpLedgerLogisticsMapper;
|
|
|
@Autowired
|
|
|
KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
|
|
|
+ @Autowired
|
|
|
+ PayOrderMapper payOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ PayOrderSubMapper payOrderSubMapper;
|
|
|
+ @Autowired
|
|
|
+ PayWalletWithdrawOrderMapper payWalletWithdrawOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ PayMemberWalletApMapper payMemberWalletApMapper;
|
|
|
|
|
|
/**
|
|
|
* 【轮循程序】
|
|
|
@@ -72,46 +92,71 @@ public class JobService {
|
|
|
LambdaQueryWrapper<KwpSettlementLogistics> settlementLogisticsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
settlementLogisticsLambdaQueryWrapper.eq(KwpSettlementLogistics::getLLedgerId, logisticsAndBuySellInfo.getId());
|
|
|
settlementLogisticsLambdaQueryWrapper.eq(KwpSettlementLogistics::getStatus, KwpSettlementLogisticsStatusEnum.Nopaid.getCode());
|
|
|
- settlementLogisticsLambdaQueryWrapper.select(KwpSettlementLogistics::getSlOrderNo);
|
|
|
+ settlementLogisticsLambdaQueryWrapper.select(KwpSettlementLogistics::getSlOrderNo, KwpSettlementLogistics::getId,
|
|
|
+ KwpSettlementLogistics::getRemark);
|
|
|
List<KwpSettlementLogistics> settlementLogistics = kwpSettlementLogisticsMapper.selectList(settlementLogisticsLambdaQueryWrapper);
|
|
|
if (settlementLogistics == null || settlementLogistics.isEmpty()) {
|
|
|
//没有未支付的结算信息 直接下一条
|
|
|
continue;
|
|
|
}
|
|
|
for (KwpSettlementLogistics settlementLogisticsInfo : settlementLogistics) {
|
|
|
+ String _cz = " ", _yp = " ", _qf = " ", _tx = " ";
|
|
|
try {
|
|
|
|
|
|
- R<PayOrderDetail> details = payCenterService.getPayDetailByOrderNo(settlementLogisticsInfo.getSlOrderNo());
|
|
|
- if (details == null || details.getCode() != 200 || details.getData() == null || !details.getStatus()) {
|
|
|
+ //记录关联单号,防止重复调用 (有值-表示已生成对应单据,无值一表示没有业务单据) remark=已支付的充值单号|预付单号|清分单号|提现单号
|
|
|
+ String remark = settlementLogisticsInfo.getRemark();
|
|
|
+ if (!StringUtils.isBlank(remark)) {
|
|
|
+ String[] split = remark.split("\\|");
|
|
|
+ if (split.length == 4) {
|
|
|
+ _cz = split[0];
|
|
|
+ _yp = split[1];
|
|
|
+ _qf = split[2];
|
|
|
+ _tx = split[3];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //检查充值
|
|
|
+ CheckResult<PayOrder> checkResultPayOrder = checkPayOrder(_cz, settlementLogisticsInfo);
|
|
|
+ if (!checkResultPayOrder.isStatus()) continue;
|
|
|
+ //已经充值成功
|
|
|
+ _cz = checkResultPayOrder.getData().getOrderNo();
|
|
|
+
|
|
|
+ //支付金额
|
|
|
+ BigDecimal money = MoneyChange.smallMoney(new BigDecimal(checkResultPayOrder.getData().getMoney()));
|
|
|
+
|
|
|
+ // 检查预付
|
|
|
+ CheckResult checkAdvancePay = checkAdvancePay(_yp, logisticsAndBuySellInfo, money);
|
|
|
+ if (!checkAdvancePay.isStatus()) {
|
|
|
+ _yp = checkAdvancePay.getBusinessNo();
|
|
|
continue;
|
|
|
}
|
|
|
- //根据充值订单状态 处理结算状态
|
|
|
- if (details.getData().getStatus() == 1) {//已支付
|
|
|
- //发起预付
|
|
|
- payCenterService.advancePayApply(logisticsAndBuySellInfo.getBuyUid() , ChannelEnum.XW,
|
|
|
- logisticsAndBuySellInfo.getSellUid() , MoneyChange.bigMoney(details.getData().getMoney()));
|
|
|
-
|
|
|
-
|
|
|
- // 1.记账
|
|
|
- List<PatchPay> list = new ArrayList<>();
|
|
|
- PatchPay patchPay = new PatchPay();
|
|
|
- patchPay.setUid(logisticsAndBuySellInfo.getSellUid() );
|
|
|
- patchPay.setMoney(MoneyChange.bigMoney(details.getData().getMoney()));
|
|
|
- list.add(patchPay);
|
|
|
- //清分
|
|
|
- payCenterService.payAgentPayV2(logisticsAndBuySellInfo.getBuyUid() , logisticsAndBuySellInfo.getSellUid() , ChannelEnum.XW,
|
|
|
- MoneyChange.bigMoney(details.getData().getMoney()), list, settlementLogisticsInfo.getSlOrderNo(), "1");
|
|
|
-
|
|
|
- //提现
|
|
|
- payCenterService.withdrawTake(logisticsAndBuySellInfo.getSellUid() , ChannelEnum.XW,
|
|
|
- MoneyChange.bigMoney(details.getData().getMoney()),
|
|
|
- "");
|
|
|
-
|
|
|
- //修改结算单状态
|
|
|
- iKwpSettlementLogisticsService.updateSettlementLogisticsStatusPaid(settlementLogisticsInfo, details.getData());
|
|
|
+
|
|
|
+ //检查清分
|
|
|
+ CheckResult checkAgentPay = checkAgentPay(_qf, settlementLogisticsInfo, logisticsAndBuySellInfo, money);
|
|
|
+ if (!checkAgentPay.isStatus()) {
|
|
|
+ _qf = checkAgentPay.getBusinessNo();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //检查提现
|
|
|
+ CheckResult checkWithdrawTake = checkWithdrawTake(_tx, logisticsAndBuySellInfo, money);
|
|
|
+ if (!checkWithdrawTake.isStatus()) {
|
|
|
+ _tx = checkWithdrawTake.getBusinessNo();
|
|
|
+ continue;
|
|
|
}
|
|
|
+ //修改结算单状态
|
|
|
+ iKwpSettlementLogisticsService.updateSettlementLogisticsStatusPaid(settlementLogisticsInfo, checkResultPayOrder.getData());
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("获取/处理 充值详情异常", e);
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ KwpSettlementLogistics newSetlementLogistics = new KwpSettlementLogistics();
|
|
|
+ newSetlementLogistics.setId(settlementLogisticsInfo.getId());
|
|
|
+ String remark = (_cz) + "|" + (_yp) + "|" + (_qf) + "|" + (_tx);
|
|
|
+ newSetlementLogistics.setRemark(remark);
|
|
|
+ kwpSettlementLogisticsMapper.updateById(newSetlementLogistics);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("修改结算单状态异常", e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -131,4 +176,162 @@ public class JobService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @description:检查充值订单
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/2/10 星期一 14:17
|
|
|
+ * @param:
|
|
|
+ * @return:
|
|
|
+ **/
|
|
|
+ private CheckResult<PayOrder> checkPayOrder(String _cz, KwpSettlementLogistics settlementLogisticsInfo) {
|
|
|
+ CheckResult<PayOrder> checkResult = new CheckResult<PayOrder>();
|
|
|
+ //直接查充值订单
|
|
|
+ LambdaQueryWrapper<PayOrder> payOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ payOrderLambdaQueryWrapper.eq(PayOrder::getOrderNo, settlementLogisticsInfo.getSlOrderNo());
|
|
|
+ payOrderLambdaQueryWrapper.eq(PayOrder::getStatus, 1);//已支付
|
|
|
+ List<PayOrder> payOrders = payOrderMapper.selectList(payOrderLambdaQueryWrapper);
|
|
|
+ if (payOrders == null || payOrders.isEmpty()) {
|
|
|
+ //没有已支付的充值订单信息,不做处理
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ } else {
|
|
|
+ PayOrder details = payOrders.get(0);
|
|
|
+ checkResult.setStatus(true);
|
|
|
+ checkResult.setBusinessNo(details.getOrderNo());
|
|
|
+ checkResult.setData(details);
|
|
|
+ }
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description:检查预付单状态
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/2/10 星期一 14:24
|
|
|
+ * @param:
|
|
|
+ * @return: null
|
|
|
+ **/
|
|
|
+ private CheckResult checkAdvancePay(String _yp, LedgerLogisticsAndBuySellInfo logisticsAndBuySellInfo, BigDecimal money) {
|
|
|
+ CheckResult checkResult = new CheckResult();
|
|
|
+ // 检查预付
|
|
|
+ if (StringUtils.isBlank(_yp)) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ //发起预付
|
|
|
+ R<Order> orderR = payCenterService.advancePayApply(logisticsAndBuySellInfo.getBuyUid(), ChannelEnum.XW,
|
|
|
+ logisticsAndBuySellInfo.getSellUid(), MoneyChange.bigMoney(money));
|
|
|
+ if (orderR == null || !orderR.getStatus() || orderR.getData() == null) {
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ return checkResult;
|
|
|
+ } else {
|
|
|
+ _yp = orderR.getData().getOrderNo();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("检查预付异常", e);
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<PayMemberWalletAp> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(PayMemberWalletAp::getApNo, _yp);
|
|
|
+ PayMemberWalletAp walletAp = payMemberWalletApMapper.selectOne(wrapper);
|
|
|
+ checkResult.setBusinessNo(_yp);
|
|
|
+ if (walletAp.getStatus().equals(2)) {
|
|
|
+ checkResult.setStatus(true);
|
|
|
+ } else {
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ }
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description:检查清分
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/2/10 星期一 14:28
|
|
|
+ * @param:
|
|
|
+ * @return: null
|
|
|
+ **/
|
|
|
+ private CheckResult checkAgentPay(String _qf, KwpSettlementLogistics settlementLogisticsInfo, LedgerLogisticsAndBuySellInfo logisticsAndBuySellInfo, BigDecimal money) {
|
|
|
+ CheckResult<PayOrderSub> checkResult = new CheckResult<>();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(_qf)) {
|
|
|
+ // 1.记账
|
|
|
+ List<PatchPay> list = new ArrayList<>();
|
|
|
+ PatchPay patchPay = new PatchPay();
|
|
|
+ patchPay.setUid(logisticsAndBuySellInfo.getSellUid());
|
|
|
+ patchPay.setMoney(MoneyChange.bigMoney(money));
|
|
|
+ patchPay.setRemark("对账单结算");
|
|
|
+ list.add(patchPay);
|
|
|
+ try {
|
|
|
+ //清分
|
|
|
+ R<BusinessNo> businessNoR = payCenterService.payAgentPayV2(logisticsAndBuySellInfo.getBuyUid(), logisticsAndBuySellInfo.getSellUid(), ChannelEnum.XW,
|
|
|
+ MoneyChange.bigMoney(money), list, settlementLogisticsInfo.getSlOrderNo(), "1");
|
|
|
+ log.info("发起清分结果->{}", businessNoR);
|
|
|
+ if (businessNoR == null || !businessNoR.getStatus() || businessNoR.getData() == null) {
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+ _qf = businessNoR.getData().getBusinessNo();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发起清分异常", e);
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<PayOrderSub> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(PayOrderSub::getSubNo, _qf);
|
|
|
+
|
|
|
+ List<PayOrderSub> orderSubs = payOrderSubMapper.selectList(wrapper);
|
|
|
+ if (orderSubs == null || orderSubs.isEmpty()) {
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ return checkResult;
|
|
|
+ } else {
|
|
|
+ PayOrderSub orderSub = orderSubs.get(0);
|
|
|
+ if (orderSub.getStatus().equals(1)) {
|
|
|
+ checkResult.setStatus(true);
|
|
|
+ } else {
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ }
|
|
|
+ checkResult.setBusinessNo(_qf);
|
|
|
+ checkResult.setData(orderSubs.get(0));
|
|
|
+ }
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 检查提现
|
|
|
+ * @author: xj
|
|
|
+ * @date: 2025/2/10 星期一 14:56
|
|
|
+ * @param:
|
|
|
+ * @return: null
|
|
|
+ **/
|
|
|
+ private CheckResult checkWithdrawTake(String _tx, LedgerLogisticsAndBuySellInfo logisticsAndBuySellInfo, BigDecimal money) {
|
|
|
+ CheckResult checkResult = new CheckResult();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(_tx)) {
|
|
|
+ try {
|
|
|
+ //提现
|
|
|
+ R<Order> withdrawTake = payCenterService.withdrawTake(logisticsAndBuySellInfo.getSellUid(), ChannelEnum.XW,
|
|
|
+ MoneyChange.bigMoney(money), "提现");
|
|
|
+ if (withdrawTake == null || !withdrawTake.getStatus() || withdrawTake.getData() == null) {
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+ _tx = withdrawTake.getData().getOrderNo();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ checkResult.setBusinessNo(_tx);
|
|
|
+ LambdaQueryWrapper<PayWalletWithdrawOrder> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(PayWalletWithdrawOrder::getOrderNo, _tx);
|
|
|
+ PayWalletWithdrawOrder payWalletWithdrawOrder = payWalletWithdrawOrderMapper.selectOne(wrapper);
|
|
|
+ checkResult.setData(payWalletWithdrawOrder);
|
|
|
+ if (payWalletWithdrawOrder.getStatus().equals(1)) {
|
|
|
+ checkResult.setStatus(true);
|
|
|
+ } else {
|
|
|
+ checkResult.setStatus(false);
|
|
|
+ }
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
}
|