交易分账 重构

This commit is contained in:
2023-08-28 19:21:41 +08:00
parent 6c973bff6f
commit 462462a79d

View File

@@ -1143,6 +1143,56 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
}
}
private void balancePaymentOrderRefundV2(OrderBasicInfo orderBasicInfo) {
// 订单编号
String orderCode = orderBasicInfo.getOrderCode();
// 订单消费金额
BigDecimal orderAmount = orderBasicInfo.getOrderAmount();
// 查支付记录
List<OrderPayRecord> payRecordList = orderPayRecordService.getOrderPayRecordList(orderCode);
Map<String, OrderPayRecord> payRecordMap = payRecordList.stream()
.collect(Collectors.toMap(OrderPayRecord::getPayMode, Function.identity(), (k1, k2) -> k1));
// 取出本金支付金额
BigDecimal principalPay = null;
// 获取本金支付的记录
OrderPayRecord principalPayRecord = payRecordMap.get(Constants.ONE);
if (principalPayRecord != null) {
principalPay = principalPayRecord.getPayAmount();
}
Map<String, BigDecimal> returnAmountMap = calculateReturnAmount(principalPay, null, orderAmount);
logger.info("结算订单:{}, 剩余金额退回余额, 订单消费金额:{}, 本金支付金额:{}, 赠送支付金额:{}, 退回金额map:{}",
orderCode, orderAmount, principalPay, null, JSONObject.toJSONString(returnAmountMap));
// 需要退回本金的金额
BigDecimal returnPrincipal = returnAmountMap.get("returnPrincipal");
// 更新会员钱包
UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
.memberId(orderBasicInfo.getMemberId())
.type(MemberWalletEnum.TYPE_IN.getValue()) // 进账
.subType(MemberWalletEnum.SUBTYPE_ORDER_SETTLEMENT_REFUND.getValue()) // 订单结算退款
.updatePrincipalBalance(returnPrincipal)
.relatedOrderCode(orderCode)
.build();
memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
// 更新order_pay_record
// 更新订单支付记录
// List<OrderPayRecord> updatePayRecordList = Lists.newArrayList();
// if (returnPrincipal != null && principalPayRecord != null) {
// principalPayRecord.setRefundAmount(returnPrincipal);
// updatePayRecordList.add(principalPayRecord);
// }
// if (CollectionUtils.isNotEmpty(updatePayRecordList)) {
// orderPayRecordService.updateBatch(updatePayRecordList);
// }
}
/**
* 订单分账逻辑
* orderSplittingOperations