From 0a34deda55fa69c61381a638a797fb5baee6dd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=BD=98?= <925116093@qq.com> Date: Wed, 13 Aug 2025 01:24:37 +0800 Subject: [PATCH] 202507251746 --- .../controller/UsersPayBeforController.java | 171 ++++++- ruoyi-ui/src/api/system/UsersPayBefor.js | 10 + .../system/GoodsOrder/UnifiedRefundDialog.vue | 426 ++++++++++++++++++ .../src/views/system/GoodsOrder/index.vue | 63 ++- 4 files changed, 646 insertions(+), 24 deletions(-) create mode 100644 ruoyi-ui/src/api/system/UsersPayBefor.js create mode 100644 ruoyi-ui/src/views/system/GoodsOrder/UnifiedRefundDialog.vue 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 ecb4e22..c0bf697 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 @@ -34,7 +34,7 @@ import com.ruoyi.common.core.page.TableDataInfo; /** * 预支付Controller - * + * * @author ruoyi * @date 2025-07-11 */ @@ -119,23 +119,12 @@ public class UsersPayBeforController extends BaseController return toAjax(usersPayBeforService.deleteUsersPayBeforByIds(ids)); } -// /** -// * 根据订单ID查询预支付数据 -// */ -// @GetMapping("/getByOrderId/{orderId}") -// public AjaxResult getByOrderId(@PathVariable("orderId") String orderId) -// { -// UsersPayBefor usersPayBefor = usersPayBeforService.selectUsersPayBeforByOrderId(orderId); -// return success(usersPayBefor); -// } - /** * 根据订单ID查询预支付数据 */ @GetMapping("/getByOrderId/{orderId}") public AjaxResult getByOrderId(@PathVariable("orderId") String orderId) { - GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.setMainOrderId(orderId); List orders = goodsOrderService.selectGoodsOrderList(goodsOrder); @@ -148,9 +137,6 @@ public class UsersPayBeforController extends BaseController }else{ return success(); } - - - } /** @@ -221,16 +207,12 @@ public class UsersPayBeforController extends BaseController } orderLog.setContent(jsonObject.toJSONString()); int flg=orderLogService.insertOrderLog(orderLog); -// if (flg>0){ -// -// } -// OrderUtil orderUtil = new OrderUtil(); -// OrderUtil.refund(order, usersPayBefor); + // 验证退款金额不能超过支付金额 BigDecimal currentReturnMoney = originalRecord.getReturnmoney() != null ? originalRecord.getReturnmoney() : BigDecimal.ZERO; BigDecimal totalRefund = currentReturnMoney.add(returnMoney); BigDecimal paymentAmount = originalRecord.getAllmoney() != null ? originalRecord.getAllmoney() : BigDecimal.ZERO; - + if (totalRefund.compareTo(paymentAmount) > 0) { return error("退款金额不能超过支付金额"); } @@ -238,7 +220,152 @@ public class UsersPayBeforController extends BaseController originalRecord.setStatus(3L); // 更新退款金额 originalRecord.setReturnmoney(totalRefund); - + return toAjax(usersPayBeforService.updateUsersPayBefor(originalRecord)); } + + /** + * 统一退款方法 - 支持多次退款和部分退款 + */ + @Log(title = "统一退款", businessType = BusinessType.UPDATE) + @PostMapping("/unifiedRefund") + public AjaxResult unifiedRefund(@RequestBody Map params) + { + try { + 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()); + String refundRemark = params.get("refundRemark") == null ? "" : params.get("refundRemark").toString(); + + if (orderId == null || orderId.trim().isEmpty()) { + return error("订单ID不能为空"); + } + + BigDecimal totalRefund = wechatRefund.add(balanceRefund).add(shoppingGoldRefund) + .add(serviceGoldRefund).add(memberDiscountRefund).add(couponRefund); + + if (totalRefund.compareTo(BigDecimal.ZERO) <= 0) { + return error("退款金额必须大于0"); + } + + Order order = orderService.selectOrderByOrderId(orderId); + if (order == null) { + return error("订单不存在"); + } + + List payRecords = usersPayBeforService.selectPayDetailsByOrderId(orderId); + if (payRecords == null || payRecords.isEmpty()) { + return error("未找到支付记录"); + } + + // 计算已退款金额 + BigDecimal totalRefunded = BigDecimal.ZERO; + for (UsersPayBefor record : payRecords) { + if (record.getReturnmoney() != null) { + totalRefunded = totalRefunded.add(record.getReturnmoney()); + } + } + + // 计算总支付金额 + BigDecimal totalPaid = BigDecimal.ZERO; + for (UsersPayBefor record : payRecords) { + if (record.getAllmoney() != null) { + totalPaid = totalPaid.add(record.getAllmoney()); + } + } + + // 验证退款金额不能超过剩余可退款金额 + BigDecimal remainingRefundable = totalPaid.subtract(totalRefunded); + if (totalRefund.compareTo(remainingRefundable) > 0) { + return error("退款金额不能超过剩余可退款金额,剩余可退款:¥" + remainingRefundable); + } + + // 记录退款日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOrderId(orderId); + orderLog.setOid(order.getId()); + orderLog.setTitle("统一退款"); + orderLog.setType(new BigDecimal(11)); + + // 构建退款详情 + JSONObject refundDetails = new JSONObject(); + StringBuilder refundDesc = new StringBuilder("统一退款:"); + + if (wechatRefund.compareTo(BigDecimal.ZERO) > 0) { + refundDesc.append("微信支付退款¥").append(wechatRefund).append(","); + } + if (balanceRefund.compareTo(BigDecimal.ZERO) > 0) { + refundDesc.append("余额退款¥").append(balanceRefund).append(","); + } + if (shoppingGoldRefund.compareTo(BigDecimal.ZERO) > 0) { + refundDesc.append("购物金退款¥").append(shoppingGoldRefund).append(","); + } + if (serviceGoldRefund.compareTo(BigDecimal.ZERO) > 0) { + refundDesc.append("服务金退款¥").append(serviceGoldRefund).append(","); + } + if (memberDiscountRefund.compareTo(BigDecimal.ZERO) > 0) { + refundDesc.append("会员优惠退款¥").append(memberDiscountRefund).append(","); + } + if (couponRefund.compareTo(BigDecimal.ZERO) > 0) { + refundDesc.append("优惠券抵扣退款¥").append(couponRefund).append(","); + } + + if (refundDesc.charAt(refundDesc.length() - 1) == ',') { + refundDesc.setLength(refundDesc.length() - 1); + } + + refundDesc.append(",本次退款金额:¥").append(totalRefund); + refundDesc.append(",累计已退款:¥").append(totalRefunded.add(totalRefund)); + refundDesc.append(",剩余可退款:¥").append(remainingRefundable.subtract(totalRefund)); + + refundDetails.put("name", refundDesc.toString()); + refundDetails.put("wechatRefund", wechatRefund); + refundDetails.put("balanceRefund", balanceRefund); + refundDetails.put("shoppingGoldRefund", shoppingGoldRefund); + refundDetails.put("serviceGoldRefund", serviceGoldRefund); + refundDetails.put("memberDiscountRefund", memberDiscountRefund); + refundDetails.put("couponRefund", couponRefund); + refundDetails.put("totalRefund", totalRefund); + refundDetails.put("totalRefunded", totalRefunded.add(totalRefund)); + refundDetails.put("remainingRefundable", remainingRefundable.subtract(totalRefund)); + refundDetails.put("refundRemark", refundRemark); + refundDetails.put("refundTime", new java.util.Date()); + + orderLog.setContent(refundDetails.toJSONString()); + orderLogService.insertOrderLog(orderLog); + + // 更新支付记录状态和退款金额 + for (UsersPayBefor record : payRecords) { + BigDecimal currentRefunded = record.getReturnmoney() != null ? record.getReturnmoney() : BigDecimal.ZERO; + BigDecimal newTotalRefunded = currentRefunded.add(totalRefund); + + // 如果累计退款金额等于或超过支付金额,设置为已退款状态 + if (newTotalRefunded.compareTo(record.getAllmoney()) >= 0) { + record.setStatus(3L); // 完全退款 + } else { + record.setStatus(2L); // 部分退款 + } + + record.setReturnmoney(newTotalRefunded); + usersPayBeforService.updateUsersPayBefor(record); + } + + // 这里可以添加实际的退款逻辑 + // 1. 微信支付退款 - 调用微信退款API + // 2. 余额退款 - 更新用户余额 + // 3. 购物金退款 - 更新购物金余额 + // 4. 服务金退款 - 更新服务金余额 + // 5. 会员优惠退款 - 更新会员积分或优惠 + // 6. 优惠券退款 - 恢复优惠券使用状态 + // return success("退款成功", refundDetails); + return success("退款成功"); + + } catch (Exception e) { + return error("退款失败:" + e.getMessage()); + } + } } diff --git a/ruoyi-ui/src/api/system/UsersPayBefor.js b/ruoyi-ui/src/api/system/UsersPayBefor.js new file mode 100644 index 0000000..f2076f1 --- /dev/null +++ b/ruoyi-ui/src/api/system/UsersPayBefor.js @@ -0,0 +1,10 @@ +import request from '@/utils/request' + +// 统一退款 +export function unifiedRefund(data) { + return request({ + url: '/system/UsersPayBefor/unifiedRefund', + method: 'post', + data: data + }) +} \ No newline at end of file diff --git a/ruoyi-ui/src/views/system/GoodsOrder/UnifiedRefundDialog.vue b/ruoyi-ui/src/views/system/GoodsOrder/UnifiedRefundDialog.vue new file mode 100644 index 0000000..3a1643a --- /dev/null +++ b/ruoyi-ui/src/views/system/GoodsOrder/UnifiedRefundDialog.vue @@ -0,0 +1,426 @@ + + + + + \ No newline at end of file diff --git a/ruoyi-ui/src/views/system/GoodsOrder/index.vue b/ruoyi-ui/src/views/system/GoodsOrder/index.vue index 63e5faf..6a99d98 100644 --- a/ruoyi-ui/src/views/system/GoodsOrder/index.vue +++ b/ruoyi-ui/src/views/system/GoodsOrder/index.vue @@ -277,6 +277,16 @@ style="color: #E6A23C;" >售后 + + 统一退款 + + + + @@ -420,7 +438,8 @@ export default { ShipmentDialog: () => import('./ShipmentDialog.vue'), ExcelImportDialog: () => import('./ExcelImportDialog.vue'), ImportResultDialog: () => import('./ImportResultDialog.vue'), - PrePaymentDialog: () => import('./PrePaymentDialog.vue') + PrePaymentDialog: () => import('./PrePaymentDialog.vue'), + UnifiedRefundDialog: () => import('./UnifiedRefundDialog.vue') }, data() { return { @@ -599,7 +618,12 @@ export default { shipMode: 'single', currentShipOrder: null, shipLoading: false, - shipmentOrders: [] + shipmentOrders: [], + + // 统一退款对话框相关 + unifiedRefundDialogVisible: false, + currentRefundOrder: null, + currentRefundPaymentData: null } }, created() { @@ -617,6 +641,9 @@ export default { this.excelImportDialogVisible = false; this.importResultVisible = false; this.detailDialogVisible = false; + this.unifiedRefundDialogVisible = false; + this.currentRefundOrder = null; + this.currentRefundPaymentData = null; }, mounted() { // 简化mounted钩子 @@ -765,6 +792,9 @@ export default { this.excelImportDialogVisible = false; this.importResultVisible = false; this.detailDialogVisible = false; + this.unifiedRefundDialogVisible = false; + this.currentRefundOrder = null; + this.currentRefundPaymentData = null; // 使用nextTick确保弹窗完全关闭后再重置数据 this.$nextTick(() => { @@ -1275,6 +1305,35 @@ export default { this.$nextTick(() => { this.prePaymentData = null; }); + }, + + /** 统一退款对话框关闭 */ + handleUnifiedRefundClose() { + this.unifiedRefundDialogVisible = false; + this.currentRefundOrder = null; + this.currentRefundPaymentData = null; + }, + + /** 处理统一退款成功 */ + handleRefundSuccess() { + this.unifiedRefundDialogVisible = false; + this.currentRefundOrder = null; + this.currentRefundPaymentData = null; + this.getList(); // 刷新列表 + }, + + /** 统一退款按钮操作 */ + handleUnifiedRefund(row) { + this.currentRefundOrder = row; + this.currentRefundPaymentData = { + wechatAmount: row.payPrice || 0, + balanceAmount: 0, + shoppingGoldAmount: 0, + serviceGoldAmount: 0, + memberDiscountAmount: 0, + couponAmount: 0 + }; + this.unifiedRefundDialogVisible = true; } } }