fix 添加积分,扣除积分

This commit is contained in:
wells
2026-08-05 18:23:02 +08:00
parent 7f96115a6a
commit e5f60b7b30
2 changed files with 28 additions and 6 deletions
@@ -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();