|
@@ -30,6 +30,7 @@ import com.sckw.payment.model.dto.LedgerUnitDto;
|
|
|
import com.sckw.payment.model.dto.SettlementLogisticsDto;
|
|
import com.sckw.payment.model.dto.SettlementLogisticsDto;
|
|
|
import com.sckw.payment.model.dto.SettlementTradeDto;
|
|
import com.sckw.payment.model.dto.SettlementTradeDto;
|
|
|
import com.sckw.payment.model.dto.SettlementWalletDto;
|
|
import com.sckw.payment.model.dto.SettlementWalletDto;
|
|
|
|
|
+import com.sckw.payment.model.dto.common.BusinessNo;
|
|
|
import com.sckw.payment.model.vo.SettlementVo;
|
|
import com.sckw.payment.model.vo.SettlementVo;
|
|
|
import com.sckw.payment.model.vo.req.OfflinePaymentReq;
|
|
import com.sckw.payment.model.vo.req.OfflinePaymentReq;
|
|
|
import com.sckw.payment.model.vo.req.SettlementWalletReq;
|
|
import com.sckw.payment.model.vo.req.SettlementWalletReq;
|
|
@@ -215,7 +216,7 @@ public class KwpSettlementWalletService {
|
|
|
String trading = settlementLogisticsDto.getTrading();
|
|
String trading = settlementLogisticsDto.getTrading();
|
|
|
ChannelEnum channelEnum = ChannelEnum.getByTrading(trading);
|
|
ChannelEnum channelEnum = ChannelEnum.getByTrading(trading);
|
|
|
if (Objects.isNull(channelEnum)) {
|
|
if (Objects.isNull(channelEnum)) {
|
|
|
- throw new BusinessException("交易方式异常");
|
|
|
|
|
|
|
+ throw new BusinessException("交易方式不存在");
|
|
|
}
|
|
}
|
|
|
//加锁
|
|
//加锁
|
|
|
String key = String.format(RedisConstant.SETTLEMENT_KEY, offlinePaymentReq.getId());
|
|
String key = String.format(RedisConstant.SETTLEMENT_KEY, offlinePaymentReq.getId());
|
|
@@ -355,50 +356,33 @@ public class KwpSettlementWalletService {
|
|
|
public String confirmTradePayment(WalletPayReq walletPayReq) {
|
|
public String confirmTradePayment(WalletPayReq walletPayReq) {
|
|
|
log.info("采购-付款确认-货到付款:{}", JSONObject.toJSONString(walletPayReq));
|
|
log.info("采购-付款确认-货到付款:{}", JSONObject.toJSONString(walletPayReq));
|
|
|
String key = String.format(RedisConstant.SETTLEMENT_KEY, walletPayReq.getId());
|
|
String key = String.format(RedisConstant.SETTLEMENT_KEY, walletPayReq.getId());
|
|
|
|
|
+ SettlementTradeDto byId = kwpSettlementTradeService.getById(walletPayReq.getIdLong(), TradeUnitType.SELL);
|
|
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
|
|
+ throw new BusinessException("结算单不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.RECEIVE_PAY.getValue())) {
|
|
|
|
|
+ throw new BusinessException("只支持货货到付款方式订单进行当前操作");
|
|
|
|
|
+ }
|
|
|
|
|
+ KwpLedgerTradeUnit kwpLedgerTradeUnit = tradeUnitService.queryCustomerEnt(byId.getLedgerId(), TradeUnitType.PURCHASE);
|
|
|
|
|
+ KwpLedgerTradeUnit kwpLedgerTradeUnit2 = tradeUnitService.queryCustomerEnt(byId.getLedgerId(), TradeUnitType.SELL);
|
|
|
|
|
+ String uid = walletRelationService.getRelation(kwpLedgerTradeUnit.getTopEntId());
|
|
|
|
|
+ String filter = walletRelationService.getRelation(kwpLedgerTradeUnit2.getTopEntId());
|
|
|
|
|
+ if (StringUtils.isBlank(uid)) {
|
|
|
|
|
+ throw new BusinessException("我方企业暂未开通电子钱包");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(filter)) {
|
|
|
|
|
+ throw new BusinessException("客户企业暂未开通电子钱包");
|
|
|
|
|
+ }
|
|
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByTrading(byId.getTrading());
|
|
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
|
|
+ throw new BusinessException("交易方式不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ //付款金额
|
|
|
|
|
+ BigDecimal price = walletPayReq.getPrice();
|
|
|
if (redisLockUtil.tryLock(key)) {
|
|
if (redisLockUtil.tryLock(key)) {
|
|
|
try {
|
|
try {
|
|
|
- SettlementTradeDto byId = kwpSettlementTradeService.getById(walletPayReq.getIdLong(), TradeUnitType.SELL);
|
|
|
|
|
- if (Objects.isNull(byId)) {
|
|
|
|
|
- throw new BusinessException("结算单不存在");
|
|
|
|
|
- }
|
|
|
|
|
- if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.RECEIVE_PAY.getValue())) {
|
|
|
|
|
- throw new BusinessException("只支持货货到付款方式订单进行当前操作");
|
|
|
|
|
- }
|
|
|
|
|
- List<LedgerUnitDto> listById = kwpSettlementTradeService.getListById(walletPayReq.getIdLong());
|
|
|
|
|
- if (CollectionUtils.isEmpty(listById) || listById.size() != NumberConstant.TWO) {
|
|
|
|
|
- throw new BusinessException("对账单交易企业双方不存在或缺少");
|
|
|
|
|
- }
|
|
|
|
|
- Long uid = null;
|
|
|
|
|
- Long filter = null;
|
|
|
|
|
- for (LedgerUnitDto ledgerUnitDto : listById) {
|
|
|
|
|
- Integer unitType = ledgerUnitDto.getUnitType();
|
|
|
|
|
- if (TradeUnitType.PURCHASE.equals(unitType)) {
|
|
|
|
|
- uid = ledgerUnitDto.getTopEntId();
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- if (TradeUnitType.SELL.equals(unitType)) {
|
|
|
|
|
- filter = ledgerUnitDto.getTopEntId();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- String relation = walletRelationService.getRelation(uid);
|
|
|
|
|
- String filterUser = walletRelationService.getRelation(filter);
|
|
|
|
|
- if (StringUtils.isBlank(relation) || StringUtils.isBlank(filterUser)) {
|
|
|
|
|
- throw new BusinessException("顶级企业未开通电子钱包");
|
|
|
|
|
- }
|
|
|
|
|
- //付款金额
|
|
|
|
|
- BigDecimal price = walletPayReq.getPrice();
|
|
|
|
|
- //todo-xcq-完善
|
|
|
|
|
-
|
|
|
|
|
-// R<List<WalletDto>> wallet = payCenterService.wallet(relation, ChannelEnum.getByCode(byId.getTrading()), filterUser);
|
|
|
|
|
-// if (CollectionUtils.isEmpty(wallet.getData())) {
|
|
|
|
|
-// throw new BusinessException("暂未开通电子钱包");
|
|
|
|
|
-// }
|
|
|
|
|
-// List<WalletDto> data = wallet.getData();
|
|
|
|
|
-// BigDecimal bigDecimal = BigDecimal.valueOf(data.get(0).getMoney()).divide(new BigDecimal("100.0"), RoundingMode.UNNECESSARY);
|
|
|
|
|
-//
|
|
|
|
|
-// if (bigDecimal.compareTo(price) < 0) {
|
|
|
|
|
-// throw new BusinessException("钱包可用余额不足");
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ //电子钱包余额校验
|
|
|
|
|
+ walletBusinessService.checkMoney(uid, filter, channelEnum, price);
|
|
|
//待付款金额-本次付款金额= 剩余待付款金额
|
|
//待付款金额-本次付款金额= 剩余待付款金额
|
|
|
BigDecimal subtract = byId.getWaitPrice().subtract(walletPayReq.getPrice());
|
|
BigDecimal subtract = byId.getWaitPrice().subtract(walletPayReq.getPrice());
|
|
|
if (subtract.compareTo(new BigDecimal("0.0")) < NumberConstant.ZERO) {
|
|
if (subtract.compareTo(new BigDecimal("0.0")) < NumberConstant.ZERO) {
|
|
@@ -406,9 +390,11 @@ public class KwpSettlementWalletService {
|
|
|
}
|
|
}
|
|
|
/*新增记录*/
|
|
/*新增记录*/
|
|
|
//新增电子钱包结算记录
|
|
//新增电子钱包结算记录
|
|
|
|
|
+ String orderNo = OrderUtils.generateOrderNo("ST");
|
|
|
KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
kwpSettlementWallet.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
kwpSettlementWallet.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
|
|
kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
|
|
|
|
|
+ kwpSettlementWallet.setOrderNo(orderNo);
|
|
|
kwpSettlementWallet.setSettlementId(walletPayReq.getIdLong());
|
|
kwpSettlementWallet.setSettlementId(walletPayReq.getIdLong());
|
|
|
kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
|
|
kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
|
|
|
kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
|
|
kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
|
|
@@ -454,9 +440,9 @@ public class KwpSettlementWalletService {
|
|
|
tradeOrderInfoService.updateOrderStatus(updateOrderStatusParam);
|
|
tradeOrderInfoService.updateOrderStatus(updateOrderStatusParam);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //电子钱包清分接口
|
|
|
|
|
+ walletBusinessService.splitMoney(orderNo, uid, filter, channelEnum, price, "2");
|
|
|
|
|
|
|
|
- KwpLedgerTradeUnit kwpLedgerTradeUnit = tradeUnitService.queryCustomerEnt(byId.getLedgerId(), TradeUnitType.PURCHASE);
|
|
|
|
|
- KwpLedgerTradeUnit kwpLedgerTradeUnit2 = tradeUnitService.queryCustomerEnt(byId.getLedgerId(), TradeUnitType.SELL);
|
|
|
|
|
//推送双方系统管理员
|
|
//推送双方系统管理员
|
|
|
messageSender.sendManager(LoginUserHolder.getUserId(), new HashMap<>() {{
|
|
messageSender.sendManager(LoginUserHolder.getUserId(), new HashMap<>() {{
|
|
|
put("company", kwpLedgerTradeUnit.getFirmName());
|
|
put("company", kwpLedgerTradeUnit.getFirmName());
|
|
@@ -466,9 +452,6 @@ public class KwpSettlementWalletService {
|
|
|
put("company", kwpLedgerTradeUnit2.getFirmName());
|
|
put("company", kwpLedgerTradeUnit2.getFirmName());
|
|
|
put("number", kwpSettlementTrade.getStOrderNo());
|
|
put("number", kwpSettlementTrade.getStOrderNo());
|
|
|
}}, kwpLedgerTradeUnit.getEntId(), MessageEnum.SETTLEMENT_START_PURCHASE);
|
|
}}, kwpLedgerTradeUnit.getEntId(), MessageEnum.SETTLEMENT_START_PURCHASE);
|
|
|
-
|
|
|
|
|
- //todo-xcq 调用中台接口
|
|
|
|
|
-
|
|
|
|
|
return "付款确认成功";
|
|
return "付款确认成功";
|
|
|
} finally {
|
|
} finally {
|
|
|
redisLockUtil.unlock(key);
|
|
redisLockUtil.unlock(key);
|
|
@@ -585,10 +568,30 @@ public class KwpSettlementWalletService {
|
|
|
if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
|
|
if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
|
|
|
throw new BusinessException("只支持预付款交易方式进行预付款确认操作");
|
|
throw new BusinessException("只支持预付款交易方式进行预付款确认操作");
|
|
|
}
|
|
}
|
|
|
|
|
+ //冻结编号非空校验
|
|
|
List<KwpLedgerTradeOrder> kwpLedgerTradeOrders = tradeOrderService.queryList(byId.getLedgerId());
|
|
List<KwpLedgerTradeOrder> kwpLedgerTradeOrders = tradeOrderService.queryList(byId.getLedgerId());
|
|
|
if (CollectionUtils.isEmpty(kwpLedgerTradeOrders)) {
|
|
if (CollectionUtils.isEmpty(kwpLedgerTradeOrders)) {
|
|
|
throw new BusinessException("未找到关联的贸易订单");
|
|
throw new BusinessException("未找到关联的贸易订单");
|
|
|
}
|
|
}
|
|
|
|
|
+ for (KwpLedgerTradeOrder kwpLedgerTradeOrder : kwpLedgerTradeOrders) {
|
|
|
|
|
+ if (StringUtils.isBlank(kwpLedgerTradeOrder.getOrderNo())) {
|
|
|
|
|
+ throw new BusinessException(String.format("为找到贸易订单id[%s]的冻结单号", kwpLedgerTradeOrder.getTOrderId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ KwpLedgerTradeUnit kwpLedgerTradeUnit = tradeUnitService.queryCustomerEnt(byId.getLedgerId(), TradeUnitType.PURCHASE);
|
|
|
|
|
+ KwpLedgerTradeUnit kwpLedgerTradeUnit2 = tradeUnitService.queryCustomerEnt(byId.getLedgerId(), TradeUnitType.SELL);
|
|
|
|
|
+ String uid = walletRelationService.getRelation(kwpLedgerTradeUnit.getTopEntId());
|
|
|
|
|
+ if (StringUtils.isBlank(uid)) {
|
|
|
|
|
+ throw new BusinessException("客户单位暂未开通电子钱包");
|
|
|
|
|
+ }
|
|
|
|
|
+ String filter = walletRelationService.getRelation(kwpLedgerTradeUnit2.getTopEntId());
|
|
|
|
|
+ if (StringUtils.isBlank(filter)) {
|
|
|
|
|
+ throw new BusinessException("我方单位暂未开通电子钱包");
|
|
|
|
|
+ }
|
|
|
|
|
+ ChannelEnum channelEnum = ChannelEnum.getByTrading(byId.getTrading());
|
|
|
|
|
+ if (Objects.isNull(channelEnum)) {
|
|
|
|
|
+ throw new BusinessException("交易方式不存在");
|
|
|
|
|
+ }
|
|
|
if (redisLockUtil.tryLock(key)) {
|
|
if (redisLockUtil.tryLock(key)) {
|
|
|
try {
|
|
try {
|
|
|
//更新交易结算单状态和金额
|
|
//更新交易结算单状态和金额
|
|
@@ -634,8 +637,17 @@ public class KwpSettlementWalletService {
|
|
|
tradeOrderInfoService.updateOrderStatus(updateOrderStatusParam);
|
|
tradeOrderInfoService.updateOrderStatus(updateOrderStatusParam);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- KwpLedgerTradeUnit kwpLedgerTradeUnit = tradeUnitService.queryCustomerEnt(byId.getLedgerId(), TradeUnitType.PURCHASE);
|
|
|
|
|
- KwpLedgerTradeUnit kwpLedgerTradeUnit2 = tradeUnitService.queryCustomerEnt(byId.getLedgerId(), TradeUnitType.SELL);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /*电子钱包相关业务*/
|
|
|
|
|
+ //批量获取对账单关联的贸易订单 再获取冻结编号,批量解冻
|
|
|
|
|
+ for (KwpLedgerTradeOrder kwpLedgerTradeOrder : kwpLedgerTradeOrders) {
|
|
|
|
|
+ R<BusinessNo> businessNoR = payCenterService.walletUnFreeze(kwpLedgerTradeOrder.getOrderNo());
|
|
|
|
|
+ if (!businessNoR.getStatus()) {
|
|
|
|
|
+ throw new BusinessException(businessNoR.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //对结算单中的总计金额进行清分
|
|
|
|
|
+ walletBusinessService.splitMoney(orderNo, uid, filter, channelEnum, byId.getTotalPrice(), "1");
|
|
|
//推送双方系统管理员
|
|
//推送双方系统管理员
|
|
|
messageSender.sendManager(LoginUserHolder.getUserId(), new HashMap<>() {{
|
|
messageSender.sendManager(LoginUserHolder.getUserId(), new HashMap<>() {{
|
|
|
put("company", kwpLedgerTradeUnit.getFirmName());
|
|
put("company", kwpLedgerTradeUnit.getFirmName());
|