This commit is contained in:
YAS\29473
2025-12-25 11:08:11 +08:00
parent ba764eac4e
commit da6056b299

View File

@@ -1,5 +1,6 @@
package com.jsowell.pile.service.impl;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.MemberPointsInfo;
@@ -59,7 +60,7 @@ public class MemberPointsInfoServiceImpl implements MemberPointsInfoService {
@Transactional(rollbackFor = Exception.class)
public boolean addPoints(String memberId, BigDecimal points, String orderCode) {
if (StringUtils.isBlank(memberId) || points == null || points.compareTo(BigDecimal.ZERO) <= 0) {
throw new BusinessException("参数错误");
throw new BusinessException(ReturnCodeEnum.valueOf("参数错误"));
}
// 检查积分账户是否存在,不存在则初始化
@@ -76,7 +77,7 @@ public class MemberPointsInfoServiceImpl implements MemberPointsInfoService {
int updateResult = memberPointsInfoMapper.addPoints(memberId, points);
if (updateResult <= 0) {
logger.error("增加积分失败memberId: {}, points: {}", memberId, points);
throw new BusinessException("增加积分失败");
throw new BusinessException(ReturnCodeEnum.valueOf("增加积分失败"));
}
// 计算变动后积分
@@ -103,20 +104,20 @@ public class MemberPointsInfoServiceImpl implements MemberPointsInfoService {
@Transactional(rollbackFor = Exception.class)
public boolean deductPoints(String memberId, BigDecimal points, String orderCode) {
if (StringUtils.isBlank(memberId) || points == null || points.compareTo(BigDecimal.ZERO) <= 0) {
throw new BusinessException("参数错误");
throw new BusinessException(ReturnCodeEnum.valueOf("参数错误"));
}
// 检查积分余额是否充足
BigDecimal beforePoints = getPointsBalance(memberId);
if (beforePoints.compareTo(points) < 0) {
throw new BusinessException("积分余额不足");
throw new BusinessException(ReturnCodeEnum.valueOf("积分余额不足"));
}
// 原子性扣减积分
int updateResult = memberPointsInfoMapper.deductPoints(memberId, points);
if (updateResult <= 0) {
logger.error("扣减积分失败memberId: {}, points: {}", memberId, points);
throw new BusinessException("扣减积分失败");
throw new BusinessException(ReturnCodeEnum.valueOf("扣减积分失败"));
}
// 计算变动后积分