mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 19:45:09 +08:00
update
This commit is contained in:
@@ -623,6 +623,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
}
|
||||
// 消费金额就是订单总金额
|
||||
BigDecimal orderAmount = new BigDecimal(data.getConsumptionAmount());
|
||||
orderBasicInfo.setOrderAmount(orderAmount);
|
||||
|
||||
// 付款金额 - 实际消费金额,如果有剩余,需要走退款操作 当使用余额支付时payAmount = principalPay + giftPay
|
||||
BigDecimal payAmount = orderBasicInfo.getPayAmount();
|
||||
@@ -639,86 +640,13 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
// 剩余需要退回的金额 residue
|
||||
BigDecimal residue = payAmount.subtract(orderAmount);
|
||||
if (residue.compareTo(BigDecimal.ZERO) > 0) {
|
||||
// 查支付记录
|
||||
List<OrderPayRecord> payRecordList = orderPayRecordService.getOrderPayRecordList(orderCode);
|
||||
// 更新订单支付记录
|
||||
List<OrderPayRecord> updatePayRecordList = Lists.newArrayList();
|
||||
// 根据支付方式不同,走不同渠道退款
|
||||
String payMode = orderBasicInfo.getPayMode();
|
||||
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) { // 余额支付
|
||||
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("1");
|
||||
if (principalPayRecord != null) {
|
||||
principalPay = principalPayRecord.getPayAmount();
|
||||
}
|
||||
|
||||
OrderPayRecord giftPayRecord = payRecordMap.get("2");
|
||||
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);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { // 微信支付
|
||||
// 微信退款逻辑
|
||||
WeChatRefundDTO weChatRefundDTO = new WeChatRefundDTO();
|
||||
weChatRefundDTO.setOrderCode(orderCode);
|
||||
weChatRefundDTO.setRefundType("1");
|
||||
weChatRefundDTO.setRefundAmount(residue);
|
||||
|
||||
// 查到该笔订单付款金额到哪里了
|
||||
MemberTransactionRecord transactionRecord = memberTransactionRecordService.selectByOrderCode(orderCode, ActionTypeEnum.FORWARD.getValue());
|
||||
logger.info("查到该笔订单付款金额到哪里了:{}", JSON.toJSONString(transactionRecord));
|
||||
if (StringUtils.equals(transactionRecord.getPaymentInstitutions(), PaymentInstitutionsEnum.WECHAT_PAY.getValue())) {
|
||||
this.weChatRefund(weChatRefundDTO);
|
||||
} else if (StringUtils.equals(transactionRecord.getPaymentInstitutions(), PaymentInstitutionsEnum.ADAPAY.getValue())) {
|
||||
this.refundForOrderWithAdapay(weChatRefundDTO);
|
||||
}
|
||||
// 订单支付记录
|
||||
OrderPayRecord orderPayRecord = payRecordList.get(0);
|
||||
orderPayRecord.setRefundAmount(residue);
|
||||
updatePayRecordList.add(orderPayRecord);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 支付宝支付
|
||||
// 支付宝退款逻辑
|
||||
} else {
|
||||
// 白名单支付
|
||||
logger.info("订单:{}使用白名单支付,不进行退款处理", orderCode);
|
||||
// 执行退款逻辑
|
||||
try {
|
||||
refundOrder(orderBasicInfo, residue);
|
||||
} catch (Exception e) {
|
||||
logger.error("订单退款逻辑异常orderCode:{}", orderCode, e);
|
||||
}
|
||||
|
||||
// 更新order_pay_record
|
||||
if (CollectionUtils.isNotEmpty(updatePayRecordList)) {
|
||||
for (OrderPayRecord orderPayRecord : updatePayRecordList) {
|
||||
orderPayRecordService.updateByPrimaryKeySelective(orderPayRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改订单数据
|
||||
@@ -726,7 +654,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
OrderDetail orderDetail = getOrderDetailByOrderCode(orderCode);
|
||||
|
||||
// 把交易记录中的用电量,金额等信息 更新到orderBasicInfo和orderDetail
|
||||
orderBasicInfo.setOrderAmount(orderAmount); // 订单总金额
|
||||
// orderBasicInfo.setOrderAmount(orderAmount); // 订单总金额
|
||||
orderBasicInfo.setVirtualAmount(virtualAmount); // 虚拟金额
|
||||
orderBasicInfo.setSettleAmount(orderAmount.subtract(virtualAmount)); // 结算金额
|
||||
orderBasicInfo.setOrderStatus(OrderStatusEnum.ORDER_COMPLETE.getValue());
|
||||
@@ -848,6 +776,96 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
realTimeMonitorDataRedis2DB(orderBasicInfo.getTransactionCode(), orderCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款逻辑
|
||||
* @param orderBasicInfo 订单信息
|
||||
* @param residue 需退款金额
|
||||
*/
|
||||
private void refundOrder(OrderBasicInfo orderBasicInfo, BigDecimal residue) {
|
||||
String orderCode = orderBasicInfo.getOrderCode();
|
||||
BigDecimal orderAmount = orderBasicInfo.getOrderAmount();
|
||||
// 查支付记录
|
||||
List<OrderPayRecord> payRecordList = orderPayRecordService.getOrderPayRecordList(orderCode);
|
||||
// 更新订单支付记录
|
||||
List<OrderPayRecord> updatePayRecordList = Lists.newArrayList();
|
||||
// 根据支付方式不同,走不同渠道退款
|
||||
String payMode = orderBasicInfo.getPayMode();
|
||||
if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) { // 余额支付
|
||||
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("1");
|
||||
if (principalPayRecord != null) {
|
||||
principalPay = principalPayRecord.getPayAmount();
|
||||
}
|
||||
|
||||
OrderPayRecord giftPayRecord = payRecordMap.get("2");
|
||||
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);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { // 微信支付
|
||||
// 微信退款逻辑
|
||||
WeChatRefundDTO weChatRefundDTO = new WeChatRefundDTO();
|
||||
weChatRefundDTO.setOrderCode(orderCode);
|
||||
weChatRefundDTO.setRefundType("1");
|
||||
weChatRefundDTO.setRefundAmount(residue);
|
||||
|
||||
// 查到该笔订单付款金额到哪里了
|
||||
MemberTransactionRecord transactionRecord = memberTransactionRecordService.selectByOrderCode(orderCode, ActionTypeEnum.FORWARD.getValue());
|
||||
logger.info("查到该笔订单付款金额到哪里了:{}", JSON.toJSONString(transactionRecord));
|
||||
if (StringUtils.equals(transactionRecord.getPaymentInstitutions(), PaymentInstitutionsEnum.WECHAT_PAY.getValue())) {
|
||||
this.weChatRefund(weChatRefundDTO);
|
||||
} else if (StringUtils.equals(transactionRecord.getPaymentInstitutions(), PaymentInstitutionsEnum.ADAPAY.getValue())) {
|
||||
this.refundForOrderWithAdapay(weChatRefundDTO);
|
||||
}
|
||||
// 订单支付记录
|
||||
OrderPayRecord orderPayRecord = payRecordList.get(0);
|
||||
orderPayRecord.setRefundAmount(residue);
|
||||
updatePayRecordList.add(orderPayRecord);
|
||||
} else if (StringUtils.equals(payMode, OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // 支付宝支付
|
||||
// 支付宝退款逻辑
|
||||
} else {
|
||||
// 白名单支付
|
||||
logger.info("订单:{}使用白名单支付,不进行退款处理", orderCode);
|
||||
}
|
||||
|
||||
// 更新order_pay_record
|
||||
if (CollectionUtils.isNotEmpty(updatePayRecordList)) {
|
||||
for (OrderPayRecord orderPayRecord : updatePayRecordList) {
|
||||
orderPayRecordService.updateByPrimaryKeySelective(orderPayRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// uniApp 发送停止充电订阅消息
|
||||
private void sendMsg(OrderBasicInfo orderBasicInfo) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user