mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
update 操作member_adapay_record
This commit is contained in:
@@ -38,9 +38,13 @@ public interface MemberAdapayRecordService{
|
||||
|
||||
void updateSpendAmount(String paymentId, BigDecimal amount);
|
||||
|
||||
void unfreezeAmountAndUpdateSpendAmount(String paymentId, BigDecimal unfreezeAmount, BigDecimal spendAmount);
|
||||
|
||||
void updateRefundAmountFromFreezeAmount(String paymentId, BigDecimal refundAmount);
|
||||
|
||||
void updateRefundAmount(String paymentId, BigDecimal amount);
|
||||
|
||||
void updateFreezeAmount(String paymentId, BigDecimal amount);
|
||||
|
||||
void updateSpendAmountAndRefundAmountAndFreezeAmount(String paymentId, BigDecimal SpendAmount, BigDecimal RefundAmount, BigDecimal freezeAmount);
|
||||
void commonUpdateAmountMethod(String paymentId, BigDecimal SpendAmount, BigDecimal RefundAmount, BigDecimal freezeAmount);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jsowell.pile.service.impl;
|
||||
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.pile.domain.MemberAdapayRecord;
|
||||
import com.jsowell.pile.mapper.MemberAdapayRecordMapper;
|
||||
import com.jsowell.pile.service.MemberAdapayRecordService;
|
||||
@@ -84,24 +85,42 @@ public class MemberAdapayRecordServiceImpl implements MemberAdapayRecordService
|
||||
* 更新消费金额
|
||||
*/
|
||||
@Override
|
||||
public void updateSpendAmount(String paymentId, BigDecimal amount) {
|
||||
updateSpendAmountAndRefundAmountAndFreezeAmount(paymentId, amount, null, null);
|
||||
public void updateSpendAmount(String paymentId, BigDecimal spendAmount) {
|
||||
commonUpdateAmountMethod(paymentId, spendAmount, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解冻金额并更新消费金额
|
||||
* unfreezeAmount
|
||||
*/
|
||||
@Override
|
||||
public void unfreezeAmountAndUpdateSpendAmount(String paymentId, BigDecimal unfreezeAmount, BigDecimal spendAmount) {
|
||||
commonUpdateAmountMethod(paymentId, spendAmount, null, unfreezeAmount.negate());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从冻结金额中退款
|
||||
* 不解冻,退款
|
||||
*/
|
||||
@Override
|
||||
public void updateRefundAmountFromFreezeAmount(String paymentId, BigDecimal refundAmount) {
|
||||
commonUpdateAmountMethod(paymentId, null, refundAmount, refundAmount.negate());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新剩余金额
|
||||
*/
|
||||
@Override
|
||||
public void updateRefundAmount(String paymentId, BigDecimal amount) {
|
||||
updateSpendAmountAndRefundAmountAndFreezeAmount(paymentId, null, amount, null);
|
||||
public void updateRefundAmount(String paymentId, BigDecimal refundAmount) {
|
||||
commonUpdateAmountMethod(paymentId, null, refundAmount, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新冻结金额
|
||||
*/
|
||||
@Override
|
||||
public void updateFreezeAmount(String paymentId, BigDecimal amount) {
|
||||
updateSpendAmountAndRefundAmountAndFreezeAmount(paymentId, null, null, amount);
|
||||
public void updateFreezeAmount(String paymentId, BigDecimal freezeAmount) {
|
||||
commonUpdateAmountMethod(paymentId, null, null, freezeAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,32 +132,55 @@ public class MemberAdapayRecordServiceImpl implements MemberAdapayRecordService
|
||||
* @param freezeAmount 冻结金额
|
||||
*/
|
||||
@Override
|
||||
public void updateSpendAmountAndRefundAmountAndFreezeAmount(String paymentId, BigDecimal SpendAmount, BigDecimal RefundAmount, BigDecimal freezeAmount) {
|
||||
public void commonUpdateAmountMethod(String paymentId, BigDecimal SpendAmount, BigDecimal RefundAmount, BigDecimal freezeAmount) {
|
||||
MemberAdapayRecord record = selectByPaymentId(paymentId);
|
||||
if (record == null) {
|
||||
log.info("更新交易记录的消费金额和退款金额paymentId:{}, 查询为空", paymentId);
|
||||
return;
|
||||
}
|
||||
// 此时数据库中的值
|
||||
BigDecimal spendAmt = record.getSpendAmt();
|
||||
BigDecimal refundAmt = record.getRefundAmt();
|
||||
BigDecimal freezeAmt = record.getFreezeAmt();
|
||||
BigDecimal balanceAmt = record.getBalanceAmt();
|
||||
|
||||
if (freezeAmount != null) {
|
||||
if (BigDecimal.ZERO.compareTo(freezeAmount) > 0) {
|
||||
// 如果冻结金额传过来是负数,说明是解冻
|
||||
if (freezeAmount.negate().compareTo(freezeAmt) > 0) {
|
||||
throw new BusinessException("", "解冻金额大于冻结金额");
|
||||
}
|
||||
balanceAmt = balanceAmt.add(freezeAmount.negate()); // 剩余金额增加
|
||||
} else {
|
||||
if (freezeAmount.compareTo(balanceAmt) > 0) {
|
||||
throw new BusinessException("", "冻结金额大于剩余金额");
|
||||
}
|
||||
}
|
||||
freezeAmt = freezeAmt.add(freezeAmount); // 冻结金额减少
|
||||
// 设置冻结金额 = 历史冻结金额 + 本次冻结金额
|
||||
record.setFreezeAmt(freezeAmt);
|
||||
}
|
||||
if (RefundAmount != null) {
|
||||
if (RefundAmount.compareTo(balanceAmt) > 0) {
|
||||
throw new BusinessException("", "退款金额大于剩余金额");
|
||||
}
|
||||
// 设置退款金额 = 历史退款金额 + 本次退款金额
|
||||
record.setRefundAmt(record.getRefundAmt().add(RefundAmount));
|
||||
refundAmt = refundAmt.add(RefundAmount);
|
||||
record.setRefundAmt(refundAmt);
|
||||
}
|
||||
if (SpendAmount != null) {
|
||||
if (SpendAmount.compareTo(balanceAmt) > 0) {
|
||||
throw new BusinessException("", "消费金额大于剩余金额");
|
||||
}
|
||||
// 设置消费金额 = 历史消费金额 + 本次消费金额
|
||||
record.setSpendAmt(record.getSpendAmt().add(SpendAmount));
|
||||
}
|
||||
if (freezeAmount != null) {
|
||||
// 设置冻结金额 = 历史冻结金额 + 本次冻结金额
|
||||
record.setFreezeAmt(record.getFreezeAmt().add(freezeAmount));
|
||||
spendAmt = spendAmt.add(SpendAmount);
|
||||
record.setSpendAmt(spendAmt);
|
||||
}
|
||||
// 更新此笔交易单的剩余金额 = 支付金额 - 累计退款金额 - 累计消费金额 - 累计冻结金额
|
||||
record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()).subtract(record.getFreezeAmt()));
|
||||
balanceAmt = record.getPayAmt().subtract(refundAmt).subtract(spendAmt).subtract(freezeAmt);
|
||||
record.setBalanceAmt(balanceAmt);
|
||||
updateByPrimaryKeySelective(record);
|
||||
|
||||
// if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
// log.error("订单分账结束后账不平,paymentId:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
// paymentId, record.getPayAmt(), SpendAmount, RefundAmount);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -678,7 +678,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算订单逻辑
|
||||
* 结算订单逻辑/订单结算逻辑
|
||||
*
|
||||
* @param data 交易记录数据
|
||||
* @param orderBasicInfo 订单主表信息,由调用方传过来
|
||||
@@ -829,8 +829,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
String deductionRecord = record.getDeductionRecord();
|
||||
JSONObject jsonObject = JSON.parseObject(deductionRecord);
|
||||
String paymentId = jsonObject.getString("paymentId");
|
||||
// 更新member_adapay_record 中的冻结金额
|
||||
memberAdapayRecordService.updateFreezeAmount(paymentId, orderBasicInfo.getSettleAmount());
|
||||
|
||||
}
|
||||
|
||||
// 订单支付记录,保存一下消费记录 deduction_record
|
||||
@@ -2449,7 +2448,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
// record.setBalanceAmt(record.getPayAmt().subtract(record.getRefundAmt()).subtract(record.getSpendAmt()));
|
||||
// memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
|
||||
memberAdapayRecordService.updateSpendAmountAndRefundAmountAndFreezeAmount(paymentId, spendAmt, reverseAmt, null);
|
||||
memberAdapayRecordService.commonUpdateAmountMethod(paymentId, spendAmt, reverseAmt, null);
|
||||
// if (BigDecimal.ZERO.compareTo(record.getBalanceAmt()) != 0) {
|
||||
// logger.error("订单分账结束后账不平,paymentId:{}, orderCode:{}, 支付金额:{}, 消费金额:{}, 退款金额:{}",
|
||||
// paymentId, dto.getOrderCode(), payAmt, spendAmt, reverseAmt);
|
||||
@@ -2475,7 +2474,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
// }
|
||||
// memberAdapayRecordService.updateByPrimaryKeySelective(record);
|
||||
|
||||
memberAdapayRecordService.updateSpendAmountAndRefundAmountAndFreezeAmount(paymentId, spendAmt, refundAmt, null);
|
||||
memberAdapayRecordService.commonUpdateAmountMethod(paymentId, spendAmt, refundAmt, null);
|
||||
}
|
||||
}
|
||||
// if (StringUtils.equals("", payMode)) {
|
||||
|
||||
Reference in New Issue
Block a user