xucaiqin 2 роки тому
батько
коміт
1e1ef4c98f

+ 1 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpLedgerLogisticsOrderService.java

@@ -51,7 +51,7 @@ public class KwpLedgerLogisticsOrderService {
     /**
     /**
      * 根据id查询
      * 根据id查询
      *
      *
-     * @param id
+     * @param id 物流对账单id
      * @return
      * @return
      */
      */
     public List<KwpLedgerLogisticsOrder> queryList(Long id) {
     public List<KwpLedgerLogisticsOrder> queryList(Long id) {

+ 17 - 12
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/KwpSettlementWalletService.java

@@ -568,6 +568,8 @@ public class KwpSettlementWalletService {
 
 
     /**
     /**
      * 销售-预付款
      * 销售-预付款
+     * 贸易订单下单时,冻结资金
+     * 预付款结算时,解冻资金。在进行清分。
      *
      *
      * @param id 结算单id
      * @param id 结算单id
      * @return
      * @return
@@ -576,20 +578,19 @@ public class KwpSettlementWalletService {
     public String confirmTradeCollection(Long id) {
     public String confirmTradeCollection(Long id) {
         log.info("销售预付款确认,结算单id:{}", id);
         log.info("销售预付款确认,结算单id:{}", id);
         String key = String.format(RedisConstant.SETTLEMENT_KEY, id);
         String key = String.format(RedisConstant.SETTLEMENT_KEY, id);
-
+        SettlementTradeDto byId = kwpSettlementTradeService.getById(id, TradeUnitType.PURCHASE);
+        if (Objects.isNull(byId)) {
+            throw new BusinessException("结算单不存在");
+        }
+        if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
+            throw new BusinessException("只支持预付款交易方式进行预付款确认操作");
+        }
+        List<KwpLedgerTradeOrder> kwpLedgerTradeOrders = tradeOrderService.queryList(byId.getLedgerId());
+        if (CollectionUtils.isEmpty(kwpLedgerTradeOrders)) {
+            throw new BusinessException("未找到关联的贸易订单");
+        }
         if (redisLockUtil.tryLock(key)) {
         if (redisLockUtil.tryLock(key)) {
             try {
             try {
-                SettlementTradeDto byId = kwpSettlementTradeService.getById(id, TradeUnitType.PURCHASE);
-                if (Objects.isNull(byId)) {
-                    throw new BusinessException("结算单不存在");
-                }
-                if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
-                    throw new BusinessException("只支持预付款交易方式进行预付款确认操作");
-                }
-                List<KwpLedgerTradeOrder> kwpLedgerTradeOrders = tradeOrderService.queryList(byId.getLedgerId());
-                if (CollectionUtils.isEmpty(kwpLedgerTradeOrders)) {
-                    throw new BusinessException("未找到关联的贸易订单");
-                }
                 //更新交易结算单状态和金额
                 //更新交易结算单状态和金额
                 KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
                 KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
                 kwpSettlementTrade.setId(byId.getId());
                 kwpSettlementTrade.setId(byId.getId());
@@ -601,9 +602,12 @@ public class KwpSettlementWalletService {
                 //预付款-更新对账单已付金额
                 //预付款-更新对账单已付金额
                 kwpLedgerTradeService.updateActualPrice(byId.gettLedgerId(), byId.getTotalPrice());
                 kwpLedgerTradeService.updateActualPrice(byId.gettLedgerId(), byId.getTotalPrice());
                 //新增电子钱包结算记录
                 //新增电子钱包结算记录
+                //清分单号
+                String orderNo = OrderUtils.generateOrderNo("ST");
                 KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
                 KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
                 kwpSettlementWallet.setId(new IdWorker(1).nextId());
                 kwpSettlementWallet.setId(new IdWorker(1).nextId());
                 kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
                 kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
+                kwpSettlementWallet.setOrderNo(orderNo);
                 kwpSettlementWallet.setSettlementId(byId.getId());
                 kwpSettlementWallet.setSettlementId(byId.getId());
                 kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
                 kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
                 kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
                 kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
@@ -644,6 +648,7 @@ public class KwpSettlementWalletService {
 
 
                 //todo-xcq 调用中台接口
                 //todo-xcq 调用中台接口
 
 
+
                 return "确认回款成功";
                 return "确认回款成功";
             } finally {
             } finally {
                 redisLockUtil.unlock(key);
                 redisLockUtil.unlock(key);

+ 35 - 0
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/WalletService.java

@@ -12,6 +12,7 @@ import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.OrderUtils;
 import com.sckw.core.utils.OrderUtils;
 import com.sckw.core.utils.StringTimeUtil;
 import com.sckw.core.utils.StringTimeUtil;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.context.LoginUserHolder;
+import com.sckw.core.web.response.HttpResult;
 import com.sckw.manage.api.RemoteManageService;
 import com.sckw.manage.api.RemoteManageService;
 import com.sckw.manage.api.model.dto.res.FindEntCooperateResVo;
 import com.sckw.manage.api.model.dto.res.FindEntCooperateResVo;
 import com.sckw.payment.api.model.constant.ChannelEnum;
 import com.sckw.payment.api.model.constant.ChannelEnum;
@@ -128,6 +129,19 @@ public class WalletService {
         return walletRelationService.getEnt(id);
         return walletRelationService.getEnt(id);
     }
     }
 
 
+    /**
+     * 查询中台用户id
+     *
+     * @param id
+     * @return
+     */
+    private String getUid(Long id) {
+        if (Objects.isNull(id)) {
+            return null;
+        }
+        return walletRelationService.getRelation(id);
+    }
+
     /**
     /**
      * 通过企业名称查询关联的中台用户id
      * 通过企业名称查询关联的中台用户id
      *
      *
@@ -1466,6 +1480,27 @@ public class WalletService {
         return null;
         return null;
     }
     }
 
 
+    /**
+     * 贸易订单预支付下单时,冻结预付款金额
+     *
+     * @param payEntId     支付方企业
+     * @param channel      渠道
+     * @param receiveEntId 收款方企业
+     * @param money        冻结金额(分)
+     * @param orderNo      订单流水
+     * @return
+     */
+    public HttpResult freezeMoney(Long payEntId, ChannelEnum channel, Long receiveEntId, Long money, String orderNo) {
+        String uid = getUid(payEntId);
+        String filter = getUid(receiveEntId);
+        R<Freeze> freezeR = payCenterService.walletFreeze(uid, channel, filter, money, orderNo);
+        if (!freezeR.getStatus()) {
+            log.error("资金冻结异常:{}", JSONObject.toJSONString(freezeR));
+            HttpResult.error(freezeR.getMsg());
+        }
+        return HttpResult.ok("冻结成功");
+    }
+
     /**
     /**
      * 退款处理
      * 退款处理
      *
      *

+ 7 - 1
sckw-modules/sckw-payment/src/main/java/com/sckw/payment/service/dubbo/PaymentDubboServiceImpl.java

@@ -2,6 +2,7 @@ package com.sckw.payment.service.dubbo;
 
 
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.exception.BusinessException;
 import com.sckw.core.utils.OrderUtils;
 import com.sckw.core.utils.OrderUtils;
+import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.payment.api.dubbo.PaymentDubboService;
 import com.sckw.payment.api.dubbo.PaymentDubboService;
 import com.sckw.payment.api.model.constant.ChannelEnum;
 import com.sckw.payment.api.model.constant.ChannelEnum;
@@ -72,6 +73,9 @@ public class PaymentDubboServiceImpl implements PaymentDubboService {
         if (Objects.isNull(money)) {
         if (Objects.isNull(money)) {
             return HttpResult.error("订单金额不能为空");
             return HttpResult.error("订单金额不能为空");
         }
         }
+        if (Objects.isNull(tOrderId)) {
+            return HttpResult.error("贸易订单id不能为空");
+        }
         long m;
         long m;
         try {
         try {
             m = money.multiply(new BigDecimal("100")).longValueExact();
             m = money.multiply(new BigDecimal("100")).longValueExact();
@@ -83,7 +87,9 @@ public class PaymentDubboServiceImpl implements PaymentDubboService {
         String orderNo = OrderUtils.generateOrderNo("STF");
         String orderNo = OrderUtils.generateOrderNo("STF");
         HttpResult httpResult = walletService.freezeMoney(payEntId, channel, receiveEntId, m, orderNo);
         HttpResult httpResult = walletService.freezeMoney(payEntId, channel, receiveEntId, m, orderNo);
         //记录订单流水号
         //记录订单流水号
-        kwpTradeFreezeService.save(tOrderId, orderNo);
+        if (httpResult.getCode() == HttpStatus.SUCCESS_CODE) {
+            kwpTradeFreezeService.save(tOrderId, orderNo);
+        }
         return httpResult;
         return httpResult;
     }
     }