202507251746333

This commit is contained in:
张潘 2025-08-14 22:42:52 +08:00
parent 99b958a3b7
commit bae71b2015
3 changed files with 659 additions and 403 deletions

View File

@ -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;
@ -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")) {
// Map<String, Object> refundResult = refundUtil.processUnifiedRefund(
// orderId, wechatRefund, balanceRefund, shoppingGoldRefund,
// serviceGoldRefund, memberDiscountRefund, couponRefund, refundRemark
// );
return success("退款成功");
} else {
String errorMsg = (String) refundResult.get("message");
return error(errorMsg != null ? errorMsg : "退款处理失败");
}
// 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());

View File

@ -6,6 +6,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.ruoyi.system.controller.UserMemberRechargeLogController;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.slf4j.Logger;
@ -16,6 +17,8 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.spring.SpringUtils;
import static java.math.BigDecimal.*;
/**
* 购物金服务金工具类
*
@ -34,6 +37,9 @@ public class BenefitPointsUtil {
private static final ISiteConfigService siteConfigService = SpringUtils.getBean(ISiteConfigService.class);
private static final IUserBenefitPointsService userBenefitPointsService = SpringUtils.getBean(IUserBenefitPointsService.class);
private static final IUserUseSecondaryCardService userUseSecondaryCardService = SpringUtils.getBean(IUserUseSecondaryCardService.class);
private static final IUsersPayBeforService usersPayBeforService = SpringUtils.getBean(IUsersPayBeforService.class);
private static final IUserMemnerConsumptionLogService userMemnerConsumptionLogService = SpringUtils.getBean(IUserMemnerConsumptionLogService.class);
private static final IPayMoneyLogService payMoneyLogService = SpringUtils.getBean(IPayMoneyLogService.class);
@ -148,6 +154,9 @@ public class BenefitPointsUtil {
return null;
}
/**
* 处理服务订单 - 增加购物金
*/
@ -157,7 +166,7 @@ public class BenefitPointsUtil {
// 获取服务金转换为消费金的比例
BigDecimal servicefeeRatio = getConfigValue(config, SERVICEFEE_KEY, new BigDecimal("0"));
if (servicefeeRatio.compareTo(BigDecimal.ZERO) <= 0) {
if (servicefeeRatio.compareTo(ZERO) <= 0) {
log.warn("【警告】服务金转换比例未配置或为0");
return new BenefitPointsResult(false, "服务金转换比例未配置", null);
}
@ -166,7 +175,7 @@ public class BenefitPointsUtil {
BigDecimal consumptionIncrease = money.multiply(servicefeeRatio).divide(new BigDecimal("100"));
// 更新用户消费金余额
BigDecimal beforeConsumption = user.getConsumption() != null ? user.getConsumption() : BigDecimal.ZERO;
BigDecimal beforeConsumption = user.getConsumption() != null ? user.getConsumption() : ZERO;
BigDecimal afterConsumption = beforeConsumption.add(consumptionIncrease);
user.setConsumption(afterConsumption);
@ -215,7 +224,7 @@ public class BenefitPointsUtil {
// 获取服务金转换为消费金的比例
BigDecimal servicefeeRatio = getConfigValue(config, SERVICEFEE_KEY, new BigDecimal("0"));
if (servicefeeRatio.compareTo(BigDecimal.ZERO) <= 0) {
if (servicefeeRatio.compareTo(ZERO) <= 0) {
log.warn("【警告】服务金转换比例未配置或为0");
return new BenefitPointsResult(false, "服务金转换比例未配置", null);
}
@ -224,7 +233,7 @@ public class BenefitPointsUtil {
BigDecimal consumptionIncrease = money.multiply(servicefeeRatio).divide(new BigDecimal("100"));
// 更新用户消费金余额
BigDecimal beforeConsumption = user.getConsumption() != null ? user.getConsumption() : BigDecimal.ZERO;
BigDecimal beforeConsumption = user.getConsumption() != null ? user.getConsumption() : ZERO;
BigDecimal afterConsumption = beforeConsumption.add(consumptionIncrease);
user.setConsumption(afterConsumption);
@ -273,7 +282,7 @@ public class BenefitPointsUtil {
user=usersService.selectUsersById(order.getUid());
// 获取消费金转换为服务金的比例
BigDecimal consumptionRatio = getConfigValue(config, CONSUMPTION_KEY, new BigDecimal("0"));
if (consumptionRatio.compareTo(BigDecimal.ZERO) <= 0) {
if (consumptionRatio.compareTo(ZERO) <= 0) {
log.warn("【警告】消费金转换比例未配置或为0");
return new BenefitPointsResult(false, "消费金转换比例未配置", null);
}
@ -282,7 +291,7 @@ public class BenefitPointsUtil {
BigDecimal servicefeeIncrease = money.multiply(consumptionRatio).divide(new BigDecimal("100"));
// 更新用户服务金余额
BigDecimal beforeServicefee = user.getServicefee() != null ? user.getServicefee() : BigDecimal.ZERO;
BigDecimal beforeServicefee = user.getServicefee() != null ? user.getServicefee() : ZERO;
BigDecimal afterServicefee = beforeServicefee.add(servicefeeIncrease);
user.setServicefee(afterServicefee);
@ -418,21 +427,21 @@ public class BenefitPointsUtil {
Map<String, Object> config = getSystemConfig();
if (config == null) {
log.error("【错误】系统配置获取失败");
return new BenefitDeductionResult(false, "系统配置获取失败", BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO);
return new BenefitDeductionResult(false, "系统配置获取失败", ZERO, ZERO, ZERO);
}
BigDecimal serviceMoney = BigDecimal.ZERO;
BigDecimal shopMoney = BigDecimal.ZERO;
BigDecimal serviceMoney = ZERO;
BigDecimal shopMoney = ZERO;
BigDecimal finalAmount = amount;
if (serviceType != null && serviceType == 1) {
// 服务金抵扣
BigDecimal serviceDeductionRatio = getConfigValue(config, SERVICE_DEDUCTION_KEY, new BigDecimal("0"));
if (serviceDeductionRatio.compareTo(BigDecimal.ZERO) > 0) {
if (serviceDeductionRatio.compareTo(ZERO) > 0) {
// 获取用户最新信息
Users userDb = usersService.selectUsersById(user.getId());
if (userDb != null && userDb.getServicefee() != null && userDb.getServicefee().compareTo(BigDecimal.ZERO) > 0) {
BigDecimal serviceRate = serviceDeductionRatio.divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
if (userDb != null && userDb.getServicefee() != null && userDb.getServicefee().compareTo(ZERO) > 0) {
BigDecimal serviceRate = serviceDeductionRatio.divide(new BigDecimal("100"), 4, ROUND_HALF_UP);
serviceMoney = userDb.getServicefee().multiply(serviceRate);
log.info("【服务金抵扣】用户ID: {}, 服务金余额: {}, 抵扣比例: {}, 抵扣金额: {}",
user.getId(), userDb.getServicefee(), serviceDeductionRatio, serviceMoney);
@ -441,11 +450,11 @@ public class BenefitPointsUtil {
} else if (serviceType != null && serviceType == 2) {
// 消费金抵扣
BigDecimal consumptionDeductionRatio = getConfigValue(config, CONSUMPTION_DEDUCTION_KEY, new BigDecimal("0"));
if (consumptionDeductionRatio.compareTo(BigDecimal.ZERO) > 0) {
if (consumptionDeductionRatio.compareTo(ZERO) > 0) {
// 获取用户最新信息
Users userDb = usersService.selectUsersById(user.getId());
if (userDb != null && userDb.getConsumption() != null && userDb.getConsumption().compareTo(BigDecimal.ZERO) > 0) {
BigDecimal consumptionRate = consumptionDeductionRatio.divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
if (userDb != null && userDb.getConsumption() != null && userDb.getConsumption().compareTo(ZERO) > 0) {
BigDecimal consumptionRate = consumptionDeductionRatio.divide(new BigDecimal("100"), 4, ROUND_HALF_UP);
shopMoney = userDb.getConsumption().multiply(consumptionRate);
log.info("【消费金抵扣】用户ID: {}, 消费金余额: {}, 抵扣比例: {}, 抵扣金额: {}",
user.getId(), userDb.getConsumption(), consumptionDeductionRatio, shopMoney);
@ -455,8 +464,8 @@ public class BenefitPointsUtil {
// 计算最终支付金额
finalAmount = amount.subtract(serviceMoney).subtract(shopMoney);
if (finalAmount.compareTo(BigDecimal.ZERO) < 0) {
finalAmount = BigDecimal.ZERO;
if (finalAmount.compareTo(ZERO) < 0) {
finalAmount = ZERO;
}
log.info("【抵扣计算完成】用户ID: {}, 原金额: {}, 服务金抵扣: {}, 消费金抵扣: {}, 最终金额: {}",
@ -466,7 +475,7 @@ public class BenefitPointsUtil {
} catch (Exception e) {
log.error("【错误】获取抵扣金额异常用户ID: {}, 金额: {}, 服务类型: {}", user.getId(), amount, serviceType, e);
return new BenefitDeductionResult(false, "抵扣计算异常: " + e.getMessage(), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO);
return new BenefitDeductionResult(false, "抵扣计算异常: " + e.getMessage(), ZERO, ZERO, ZERO);
}
}
@ -503,21 +512,21 @@ public class BenefitPointsUtil {
return new BenefitPointsResult(false, "系统配置获取失败", null);
}
BigDecimal increaseAmount = BigDecimal.ZERO;
BigDecimal beforeAmount = BigDecimal.ZERO;
BigDecimal afterAmount = BigDecimal.ZERO;
BigDecimal increaseAmount = ZERO;
BigDecimal beforeAmount = ZERO;
BigDecimal afterAmount = ZERO;
String remark = "";
if (type == 1) {
// 增加服务金
BigDecimal servicefeeRatio = getConfigValue(config, SERVICEFEE_KEY, new BigDecimal("0"));
if (servicefeeRatio.compareTo(BigDecimal.ZERO) <= 0) {
if (servicefeeRatio.compareTo(ZERO) <= 0) {
log.warn("【警告】服务金转换比例未配置或为0");
return new BenefitPointsResult(false, "服务金转换比例未配置", null);
}
increaseAmount = money.multiply(servicefeeRatio).divide(new BigDecimal("100"));
beforeAmount = user.getServicefee() != null ? user.getServicefee() : BigDecimal.ZERO;
beforeAmount = user.getServicefee() != null ? user.getServicefee() : ZERO;
afterAmount = beforeAmount.add(increaseAmount);
user.setServicefee(afterAmount);
remark = "增加服务金";
@ -525,13 +534,13 @@ public class BenefitPointsUtil {
} else if (type == 2) {
// 增加购物金
BigDecimal consumptionRatio = getConfigValue(config, CONSUMPTION_KEY, new BigDecimal("0"));
if (consumptionRatio.compareTo(BigDecimal.ZERO) <= 0) {
if (consumptionRatio.compareTo(ZERO) <= 0) {
log.warn("【警告】购物金转换比例未配置或为0");
return new BenefitPointsResult(false, "购物金转换比例未配置", null);
}
increaseAmount = money.multiply(consumptionRatio).divide(new BigDecimal("100"));
beforeAmount = user.getConsumption() != null ? user.getConsumption() : BigDecimal.ZERO;
beforeAmount = user.getConsumption() != null ? user.getConsumption() : ZERO;
afterAmount = beforeAmount.add(increaseAmount);
user.setConsumption(afterAmount);
remark = "增加购物金";
@ -611,27 +620,27 @@ public class BenefitPointsUtil {
return new BenefitPointsResult(false, "系统配置获取失败", null);
}
BigDecimal deductAmount = BigDecimal.ZERO;
BigDecimal beforeAmount = BigDecimal.ZERO;
BigDecimal afterAmount = BigDecimal.ZERO;
BigDecimal deductAmount = ZERO;
BigDecimal beforeAmount = ZERO;
BigDecimal afterAmount = ZERO;
String remark = "";
if (type == 1) {
// 抵扣服务金
BigDecimal serviceDeductionRatio = getConfigValue(config, SERVICE_DEDUCTION_KEY, new BigDecimal("0"));
if (serviceDeductionRatio.compareTo(BigDecimal.ZERO) <= 0) {
if (serviceDeductionRatio.compareTo(ZERO) <= 0) {
log.warn("【警告】服务金抵扣比例未配置或为0");
return new BenefitPointsResult(false, "服务金抵扣比例未配置", null);
}
beforeAmount = user.getServicefee() != null ? user.getServicefee() : BigDecimal.ZERO;
BigDecimal serviceRate = serviceDeductionRatio.divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
beforeAmount = user.getServicefee() != null ? user.getServicefee() : ZERO;
BigDecimal serviceRate = serviceDeductionRatio.divide(new BigDecimal("100"), 4, ROUND_HALF_UP);
deductAmount = beforeAmount.multiply(serviceRate);
if (deductAmount.compareTo(BigDecimal.ZERO) > 0) {
if (deductAmount.compareTo(ZERO) > 0) {
afterAmount = beforeAmount.subtract(deductAmount);
if (afterAmount.compareTo(BigDecimal.ZERO) < 0) {
afterAmount = BigDecimal.ZERO;
if (afterAmount.compareTo(ZERO) < 0) {
afterAmount = ZERO;
}
user.setServicefee(afterAmount);
remark = "抵扣服务金";
@ -640,19 +649,19 @@ public class BenefitPointsUtil {
} else if (type == 2) {
// 抵扣购物金
BigDecimal consumptionDeductionRatio = getConfigValue(config, CONSUMPTION_DEDUCTION_KEY, new BigDecimal("0"));
if (consumptionDeductionRatio.compareTo(BigDecimal.ZERO) <= 0) {
if (consumptionDeductionRatio.compareTo(ZERO) <= 0) {
log.warn("【警告】购物金抵扣比例未配置或为0");
return new BenefitPointsResult(false, "购物金抵扣比例未配置", null);
}
beforeAmount = user.getConsumption() != null ? user.getConsumption() : BigDecimal.ZERO;
BigDecimal consumptionRate = consumptionDeductionRatio.divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
beforeAmount = user.getConsumption() != null ? user.getConsumption() : ZERO;
BigDecimal consumptionRate = consumptionDeductionRatio.divide(new BigDecimal("100"), 4, ROUND_HALF_UP);
deductAmount = beforeAmount.multiply(consumptionRate);
if (deductAmount.compareTo(BigDecimal.ZERO) > 0) {
if (deductAmount.compareTo(ZERO) > 0) {
afterAmount = beforeAmount.subtract(deductAmount);
if (afterAmount.compareTo(BigDecimal.ZERO) < 0) {
afterAmount = BigDecimal.ZERO;
if (afterAmount.compareTo(ZERO) < 0) {
afterAmount = ZERO;
}
user.setConsumption(afterAmount);
remark = "抵扣购物金";
@ -664,7 +673,7 @@ public class BenefitPointsUtil {
}
// 如果没有抵扣金额直接返回成功
if (deductAmount.compareTo(BigDecimal.ZERO) <= 0) {
if (deductAmount.compareTo(ZERO) <= 0) {
log.info("【抵扣完成】用户ID: {}, 类型: {}, 无抵扣金额", user.getId(), type);
return new BenefitPointsResult(true, "无抵扣金额", null);
}
@ -747,8 +756,8 @@ public class BenefitPointsUtil {
return new BenefitPointsResult(false, "获取用户最新信息失败", null);
}
BigDecimal beforeServicefee = userDb.getServicefee() != null ? userDb.getServicefee() : BigDecimal.ZERO;
BigDecimal beforeConsumption = userDb.getConsumption() != null ? userDb.getConsumption() : BigDecimal.ZERO;
BigDecimal beforeServicefee = userDb.getServicefee() != null ? userDb.getServicefee() : ZERO;
BigDecimal beforeConsumption = userDb.getConsumption() != null ? userDb.getConsumption() : ZERO;
log.info("【扣减前余额】用户ID: {}, 服务金余额: {}, 消费金余额: {}",
user.getId(), beforeServicefee, beforeConsumption);
@ -757,7 +766,7 @@ public class BenefitPointsUtil {
BigDecimal afterConsumption = beforeConsumption;
// 服务金抵扣时扣减金额 = usedServiceAmount / (service_deduction 百分比)
if (usedServiceAmount != null && usedServiceAmount.compareTo(BigDecimal.ZERO) > 0) {
if (usedServiceAmount != null && usedServiceAmount.compareTo(ZERO) > 0) {
// 计算实际扣减金额usedServiceAmount / (service_deduction 百分比)
// 例如service_deduction=80usedServiceAmount=100则实际扣减=100/80=1.25倍
BigDecimal actualServiceDeduction = usedServiceAmount.divide(serviceDeductionRatio, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
@ -774,7 +783,7 @@ public class BenefitPointsUtil {
// 余额不足扣完所有余额
log.warn("【警告】服务金余额不足用户ID: {}, 余额: {}, 需要扣减: {}, 将扣完所有余额",
user.getId(), beforeServicefee, actualServiceDeduction);
afterServicefee = BigDecimal.ZERO;
afterServicefee = ZERO;
userDb.setServicefee(afterServicefee);
log.info("【服务金扣减完成】用户ID: {}, 扣减前: {}, 实际扣减金额: {}, 扣减后: {}",
user.getId(), beforeServicefee, beforeServicefee, afterServicefee);
@ -782,7 +791,7 @@ public class BenefitPointsUtil {
}
// 消费金抵扣时扣减金额 = usedConsumptionAmount / (consumption_deduction 百分比)
if (usedConsumptionAmount != null && usedConsumptionAmount.compareTo(BigDecimal.ZERO) > 0) {
if (usedConsumptionAmount != null && usedConsumptionAmount.compareTo(ZERO) > 0) {
// 计算实际扣减金额usedConsumptionAmount / (consumption_deduction 百分比)
// 例如consumption_deduction=80usedConsumptionAmount=100则实际扣减=100/80=1.25倍
BigDecimal actualConsumptionDeduction = usedConsumptionAmount.divide(consumptionDeductionRatio, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
@ -799,7 +808,7 @@ public class BenefitPointsUtil {
// 余额不足扣完所有余额
log.warn("【警告】消费金余额不足用户ID: {}, 余额: {}, 需要扣减: {}, 将扣完所有余额",
user.getId(), beforeConsumption, actualConsumptionDeduction);
afterConsumption = BigDecimal.ZERO;
afterConsumption = ZERO;
userDb.setConsumption(afterConsumption);
log.info("【消费金扣减完成】用户ID: {}, 扣减前: {}, 实际扣减金额: {}, 扣减后: {}",
user.getId(), beforeConsumption, beforeConsumption, afterConsumption);
@ -815,7 +824,7 @@ public class BenefitPointsUtil {
// 记录服务金扣减日志
UserBenefitPoints serviceLog = null;
if (usedServiceAmount != null && usedServiceAmount.compareTo(BigDecimal.ZERO) > 0) {
if (usedServiceAmount != null && usedServiceAmount.compareTo(ZERO) > 0) {
// 计算实际扣减金额用于日志记录
BigDecimal actualServiceDeduction = usedServiceAmount.divide(serviceDeductionRatio, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
// 如果余额不足实际扣减金额为余额
@ -842,7 +851,7 @@ public class BenefitPointsUtil {
// 记录消费金扣减日志
UserBenefitPoints consumptionLog = null;
if (usedConsumptionAmount != null && usedConsumptionAmount.compareTo(BigDecimal.ZERO) > 0) {
if (usedConsumptionAmount != null && usedConsumptionAmount.compareTo(ZERO) > 0) {
// 计算实际扣减金额用于日志记录
BigDecimal actualConsumptionDeduction = usedConsumptionAmount.divide(consumptionDeductionRatio, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
// 如果余额不足实际扣减金额为余额
@ -928,8 +937,8 @@ public class BenefitPointsUtil {
return new BenefitPointsResult(false, "获取用户最新信息失败", null);
}
BigDecimal beforeServicefee = userDb.getServicefee() != null ? userDb.getServicefee() : BigDecimal.ZERO;
BigDecimal beforeConsumption = userDb.getConsumption() != null ? userDb.getConsumption() : BigDecimal.ZERO;
BigDecimal beforeServicefee = userDb.getServicefee() != null ? userDb.getServicefee() : ZERO;
BigDecimal beforeConsumption = userDb.getConsumption() != null ? userDb.getConsumption() : ZERO;
log.info("【退回前余额】用户ID: {}, 服务金余额: {}, 消费金余额: {}",
user.getId(), beforeServicefee, beforeConsumption);
@ -938,7 +947,7 @@ public class BenefitPointsUtil {
BigDecimal afterConsumption = beforeConsumption;
// 服务金退回时退回金额 = usedServiceAmount / (service_deduction 百分比)
if (usedServiceAmount != null && usedServiceAmount.compareTo(BigDecimal.ZERO) > 0) {
if (usedServiceAmount != null && usedServiceAmount.compareTo(ZERO) > 0) {
// 计算实际退回金额usedServiceAmount / (service_deduction 百分比)
// 例如service_deduction=80usedServiceAmount=100则实际退回=100/80=1.25倍
BigDecimal actualServiceRefund = usedServiceAmount.divide(serviceDeductionRatio, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
@ -953,7 +962,7 @@ public class BenefitPointsUtil {
}
// 消费金退回时退回金额 = usedConsumptionAmount / (consumption_deduction 百分比)
if (usedConsumptionAmount != null && usedConsumptionAmount.compareTo(BigDecimal.ZERO) > 0) {
if (usedConsumptionAmount != null && usedConsumptionAmount.compareTo(ZERO) > 0) {
// 计算实际退回金额usedConsumptionAmount / (consumption_deduction 百分比)
// 例如consumption_deduction=80usedConsumptionAmount=100则实际退回=100/80=1.25倍
BigDecimal actualConsumptionRefund = usedConsumptionAmount.divide(consumptionDeductionRatio, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
@ -976,7 +985,7 @@ public class BenefitPointsUtil {
// 记录服务金退回日志
UserBenefitPoints serviceLog = null;
if (usedServiceAmount != null && usedServiceAmount.compareTo(BigDecimal.ZERO) > 0) {
if (usedServiceAmount != null && usedServiceAmount.compareTo(ZERO) > 0) {
// 计算实际退回金额用于日志记录
BigDecimal actualServiceRefund = usedServiceAmount.divide(serviceDeductionRatio, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
@ -1001,7 +1010,7 @@ public class BenefitPointsUtil {
// 记录消费金退回日志
UserBenefitPoints consumptionLog = null;
if (usedConsumptionAmount != null && usedConsumptionAmount.compareTo(BigDecimal.ZERO) > 0) {
if (usedConsumptionAmount != null && usedConsumptionAmount.compareTo(ZERO) > 0) {
// 计算实际退回金额用于日志记录
BigDecimal actualConsumptionRefund = usedConsumptionAmount.divide(consumptionDeductionRatio, 2, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
@ -1050,11 +1059,11 @@ public class BenefitPointsUtil {
Users user = usersService.selectUsersById(userId);
if (user == null) {
log.error("【错误】用户不存在用户ID: {}", userId);
return new BenefitBalanceResult(false, "用户不存在", BigDecimal.ZERO, BigDecimal.ZERO);
return new BenefitBalanceResult(false, "用户不存在", ZERO, ZERO);
}
BigDecimal servicefee = user.getServicefee() != null ? user.getServicefee() : BigDecimal.ZERO;
BigDecimal consumption = user.getConsumption() != null ? user.getConsumption() : BigDecimal.ZERO;
BigDecimal servicefee = user.getServicefee() != null ? user.getServicefee() : ZERO;
BigDecimal consumption = user.getConsumption() != null ? user.getConsumption() : ZERO;
log.info("【余额信息】用户ID: {}, 服务金: {}, 消费金: {}", userId, servicefee, consumption);
@ -1062,7 +1071,7 @@ public class BenefitPointsUtil {
} catch (Exception e) {
log.error("【错误】获取余额信息异常用户ID: {}", userId, e);
return new BenefitBalanceResult(false, "获取余额异常: " + e.getMessage(), BigDecimal.ZERO, BigDecimal.ZERO);
return new BenefitBalanceResult(false, "获取余额异常: " + e.getMessage(), ZERO, ZERO);
}
}
@ -1129,6 +1138,11 @@ public class BenefitPointsUtil {
public void setConsumption(BigDecimal consumption) { this.consumption = consumption; }
}
/**
* 处理结果类
*/
@ -1152,4 +1166,244 @@ public class BenefitPointsUtil {
public UserBenefitPoints getLog() { return log; }
public void setLog(UserBenefitPoints log) { this.log = log; }
}
//------------------------------------------------------------------------------------------------------------------------------
//服务金变更
// private IUsersPayBeforService usersPayBeforService;
public static Map<String, Object> theBenefitPointsServiceMoneyChangeResult(UsersPayBefor usersPayBefor,BigDecimal servicemoney,int type,String reamk) {
//第一步获取系统维护的服务金比例
Map<String, Object> remap=new HashMap<>();
Map<String, Object> config = getSystemConfig();
BigDecimal servicefeeRatio = getConfigValue(config, SERVICEFEE_KEY, new BigDecimal("0"));
BigDecimal amountService = servicemoney.multiply(servicefeeRatio).divide(new BigDecimal("100"));
Users user = usersService.selectUsersById(usersPayBefor.getUid());
UsersPayBefor usersPayBeforData=usersPayBeforService.selectUsersPayBeforById(usersPayBefor.getId());
if (user==null){
remap.put("code",2);
return remap;
}
//type 1增加 0减少
if(type==1){
user.setServicefee(user.getServicefee().add(amountService));
UserBenefitPoints benefitLog = new UserBenefitPoints();
benefitLog.setOrderid(usersPayBefor.getId());
benefitLog.setUid(usersPayBefor.getUid());
benefitLog.setType(1L);//类别 1服务金 2消费金
benefitLog.setOrdertype(1L); //数据类别 1收入 2支出
benefitLog.setOrdermoney(usersPayBefor.getAllmoney());
benefitLog.setMoney(amountService);
benefitLog.setBeformoney(user.getServicefee().subtract(amountService));
benefitLog.setAftremoney(user.getServicefee());
benefitLog.setReamk(reamk);
benefitLog.setDotime(new Date());
userBenefitPointsService.insertUserBenefitPoints(benefitLog);
usersService.updateUsers(user);
//增加用户服务金金就是减少预支付的服务金
usersPayBeforData.setServicemoney(usersPayBeforData.getServicemoney().subtract(servicemoney));
usersPayBeforService.updateUsersPayBefor(usersPayBeforData);
remap.put("code",1);
return remap;
}else{
user.setServicefee(user.getServicefee().subtract(amountService));
UserBenefitPoints benefitLog = new UserBenefitPoints();
benefitLog.setOrderid(usersPayBefor.getId());
benefitLog.setUid(usersPayBefor.getUid());
benefitLog.setType(1L);//类别 1服务金 2消费金
benefitLog.setOrdertype(2L); //数据类别 1收入 2支出
benefitLog.setOrdermoney(usersPayBefor.getAllmoney());
benefitLog.setMoney(amountService);
benefitLog.setBeformoney(user.getServicefee().add(amountService));
benefitLog.setAftremoney(user.getServicefee());
benefitLog.setReamk(reamk);
benefitLog.setDotime(new Date());
userBenefitPointsService.insertUserBenefitPoints(benefitLog);
usersService.updateUsers(user);
//减少用户服务金金就是增加预支付的服务金
usersPayBeforData.setServicemoney(usersPayBeforData.getServicemoney().add(servicemoney));
usersPayBeforService.updateUsersPayBefor(usersPayBeforData);
remap.put("code",1);
return remap;
}
}
//余额变动
public static Map<String, Object> theYueChangeResult(UsersPayBefor usersPayBefor,BigDecimal money,int type,String reamk) {
Map<String, Object> remap=new HashMap<>();
//余额变动
Users user = usersService.selectUsersById(usersPayBefor.getUid());
UsersPayBefor usersPayBeforData=usersPayBeforService.selectUsersPayBeforById(usersPayBefor.getId());
if(type==1){
user.setBalance(user.getBalance().add(money));
usersPayBeforData.setYemoney(usersPayBeforData.getYemoney().subtract(money));
UserMemnerConsumptionLog userMemnerConsumptionLog=new UserMemnerConsumptionLog();
userMemnerConsumptionLog.setUid(Math.toIntExact(user.getId()));
userMemnerConsumptionLog.setConsumptiontype(2);
userMemnerConsumptionLog.setConsumptiontime(new Date());
userMemnerConsumptionLog.setConsumptionmoney(money);
userMemnerConsumptionLog.setReamk(reamk);
userMemnerConsumptionLog.setBeformoney(user.getBalance().subtract(money));
userMemnerConsumptionLog.setAftermoney(user.getBalance());
userMemnerConsumptionLog.setNowmoney(user.getBalance());
userMemnerConsumptionLog.setType(1);
userMemnerConsumptionLog.setOrderid(usersPayBefor.getOrderid());
userMemnerConsumptionLogService.insertUserMemnerConsumptionLog(userMemnerConsumptionLog);
usersService.updateUsers(user);
usersPayBeforService.updateUsersPayBefor(usersPayBeforData);
remap.put("code",1);
}else{
user.setBalance(user.getBalance().subtract(money));
usersPayBeforData.setYemoney(usersPayBeforData.getYemoney().add(money));
UserMemnerConsumptionLog userMemnerConsumptionLog=new UserMemnerConsumptionLog();
userMemnerConsumptionLog.setUid(Math.toIntExact(user.getId()));
userMemnerConsumptionLog.setConsumptiontype(2);
userMemnerConsumptionLog.setConsumptiontime(new Date());
userMemnerConsumptionLog.setConsumptionmoney(money);
userMemnerConsumptionLog.setReamk(reamk);
userMemnerConsumptionLog.setBeformoney(user.getBalance().add(money));
userMemnerConsumptionLog.setAftermoney(user.getBalance());
userMemnerConsumptionLog.setNowmoney(user.getBalance());
userMemnerConsumptionLog.setType(2);
userMemnerConsumptionLog.setOrderid(usersPayBefor.getOrderid());
userMemnerConsumptionLogService.insertUserMemnerConsumptionLog(userMemnerConsumptionLog);
usersService.updateUsers(user);
usersPayBeforService.updateUsersPayBefor(usersPayBeforData);
remap.put("code",1);
}
return remap;
}
//购物金变更
public static Map<String, Object> theBenefitPointsGoodsMoneyChangeResult(UsersPayBefor usersPayBefor,BigDecimal Goodsmoney,int type,String reamk) {
//第一步获取系统维护的服务金比例
Map<String, Object> remap=new HashMap<>();
Map<String, Object> config = getSystemConfig();
BigDecimal goodsfeeRatio = getConfigValue(config, CONSUMPTION_KEY, new BigDecimal("0"));
BigDecimal amountService = Goodsmoney.multiply(goodsfeeRatio).divide(new BigDecimal("100"));
UsersPayBefor usersPayBeforData=usersPayBeforService.selectUsersPayBeforById(usersPayBefor.getId());
Users user = usersService.selectUsersById(usersPayBefor.getUid());
if (user==null){
remap.put("code",2);
return remap;
}
//type 1增加 0减少
if(type==1){
user.setConsumption(user.getConsumption().add(amountService));
UserBenefitPoints benefitLog = new UserBenefitPoints();
benefitLog.setOrderid(usersPayBefor.getId());
benefitLog.setUid(usersPayBefor.getUid());
benefitLog.setType(2L);//类别 1服务金 2消费金
benefitLog.setOrdertype(1L); //数据类别 1收入 2支出
benefitLog.setOrdermoney(usersPayBefor.getAllmoney());
benefitLog.setMoney(amountService);
benefitLog.setBeformoney(user.getConsumption().subtract(amountService));
benefitLog.setAftremoney(user.getConsumption());
benefitLog.setReamk(reamk);
benefitLog.setDotime(new Date());
userBenefitPointsService.insertUserBenefitPoints(benefitLog);
usersService.updateUsers(user);
usersPayBeforData.setShopmoney(usersPayBeforData.getShopmoney().subtract(Goodsmoney));
usersPayBeforService.updateUsersPayBefor(usersPayBeforData);
remap.put("code",1);
return remap;
}else{
user.setConsumption(user.getConsumption().subtract(amountService));
UserBenefitPoints benefitLog = new UserBenefitPoints();
benefitLog.setOrderid(usersPayBefor.getId());
benefitLog.setUid(usersPayBefor.getUid());
benefitLog.setType(2L);//类别 1服务金 2消费金
benefitLog.setOrdertype(2L); //数据类别 1收入 2支出
benefitLog.setOrdermoney(usersPayBefor.getAllmoney());
benefitLog.setMoney(amountService);
benefitLog.setBeformoney(user.getConsumption().add(amountService));
benefitLog.setAftremoney(user.getConsumption());
benefitLog.setReamk(reamk);
benefitLog.setDotime(new Date());
userBenefitPointsService.insertUserBenefitPoints(benefitLog);
usersService.updateUsers(user);
usersPayBeforData.setShopmoney(usersPayBeforData.getShopmoney().add(Goodsmoney));
usersPayBeforService.updateUsersPayBefor(usersPayBeforData);
remap.put("code",1);
return remap;
}
}
//微信支付变动
public static Map<String, Object> theWXmoneyChangeResult(UsersPayBefor usersPayBefor,BigDecimal money,int type,String reamk) {
Map<String, Object> remap=new HashMap<>();
//余额变动
Users user = usersService.selectUsersById(usersPayBefor.getUid());
UsersPayBefor usersPayBeforData=usersPayBeforService.selectUsersPayBeforById(usersPayBefor.getId());
int allmoney=usersPayBefor.getWxmoney().multiply(new BigDecimal(100)).intValue();
int tkmoney=money.multiply(new BigDecimal(100)).intValue();
WechatPayV3Util WW=new WechatPayV3Util();
// 7. 调用微信退款接口
Map<String, Object> refundResult = WW.refund(usersPayBeforData.getOrderid(),
usersPayBeforData.getOrderid(),
allmoney,
tkmoney,
"订单退款",
WechatPayUtil.PAY_FH + "/api/secondary/card/refund/notify"
);
PayMoneyLog payMoneyLog = new PayMoneyLog();
if (usersPayBefor != null) {
payMoneyLog.setOid(usersPayBefor.getId());
}
payMoneyLog.setOrderId(usersPayBefor.getOrderid());
payMoneyLog.setUid(usersPayBefor.getUid());
if (user != null) {
payMoneyLog.setUname(user.getName());
}
payMoneyLog.setPrice(money);
payMoneyLog.setMark("订单退款");
payMoneyLog.setPayTime(new Date());
payMoneyLogService.insertPayMoneyLog(payMoneyLog);
// if(type==1){
// user.setBalance(user.getBalance().add(money));
// usersPayBeforData.setYemoney(usersPayBeforData.getYemoney().subtract(money));
// UserMemnerConsumptionLog userMemnerConsumptionLog=new UserMemnerConsumptionLog();
// userMemnerConsumptionLog.setUid(Math.toIntExact(user.getId()));
// userMemnerConsumptionLog.setConsumptiontype(2);
// userMemnerConsumptionLog.setConsumptiontime(new Date());
// userMemnerConsumptionLog.setConsumptionmoney(money);
// userMemnerConsumptionLog.setReamk(reamk);
// userMemnerConsumptionLog.setBeformoney(user.getBalance().subtract(money));
// userMemnerConsumptionLog.setAftermoney(user.getBalance());
// userMemnerConsumptionLog.setNowmoney(user.getBalance());
// userMemnerConsumptionLog.setType(1);
// userMemnerConsumptionLog.setOrderid(usersPayBefor.getOrderid());
// userMemnerConsumptionLogService.insertUserMemnerConsumptionLog(userMemnerConsumptionLog);
// usersService.updateUsers(user);
// usersPayBeforService.updateUsersPayBefor(usersPayBeforData);
// remap.put("code",1);
// }else{
// user.setBalance(user.getBalance().subtract(money));
// usersPayBeforData.setYemoney(usersPayBeforData.getYemoney().add(money));
// UserMemnerConsumptionLog userMemnerConsumptionLog=new UserMemnerConsumptionLog();
// userMemnerConsumptionLog.setUid(Math.toIntExact(user.getId()));
// userMemnerConsumptionLog.setConsumptiontype(2);
// userMemnerConsumptionLog.setConsumptiontime(new Date());
// userMemnerConsumptionLog.setConsumptionmoney(money);
// userMemnerConsumptionLog.setReamk(reamk);
// userMemnerConsumptionLog.setBeformoney(user.getBalance().add(money));
// userMemnerConsumptionLog.setAftermoney(user.getBalance());
// userMemnerConsumptionLog.setNowmoney(user.getBalance());
// userMemnerConsumptionLog.setType(2);
// userMemnerConsumptionLog.setOrderid(usersPayBefor.getOrderid());
// userMemnerConsumptionLogService.insertUserMemnerConsumptionLog(userMemnerConsumptionLog);
// usersService.updateUsers(user);
// usersPayBeforService.updateUsersPayBefor(usersPayBeforData);
// remap.put("code",1);
// }
return remap;
}
}

View File

@ -654,4 +654,10 @@ public class RefundUtil {
return false;
}
}
}