优化余额支付订单

This commit is contained in:
2023-09-28 16:48:24 +08:00
parent 8153b60610
commit 1bb9efc745
4 changed files with 88 additions and 455 deletions

View File

@@ -35,7 +35,6 @@ import com.jsowell.pile.vo.web.BalanceDeductionAmountVO;
import com.jsowell.pile.vo.web.BillingTemplateVO;
import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO;
import com.jsowell.wxpay.dto.WechatSendMsgDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -248,7 +247,6 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), chargeAmount);
// 记录订单支付流水
// JSONArray jsonArray = new JSONArray();
BigDecimal payAmt = BigDecimal.ZERO;
List<PaymentInfo> paymentInfos = Lists.newArrayList();
for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
@@ -256,10 +254,6 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
// 此交易单扣除金额
BigDecimal deductionAmount = balanceDeductionAmountVO.getDeductionAmount();
payAmt = payAmt.add(deductionAmount);
// JSONObject json = new JSONObject();
// json.put("paymentId", paymentId);
// json.put("amount", deductionAmount);
// jsonArray.add(json);
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setPaymentId(paymentId);
@@ -279,21 +273,17 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
// 记录支订单付流水
List<OrderPayRecord> payRecordList = Lists.newArrayList(build);
orderPayRecordService.batchInsert(payRecordList);
// 订单支付流水入库
if (CollectionUtils.isNotEmpty(payRecordList)) {
orderPayRecordService.batchInsert(payRecordList);
// 把消费金额冻结
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
// 循环冻结金额
for (PaymentInfo paymentInfo : paymentInfoList) {
String paymentId = paymentInfo.getPaymentId();
BigDecimal amount = new BigDecimal(paymentInfo.getAmount());
// 余额支付 临时冻结金额
memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
}
// 把消费金额冻结
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
// 循环冻结金额
for (PaymentInfo paymentInfo : paymentInfoList) {
String paymentId = paymentInfo.getPaymentId();
BigDecimal amount = new BigDecimal(paymentInfo.getAmount());
// 余额支付 临时冻结金额
memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
}
}

View File

@@ -35,7 +35,6 @@ import com.jsowell.pile.vo.web.BalanceDeductionAmountVO;
import com.jsowell.pile.vo.web.BillingTemplateVO;
import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO;
import com.jsowell.wxpay.dto.WechatSendMsgDTO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -248,36 +247,39 @@ public class NotDelayMerchantOrderLogic extends AbstractOrderLogic{
// 查询余额充值有剩余的记录
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), chargeAmount);
// 记录支订单付流水
List<OrderPayRecord> payRecordList = Lists.newArrayList();
List<PaymentInfo> paymentInfos = Lists.newArrayList();
BigDecimal deductionAmount = BigDecimal.ZERO;
for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
String paymentId = balanceDeductionAmountVO.getPaymentId();
BigDecimal deductionAmount = balanceDeductionAmountVO.getDeductionAmount();
// JSONObject json = new JSONObject();
// json.put("paymentId", paymentId);
// json.put("amount", deductionAmount);
deductionAmount = deductionAmount.add(balanceDeductionAmountVO.getDeductionAmount());
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setPaymentId(paymentId);
paymentInfo.setAmount(deductionAmount.toString());
// 记录流水
payRecordList.add(OrderPayRecord.builder()
.orderCode(orderCode)
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
.payAmount(deductionAmount)
.acquirer(AcquirerEnum.LOCAL.getValue())
// .deductionRecord(json.toJSONString())
.deductionRecord(JSON.toJSONString(paymentInfo))
.createBy(dto.getMemberId())
.delFlag(DelFlagEnum.NORMAL.getValue())
.build());
paymentInfos.add(paymentInfo);
}
// 记录流水
OrderPayRecord orderPayRecord = OrderPayRecord.builder()
.orderCode(orderCode)
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
.payAmount(deductionAmount)
.acquirer(AcquirerEnum.LOCAL.getValue())
.deductionRecord(JSON.toJSONString(paymentInfos))
.createBy(dto.getMemberId())
.delFlag(DelFlagEnum.NORMAL.getValue())
.build();
// 订单支付流水入库
if (CollectionUtils.isNotEmpty(payRecordList)) {
orderPayRecordService.batchInsert(payRecordList);
for (OrderPayRecord record : payRecordList) {
String deductionRecord = record.getDeductionRecord();
JSONObject jsonObject = JSON.parseObject(deductionRecord);
String paymentId = jsonObject.getString("paymentId");
BigDecimal amount = jsonObject.getBigDecimal("amount");
List<OrderPayRecord> payRecordList = Lists.newArrayList(orderPayRecord);
orderPayRecordService.batchInsert(payRecordList);
// 把消费金额冻结
for (OrderPayRecord record : payRecordList) {
List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
// 循环冻结金额
for (PaymentInfo paymentInfo : paymentInfoList) {
String paymentId = paymentInfo.getPaymentId();
BigDecimal amount = new BigDecimal(paymentInfo.getAmount());
// 余额支付 临时冻结金额
memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
}