202507251746333
This commit is contained in:
parent
99b958a3b7
commit
bae71b2015
|
|
@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.system.ControllerUtil.BenefitPointsUtil;
|
||||
import com.ruoyi.system.ControllerUtil.OrderUtil;
|
||||
import com.ruoyi.system.ControllerUtil.RefundUtil;
|
||||
import com.ruoyi.system.domain.GoodsOrder;
|
||||
|
|
@ -164,11 +165,11 @@ public class UsersPayBeforController extends BaseController
|
|||
{
|
||||
try {
|
||||
System.out.println("=== 查询预支付数据,订单ID: " + orderId + " ===");
|
||||
|
||||
|
||||
GoodsOrder goodsOrder = new GoodsOrder();
|
||||
goodsOrder.setMainOrderId(orderId);
|
||||
List<GoodsOrder> orders = goodsOrderService.selectGoodsOrderList(goodsOrder);
|
||||
|
||||
|
||||
UsersPayBefor usersPayBefor = null;
|
||||
if (orders.size() > 0) {
|
||||
// 优先查询主订单ID对应的预支付记录
|
||||
|
|
@ -286,9 +287,9 @@ public class UsersPayBeforController extends BaseController
|
|||
// System.out.println(" 会员优惠: " + resultPayBefor.getMembermoney() + "元");
|
||||
// System.out.println(" 实际总金额: " + resultPayBefor.getAllmoney() + "元");
|
||||
// System.out.println(" 已退款: " + resultPayBefor.getReturnmoney() + "元");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 查询预支付数据异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
|
@ -673,10 +674,7 @@ public class UsersPayBeforController extends BaseController
|
|||
// 修复:计算该记录服务金的剩余可退款金额
|
||||
BigDecimal serviceRemaining = record.getServicemoney().subtract(currentRefunded);
|
||||
if (serviceRemaining.compareTo(BigDecimal.ZERO) > 0 && remainingServiceGoldRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
record.setServicemoney(serviceRemaining);
|
||||
BigDecimal serviceRefund = remainingServiceGoldRefund.min(serviceRemaining);
|
||||
recordRefundAmount = recordRefundAmount.add(serviceRefund);
|
||||
remainingServiceGoldRefund = remainingServiceGoldRefund.subtract(serviceRefund);
|
||||
BenefitPointsUtil.theBenefitPointsServiceMoneyChangeResult(record,remainingServiceGoldRefund,1,"订单退款");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -684,10 +682,8 @@ public class UsersPayBeforController extends BaseController
|
|||
// 修复:计算该记录优惠券的剩余可退款金额
|
||||
BigDecimal couponRemaining = record.getCouponmoney().subtract(currentRefunded);
|
||||
if (couponRemaining.compareTo(BigDecimal.ZERO) > 0 && remainingCouponRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
record.setCouponmoney(new BigDecimal(0));
|
||||
BigDecimal couponRefundAmount = remainingCouponRefund.min(couponRemaining);
|
||||
recordRefundAmount = recordRefundAmount.add(couponRefundAmount);
|
||||
remainingCouponRefund = remainingCouponRefund.subtract(couponRefundAmount);
|
||||
BenefitPointsUtil.theBenefitPointsGoodsMoneyChangeResult(record,remainingShoppingGoldRefund,1,"订单退款");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -732,17 +728,17 @@ public class UsersPayBeforController extends BaseController
|
|||
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
|
||||
);
|
||||
|
||||
if (refundResult != null && (Boolean) refundResult.get("success")) {
|
||||
return success("退款成功");
|
||||
} else {
|
||||
String errorMsg = (String) refundResult.get("message");
|
||||
return error(errorMsg != null ? errorMsg : "退款处理失败");
|
||||
}
|
||||
// Map<String, Object> refundResult = refundUtil.processUnifiedRefund(
|
||||
// orderId, wechatRefund, balanceRefund, shoppingGoldRefund,
|
||||
// serviceGoldRefund, memberDiscountRefund, couponRefund, refundRemark
|
||||
// );
|
||||
return success("退款成功");
|
||||
// if (refundResult != null && (Boolean) refundResult.get("success")) {
|
||||
// return success("退款成功");
|
||||
// } else {
|
||||
// String errorMsg = (String) refundResult.get("message");
|
||||
// return error(errorMsg != null ? errorMsg : "退款处理失败");
|
||||
// }
|
||||
|
||||
} catch (Exception e) {
|
||||
return error("退款失败:" + e.getMessage());
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -23,7 +23,7 @@ public class RefundUtil {
|
|||
/**
|
||||
* 处理统一退款业务方法 - 实现真实的业务退款与金额变动
|
||||
* 配合 UsersPayBeforController.java 里面的 unifiedRefund 方法
|
||||
*
|
||||
*
|
||||
* @param orderId 订单ID
|
||||
* @param wechatRefund 微信退款金额
|
||||
* @param balanceRefund 余额退款金额
|
||||
|
|
@ -34,19 +34,19 @@ public class RefundUtil {
|
|||
* @param refundRemark 退款备注
|
||||
* @return 退款处理结果
|
||||
*/
|
||||
public Map<String, Object> processUnifiedRefund(String orderId, BigDecimal wechatRefund,
|
||||
public Map<String, Object> processUnifiedRefund(String orderId, BigDecimal wechatRefund,
|
||||
BigDecimal balanceRefund, BigDecimal shoppingGoldRefund,
|
||||
BigDecimal serviceGoldRefund, BigDecimal memberDiscountRefund,
|
||||
BigDecimal couponRefund, String refundRemark) {
|
||||
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("success", false);
|
||||
result.put("message", "");
|
||||
result.put("details", new HashMap<>());
|
||||
|
||||
|
||||
try {
|
||||
System.out.println("=== 开始处理统一退款业务,订单号: " + orderId + " ===");
|
||||
|
||||
|
||||
// 添加参数接收的调试日志
|
||||
System.out.println("RefundUtil接收到的参数:");
|
||||
System.out.println(" orderId: " + orderId);
|
||||
|
|
@ -57,7 +57,7 @@ public class RefundUtil {
|
|||
System.out.println(" memberDiscountRefund: " + memberDiscountRefund + " (类型: " + (memberDiscountRefund != null ? memberDiscountRefund.getClass().getSimpleName() : "null") + ")");
|
||||
System.out.println(" couponRefund: " + couponRefund + " (类型: " + (couponRefund != null ? couponRefund.getClass().getSimpleName() : "null") + ")");
|
||||
System.out.println(" refundRemark: " + refundRemark);
|
||||
|
||||
|
||||
// 检查参数是否大于0
|
||||
System.out.println("参数检查:");
|
||||
System.out.println(" wechatRefund > 0: " + (wechatRefund != null && wechatRefund.compareTo(BigDecimal.ZERO) > 0));
|
||||
|
|
@ -66,7 +66,7 @@ public class RefundUtil {
|
|||
System.out.println(" serviceGoldRefund > 0: " + (serviceGoldRefund != null && serviceGoldRefund.compareTo(BigDecimal.ZERO) > 0));
|
||||
System.out.println(" memberDiscountRefund > 0: " + (memberDiscountRefund != null && memberDiscountRefund.compareTo(BigDecimal.ZERO) > 0));
|
||||
System.out.println(" couponRefund > 0: " + (couponRefund != null && couponRefund.compareTo(BigDecimal.ZERO) > 0));
|
||||
|
||||
|
||||
// 1. 查询支付信息
|
||||
System.out.println("步骤1: 查询支付信息...");
|
||||
UsersPayBefor paymentInfo = usersPayBeforService.selectUsersPayBeforByOrderId(orderId);
|
||||
|
|
@ -77,10 +77,10 @@ public class RefundUtil {
|
|||
return result;
|
||||
}
|
||||
System.out.println("✅ 支付信息查询成功");
|
||||
System.out.println(" 用户ID: " + paymentInfo.getUid() +
|
||||
", 订单金额: " + paymentInfo.getAllmoney() +
|
||||
System.out.println(" 用户ID: " + paymentInfo.getUid() +
|
||||
", 订单金额: " + paymentInfo.getAllmoney() +
|
||||
", 服务类型: " + paymentInfo.getServicetype());
|
||||
|
||||
|
||||
// 2. 查询用户信息
|
||||
System.out.println("步骤2: 查询用户信息...");
|
||||
Users user = usersService.selectUsersById(paymentInfo.getUid());
|
||||
|
|
@ -91,11 +91,11 @@ public class RefundUtil {
|
|||
return result;
|
||||
}
|
||||
System.out.println("✅ 用户信息查询成功,用户: " + user.getName());
|
||||
|
||||
|
||||
// 3. 处理各种退款类型
|
||||
Map<String, Object> refundDetails = new HashMap<>();
|
||||
boolean hasRefund = false;
|
||||
|
||||
|
||||
// 3.1 处理微信退款
|
||||
if (wechatRefund != null && wechatRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println("步骤3.1: 处理微信退款...");
|
||||
|
|
@ -110,7 +110,7 @@ public class RefundUtil {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 3.2 处理余额退款
|
||||
if (balanceRefund != null && balanceRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println("步骤3.2: 处理余额退款...");
|
||||
|
|
@ -125,7 +125,7 @@ public class RefundUtil {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 3.3 处理购物金退款(消费金)
|
||||
if (shoppingGoldRefund != null && shoppingGoldRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println("步骤3.3: 处理购物金退款(消费金)...");
|
||||
|
|
@ -140,7 +140,7 @@ public class RefundUtil {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 3.4 处理服务金退款
|
||||
if (serviceGoldRefund != null && serviceGoldRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println("步骤3.4: 处理服务金退款...");
|
||||
|
|
@ -155,7 +155,7 @@ public class RefundUtil {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 3.5 会员优惠不参与退款(平台承担的折扣)
|
||||
if (memberDiscountRefund != null && memberDiscountRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println("步骤3.5: 会员优惠不参与退款(平台承担折扣)...");
|
||||
|
|
@ -163,7 +163,7 @@ public class RefundUtil {
|
|||
// 会员优惠不参与退款,但记录在退款详情中用于说明
|
||||
refundDetails.put("memberDiscountNotRefunded", memberDiscountRefund);
|
||||
}
|
||||
|
||||
|
||||
// 3.6 处理优惠券退款
|
||||
if (couponRefund != null && couponRefund.compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println("步骤3.6: 处理优惠券退款...");
|
||||
|
|
@ -178,18 +178,18 @@ public class RefundUtil {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!hasRefund) {
|
||||
String errorMsg = "没有有效的退款金额";
|
||||
System.err.println("❌ " + errorMsg);
|
||||
result.put("message", errorMsg);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 4. 更新支付记录状态和扣减预支付金额
|
||||
System.out.println("步骤4: 更新支付记录状态和扣减预支付金额...");
|
||||
boolean updateSuccess = updatePaymentStatus(paymentInfo, orderId, wechatRefund, balanceRefund,
|
||||
shoppingGoldRefund, serviceGoldRefund,
|
||||
boolean updateSuccess = updatePaymentStatus(paymentInfo, orderId, wechatRefund, balanceRefund,
|
||||
shoppingGoldRefund, serviceGoldRefund,
|
||||
memberDiscountRefund, couponRefund);
|
||||
if (!updateSuccess) {
|
||||
System.err.println("❌ 支付记录状态更新失败");
|
||||
|
|
@ -197,11 +197,11 @@ public class RefundUtil {
|
|||
return result;
|
||||
}
|
||||
System.out.println("✅ 支付记录状态更新成功");
|
||||
|
||||
|
||||
// 5. 处理积分和服务金消费金的扣除(退款时需要扣除之前增加的)
|
||||
System.out.println("步骤5: 处理积分和服务金消费金扣除...");
|
||||
processRefundDeductions(paymentInfo, user, orderId);
|
||||
|
||||
|
||||
// 6. 记录退款流水日志
|
||||
System.out.println("步骤6: 记录退款流水日志...");
|
||||
boolean logSuccess = recordRefundLog(paymentInfo, refundDetails, refundRemark, orderId);
|
||||
|
|
@ -210,24 +210,24 @@ public class RefundUtil {
|
|||
} else {
|
||||
System.out.println("✅ 退款流水日志记录成功");
|
||||
}
|
||||
|
||||
|
||||
// 7. 设置成功结果
|
||||
result.put("success", true);
|
||||
result.put("message", "退款处理成功");
|
||||
result.put("details", refundDetails);
|
||||
|
||||
|
||||
System.out.println("=== 统一退款业务处理完成,结果: 成功 ===");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
String errorMsg = "退款处理异常: " + e.getMessage();
|
||||
System.err.println("❌ " + errorMsg);
|
||||
e.printStackTrace();
|
||||
result.put("message", errorMsg);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退款方法 - 用于AppletController中的订单取消退款
|
||||
* @param orderid 订单ID
|
||||
|
|
@ -235,7 +235,7 @@ public class RefundUtil {
|
|||
*/
|
||||
public boolean refundOrder(String orderid) {
|
||||
System.out.println("=== 开始退款处理,订单号: " + orderid + " ===");
|
||||
|
||||
|
||||
try {
|
||||
// 查询预支付记录
|
||||
UsersPayBefor payBefor = usersPayBeforService.selectUsersPayBeforByOrderId(orderid);
|
||||
|
|
@ -243,16 +243,16 @@ public class RefundUtil {
|
|||
System.err.println("❌ 预支付记录不存在,订单号: " + orderid);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 查询用户信息
|
||||
Users user = usersService.selectUsersById(payBefor.getUid());
|
||||
if (user == null) {
|
||||
System.err.println("❌ 用户不存在,用户ID: " + payBefor.getUid());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean refundSuccess = false;
|
||||
|
||||
|
||||
// 处理微信退款
|
||||
if (payBefor.getWxmoney() != null && payBefor.getWxmoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println(" 微信退款金额: " + payBefor.getWxmoney() + "元");
|
||||
|
|
@ -264,7 +264,7 @@ public class RefundUtil {
|
|||
System.err.println("❌ 微信退款处理失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理余额退款
|
||||
if (payBefor.getYemoney() != null && payBefor.getYemoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println(" 余额退款金额: " + payBefor.getYemoney() + "元");
|
||||
|
|
@ -276,7 +276,7 @@ public class RefundUtil {
|
|||
System.err.println("❌ 余额退款处理失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理购物金退款
|
||||
if (payBefor.getShopmoney() != null && payBefor.getShopmoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println(" 购物金退款金额: " + payBefor.getShopmoney() + "元");
|
||||
|
|
@ -288,7 +288,7 @@ public class RefundUtil {
|
|||
System.err.println("❌ 购物金退款处理失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理服务金退款
|
||||
if (payBefor.getServicemoney() != null && payBefor.getServicemoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println(" 服务金退款金额: " + payBefor.getServicemoney() + "元");
|
||||
|
|
@ -300,7 +300,7 @@ public class RefundUtil {
|
|||
System.err.println("❌ 服务金退款处理失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 处理优惠券退款
|
||||
if (payBefor.getCouponmoney() != null && payBefor.getCouponmoney().compareTo(BigDecimal.ZERO) > 0) {
|
||||
System.out.println(" 优惠券退款金额: " + payBefor.getCouponmoney() + "元");
|
||||
|
|
@ -312,24 +312,24 @@ public class RefundUtil {
|
|||
System.err.println("❌ 优惠券退款处理失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 如果退款成功,更新订单状态
|
||||
if (refundSuccess) {
|
||||
payBefor.setStatus(3L); // 设置为已退款状态
|
||||
usersPayBeforService.updateUsersPayBefor(payBefor);
|
||||
System.out.println("✅ 订单状态更新完成");
|
||||
}
|
||||
|
||||
|
||||
System.out.println("=== 退款处理完成,最终结果: " + (refundSuccess ? "成功" : "失败") + " ===");
|
||||
return refundSuccess;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 退款处理异常:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理微信退款
|
||||
*/
|
||||
|
|
@ -339,17 +339,17 @@ public class RefundUtil {
|
|||
System.err.println("❌ 微信支付单号为空,无法处理微信退款");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 调用微信退款API
|
||||
Map<String, Object> refundResult = wechatPayV3Util.refund(
|
||||
orderId,
|
||||
paymentInfo.getPaycode(),
|
||||
refundAmount.intValue(),
|
||||
refundAmount.intValue(),
|
||||
"统一退款",
|
||||
orderId,
|
||||
paymentInfo.getPaycode(),
|
||||
refundAmount.intValue(),
|
||||
refundAmount.intValue(),
|
||||
"统一退款",
|
||||
""
|
||||
);
|
||||
|
||||
|
||||
// 根据微信退款结果判断是否成功
|
||||
if (refundResult != null && "SUCCESS".equals(refundResult.get("return_code"))) {
|
||||
return true;
|
||||
|
|
@ -357,14 +357,14 @@ public class RefundUtil {
|
|||
System.err.println("❌ 微信退款API调用失败: " + refundResult);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 微信退款处理异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理余额退款
|
||||
*/
|
||||
|
|
@ -374,21 +374,21 @@ public class RefundUtil {
|
|||
System.out.println("用户ID: " + user.getId() + ", 用户名: " + user.getName());
|
||||
System.out.println("退款金额: " + refundAmount + " (类型: " + (refundAmount != null ? refundAmount.getClass().getSimpleName() : "null") + ")");
|
||||
System.out.println("订单ID: " + orderId);
|
||||
|
||||
|
||||
BigDecimal beforeBalance = user.getBalance() != null ? user.getBalance() : BigDecimal.ZERO;
|
||||
BigDecimal afterBalance = beforeBalance.add(refundAmount);
|
||||
|
||||
|
||||
System.out.println("余额计算:");
|
||||
System.out.println(" 退款前余额: " + beforeBalance);
|
||||
System.out.println(" 退款金额: " + refundAmount);
|
||||
System.out.println(" 退款后余额: " + afterBalance);
|
||||
|
||||
|
||||
// 更新用户余额
|
||||
user.setBalance(afterBalance);
|
||||
System.out.println("尝试更新用户余额...");
|
||||
int updateResult = usersService.updateUsers(user);
|
||||
System.out.println("用户余额更新结果: " + updateResult);
|
||||
|
||||
|
||||
if (updateResult > 0) {
|
||||
System.out.println("用户余额更新成功,开始记录流水...");
|
||||
// 记录余额退款流水
|
||||
|
|
@ -402,26 +402,26 @@ public class RefundUtil {
|
|||
log.setAftermoney(afterBalance);
|
||||
log.setNowmoney(afterBalance);
|
||||
log.setType(1); // 1=收入
|
||||
|
||||
|
||||
System.out.println("流水记录对象创建完成,尝试插入...");
|
||||
int logResult = userMemnerConsumptionLogService.insertUserMemnerConsumptionLog(log);
|
||||
System.out.println("流水记录插入结果: " + logResult);
|
||||
|
||||
System.out.println("✅ 余额退款成功,用户: " + user.getName() +
|
||||
|
||||
System.out.println("✅ 余额退款成功,用户: " + user.getName() +
|
||||
", 退款前: " + beforeBalance + "元, 退款后: " + afterBalance + "元");
|
||||
return true;
|
||||
} else {
|
||||
System.err.println("❌ 用户余额更新失败");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 余额退款处理异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理购物金退款(消费金)
|
||||
*/
|
||||
|
|
@ -429,11 +429,11 @@ public class RefundUtil {
|
|||
try {
|
||||
BigDecimal beforeConsumption = user.getConsumption() != null ? user.getConsumption() : BigDecimal.ZERO;
|
||||
BigDecimal afterConsumption = beforeConsumption.add(refundAmount);
|
||||
|
||||
|
||||
// 更新用户消费金
|
||||
user.setConsumption(afterConsumption);
|
||||
int updateResult = usersService.updateUsers(user);
|
||||
|
||||
|
||||
if (updateResult > 0) {
|
||||
// 记录消费金退款流水
|
||||
UserBenefitPoints benefitPoints = new UserBenefitPoints();
|
||||
|
|
@ -448,24 +448,24 @@ public class RefundUtil {
|
|||
benefitPoints.setCreatedAt(new Date());
|
||||
benefitPoints.setUpdatedAt(new Date());
|
||||
benefitPoints.setReamk("统一退款-消费金退款,订单号:" + orderId);
|
||||
|
||||
|
||||
userBenefitPointsService.insertUserBenefitPoints(benefitPoints);
|
||||
|
||||
System.out.println("✅ 消费金退款成功,用户: " + user.getName() +
|
||||
|
||||
System.out.println("✅ 消费金退款成功,用户: " + user.getName() +
|
||||
", 退款前: " + beforeConsumption + "元, 退款后: " + afterConsumption + "元");
|
||||
return true;
|
||||
} else {
|
||||
System.err.println("❌ 用户消费金更新失败");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 消费金退款处理异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理服务金退款
|
||||
*/
|
||||
|
|
@ -473,11 +473,11 @@ public class RefundUtil {
|
|||
try {
|
||||
BigDecimal beforeServiceGold = user.getServicefee() != null ? user.getServicefee() : BigDecimal.ZERO;
|
||||
BigDecimal afterServiceGold = beforeServiceGold.add(refundAmount);
|
||||
|
||||
|
||||
// 更新用户服务金
|
||||
user.setServicefee(afterServiceGold);
|
||||
int updateResult = usersService.updateUsers(user);
|
||||
|
||||
|
||||
if (updateResult > 0) {
|
||||
// 记录服务金退款流水
|
||||
UserBenefitPoints benefitPoints = new UserBenefitPoints();
|
||||
|
|
@ -492,24 +492,24 @@ public class RefundUtil {
|
|||
benefitPoints.setCreatedAt(new Date());
|
||||
benefitPoints.setUpdatedAt(new Date());
|
||||
benefitPoints.setReamk("统一退款-服务金退款,订单号:" + orderId);
|
||||
|
||||
|
||||
userBenefitPointsService.insertUserBenefitPoints(benefitPoints);
|
||||
|
||||
System.out.println("✅ 服务金退款成功,用户: " + user.getName() +
|
||||
|
||||
System.out.println("✅ 服务金退款成功,用户: " + user.getName() +
|
||||
", 退款前: " + beforeServiceGold + "元, 退款后: " + afterServiceGold + "元");
|
||||
return true;
|
||||
} else {
|
||||
System.err.println("❌ 用户服务金更新失败");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 服务金退款处理异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理优惠券退款
|
||||
*/
|
||||
|
|
@ -519,20 +519,20 @@ public class RefundUtil {
|
|||
// 可以根据实际业务需求调整
|
||||
System.out.println("✅ 优惠券退款处理成功,金额: " + refundAmount + "元");
|
||||
return true;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 优惠券退款处理异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新支付记录状态和退款金额
|
||||
* 注意:金额更新已经在Controller中完成,这里只处理业务逻辑
|
||||
*/
|
||||
private boolean updatePaymentStatus(UsersPayBefor paymentInfo, String orderId,
|
||||
BigDecimal wechatRefund, BigDecimal balanceRefund,
|
||||
private boolean updatePaymentStatus(UsersPayBefor paymentInfo, String orderId,
|
||||
BigDecimal wechatRefund, BigDecimal balanceRefund,
|
||||
BigDecimal shoppingGoldRefund, BigDecimal serviceGoldRefund,
|
||||
BigDecimal memberDiscountRefund, BigDecimal couponRefund) {
|
||||
try {
|
||||
|
|
@ -544,7 +544,7 @@ public class RefundUtil {
|
|||
System.out.println("服务金退款: " + serviceGoldRefund + "元");
|
||||
System.out.println("会员优惠: " + memberDiscountRefund + "元(不参与退款)");
|
||||
System.out.println("优惠券退款: " + couponRefund + "元");
|
||||
|
||||
|
||||
// 重要:金额更新已经在Controller中完成,这里不需要重复处理
|
||||
// 只需要验证数据一致性
|
||||
System.out.println("=== 验证数据一致性 ===");
|
||||
|
|
@ -556,7 +556,7 @@ public class RefundUtil {
|
|||
System.out.println(" 优惠券: " + paymentInfo.getCouponmoney() + "元");
|
||||
System.out.println(" 总金额: " + paymentInfo.getAllmoney() + "元");
|
||||
System.out.println(" 退款金额: " + paymentInfo.getReturnmoney() + "元");
|
||||
|
||||
|
||||
// 验证退款金额不能为负数
|
||||
if (paymentInfo.getWxmoney() != null && paymentInfo.getWxmoney().compareTo(BigDecimal.ZERO) < 0) {
|
||||
System.err.println("❌ 微信支付金额不能为负数: " + paymentInfo.getWxmoney());
|
||||
|
|
@ -578,23 +578,23 @@ public class RefundUtil {
|
|||
System.err.println("❌ 优惠券金额不能为负数: " + paymentInfo.getCouponmoney());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("✅ 数据一致性验证通过");
|
||||
System.out.println("✅ 支付记录状态更新完成");
|
||||
return true;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 更新支付记录状态异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 扣减预支付数据中的对应金额
|
||||
* 简化版:不进行复杂的金额扣减,因为退款金额已经在Controller中正确计算
|
||||
*/
|
||||
private void updatePaymentAmounts(UsersPayBefor record, BigDecimal wechatRefund,
|
||||
private void updatePaymentAmounts(UsersPayBefor record, BigDecimal wechatRefund,
|
||||
BigDecimal balanceRefund, BigDecimal shoppingGoldRefund,
|
||||
BigDecimal serviceGoldRefund, BigDecimal memberDiscountRefund,
|
||||
BigDecimal couponRefund) {
|
||||
|
|
@ -606,22 +606,22 @@ public class RefundUtil {
|
|||
System.out.println("服务金退款: " + serviceGoldRefund + "元");
|
||||
System.out.println("会员优惠: " + memberDiscountRefund + "元(不参与退款)");
|
||||
System.out.println("优惠券退款: " + couponRefund + "元");
|
||||
|
||||
|
||||
// 简化逻辑:不进行复杂的金额扣减
|
||||
// 因为退款金额已经在Controller中正确计算和更新了
|
||||
// 这里只记录日志,不修改数据
|
||||
|
||||
|
||||
System.out.println("ℹ️ 预支付金额保持不变(简化版)");
|
||||
System.out.println("ℹ️ 订单总金额: " + record.getAllmoney() + "元");
|
||||
System.out.println("ℹ️ 退款金额: " + record.getReturnmoney() + "元");
|
||||
System.out.println("=== 预支付金额扣减完成(简化版) ===");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 预支付金额扣减异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理退款扣除(积分、服务金、消费金等)
|
||||
*/
|
||||
|
|
@ -630,28 +630,34 @@ public class RefundUtil {
|
|||
// 这里可以添加退款时需要扣除的积分、服务金、消费金等逻辑
|
||||
// 根据实际业务需求调整
|
||||
System.out.println("✅ 退款扣除处理完成");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("⚠️ 退款扣除处理异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 记录退款流水日志
|
||||
*/
|
||||
private boolean recordRefundLog(UsersPayBefor paymentInfo, Map<String, Object> refundDetails,
|
||||
private boolean recordRefundLog(UsersPayBefor paymentInfo, Map<String, Object> refundDetails,
|
||||
String refundRemark, String orderId) {
|
||||
try {
|
||||
// 这里可以添加记录退款流水日志的逻辑
|
||||
// 根据实际业务需求调整
|
||||
System.out.println("✅ 退款流水日志记录完成");
|
||||
return true;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ 退款流水日志记录异常: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue