mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 19:45:09 +08:00
交易分账 重构
This commit is contained in:
@@ -779,7 +779,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
String payMode = orderBasicInfo.getPayMode();
|
||||
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
|
||||
// 余额支付
|
||||
balancePaymentOrderRefund(orderBasicInfo);
|
||||
balancePaymentOrderRefundV2(orderBasicInfo);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
|
||||
// 微信支付
|
||||
onlinePaymentOrderRefund(orderBasicInfo);
|
||||
@@ -1085,63 +1085,63 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
/**
|
||||
* 余额支付的订单退款
|
||||
*/
|
||||
private void balancePaymentOrderRefund(OrderBasicInfo orderBasicInfo) {
|
||||
// 订单编号
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
// 订单消费金额
|
||||
BigDecimal orderAmount = orderBasicInfo.getOrderAmount();
|
||||
// 查支付记录
|
||||
List<OrderPayRecord> payRecordList = orderPayRecordService.getOrderPayRecordList(orderCode);
|
||||
// 更新订单支付记录
|
||||
List<OrderPayRecord> updatePayRecordList = Lists.newArrayList();
|
||||
|
||||
Map<String, OrderPayRecord> payRecordMap = payRecordList.stream()
|
||||
.collect(Collectors.toMap(OrderPayRecord::getPayMode, Function.identity(), (k1, k2) -> k1));
|
||||
// 取出本金支付金额,赠送支付金额
|
||||
BigDecimal principalPay = null;
|
||||
BigDecimal giftPay = null;
|
||||
|
||||
OrderPayRecord principalPayRecord = payRecordMap.get(Constants.ONE);
|
||||
if (principalPayRecord != null) {
|
||||
principalPay = principalPayRecord.getPayAmount();
|
||||
}
|
||||
|
||||
OrderPayRecord giftPayRecord = payRecordMap.get(Constants.TWO);
|
||||
if (giftPayRecord != null) {
|
||||
giftPay = giftPayRecord.getPayAmount();
|
||||
}
|
||||
|
||||
Map<String, BigDecimal> returnAmountMap = calculateReturnAmount(principalPay, giftPay, orderAmount);
|
||||
logger.info("结算订单:{}, 剩余金额退回余额, 订单消费金额:{}, 本金支付金额:{}, 赠送支付金额:{}, 退回金额map:{}",
|
||||
orderCode, orderAmount, principalPay, giftPay, JSONObject.toJSONString(returnAmountMap));
|
||||
// 更新会员钱包
|
||||
BigDecimal returnPrincipal = returnAmountMap.get("returnPrincipal");
|
||||
if (returnPrincipal != null && principalPayRecord != null) {
|
||||
principalPayRecord.setRefundAmount(returnPrincipal);
|
||||
updatePayRecordList.add(principalPayRecord);
|
||||
}
|
||||
BigDecimal returnGift = returnAmountMap.get("returnGift");
|
||||
if (returnGift != null && giftPayRecord != null) {
|
||||
giftPayRecord.setRefundAmount(returnGift);
|
||||
updatePayRecordList.add(giftPayRecord);
|
||||
// 支付的赠送金额-退回的赠送金额 = 实际使用赠送金额消费的部分
|
||||
// virtualAmount = giftPay.subtract(returnGift);
|
||||
}
|
||||
UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
|
||||
.memberId(orderBasicInfo.getMemberId())
|
||||
.type(MemberWalletEnum.TYPE_IN.getValue()) // 进账
|
||||
.subType(MemberWalletEnum.SUBTYPE_ORDER_SETTLEMENT_REFUND.getValue()) // 订单结算退款
|
||||
.updatePrincipalBalance(returnPrincipal)
|
||||
.updateGiftBalance(returnGift)
|
||||
.relatedOrderCode(orderCode)
|
||||
.build();
|
||||
memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
|
||||
|
||||
// 更新order_pay_record
|
||||
if (CollectionUtils.isNotEmpty(updatePayRecordList)) {
|
||||
orderPayRecordService.updateBatch(updatePayRecordList);
|
||||
}
|
||||
}
|
||||
// private void balancePaymentOrderRefund(OrderBasicInfo orderBasicInfo) {
|
||||
// // 订单编号
|
||||
// String orderCode = orderBasicInfo.getOrderCode();
|
||||
// // 订单消费金额
|
||||
// BigDecimal orderAmount = orderBasicInfo.getOrderAmount();
|
||||
// // 查支付记录
|
||||
// List<OrderPayRecord> payRecordList = orderPayRecordService.getOrderPayRecordList(orderCode);
|
||||
// // 更新订单支付记录
|
||||
// List<OrderPayRecord> updatePayRecordList = Lists.newArrayList();
|
||||
//
|
||||
// Map<String, OrderPayRecord> payRecordMap = payRecordList.stream()
|
||||
// .collect(Collectors.toMap(OrderPayRecord::getPayMode, Function.identity(), (k1, k2) -> k1));
|
||||
// // 取出本金支付金额,赠送支付金额
|
||||
// BigDecimal principalPay = null;
|
||||
// BigDecimal giftPay = null;
|
||||
//
|
||||
// OrderPayRecord principalPayRecord = payRecordMap.get(Constants.ONE);
|
||||
// if (principalPayRecord != null) {
|
||||
// principalPay = principalPayRecord.getPayAmount();
|
||||
// }
|
||||
//
|
||||
// OrderPayRecord giftPayRecord = payRecordMap.get(Constants.TWO);
|
||||
// if (giftPayRecord != null) {
|
||||
// giftPay = giftPayRecord.getPayAmount();
|
||||
// }
|
||||
//
|
||||
// Map<String, BigDecimal> returnAmountMap = calculateReturnAmount(principalPay, giftPay, orderAmount);
|
||||
// logger.info("结算订单:{}, 剩余金额退回余额, 订单消费金额:{}, 本金支付金额:{}, 赠送支付金额:{}, 退回金额map:{}",
|
||||
// orderCode, orderAmount, principalPay, giftPay, JSONObject.toJSONString(returnAmountMap));
|
||||
// // 更新会员钱包
|
||||
// BigDecimal returnPrincipal = returnAmountMap.get("returnPrincipal");
|
||||
// if (returnPrincipal != null && principalPayRecord != null) {
|
||||
// principalPayRecord.setRefundAmount(returnPrincipal);
|
||||
// updatePayRecordList.add(principalPayRecord);
|
||||
// }
|
||||
// BigDecimal returnGift = returnAmountMap.get("returnGift");
|
||||
// if (returnGift != null && giftPayRecord != null) {
|
||||
// giftPayRecord.setRefundAmount(returnGift);
|
||||
// updatePayRecordList.add(giftPayRecord);
|
||||
// // 支付的赠送金额-退回的赠送金额 = 实际使用赠送金额消费的部分
|
||||
// // virtualAmount = giftPay.subtract(returnGift);
|
||||
// }
|
||||
// UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
|
||||
// .memberId(orderBasicInfo.getMemberId())
|
||||
// .type(MemberWalletEnum.TYPE_IN.getValue()) // 进账
|
||||
// .subType(MemberWalletEnum.SUBTYPE_ORDER_SETTLEMENT_REFUND.getValue()) // 订单结算退款
|
||||
// .updatePrincipalBalance(returnPrincipal)
|
||||
// .updateGiftBalance(returnGift)
|
||||
// .relatedOrderCode(orderCode)
|
||||
// .build();
|
||||
// memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
|
||||
//
|
||||
// // 更新order_pay_record
|
||||
// if (CollectionUtils.isNotEmpty(updatePayRecordList)) {
|
||||
// orderPayRecordService.updateBatch(updatePayRecordList);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void balancePaymentOrderRefundV2(OrderBasicInfo orderBasicInfo) {
|
||||
// 订单编号
|
||||
|
||||
Reference in New Issue
Block a user