fix 添加积分,扣除积分
This commit is contained in:
@@ -35,10 +35,14 @@ public class PointsServiceImpl implements IPointsService {
|
||||
}
|
||||
|
||||
Long before = user.getPoints();
|
||||
Long after = before + amount;
|
||||
|
||||
user.setPoints(after);
|
||||
userMapper.updateById(user);
|
||||
// 原子增加积分
|
||||
int rows = userMapper.addPoints(userId, amount);
|
||||
if (rows == 0) {
|
||||
throw new RuntimeException("积分增加失败");
|
||||
}
|
||||
|
||||
Long after = before + amount;
|
||||
|
||||
// 记录流水
|
||||
PointsFlow flow = new PointsFlow();
|
||||
@@ -68,10 +72,14 @@ public class PointsServiceImpl implements IPointsService {
|
||||
}
|
||||
|
||||
Long before = user.getPoints();
|
||||
Long after = before - amount;
|
||||
|
||||
user.setPoints(after);
|
||||
userMapper.updateById(user);
|
||||
// 原子扣除积分(SQL层保证余额充足才扣)
|
||||
int rows = userMapper.subPoints(userId, amount);
|
||||
if (rows == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Long after = before - amount;
|
||||
|
||||
// 记录流水
|
||||
PointsFlow flow = new PointsFlow();
|
||||
|
||||
Reference in New Issue
Block a user