This commit is contained in:
Guoqs
2024-11-16 16:29:49 +08:00
parent c773da3653
commit 4b09d58aee
2 changed files with 19 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
package com.jsowell.pile.dto;
import com.jsowell.pile.domain.OrderBasicInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@@ -69,4 +70,9 @@ public class AfterSettleOrderDTO {
* 订单退款金额
*/
private BigDecimal orderRefundAmount;
/**
* 订单信息, 查询后放入DTO方便后面使用
*/
private OrderBasicInfo orderBasicInfo;
}

View File

@@ -853,6 +853,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
* 返回更新后的OrderBasicInfo对象
* 专用方法,其他地方如果要用请仔细检查
*/
@Override
public void returnUpdateOrderBasicInfo(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
// 订单编号
String orderCode = orderBasicInfo.getOrderCode();
@@ -893,6 +894,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
*
* @return 查询并更新过数据的orderDetail
*/
@Override
public OrderDetail returnUpdateOrderDetail(OrderBasicInfo orderBasicInfo, TransactionRecordsData data) {
String orderCode = orderBasicInfo.getOrderCode();
BigDecimal orderAmount = orderBasicInfo.getOrderAmount();
@@ -1512,63 +1514,36 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
BigDecimal orderPayAmount = afterSettleOrderDTO.getOrderPayAmount(); // 支付金额
BigDecimal orderConsumeAmount = afterSettleOrderDTO.getOrderConsumeAmount(); // 消费金额
BigDecimal orderRefundAmount = afterSettleOrderDTO.getOrderRefundAmount(); // 退款金额
BigDecimal orderSettleAmount = afterSettleOrderDTO.getOrderSettleAmount(); // 结算金额
if (orderConsumeAmount.add(orderRefundAmount).compareTo(orderPayAmount) != 0) {
logger.info("订单支付金额与消费金额+退款金额不相等");
return null;
}
OrderBasicInfo orderBasicInfo = this.getOrderInfoByOrderCode(afterSettleOrderDTO.getOrderCode());
afterSettleOrderDTO.setOrderBasicInfo(orderBasicInfo);
// 订单结算金额,汇付分账
splittingMethod(orderSettleAmount, afterSettleOrderDTO);
splittingMethod(afterSettleOrderDTO);
// 订单退款,汇付退款
refundMethod(afterSettleOrderDTO);
return null;
}
/**
* 分账方法
* @param orderSettleAmount
* @param afterSettleOrderDTO
*/
private void splittingMethod(BigDecimal orderSettleAmount, AfterSettleOrderDTO afterSettleOrderDTO) {
private void splittingMethod(AfterSettleOrderDTO afterSettleOrderDTO) {
BigDecimal orderSettleAmount = afterSettleOrderDTO.getOrderSettleAmount(); // 结算金额
}
/**
* 执行订单退款
* @param orderBasicInfo
*/
private void refundOrder(OrderBasicInfo orderBasicInfo) {
BigDecimal refundAmount = orderBasicInfo.getRefundAmount();
// 查询该笔订单的退款记录
List<OrderDetailInfoVO.OrderRefundInfo> orderRefundInfoList = this.getOrderRefundInfoList(orderBasicInfo);
if (CollectionUtils.isNotEmpty(orderRefundInfoList)) {
// 已退款金额
BigDecimal refunded = orderRefundInfoList.stream()
.map(x -> Objects.nonNull(x.getReverseAmt()) ? new BigDecimal(x.getReverseAmt()) : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO,BigDecimal::add);
if (refunded.compareTo(refundAmount) >= 0) {
logger.info("执行订单退款-校验已退款金额orderCode:{}, 应退款金额:{}, 已经退款金额:{}, 不再执行退款", orderBasicInfo.getOrderCode(), refundAmount, refunded);
return;
}
}
private void refundMethod(AfterSettleOrderDTO afterSettleOrderDTO) {
OrderBasicInfo orderBasicInfo = afterSettleOrderDTO.getOrderBasicInfo();
try {
String payMode = orderBasicInfo.getPayMode();
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_PRINCIPAL_BALANCE.getValue())) {
// 余额支付
balancePaymentOrderRefund(orderBasicInfo);
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())
|| StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) {
// 在线支付
onlinePaymentOrderRefund(orderBasicInfo);
} else {
// 白名单支付或者ETC支付
logger.info("订单:{}使用:{},不进行退款处理", orderBasicInfo.getOrderCode(), OrderPayModeEnum.getPayModeDescription(payMode));
}
} catch (Exception e) {
logger.error("【{}】-订单退款逻辑异常orderCode:{}", this.getClass().getSimpleName(), orderBasicInfo.getOrderCode(), e);
}
}
/**
@@ -3995,6 +3970,7 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
* @param stationId
* @return
*/
@Override
public List<SupStationStatsVO> queryOrderListByStationId(String stationId) {
List<SupStationStatsVO> orderVOS = orderBasicInfoMapper.queryOrderListByStationId(stationId);
for (SupStationStatsVO orderVO : orderVOS) {