202507251746

This commit is contained in:
张潘 2025-08-13 22:45:57 +08:00
parent 90268bd97b
commit 64d1cd8fad
3 changed files with 312 additions and 123 deletions

View File

@ -54,6 +54,38 @@ public class UsersPayBeforController extends BaseController
@Autowired @Autowired
private RefundUtil refundUtil; 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); System.out.println("接收到的参数: " + params);
String orderId = params.get("orderId") == null ? null : params.get("orderId").toString(); 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转换正确处理可能的null值和类型问题
BigDecimal shoppingGoldRefund = params.get("shoppingGoldRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("shoppingGoldRefund").toString()); BigDecimal wechatRefund = BigDecimal.ZERO;
BigDecimal serviceGoldRefund = params.get("serviceGoldRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("serviceGoldRefund").toString()); BigDecimal balanceRefund = BigDecimal.ZERO;
BigDecimal memberDiscountRefund = params.get("memberDiscountRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("memberDiscountRefund").toString()); BigDecimal shoppingGoldRefund = BigDecimal.ZERO;
BigDecimal couponRefund = params.get("couponRefund") == null ? BigDecimal.ZERO : new BigDecimal(params.get("couponRefund").toString()); 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(); String refundRemark = params.get("refundRemark") == null ? "" : params.get("refundRemark").toString();
// 添加参数解析后的调试日志 // 添加参数解析后的调试日志
System.out.println("解析后的参数:"); System.out.println("=== 解析后的参数 ===");
System.out.println(" orderId: " + orderId); System.out.println(" orderId: " + orderId);
System.out.println(" wechatRefund: " + wechatRefund); System.out.println(" wechatRefund: " + wechatRefund + " (类型: " + wechatRefund.getClass().getName() + ")");
System.out.println(" balanceRefund: " + balanceRefund); System.out.println(" balanceRefund: " + balanceRefund + " (类型: " + balanceRefund.getClass().getName() + ")");
System.out.println(" shoppingGoldRefund: " + shoppingGoldRefund); System.out.println(" shoppingGoldRefund: " + shoppingGoldRefund + " (类型: " + shoppingGoldRefund.getClass().getName() + ")");
System.out.println(" serviceGoldRefund: " + serviceGoldRefund); System.out.println(" serviceGoldRefund: " + serviceGoldRefund + " (类型: " + serviceGoldRefund.getClass().getName() + ")");
System.out.println(" memberDiscountRefund: " + memberDiscountRefund); System.out.println(" memberDiscountRefund: " + memberDiscountRefund + " (类型: " + memberDiscountRefund.getClass().getName() + ")");
System.out.println(" couponRefund: " + couponRefund); System.out.println(" couponRefund: " + couponRefund + " (类型: " + couponRefund.getClass().getName() + ")");
System.out.println(" refundRemark: " + refundRemark); System.out.println(" refundRemark: " + refundRemark);
if (orderId == null || orderId.trim().isEmpty()) { if (orderId == null || orderId.trim().isEmpty()) {
@ -301,6 +366,7 @@ public class UsersPayBeforController extends BaseController
// } // }
List<UsersPayBefor> payRecords = usersPayBeforService.selectPayDetailsByOrderId(orderId); List<UsersPayBefor> payRecords = usersPayBeforService.selectPayDetailsByOrderId(orderId);
System.out.println("000%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+payRecords.size());
if (payRecords == null || payRecords.isEmpty()) { if (payRecords == null || payRecords.isEmpty()) {
return error("未找到支付记录"); return error("未找到支付记录");
} }
@ -308,11 +374,12 @@ public class UsersPayBeforController extends BaseController
// 计算已退款金额 // 计算已退款金额
BigDecimal totalRefunded = BigDecimal.ZERO; BigDecimal totalRefunded = BigDecimal.ZERO;
for (UsersPayBefor record : payRecords) { for (UsersPayBefor record : payRecords) {
System.out.println("111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+record.getReturnmoney());
if (record.getReturnmoney() != null) { if (record.getReturnmoney() != null) {
totalRefunded = totalRefunded.add(record.getReturnmoney()); totalRefunded = totalRefunded.add(record.getReturnmoney());
} }
} }
System.out.println("222%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+totalRefunded);
// 计算总支付金额减去会员优惠因为会员优惠不参与退款 // 计算总支付金额减去会员优惠因为会员优惠不参与退款
BigDecimal totalPaid = BigDecimal.ZERO; BigDecimal totalPaid = BigDecimal.ZERO;
BigDecimal totalMemberDiscount = BigDecimal.ZERO; BigDecimal totalMemberDiscount = BigDecimal.ZERO;
@ -328,7 +395,7 @@ public class UsersPayBeforController extends BaseController
// 实际可退款金额 = 总支付金额 - 会员优惠金额 // 实际可退款金额 = 总支付金额 - 会员优惠金额
BigDecimal actualRefundableAmount = totalPaid.subtract(totalMemberDiscount); BigDecimal actualRefundableAmount = totalPaid.subtract(totalMemberDiscount);
//退款金额不能超过剩余可退款金额剩余可退款10.90总支付199.00会员优惠9.90已退款178.20
// 验证退款金额不能超过剩余可退款金额基于实际可退金额 // 验证退款金额不能超过剩余可退款金额基于实际可退金额
BigDecimal remainingRefundable = actualRefundableAmount.subtract(totalRefunded); BigDecimal remainingRefundable = actualRefundableAmount.subtract(totalRefunded);
if (totalRefund.compareTo(remainingRefundable) > 0) { if (totalRefund.compareTo(remainingRefundable) > 0) {
@ -336,6 +403,45 @@ public class UsersPayBeforController extends BaseController
"(总支付:¥" + totalPaid + ",会员优惠:¥" + totalMemberDiscount + ",已退款:¥" + totalRefunded + ""); "(总支付:¥" + 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 orderLog = new OrderLog();
orderLog.setOrderId(orderId); orderLog.setOrderId(orderId);
@ -402,6 +508,7 @@ public class UsersPayBeforController extends BaseController
BigDecimal remainingServiceGoldRefund = serviceGoldRefund; BigDecimal remainingServiceGoldRefund = serviceGoldRefund;
BigDecimal remainingCouponRefund = couponRefund; BigDecimal remainingCouponRefund = couponRefund;
// 修复正确计算各项支付方式的退款金额
for (UsersPayBefor record : payRecords) { for (UsersPayBefor record : payRecords) {
BigDecimal currentRefunded = record.getReturnmoney() != null ? record.getReturnmoney() : BigDecimal.ZERO; 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) { 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); recordRefundAmount = recordRefundAmount.add(wxRefund);
remainingWechatRefund = remainingWechatRefund.subtract(wxRefund); remainingWechatRefund = remainingWechatRefund.subtract(wxRefund);
} }
} }
if (record.getYemoney() != null && record.getYemoney().compareTo(BigDecimal.ZERO) > 0) { 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); recordRefundAmount = recordRefundAmount.add(yeRefund);
remainingBalanceRefund = remainingBalanceRefund.subtract(yeRefund); remainingBalanceRefund = remainingBalanceRefund.subtract(yeRefund);
} }
} }
if (record.getShopmoney() != null && record.getShopmoney().compareTo(BigDecimal.ZERO) > 0) { 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); recordRefundAmount = recordRefundAmount.add(shopRefund);
remainingShoppingGoldRefund = remainingShoppingGoldRefund.subtract(shopRefund); remainingShoppingGoldRefund = remainingShoppingGoldRefund.subtract(shopRefund);
} }
} }
if (record.getServicemoney() != null && record.getServicemoney().compareTo(BigDecimal.ZERO) > 0) { 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); recordRefundAmount = recordRefundAmount.add(serviceRefund);
remainingServiceGoldRefund = remainingServiceGoldRefund.subtract(serviceRefund); remainingServiceGoldRefund = remainingServiceGoldRefund.subtract(serviceRefund);
} }
} }
if (record.getCouponmoney() != null && record.getCouponmoney().compareTo(BigDecimal.ZERO) > 0) { 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); recordRefundAmount = recordRefundAmount.add(couponRefundAmount);
remainingCouponRefund = remainingCouponRefund.subtract(couponRefundAmount); remainingCouponRefund = remainingCouponRefund.subtract(couponRefundAmount);
} }
@ -462,11 +579,34 @@ public class UsersPayBeforController extends BaseController
record.setReturnmoney(newTotalRefunded); record.setReturnmoney(newTotalRefunded);
usersPayBeforService.updateUsersPayBefor(record); 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( Map<String, Object> refundResult = refundUtil.processUnifiedRefund(
orderId, wechatRefund, balanceRefund, shoppingGoldRefund, orderId, wechatRefund, balanceRefund, shoppingGoldRefund,
serviceGoldRefund, memberDiscountRefund, couponRefund, refundRemark serviceGoldRefund, memberDiscountRefund, couponRefund, refundRemark

View File

@ -9,8 +9,17 @@
<div class="payment-info" v-if="actualPaymentData"> <div class="payment-info" v-if="actualPaymentData">
<h4>支付信息</h4> <h4>支付信息</h4>
<!-- 调试信息 --> <!-- &lt;!&ndash; 调试信息 &ndash;&gt;-->
<!-- <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-row :gutter="20">
<el-col :span="8"> <el-col :span="8">
@ -56,7 +65,7 @@
</div> </div>
<div class="total-amount"> <div class="total-amount">
<label>总支付金额</label> <label>总支付金额</label>
<span class="amount total">{{ formatAmount(totalPaymentAmount) }}</span> <span class="amount total">{{ formatAmount(actualPaymentData.allmoney) }}</span>
</div> </div>
<!-- 退款统计信息 --> <!-- 退款统计信息 -->
@ -76,7 +85,7 @@
</el-col> </el-col>
</el-row> </el-row>
<div class="summary-note"> <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>
<!-- <div class="summary-extra">--> <!-- <div class="summary-extra">-->
<!-- <span class="refund-count">退款次数{{ refundHistory.length }}</span>--> <!-- <span class="refund-count">退款次数{{ refundHistory.length }}</span>-->
@ -274,7 +283,7 @@
<div class="timeline-header"> <div class="timeline-header">
<div class="header-title"> <div class="header-title">
<span class="title-text">退款记录 #{{ index + 1 }}</span> <span class="title-text">退款记录 #{{ index + 1 }}</span>
<span class="title-time">&nbsp;&nbsp;&nbsp;{{ formatTime(item.createdAt) }}</span> <span class="title-time">&nbsp;&nbsp;&nbsp;{{ formatTime(item.createTime) }}</span>
</div> </div>
<!-- <div class="header-actions">--> <!-- <div class="header-actions">-->
<!-- <el-button--> <!-- <el-button-->
@ -395,18 +404,17 @@ export default {
computed: { computed: {
totalPaymentAmount() { totalPaymentAmount() {
if (!this.actualPaymentData) return "0.00"; if (!this.actualPaymentData) return "0.00";
const total = (this.actualPaymentData.wxmoney || 0) + (this.actualPaymentData.yemoney || 0) + // allmoney
(this.actualPaymentData.shopmoney || 0) + (this.actualPaymentData.servicemoney || 0) + return this.formatAmount(this.actualPaymentData.allmoney);
(this.actualPaymentData.membermoney || 0) + (this.actualPaymentData.couponmoney || 0);
return total.toFixed(2);
}, },
// 退 // 退
actualRefundableAmount() { actualRefundableAmount() {
if (!this.actualPaymentData) return "0.00"; if (!this.actualPaymentData) return "0.00";
const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0); const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
const total = parseFloat(this.totalPaymentAmount); // 退 = allmoney -
return (total - memberDiscount).toFixed(2); return (allMoney - memberDiscount).toFixed(2);
}, },
canRefund() { canRefund() {
@ -625,10 +633,24 @@ export default {
this.actualPaymentData = response.data; this.actualPaymentData = response.data;
console.log('支付数据加载成功:', this.actualPaymentData); console.log('支付数据加载成功:', this.actualPaymentData);
//
if (!this.actualPaymentData.allmoney) {
console.warn('警告支付数据缺少allmoney字段');
this.$message.warning("支付数据不完整,请检查数据源");
}
// 退 // 退
this.refundHistory = []; this.refundHistory = [];
this.totalRefundedAmount = "0.00"; 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(); await this.loadRefundHistory();
@ -712,7 +734,10 @@ export default {
if (attempt === maxRetries) { // if (attempt === maxRetries) { //
this.refundHistory = []; this.refundHistory = [];
this.totalRefundedAmount = "0.00"; 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 = response.msg || "加载退款历史失败"; this.refundHistoryError = response.msg || "加载退款历史失败";
this.errorDetails = { this.errorDetails = {
code: response.code, code: response.code,
@ -732,7 +757,10 @@ export default {
if (attempt === maxRetries) { // if (attempt === maxRetries) { //
this.refundHistory = []; this.refundHistory = [];
this.totalRefundedAmount = "0.00"; 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.refundHistoryError = "加载退款历史失败,请稍后再试";
this.errorDetails = { this.errorDetails = {
code: 'N/A', code: 'N/A',
@ -799,13 +827,21 @@ export default {
this.totalRefundedAmount = total.toFixed(2); this.totalRefundedAmount = total.toFixed(2);
// 退退 - 退 // 退 = allmoney - - returnmoney
const actualRefundable = parseFloat(this.actualRefundableAmount); const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
const totalRefunded = parseFloat(this.totalRefundedAmount); 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); 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() { initForm() {
@ -826,8 +862,10 @@ export default {
if (this.refundHistory.length > 0) { if (this.refundHistory.length > 0) {
this.calculateTotalRefunded(); this.calculateTotalRefunded();
} else { } else {
// 退 // 退allmoney -
this.remainingRefundableAmount = this.actualRefundableAmount; const allMoney = parseFloat(this.actualPaymentData.allmoney || 0);
const memberDiscount = parseFloat(this.actualPaymentData.membermoney || 0);
this.remainingRefundableAmount = (allMoney - memberDiscount).toFixed(2);
} }
this.calculateTotalRefund(); this.calculateTotalRefund();
@ -894,17 +932,28 @@ export default {
refundRemark: this.refundForm.refundRemark refundRemark: this.refundForm.refundRemark
}; };
console.log('构建的参数:', params); //
console.log('参数类型检查:'); console.log('=== 参数验证和转换 ===');
console.log(' orderId:', typeof params.orderId, params.orderId); console.log('原始表单数据:', this.refundForm);
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);
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); console.log('退款接口响应:', response);
@ -912,8 +961,8 @@ export default {
this.$message.success("退款成功"); this.$message.success("退款成功");
this.$emit("success", response.data); this.$emit("success", response.data);
// 退 // 退
await this.loadRefundHistory(); await this.loadPaymentData();
this.handleClose(); this.handleClose();
} else { } else {

View File

@ -276,10 +276,10 @@
@click="handleAfterSale(scope.row)" @click="handleAfterSale(scope.row)"
style="color: #E6A23C;" style="color: #E6A23C;"
>售后</el-button> >售后</el-button>
<!-- v-if="scope.row.status >= 15"-->
<!-- 统一退款按钮 --> <!-- 统一退款按钮 -->
<el-button <el-button
v-if="scope.row.status >= 15"
size="mini" size="mini"
type="text" type="text"
icon="el-icon-money" icon="el-icon-money"