mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-19 18:45:03 +08:00
update
This commit is contained in:
@@ -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("扣减积分失败"));
|
||||
}
|
||||
|
||||
// 计算变动后积分
|
||||
|
||||
Reference in New Issue
Block a user