202507251746
This commit is contained in:
parent
90268bd97b
commit
64d1cd8fad
|
|
@ -54,6 +54,38 @@ public class UsersPayBeforController extends BaseController
|
|||
@Autowired
|
||||
private RefundUtil refundUtil;
|
||||
|
||||
/**
|
||||
* 安全地解析BigDecimal参数
|
||||
*/
|
||||
private BigDecimal parseBigDecimalSafely(Object obj) {
|
||||
if (obj == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
try {
|
||||
if (obj instanceof BigDecimal) {
|
||||
return (BigDecimal) obj;
|
||||
} else if (obj instanceof Number) {
|
||||
return new BigDecimal(obj.toString());
|
||||
} else if (obj instanceof String) {
|
||||
String str = ((String) obj).trim();
|
||||
if (str.isEmpty() || "0".equals(str) || "0.00".equals(str)) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return new BigDecimal(str);
|
||||
} else {
|
||||
String str = obj.toString().trim();
|
||||
if (str.isEmpty() || "0".equals(str) || "0.00".equals(str)) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return new BigDecimal(str);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("无法解析BigDecimal: " + obj + ", 错误: " + e.getMessage());
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询预支付列表
|
||||
*/
|
||||
|
|
@ -240,23 +272,56 @@ public class UsersPayBeforController extends BaseController
|
|||
System.out.println("接收到的参数: " + params);
|
||||
|
||||
String orderId = params.get("orderId") == null ? null : params.get("orderId").toString();
|
||||
BigDecimal wechatRefund = params.get("wechatRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("wechatRefund").toString());
|
||||
BigDecimal balanceRefund = params.get("balanceRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("balanceRefund").toString());
|
||||
BigDecimal shoppingGoldRefund = params.get("shoppingGoldRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("shoppingGoldRefund").toString());
|
||||
BigDecimal serviceGoldRefund = params.get("serviceGoldRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("serviceGoldRefund").toString());
|
||||
BigDecimal memberDiscountRefund = params.get("memberDiscountRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("memberDiscountRefund").toString());
|
||||
BigDecimal couponRefund = params.get("couponRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("couponRefund").toString());
|
||||
|
||||
// 修复:确保BigDecimal转换正确,处理可能的null值和类型问题
|
||||
BigDecimal wechatRefund = BigDecimal.ZERO;
|
||||
BigDecimal balanceRefund = BigDecimal.ZERO;
|
||||
BigDecimal shoppingGoldRefund = BigDecimal.ZERO;
|
||||
BigDecimal serviceGoldRefund = BigDecimal.ZERO;
|
||||
BigDecimal memberDiscountRefund = BigDecimal.ZERO;
|
||||
BigDecimal couponRefund = BigDecimal.ZERO;
|
||||
|
||||
try {
|
||||
Object wxObj = params.get("wechatRefund");
|
||||
Object balanceObj = params.get("balanceRefund");
|
||||
Object shopObj = params.get("shoppingGoldRefund");
|
||||
Object serviceObj = params.get("serviceGoldRefund");
|
||||
Object memberObj = params.get("memberDiscountRefund");
|
||||
Object couponObj = params.get("couponRefund");
|
||||
|
||||
System.out.println("=== 参数对象类型检查 ===");
|
||||
System.out.println("wechatRefund对象: " + wxObj + " (类型: " + (wxObj != null ? wxObj.getClass().getName() : "null") + ")");
|
||||
System.out.println("balanceRefund对象: " + balanceObj + " (类型: " + (balanceObj != null ? balanceObj.getClass().getName() : "null") + ")");
|
||||
System.out.println("shoppingGoldRefund对象: " + shopObj + " (类型: " + (shopObj != null ? shopObj.getClass().getName() : "null") + ")");
|
||||
System.out.println("serviceGoldRefund对象: " + serviceObj + " (类型: " + (serviceObj != null ? serviceObj.getClass().getName() : "null") + ")");
|
||||
System.out.println("memberDiscountRefund对象: " + memberObj + " (类型: " + (memberObj != null ? memberObj.getClass().getName() : "null") + ")");
|
||||
System.out.println("couponRefund对象: " + couponObj + " (类型: " + (couponObj != null ? couponObj.getClass().getName() : "null") + ")");
|
||||
|
||||
// 安全的BigDecimal转换
|
||||
wechatRefund = parseBigDecimalSafely(wxObj);
|
||||
balanceRefund = parseBigDecimalSafely(balanceObj);
|
||||
shoppingGoldRefund = parseBigDecimalSafely(shopObj);
|
||||
serviceGoldRefund = parseBigDecimalSafely(serviceObj);
|
||||
memberDiscountRefund = parseBigDecimalSafely(memberObj);
|
||||
couponRefund = parseBigDecimalSafely(couponObj);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("参数转换异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return error("参数转换失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
String refundRemark = params.get("refundRemark") == null ? "" : params.get("refundRemark").toString();
|
||||
|
||||
// 添加参数解析后的调试日志
|
||||
System.out.println("解析后的参数:");
|
||||
System.out.println("=== 解析后的参数 ===");
|
||||
System.out.println(" orderId: " + orderId);
|
||||
System.out.println(" wechatRefund: " + wechatRefund);
|
||||
System.out.println(" balanceRefund: " + balanceRefund);
|
||||
System.out.println(" shoppingGoldRefund: " + shoppingGoldRefund);
|
||||
System.out.println(" serviceGoldRefund: " + serviceGoldRefund);
|
||||
System.out.println(" memberDiscountRefund: " + memberDiscountRefund);
|
||||
System.out.println(" couponRefund: " + couponRefund);
|
||||
System.out.println(" wechatRefund: " + wechatRefund + " (类型: " + wechatRefund.getClass().getName() + ")");
|
||||
System.out.println(" balanceRefund: " + balanceRefund + " (类型: " + balanceRefund.getClass().getName() + ")");
|
||||
System.out.println(" shoppingGoldRefund: " + shoppingGoldRefund + " (类型: " + shoppingGoldRefund.getClass().getName() + ")");
|
||||
System.out.println(" serviceGoldRefund: " + serviceGoldRefund + " (类型: " + serviceGoldRefund.getClass().getName() + ")");
|
||||
System.out.println(" memberDiscountRefund: " + memberDiscountRefund + " (类型: " + memberDiscountRefund.getClass().getName() + ")");
|
||||
System.out.println(" couponRefund: " + couponRefund + " (类型: " + couponRefund.getClass().getName() + ")");
|
||||
System.out.println(" refundRemark: " + refundRemark);
|
||||
|
||||
if (orderId == null || orderId.trim().isEmpty()) {
|
||||
|
|
@ -301,6 +366,7 @@ public class UsersPayBeforController extends BaseController
|
|||
// }
|
||||
|
||||
List<UsersPayBefor> payRecords = usersPayBeforService.selectPayDetailsByOrderId(orderId);
|
||||
System.out.println("000%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+payRecords.size());
|
||||
if (payRecords == null || payRecords.isEmpty()) {
|
||||
return error("未找到支付记录");
|
||||
}
|
||||
|
|
@ -308,11 +374,12 @@ public class UsersPayBeforController extends BaseController
|
|||
// 计算已退款金额
|
||||
BigDecimal totalRefunded = BigDecimal.ZERO;
|
||||
for (UsersPayBefor record : payRecords) {
|
||||
System.out.println("111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+record.getReturnmoney());
|
||||
if (record.getReturnmoney() != null) {
|
||||
totalRefunded = totalRefunded.add(record.getReturnmoney());
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("222%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+totalRefunded);
|
||||
// 计算总支付金额(减去会员优惠,因为会员优惠不参与退款)
|
||||
BigDecimal totalPaid = BigDecimal.ZERO;
|
||||
BigDecimal totalMemberDiscount = BigDecimal.ZERO;
|
||||
|
|
@ -328,7 +395,7 @@ public class UsersPayBeforController extends BaseController
|
|||
|
||||
// 实际可退款金额 = 总支付金额 - 会员优惠金额
|
||||
BigDecimal actualRefundableAmount = totalPaid.subtract(totalMemberDiscount);
|
||||
|
||||
//退款金额不能超过剩余可退款金额,剩余可退款:¥10.90(总支付:¥199.00,会员优惠:¥9.90,已退款:¥178.20)
|
||||
// 验证退款金额不能超过剩余可退款金额(基于实际可退金额)
|
||||
BigDecimal remainingRefundable = actualRefundableAmount.subtract(totalRefunded);
|
||||
if (totalRefund.compareTo(remainingRefundable) > 0) {
|
||||
|
|
@ -336,6 +403,45 @@ public class UsersPayBeforController extends BaseController
|
|||
"(总支付:¥" + totalPaid + ",会员优惠:¥" + totalMemberDiscount + ",已退款:¥" + totalRefunded + ")");
|
||||
}
|
||||
|
||||
// 添加关键验证:确保各项退款金额不超过对应的支付金额
|
||||
System.out.println("=== 退款金额验证 ===");
|
||||
System.out.println("微信退款: " + wechatRefund + " vs 微信支付: " + paymentInfo.getWxmoney());
|
||||
System.out.println("余额退款: " + balanceRefund + " vs 余额支付: " + paymentInfo.getYemoney());
|
||||
System.out.println("购物金退款: " + shoppingGoldRefund + " vs 购物金: " + paymentInfo.getShopmoney());
|
||||
System.out.println("服务金退款: " + serviceGoldRefund + " vs 服务金: " + paymentInfo.getServicemoney());
|
||||
System.out.println("优惠券退款: " + couponRefund + " vs 优惠券: " + paymentInfo.getCouponmoney());
|
||||
|
||||
// 验证各项退款金额不超过对应的支付金额
|
||||
if (wechatRefund.compareTo(BigDecimal.ZERO) > 0 &&
|
||||
paymentInfo.getWxmoney() != null &&
|
||||
wechatRefund.compareTo(paymentInfo.getWxmoney()) > 0) {
|
||||
return error("微信退款金额不能超过微信支付金额");
|
||||
}
|
||||
|
||||
if (balanceRefund.compareTo(BigDecimal.ZERO) > 0 &&
|
||||
paymentInfo.getYemoney() != null &&
|
||||
balanceRefund.compareTo(paymentInfo.getYemoney()) > 0) {
|
||||
return error("余额退款金额不能超过余额支付金额");
|
||||
}
|
||||
|
||||
if (shoppingGoldRefund.compareTo(BigDecimal.ZERO) > 0 &&
|
||||
paymentInfo.getShopmoney() != null &&
|
||||
shoppingGoldRefund.compareTo(paymentInfo.getShopmoney()) > 0) {
|
||||
return error("购物金退款金额不能超过购物金金额");
|
||||
}
|
||||
|
||||
if (serviceGoldRefund.compareTo(BigDecimal.ZERO) > 0 &&
|
||||
paymentInfo.getServicemoney() != null &&
|
||||
serviceGoldRefund.compareTo(paymentInfo.getServicemoney()) > 0) {
|
||||
return error("服务金退款金额不能超过服务金金额");
|
||||
}
|
||||
|
||||
if (couponRefund.compareTo(BigDecimal.ZERO) > 0 &&
|
||||
paymentInfo.getCouponmoney() != null &&
|
||||
couponRefund.compareTo(paymentInfo.getCouponmoney()) > 0) {
|
||||
return error("优惠券退款金额不能超过优惠券金额");
|
||||
}
|
||||
|
||||
// 记录退款日志
|
||||
OrderLog orderLog = new OrderLog();
|
||||
orderLog.setOrderId(orderId);
|
||||
|
|
@ -402,6 +508,7 @@ public class UsersPayBeforController extends BaseController
|
|||
BigDecimal remainingServiceGoldRefund = serviceGoldRefund;
|
||||
BigDecimal remainingCouponRefund = couponRefund;
|
||||
|
||||
// 修复:正确计算各项支付方式的退款金额
|
||||
for (UsersPayBefor record : payRecords) {
|
||||
BigDecimal currentRefunded = record.getReturnmoney() != null ? record.getReturnmoney() : BigDecimal.ZERO;
|
||||
|
||||
|
|
@ -410,40 +517,50 @@ public class UsersPayBeforController extends BaseController
|
|||
|
||||
// 根据该记录的支付方式分配退款金额
|
||||
if (record.getWxmoney() != null && record.getWxmoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal wxRefund = remainingWechatRefund.min(record.getWxmoney().subtract(currentRefunded));
|
||||
if (wxRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
// 修复:计算该记录微信支付的剩余可退款金额
|
||||
BigDecimal wxRemaining = record.getWxmoney().subtract(currentRefunded);
|
||||
if (wxRemaining.compareTo(BigDecimal.ZERO) > 0 && remainingWechatRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal wxRefund = remainingWechatRefund.min(wxRemaining);
|
||||
recordRefundAmount = recordRefundAmount.add(wxRefund);
|
||||
remainingWechatRefund = remainingWechatRefund.subtract(wxRefund);
|
||||
}
|
||||
}
|
||||
|
||||
if (record.getYemoney() != null && record.getYemoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal yeRefund = remainingBalanceRefund.min(record.getYemoney().subtract(currentRefunded));
|
||||
if (yeRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
// 修复:计算该记录余额支付的剩余可退款金额
|
||||
BigDecimal yeRemaining = record.getYemoney().subtract(currentRefunded);
|
||||
if (yeRemaining.compareTo(BigDecimal.ZERO) > 0 && remainingBalanceRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal yeRefund = remainingBalanceRefund.min(yeRemaining);
|
||||
recordRefundAmount = recordRefundAmount.add(yeRefund);
|
||||
remainingBalanceRefund = remainingBalanceRefund.subtract(yeRefund);
|
||||
}
|
||||
}
|
||||
|
||||
if (record.getShopmoney() != null && record.getShopmoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal shopRefund = remainingShoppingGoldRefund.min(record.getShopmoney().subtract(currentRefunded));
|
||||
if (shopRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
// 修复:计算该记录购物金的剩余可退款金额
|
||||
BigDecimal shopRemaining = record.getShopmoney().subtract(currentRefunded);
|
||||
if (shopRemaining.compareTo(BigDecimal.ZERO) > 0 && remainingShoppingGoldRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal shopRefund = remainingShoppingGoldRefund.min(shopRemaining);
|
||||
recordRefundAmount = recordRefundAmount.add(shopRefund);
|
||||
remainingShoppingGoldRefund = remainingShoppingGoldRefund.subtract(shopRefund);
|
||||
}
|
||||
}
|
||||
|
||||
if (record.getServicemoney() != null && record.getServicemoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal serviceRefund = remainingServiceGoldRefund.min(record.getServicemoney().subtract(currentRefunded));
|
||||
if (serviceRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
// 修复:计算该记录服务金的剩余可退款金额
|
||||
BigDecimal serviceRemaining = record.getServicemoney().subtract(currentRefunded);
|
||||
if (serviceRemaining.compareTo(BigDecimal.ZERO) > 0 && remainingServiceGoldRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal serviceRefund = remainingServiceGoldRefund.min(serviceRemaining);
|
||||
recordRefundAmount = recordRefundAmount.add(serviceRefund);
|
||||
remainingServiceGoldRefund = remainingServiceGoldRefund.subtract(serviceRefund);
|
||||
}
|
||||
}
|
||||
|
||||
if (record.getCouponmoney() != null && record.getCouponmoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal couponRefundAmount = remainingCouponRefund.min(record.getCouponmoney().subtract(currentRefunded));
|
||||
if (couponRefundAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
// 修复:计算该记录优惠券的剩余可退款金额
|
||||
BigDecimal couponRemaining = record.getCouponmoney().subtract(currentRefunded);
|
||||
if (couponRemaining.compareTo(BigDecimal.ZERO) > 0 && remainingCouponRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal couponRefundAmount = remainingCouponRefund.min(couponRemaining);
|
||||
recordRefundAmount = recordRefundAmount.add(couponRefundAmount);
|
||||
remainingCouponRefund = remainingCouponRefund.subtract(couponRefundAmount);
|
||||
}
|
||||
|
|
@ -462,11 +579,34 @@ public class UsersPayBeforController extends BaseController
|
|||
|
||||
record.setReturnmoney(newTotalRefunded);
|
||||
usersPayBeforService.updateUsersPayBefor(record);
|
||||
|
||||
System.out.println("更新支付记录: ID=" + record.getId() +
|
||||
", 原退款金额=" + currentRefunded +
|
||||
", 本次退款=" + recordRefundAmount +
|
||||
", 新总退款=" + newTotalRefunded +
|
||||
", 状态=" + record.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
// 调用退款工具方法实现真实的业务退款与金额变动
|
||||
// 使用原始参数,而不是被修改的副本
|
||||
System.out.println("=== 调用退款工具方法前的参数验证 ===");
|
||||
System.out.println("原始退款参数:");
|
||||
System.out.println(" orderId: " + orderId);
|
||||
System.out.println(" wechatRefund: " + wechatRefund);
|
||||
System.out.println(" balanceRefund: " + balanceRefund);
|
||||
System.out.println(" shoppingGoldRefund: " + shoppingGoldRefund);
|
||||
System.out.println(" serviceGoldRefund: " + serviceGoldRefund);
|
||||
System.out.println(" memberDiscountRefund: " + memberDiscountRefund);
|
||||
System.out.println(" couponRefund: " + couponRefund);
|
||||
System.out.println(" refundRemark: " + refundRemark);
|
||||
|
||||
// 验证参数类型和值
|
||||
System.out.println("参数类型检查:");
|
||||
System.out.println(" balanceRefund类型: " + balanceRefund.getClass().getName());
|
||||
System.out.println(" balanceRefund值: " + balanceRefund);
|
||||
System.out.println(" balanceRefund比较0: " + balanceRefund.compareTo(BigDecimal.ZERO));
|
||||
|
||||
Map<String, Object> refundResult = refundUtil.processUnifiedRefund(
|
||||
orderId, wechatRefund, balanceRefund, shoppingGoldRefund,
|
||||
serviceGoldRefund, memberDiscountRefund, couponRefund, refundRemark
|
||||
|
|
|
|||
|
|
@ -9,8 +9,17 @@
|
|||
<div class="payment-info" v-if="actualPaymentData">
|
||||
<h4>支付信息</h4>
|
||||
|
||||
<!-- 调试信息 -->
|
||||
|
||||
<!-- <!– 调试信息 –>-->
|
||||
<!-- <div class="debug-info" style="background: #f0f9ff; padding: 10px; margin-bottom: 15px; border-radius: 4px; font-size: 12px;">-->
|
||||
<!-- <div>调试信息:</div>-->
|
||||
<!-- <div>allmoney: {{ actualPaymentData.allmoney }}</div>-->
|
||||
<!-- <div>wxmoney: {{ actualPaymentData.wxmoney }}</div>-->
|
||||
<!-- <div>yemoney: {{ actualPaymentData.yemoney }}</div>-->
|
||||
<!-- <div>shopmoney: {{ actualPaymentData.shopmoney }}</div>-->
|
||||
<!-- <div>servicemoney: {{ actualPaymentData.servicemoney }}</div>-->
|
||||
<!-- <div>couponmoney: {{ actualPaymentData.couponmoney }}</div>-->
|
||||
<!-- <div>membermoney: {{ actualPaymentData.membermoney }}</div>-->
|
||||
<!-- </div>-->
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="8">
|
||||
|
|
@ -56,7 +65,7 @@
|
|||
</div>
|
||||
<div class="total-amount">
|
||||
<label>总支付金额:</label>
|
||||
<span class="amount total">¥{{ formatAmount(totalPaymentAmount) }}</span>
|
||||
<span class="amount total">¥{{ formatAmount(actualPaymentData.allmoney) }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 退款统计信息 -->
|
||||
|
|
@ -76,7 +85,7 @@
|
|||
</el-col>
|
||||
</el-row>
|
||||
<div class="summary-note">
|
||||
<span class="note-text">💡 实际可退款金额:¥{{ formatAmount(actualRefundableAmount) }}(总支付:¥{{ formatAmount(totalPaymentAmount) }} - 会员优惠:¥{{ formatAmount(actualPaymentData.membermoney || 0) }})</span>
|
||||
<span class="note-text">💡 实际可退款金额:¥{{ formatAmount(actualRefundableAmount) }}(总支付:¥{{ formatAmount(actualPaymentData.allmoney) }} - 会员优惠:¥{{ formatAmount(actualPaymentData.membermoney || 0) }})</span>
|
||||
</div>
|
||||
<!-- <div class="summary-extra">-->
|
||||
<!-- <span class="refund-count">退款次数:{{ refundHistory.length }}次</span>-->
|
||||
|
|
@ -274,7 +283,7 @@
|
|||
<div class="timeline-header">
|
||||
<div class="header-title">
|
||||
<span class="title-text">退款记录 #{{ index + 1 }}</span>
|
||||
<span class="title-time"> {{ formatTime(item.createdAt) }}</span>
|
||||
<span class="title-time"> {{ formatTime(item.createTime) }}</span>
|
||||
</div>
|
||||
<!-- <div class="header-actions">-->
|
||||
<!-- <el-button-->
|
||||
|
|
@ -395,18 +404,17 @@ export default {
|
|||
computed: {
|
||||
totalPaymentAmount() {
|
||||
if (!this.actualPaymentData) return "0.00";
|
||||
const total = (this.actualPaymentData.wxmoney || 0) + (this.actualPaymentData.yemoney || 0) +
|
||||
(this.actualPaymentData.shopmoney || 0) + (this.actualPaymentData.servicemoney || 0) +
|
||||
(this.actualPaymentData.membermoney || 0) + (this.actualPaymentData.couponmoney || 0);
|
||||
return total.toFixed(2);
|
||||
// 修复:总支付金额应该是 allmoney 字段,而不是各项相加
|
||||
return this.formatAmount(this.actualPaymentData.allmoney);
|
||||
},
|
||||
|
||||
// 计算实际可退款金额(减去会员优惠)
|
||||
actualRefundableAmount() {
|
||||
if (!this.actualPaymentData) return "0.00";
|
||||
const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
|
||||
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
|
||||
const total = parseFloat(this.totalPaymentAmount);
|
||||
return (total - memberDiscount).toFixed(2);
|
||||
// 实际可退款金额 = allmoney - 会员优惠
|
||||
return (allMoney - memberDiscount).toFixed(2);
|
||||
},
|
||||
|
||||
canRefund() {
|
||||
|
|
@ -625,10 +633,24 @@ export default {
|
|||
this.actualPaymentData = response.data;
|
||||
console.log('支付数据加载成功:', this.actualPaymentData);
|
||||
|
||||
// 数据验证:检查关键字段是否存在
|
||||
if (!this.actualPaymentData.allmoney) {
|
||||
console.warn('警告:支付数据缺少allmoney字段');
|
||||
this.$message.warning("支付数据不完整,请检查数据源");
|
||||
}
|
||||
|
||||
// 设置退款相关数据
|
||||
this.refundHistory = [];
|
||||
this.totalRefundedAmount = "0.00";
|
||||
this.remainingRefundableAmount = this.actualRefundableAmount;
|
||||
// 修复:初始剩余可退款金额 = allmoney - 优惠金额(因为还没有退款记录)
|
||||
const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
|
||||
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
|
||||
this.remainingRefundableAmount = (allMoney - memberDiscount).toFixed(2);
|
||||
|
||||
console.log('初始计算:');
|
||||
console.log(' allmoney:', allMoney);
|
||||
console.log(' 会员优惠:', memberDiscount);
|
||||
console.log(' 初始剩余可退款:', this.remainingRefundableAmount);
|
||||
|
||||
// 加载退款历史
|
||||
await this.loadRefundHistory();
|
||||
|
|
@ -710,9 +732,12 @@ export default {
|
|||
console.warn('响应码:', response.code, '响应消息:', response.msg);
|
||||
|
||||
if (attempt === maxRetries) { // 最后一次尝试失败
|
||||
this.refundHistory = [];
|
||||
this.totalRefundedAmount = "0.00";
|
||||
this.remainingRefundableAmount = this.totalPaymentAmount;
|
||||
this.refundHistory = [];
|
||||
this.totalRefundedAmount = "0.00";
|
||||
// 修复:使用正确的计算公式
|
||||
const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
|
||||
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
|
||||
this.remainingRefundableAmount = (allMoney - memberDiscount).toFixed(2);
|
||||
this.refundHistoryError = response.msg || "加载退款历史失败";
|
||||
this.errorDetails = {
|
||||
code: response.code,
|
||||
|
|
@ -726,13 +751,16 @@ export default {
|
|||
await new Promise(resolve => setTimeout(resolve, delay));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error) {
|
||||
console.error(`加载退款历史失败,第${attempt}次尝试:`, error);
|
||||
|
||||
if (attempt === maxRetries) { // 最后一次尝试失败
|
||||
this.refundHistory = [];
|
||||
this.totalRefundedAmount = "0.00";
|
||||
this.remainingRefundableAmount = this.totalPaymentAmount;
|
||||
// 修复:使用正确的计算公式
|
||||
const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
|
||||
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
|
||||
this.remainingRefundableAmount = (allMoney - memberDiscount).toFixed(2);
|
||||
this.refundHistoryError = "加载退款历史失败,请稍后再试";
|
||||
this.errorDetails = {
|
||||
code: 'N/A',
|
||||
|
|
@ -799,13 +827,21 @@ export default {
|
|||
|
||||
this.totalRefundedAmount = total.toFixed(2);
|
||||
|
||||
// 计算剩余可退款金额:实际可退款金额 - 已退款金额
|
||||
const actualRefundable = parseFloat(this.actualRefundableAmount);
|
||||
// 修复:剩余可退款金额 = allmoney - 优惠金额 - returnmoney
|
||||
const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
|
||||
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
|
||||
const totalRefunded = parseFloat(this.totalRefundedAmount);
|
||||
const remaining = Math.max(0, actualRefundable - totalRefunded);
|
||||
|
||||
// 正确的计算公式:allmoney - 优惠金额 - returnmoney
|
||||
const remaining = Math.max(0, allMoney - memberDiscount - totalRefunded);
|
||||
this.remainingRefundableAmount = remaining.toFixed(2);
|
||||
|
||||
console.log('累计退款金额:', this.totalRefundedAmount, '实际可退款金额:', this.actualRefundableAmount, '剩余可退款:', this.remainingRefundableAmount);
|
||||
console.log('计算详情:');
|
||||
console.log(' allmoney:', allMoney);
|
||||
console.log(' 会员优惠:', memberDiscount);
|
||||
console.log(' 累计已退款:', totalRefunded);
|
||||
console.log(' 剩余可退款:', this.remainingRefundableAmount);
|
||||
console.log(' 计算公式: allmoney - 优惠金额 - returnmoney =', allMoney, '-', memberDiscount, '-', totalRefunded, '=', remaining);
|
||||
},
|
||||
|
||||
initForm() {
|
||||
|
|
@ -826,8 +862,10 @@ export default {
|
|||
if (this.refundHistory.length > 0) {
|
||||
this.calculateTotalRefunded();
|
||||
} else {
|
||||
// 如果没有退款历史,设置默认值
|
||||
this.remainingRefundableAmount = this.actualRefundableAmount;
|
||||
// 如果没有退款历史,设置默认值:allmoney - 优惠金额
|
||||
const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
|
||||
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
|
||||
this.remainingRefundableAmount = (allMoney - memberDiscount).toFixed(2);
|
||||
}
|
||||
|
||||
this.calculateTotalRefund();
|
||||
|
|
@ -894,17 +932,28 @@ export default {
|
|||
refundRemark: this.refundForm.refundRemark
|
||||
};
|
||||
|
||||
console.log('构建的参数:', params);
|
||||
console.log('参数类型检查:');
|
||||
console.log(' orderId:', typeof params.orderId, params.orderId);
|
||||
console.log(' wechatRefund:', typeof params.wechatRefund, params.wechatRefund);
|
||||
console.log(' balanceRefund:', typeof params.balanceRefund, params.balanceRefund);
|
||||
console.log(' shoppingGoldRefund:', typeof params.shoppingGoldRefund, params.shoppingGoldRefund);
|
||||
console.log(' serviceGoldRefund:', typeof params.serviceGoldRefund, params.serviceGoldRefund);
|
||||
console.log(' couponRefund:', typeof params.couponRefund, params.couponRefund);
|
||||
console.log(' refundRemark:', typeof params.refundRemark, params.refundRemark);
|
||||
// 添加参数验证和转换
|
||||
console.log('=== 参数验证和转换 ===');
|
||||
console.log('原始表单数据:', this.refundForm);
|
||||
|
||||
const response = await unifiedRefund(params);
|
||||
// 确保所有金额都是有效的数字字符串
|
||||
const validatedParams = {
|
||||
orderId: this.orderId,
|
||||
wechatRefund: parseFloat(this.refundForm.wechatRefund || "0").toFixed(2),
|
||||
balanceRefund: parseFloat(this.refundForm.balanceRefund || "0").toFixed(2),
|
||||
shoppingGoldRefund: parseFloat(this.refundForm.shoppingGoldRefund || "0").toFixed(2),
|
||||
serviceGoldRefund: parseFloat(this.refundForm.serviceGoldRefund || "0").toFixed(2),
|
||||
couponRefund: this.refundForm.couponRefund === '1' ? parseFloat(this.actualPaymentData.couponmoney || "0").toFixed(2) : "0.00",
|
||||
refundRemark: this.refundForm.refundRemark
|
||||
};
|
||||
|
||||
console.log('验证后的参数:', validatedParams);
|
||||
console.log('参数类型检查:');
|
||||
console.log(' balanceRefund:', typeof validatedParams.balanceRefund, validatedParams.balanceRefund);
|
||||
console.log(' balanceRefund数值:', parseFloat(validatedParams.balanceRefund));
|
||||
|
||||
// 使用验证后的参数
|
||||
const response = await unifiedRefund(validatedParams);
|
||||
|
||||
console.log('退款接口响应:', response);
|
||||
|
||||
|
|
@ -912,8 +961,8 @@ export default {
|
|||
this.$message.success("退款成功");
|
||||
this.$emit("success", response.data);
|
||||
|
||||
// 刷新退款历史
|
||||
await this.loadRefundHistory();
|
||||
// 刷新退款历史和支付数据
|
||||
await this.loadPaymentData();
|
||||
|
||||
this.handleClose();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -276,10 +276,10 @@
|
|||
@click="handleAfterSale(scope.row)"
|
||||
style="color: #E6A23C;"
|
||||
>售后</el-button>
|
||||
|
||||
<!-- v-if="scope.row.status >= 15"-->
|
||||
<!-- 统一退款按钮 -->
|
||||
<el-button
|
||||
v-if="scope.row.status >= 15"
|
||||
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-money"
|
||||
|
|
|
|||
Loading…
Reference in New Issue