|
|
@@ -2,15 +2,22 @@ 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.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;
|
|
|
@@ -48,6 +55,12 @@ public class JobService {
|
|
|
KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
|
|
|
@Autowired
|
|
|
PayOrderMapper payOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ PayOrderSubMapper payOrderSubMapper;
|
|
|
+ @Autowired
|
|
|
+ PayWalletWithdrawOrderMapper payWalletWithdrawOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ PayMemberWalletApMapper payMemberWalletApMapper;
|
|
|
|
|
|
/**
|
|
|
* 【轮循程序】
|
|
|
@@ -87,100 +100,58 @@ public class JobService {
|
|
|
continue;
|
|
|
}
|
|
|
for (KwpSettlementLogistics settlementLogisticsInfo : settlementLogistics) {
|
|
|
- boolean _cz = false, _yp = false, _qf = false, _tx = false;
|
|
|
+ String _cz = " ", _yp = " ", _qf = " ", _tx = " ";
|
|
|
try {
|
|
|
|
|
|
-// R<PayOrderDetail> details = payCenterService.getPayDetailByOrderNo(settlementLogisticsInfo.getSlOrderNo());
|
|
|
-// if (details == null || details.getCode() != 200 || details.getData() == null || !details.getStatus()) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
- //记录先关单号,防止重复调用 (0-失败,1一成功) remark=充值状态|预付状态|清分状态|提现状态
|
|
|
+ //记录关联单号,防止重复调用 (有值-表示已生成对应单据,无值一表示没有业务单据) remark=已支付的充值单号|预付单号|清分单号|提现单号
|
|
|
String remark = settlementLogisticsInfo.getRemark();
|
|
|
if (!StringUtils.isBlank(remark)) {
|
|
|
String[] split = remark.split("\\|");
|
|
|
if (split.length == 4) {
|
|
|
- _cz = split[0].equals("1");
|
|
|
- _yp = split[1].equals("1");
|
|
|
- _qf = split[2].equals("1");
|
|
|
- _tx = split[3].equals("1");
|
|
|
+ _cz = split[0];
|
|
|
+ _yp = split[1];
|
|
|
+ _qf = split[2];
|
|
|
+ _tx = split[3];
|
|
|
}
|
|
|
}
|
|
|
- //只接查充值订单
|
|
|
- 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()) {
|
|
|
- _cz = false;
|
|
|
+ //检查充值
|
|
|
+ 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;
|
|
|
}
|
|
|
- _cz = true;
|
|
|
- PayOrder details = payOrders.get(0);
|
|
|
- BigDecimal money = MoneyChange.smallMoney(new BigDecimal(details.getMoney()));
|
|
|
- //根据充值订单状态 处理结算状态
|
|
|
- //if (details.getData().getStatus() == 1) {//已支付
|
|
|
- if (!_yp) { //发起预付
|
|
|
- R<Order> orderR = payCenterService.advancePayApply(logisticsAndBuySellInfo.getBuyUid(), ChannelEnum.XW,
|
|
|
- logisticsAndBuySellInfo.getSellUid(), MoneyChange.bigMoney(money));
|
|
|
- if (orderR == null || !orderR.getStatus() || orderR.getData() == null) {
|
|
|
- _yp = false;
|
|
|
- continue;
|
|
|
- }
|
|
|
- _yp = true;
|
|
|
- }
|
|
|
- if (_yp && !_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");
|
|
|
- if (businessNoR == null || !businessNoR.getStatus() || businessNoR.getData() == null) {
|
|
|
- _qf = false;
|
|
|
- continue;
|
|
|
- }
|
|
|
- _qf = true;
|
|
|
- } catch (Exception e) {
|
|
|
- _qf = false;
|
|
|
- log.error("发起预付异常", e);
|
|
|
- }
|
|
|
|
|
|
+ //检查清分
|
|
|
+ CheckResult checkAgentPay = checkAgentPay(_qf, settlementLogisticsInfo, logisticsAndBuySellInfo, money);
|
|
|
+ if (!checkAgentPay.isStatus()) {
|
|
|
+ _qf = checkAgentPay.getBusinessNo();
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (_qf && !_tx) {
|
|
|
- try {
|
|
|
- //提现
|
|
|
- R<Order> withdrawTake = payCenterService.withdrawTake(logisticsAndBuySellInfo.getSellUid(), ChannelEnum.XW,
|
|
|
- MoneyChange.bigMoney(money),
|
|
|
- "提现");
|
|
|
- if (withdrawTake == null || !withdrawTake.getStatus() || withdrawTake.getData() == null) {
|
|
|
- _tx = false;
|
|
|
- continue;
|
|
|
- }
|
|
|
- _tx = true;
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- _tx = false;
|
|
|
- continue;
|
|
|
- }
|
|
|
+ //检查提现
|
|
|
+ CheckResult checkWithdrawTake = checkWithdrawTake(_tx, logisticsAndBuySellInfo, money);
|
|
|
+ if (!checkWithdrawTake.isStatus()) {
|
|
|
+ _tx = checkWithdrawTake.getBusinessNo();
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (_tx) {
|
|
|
- //修改结算单状态
|
|
|
- iKwpSettlementLogisticsService.updateSettlementLogisticsStatusPaid(settlementLogisticsInfo, details);
|
|
|
- } // }
|
|
|
+ //修改结算单状态
|
|
|
+ iKwpSettlementLogisticsService.updateSettlementLogisticsStatusPaid(settlementLogisticsInfo, checkResultPayOrder.getData());
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("获取/处理 充值详情异常", e);
|
|
|
- }
|
|
|
- finally {
|
|
|
+ } finally {
|
|
|
try {
|
|
|
KwpSettlementLogistics newSetlementLogistics = new KwpSettlementLogistics();
|
|
|
newSetlementLogistics.setId(settlementLogisticsInfo.getId());
|
|
|
- String remark =(_cz?"1":"0")+"|"+(_yp?"1":"0")+"|"+(_qf?"1":"0")+"|"+(_tx?"1":"0");
|
|
|
+ String remark = (_cz) + "|" + (_yp) + "|" + (_qf) + "|" + (_tx);
|
|
|
newSetlementLogistics.setRemark(remark);
|
|
|
kwpSettlementLogisticsMapper.updateById(newSetlementLogistics);
|
|
|
} catch (Exception e) {
|
|
|
@@ -205,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;
|
|
|
+ }
|
|
|
}
|