diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UsersPayBeforController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UsersPayBeforController.java index f394353..a6d2468 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UsersPayBeforController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UsersPayBeforController.java @@ -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; + } + } + /** * 查询预支付列表 */ @@ -238,25 +270,58 @@ public class UsersPayBeforController extends BaseController // 添加调试日志 System.out.println("=== 统一退款接口开始 ==="); 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 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; @@ -325,17 +392,56 @@ public class UsersPayBeforController extends BaseController totalMemberDiscount = totalMemberDiscount.add(record.getMembermoney()); } } - + // 实际可退款金额 = 总支付金额 - 会员优惠金额 BigDecimal actualRefundableAmount = totalPaid.subtract(totalMemberDiscount); - + //退款金额不能超过剩余可退款金额,剩余可退款:¥10.90(总支付:¥199.00,会员优惠:¥9.90,已退款:¥178.20) // 验证退款金额不能超过剩余可退款金额(基于实际可退金额) BigDecimal remainingRefundable = actualRefundableAmount.subtract(totalRefunded); if (totalRefund.compareTo(remainingRefundable) > 0) { - return error("退款金额不能超过剩余可退款金额,剩余可退款:¥" + remainingRefundable + + return error("退款金额不能超过剩余可退款金额,剩余可退款:¥" + remainingRefundable + "(总支付:¥" + 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); @@ -401,77 +507,111 @@ public class UsersPayBeforController extends BaseController BigDecimal remainingShoppingGoldRefund = shoppingGoldRefund; BigDecimal remainingServiceGoldRefund = serviceGoldRefund; BigDecimal remainingCouponRefund = couponRefund; - + + // 修复:正确计算各项支付方式的退款金额 for (UsersPayBefor record : payRecords) { BigDecimal currentRefunded = record.getReturnmoney() != null ? record.getReturnmoney() : BigDecimal.ZERO; - + // 计算本次退款中该记录应承担的退款金额 BigDecimal recordRefundAmount = BigDecimal.ZERO; - + // 根据该记录的支付方式分配退款金额 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); } } - + // 如果该记录有退款金额,则更新 if (recordRefundAmount.compareTo(BigDecimal.ZERO) > 0) { BigDecimal newTotalRefunded = currentRefunded.add(recordRefundAmount); - + // 如果累计退款金额等于或超过支付金额,设置为已退款状态 if (newTotalRefunded.compareTo(record.getAllmoney()) >= 0) { record.setStatus(3L); // 完全退款 } else { record.setStatus(2L); // 部分退款 } - + 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 refundResult = refundUtil.processUnifiedRefund( orderId, wechatRefund, balanceRefund, shoppingGoldRefund, serviceGoldRefund, memberDiscountRefund, couponRefund, refundRemark ); - + if (refundResult != null && (Boolean) refundResult.get("success")) { return success("退款成功"); } else { diff --git a/ruoyi-ui/src/views/system/GoodsOrder/UnifiedRefundDialog.vue b/ruoyi-ui/src/views/system/GoodsOrder/UnifiedRefundDialog.vue index 71cd815..03745a2 100644 --- a/ruoyi-ui/src/views/system/GoodsOrder/UnifiedRefundDialog.vue +++ b/ruoyi-ui/src/views/system/GoodsOrder/UnifiedRefundDialog.vue @@ -9,8 +9,17 @@

支付信息

- - + + + + + + + + + + + @@ -46,7 +55,7 @@
- +
@@ -56,7 +65,7 @@
- ¥{{ formatAmount(totalPaymentAmount) }} + ¥{{ formatAmount(actualPaymentData.allmoney) }}
@@ -76,7 +85,7 @@
- 💡 实际可退款金额:¥{{ formatAmount(actualRefundableAmount) }}(总支付:¥{{ formatAmount(totalPaymentAmount) }} - 会员优惠:¥{{ formatAmount(actualPaymentData.membermoney || 0) }}) + 💡 实际可退款金额:¥{{ formatAmount(actualRefundableAmount) }}(总支付:¥{{ formatAmount(actualPaymentData.allmoney) }} - 会员优惠:¥{{ formatAmount(actualPaymentData.membermoney || 0) }})
@@ -274,7 +283,7 @@
退款记录 #{{ index + 1 }} -    {{ formatTime(item.createdAt) }} +    {{ formatTime(item.createTime) }}
@@ -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', @@ -798,14 +826,22 @@ 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() { @@ -821,38 +857,40 @@ export default { this.refundForm.serviceGoldRefund = ""; this.refundForm.couponRefund = "0"; // 默认不退 this.refundForm.refundRemark = ""; - + // 等待退款历史加载完成后再设置剩余可退款金额 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(); }, calculateTotalRefund() { console.log('=== 开始计算总退款金额 ==='); console.log('refundForm:', this.refundForm); - + const wechatAmount = parseFloat(this.refundForm.wechatRefund) || 0; const balanceAmount = parseFloat(this.refundForm.balanceRefund) || 0; const shoppingAmount = parseFloat(this.refundForm.shoppingGoldRefund) || 0; const serviceAmount = parseFloat(this.refundForm.serviceGoldRefund) || 0; const couponAmount = parseFloat(this.refundForm.couponRefund === '1' ? this.actualPaymentData.couponmoney : 0) || 0; - + console.log('各项金额:'); console.log(' 微信退款:', wechatAmount); console.log(' 余额退款:', balanceAmount); console.log(' 购物金退款:', shoppingAmount); console.log(' 服务金退款:', serviceAmount); console.log(' 优惠券退款:', couponAmount); - + const total = wechatAmount + balanceAmount + shoppingAmount + serviceAmount + couponAmount; this.totalRefundAmount = total.toFixed(2); - + console.log('总退款金额:', this.totalRefundAmount); }, @@ -883,7 +921,7 @@ export default { console.log('=== 开始确认退款 ==='); console.log('refundForm:', this.refundForm); console.log('actualPaymentData:', this.actualPaymentData); - + const params = { orderId: this.orderId, wechatRefund: this.refundForm.wechatRefund || "0", @@ -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 { @@ -1191,11 +1240,11 @@ export default { .payment-info h4 { margin: 0 0 15px 0; color: #303133; font-size: 16px; font-weight: 600; } .info-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding: 8px 0; } .info-item label { font-weight: 500; color: #606266; min-width: 80px; } -.info-item .member-discount-note { - font-size: 12px; - color: #909399; - margin-top: 5px; - font-style: italic; +.info-item .member-discount-note { + font-size: 12px; + color: #909399; + margin-top: 5px; + font-style: italic; text-align: center; width: 100%; } diff --git a/ruoyi-ui/src/views/system/GoodsOrder/index.vue b/ruoyi-ui/src/views/system/GoodsOrder/index.vue index 7ef5c0b..a838736 100644 --- a/ruoyi-ui/src/views/system/GoodsOrder/index.vue +++ b/ruoyi-ui/src/views/system/GoodsOrder/index.vue @@ -10,7 +10,7 @@ @keyup.enter.native="handleQuery" /> - + - + Excel批量发货 - + - + - + - + - + - + - +