mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-25 13:35:15 +08:00
update 订单分账
This commit is contained in:
@@ -11,8 +11,8 @@ import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 站点分成配置表
|
||||
*/
|
||||
* 站点分成配置表
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@SuperBuilder
|
||||
|
||||
@@ -1379,6 +1379,59 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public OrderSplitResult doBalancePaymentWithDelay(OrderBasicInfo orderBasicInfo, List<DivMember> divMemberList, String wechatAppId) throws BaseAdaPayException {
|
||||
// 订单结算金额
|
||||
BigDecimal settleAmount = orderBasicInfo.getSettleAmount();
|
||||
// 订单编号
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
|
||||
BigDecimal confirmAmt = BigDecimal.ZERO; // 消费金额
|
||||
BigDecimal feeAmt = BigDecimal.ZERO; // 手续费金额
|
||||
String status = null; // 状态
|
||||
|
||||
// 获取余额支付扣除金额 也许存在一笔不够扣,需要扣多笔的情况
|
||||
List<BalanceDeductionAmountVO> list = calculateSplitTheBillAmount(orderBasicInfo.getMemberId(), settleAmount);
|
||||
// List<String> collect = list.stream().map(BalanceDeductionAmountVO::getPaymentId).collect(Collectors.toList());
|
||||
|
||||
List<OrderPayRecord> orderPayRecordList = orderPayRecordService.getOrderPayRecordList(orderBasicInfo.getOrderCode());
|
||||
List<PaymentInfo> paymentInfos = Lists.newArrayList();
|
||||
for (OrderPayRecord orderPayRecord : orderPayRecordList) {
|
||||
String deductionRecord = orderPayRecord.getDeductionRecord();
|
||||
paymentInfos.addAll(orderPayRecordService.parseDeductionRecord(deductionRecord));
|
||||
}
|
||||
List<String> collect = paymentInfos.stream().map(PaymentInfo::getPaymentId).collect(Collectors.toList());
|
||||
|
||||
// 校验是否分账
|
||||
OrderSplitResult result = verifyOrderConfirmAmount(collect, orderCode, settleAmount, wechatAppId);
|
||||
if (!AdapayStatusEnum.SUCCEEDED.getValue().equals(result.getStatus())) {
|
||||
// 没有分账,执行分账逻辑
|
||||
for (BalanceDeductionAmountVO vo : list) {
|
||||
String paymentId = vo.getPaymentId();
|
||||
BigDecimal deductionAmount = vo.getDeductionAmount();
|
||||
|
||||
// 延时分账,使用确认交易API
|
||||
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequestMultiuser(paymentId,
|
||||
divMemberList, deductionAmount, orderCode, wechatAppId);
|
||||
|
||||
if (paymentConfirmResponse != null && paymentConfirmResponse.isNotFailed()) {
|
||||
confirmAmt = confirmAmt.add(new BigDecimal(paymentConfirmResponse.getConfirm_amt()));
|
||||
feeAmt = feeAmt.add(new BigDecimal(paymentConfirmResponse.getFee_amt()));
|
||||
status = paymentConfirmResponse.getStatus();
|
||||
memberAdapayRecordService.unfreezeAmountAndUpdateSpendAmount(paymentId, confirmAmt, confirmAmt);
|
||||
}
|
||||
}
|
||||
|
||||
// 分账接口返回的信息
|
||||
result = new OrderSplitResult();
|
||||
result.setConfirmAmt(confirmAmt.toString());
|
||||
result.setStatus(status);
|
||||
result.setFeeAmt(feeAmt.toString());
|
||||
result.setOrderCode(orderCode);
|
||||
result.setSettleAmt(settleAmount.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算分账扣除金额
|
||||
*/
|
||||
@@ -1520,6 +1573,60 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟交易订单 交易确认 多账户
|
||||
* @param orderBasicInfo
|
||||
* @param divMemberList
|
||||
* @param wechatAppId
|
||||
* @return
|
||||
* @throws BaseAdaPayException
|
||||
*/
|
||||
public OrderSplitResult doPaymentConfirmWithDelay(OrderBasicInfo orderBasicInfo, List<DivMember> divMemberList, String wechatAppId) throws BaseAdaPayException {
|
||||
// 订单编号
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
// 订单结算金额
|
||||
BigDecimal settleAmount = orderBasicInfo.getSettleAmount();
|
||||
|
||||
// 查询订单支付记录
|
||||
List<OrderPayRecord> orderPayRecordList = orderPayRecordService.getOrderPayRecordList(orderCode);
|
||||
|
||||
// 选出需要分账的支付id
|
||||
List<PaymentInfo> paymentInfos = Lists.newArrayList();
|
||||
for (OrderPayRecord orderPayRecord : orderPayRecordList) {
|
||||
BigDecimal payAmount = orderPayRecord.getPayAmount();
|
||||
BigDecimal refundAmount = orderPayRecord.getRefundAmount() == null ? BigDecimal.ZERO : orderPayRecord.getRefundAmount();
|
||||
// 如果相减等于0,说明这笔支付单退完了,就不用分账了
|
||||
BigDecimal subtract = payAmount.subtract(refundAmount);
|
||||
if (subtract.compareTo(BigDecimal.ZERO) > 0) {
|
||||
paymentInfos.addAll(orderPayRecordService.parseDeductionRecord(orderPayRecord.getDeductionRecord()));
|
||||
}
|
||||
}
|
||||
|
||||
List<String> paymentIds = paymentInfos.stream().map(PaymentInfo::getPaymentId).collect(Collectors.toList());
|
||||
|
||||
// 支付id
|
||||
String paymentId = paymentInfos.get(0).getPaymentId();
|
||||
|
||||
// 校验订单分账金额
|
||||
OrderSplitResult result = verifyOrderConfirmAmount(paymentIds, orderCode, settleAmount, wechatAppId);
|
||||
|
||||
// 校验订单是否分账 状态为非交易完成的时候,进行分账处理
|
||||
if (!AdapayStatusEnum.SUCCEEDED.getValue().equals(result.getStatus())) {
|
||||
// 调汇付的分账接口 确认交易
|
||||
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequestMultiuser(paymentId,
|
||||
divMemberList, settleAmount, orderCode, wechatAppId);
|
||||
|
||||
// 分账接口返回的信息
|
||||
result = new OrderSplitResult();
|
||||
result.setConfirmAmt(paymentConfirmResponse.getConfirm_amt());
|
||||
result.setStatus(paymentConfirmResponse.getStatus());
|
||||
result.setFeeAmt(paymentConfirmResponse.getFee_amt());
|
||||
result.setOrderCode(orderCode);
|
||||
result.setSettleAmt(settleAmount.toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单实时分账方法
|
||||
* 2024年9月24日16点17分 新的分账方法
|
||||
@@ -1547,7 +1654,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分账方法
|
||||
* TODO 分账方法
|
||||
* @param afterSettleOrderDTO
|
||||
*/
|
||||
private void splittingMethod(AfterSettleOrderDTO afterSettleOrderDTO) {
|
||||
@@ -1556,6 +1663,9 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
if (orderSettleAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
}
|
||||
|
||||
// 根据站点id查询分账配置
|
||||
List<StationSplitConfig> stationSplitConfigList = stationSplitConfigService.queryByStationId(afterSettleOrderDTO.getStationId());
|
||||
|
||||
// 订单分账
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user