记录退款金额到订单支付记录

This commit is contained in:
2024-01-17 16:35:03 +08:00
parent 5a35135500
commit 8f7e3eaa94
8 changed files with 61 additions and 42 deletions

View File

@@ -1,8 +1,10 @@
package com.jsowell.pile.service;
import com.jsowell.adapay.vo.PaymentInfo;
import com.jsowell.pile.domain.OrderPayRecord;
import com.jsowell.pile.vo.web.OrderDetailInfoVO;
import java.math.BigDecimal;
import java.util.List;
public interface OrderPayRecordService{
@@ -31,4 +33,8 @@ public interface OrderPayRecordService{
List<OrderDetailInfoVO.PayRecord> selectOrderPayInfoList(String orderCode);
List<PaymentInfo> parseDeductionRecord(String deductionRecord);
// 更新订单退款金额
void updateRefundAmount(String orderCode, String paymentId, BigDecimal refundAmt);
}

View File

@@ -1299,11 +1299,10 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
// List<String> collect = list.stream().map(BalanceDeductionAmountVO::getPaymentId).collect(Collectors.toList());
List<OrderPayRecord> orderPayRecordList = orderPayRecordService.getOrderPayRecordList(orderBasicInfo.getOrderCode());
AbstractProgramLogic orderLogic = new DelayMerchantProgramLogic();
List<PaymentInfo> paymentInfos = Lists.newArrayList();
for (OrderPayRecord orderPayRecord : orderPayRecordList) {
String deductionRecord = orderPayRecord.getDeductionRecord();
paymentInfos.addAll(orderLogic.parseDeductionRecord(deductionRecord));
paymentInfos.addAll(orderPayRecordService.parseDeductionRecord(deductionRecord));
}
List<String> collect = paymentInfos.stream().map(PaymentInfo::getPaymentId).collect(Collectors.toList());

View File

@@ -1,6 +1,9 @@
package com.jsowell.pile.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.google.common.collect.Lists;
import com.jsowell.adapay.vo.PaymentInfo;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.ykc.ActionTypeEnum;
@@ -18,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -155,6 +159,44 @@ public class OrderPayRecordServiceImpl implements OrderPayRecordService {
return payRecordList;
}
/**
* 解析deductionRecord
* 【公共方法】
*/
@Override
public List<PaymentInfo> parseDeductionRecord(String deductionRecord) {
List<PaymentInfo> resultList = Lists.newArrayList();
if (StringUtils.isBlank(deductionRecord)) {
return resultList;
}
Object object = JSON.parse(deductionRecord);
// 都放入list里
String s = JSON.toJSONString(object);
if (object instanceof JSONArray) {
List<PaymentInfo> paymentInfos = JSON.parseArray(s, PaymentInfo.class);
resultList.addAll(paymentInfos);
} else {
PaymentInfo paymentInfo = JSON.parseObject(s, PaymentInfo.class);
resultList.add(paymentInfo);
}
return resultList;
}
@Override
public void updateRefundAmount(String orderCode, String paymentId, BigDecimal refundAmt) {
List<OrderPayRecord> orderPayRecordList = getOrderPayRecordList(orderCode);
for (OrderPayRecord orderPayRecord : orderPayRecordList) {
List<PaymentInfo> paymentInfos = parseDeductionRecord(orderPayRecord.getDeductionRecord());
for (PaymentInfo paymentInfo : paymentInfos) {
if (StringUtils.equals(paymentId, paymentInfo.getPaymentId())) {
orderPayRecord.setRefundAmount(refundAmt);
updateByPrimaryKeySelective(orderPayRecord);
}
}
}
}
@Override
public int insertSelective(OrderPayRecord record) {
return orderPayRecordMapper.insertSelective(record);

View File

@@ -1,7 +1,5 @@
package com.jsowell.pile.service.programlogic;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -489,7 +487,7 @@ public abstract class AbstractProgramLogic implements InitializingBean {
BigDecimal tempAmount = new BigDecimal(orderAmount.toString()); // 临时金额
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfos = parseDeductionRecord(record.getDeductionRecord());
List<PaymentInfo> paymentInfos = orderPayRecordService.parseDeductionRecord(record.getDeductionRecord());
for (PaymentInfo object : paymentInfos) {
String paymentId = object.getPaymentId();
BigDecimal payAmount = new BigDecimal(object.getAmount()); // 此交易单支付的金额
@@ -517,29 +515,6 @@ public abstract class AbstractProgramLogic implements InitializingBean {
return resultList;
}
/**
* 解析deductionRecord
* 【公共方法】
*/
public List<PaymentInfo> parseDeductionRecord(String deductionRecord) {
List<PaymentInfo> resultList = Lists.newArrayList();
if (StringUtils.isBlank(deductionRecord)) {
return resultList;
}
Object object = JSON.parse(deductionRecord);
// 都放入list里
String s = JSON.toJSONString(object);
if (object instanceof JSONArray) {
List<PaymentInfo> paymentInfos = JSON.parseArray(s, PaymentInfo.class);
resultList.addAll(paymentInfos);
} else {
PaymentInfo paymentInfo = JSON.parseObject(s, PaymentInfo.class);
resultList.add(paymentInfo);
}
return resultList;
}
/**
* 从redis中取出实时记录保存到表中j
* 当订单完成的时候调用

View File

@@ -173,7 +173,7 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
// 把消费金额冻结
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
List<PaymentInfo> paymentInfoList = orderPayRecordService.parseDeductionRecord(record.getDeductionRecord());
// 循环冻结金额
for (PaymentInfo paymentInfo : paymentInfoList) {
String paymentId = paymentInfo.getPaymentId();
@@ -677,20 +677,15 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
// BigDecimal refundAmt = null; // 交易退款金额
// 延迟分账未确认调撤销调撤销接口退款
// PaymentReverseOperation operation = new PaymentReverseOperation();
// operation.setPaymentId(paymentId);
// operation.setReverseAmt(refundAmount);
// operation.setMerchantKey(dto.getWechatAppId());
// operation.setMemberId(dto.getMemberId());
// operation.setScenarioType(ScenarioEnum.ORDER.getValue());
// operation.setOrderCode(dto.getOrderCode());
// PaymentReverseResponse response = adapayService.createPaymentReverseRequest(operation);
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(paymentId, refundAmount,
dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(), dto.getOrderCode());
if (response != null && response.isNotFailed()) {
// 交易退款金额
BigDecimal refundAmt = new BigDecimal(response.getReverse_amt());
memberAdapayRecordService.updateRefundAmountFromFreezeAmount(paymentId, refundAmt);
// 更新订单支付记录的退款金额
orderPayRecordService.updateRefundAmount(dto.getOrderCode(), paymentId, refundAmt);
}
}
}

View File

@@ -284,7 +284,7 @@ public class NotDelayMerchantProgramLogic extends AbstractProgramLogic {
// 把消费金额冻结
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
List<PaymentInfo> paymentInfoList = orderPayRecordService.parseDeductionRecord(record.getDeductionRecord());
// 循环冻结金额
for (PaymentInfo paymentInfo : paymentInfoList) {
String paymentId = paymentInfo.getPaymentId();

View File

@@ -84,6 +84,11 @@ public class UniAppOrderVO {
*/
private String chargingAmount;
/**
* 应补缴金额
*/
private String remedialAmount;
/**
* 充电电量
*/