fix: 修复金币操作时coins为null的问题

- consumeCoins方法处理coins为null的情况
- addCoins方法处理coins为null的情况
- deductCoins方法处理coins为null的情况
This commit is contained in:
H1d3rOne committed 2026-03-10 06:02:34 +08:00
1 parent 04882156c4
commit 467895a9c0
1 file changed
+8 -5
@@ -70,7 +70,8 @@ public class UserInfoService {
}
UserInfo user = userInfoRepository.findByUserId(userId);
if (user != null) {
user.setCoins(user.getCoins() + amount);
Integer userCoins = user.getCoins() != null ? user.getCoins() : 0;
user.setCoins(userCoins + amount);
return userInfoRepository.save(user);
}
return null;
@@ -82,10 +83,11 @@ public class UserInfoService {
}
UserInfo user = userInfoRepository.findByUserId(userId);
if (user != null) {
if (user.getCoins() < amount) {
Integer userCoins = user.getCoins() != null ? user.getCoins() : 0;
if (userCoins < amount) {
throw new IllegalArgumentException("金币不足");
}
user.setCoins(user.getCoins() - amount);
user.setCoins(userCoins - amount);
return userInfoRepository.save(user);
}
return null;
@@ -135,10 +137,11 @@ public class UserInfoService {
if (user.getVipLevel() != null && user.getVipLevel() > 0) {
return user;
}
if (user.getCoins() < amount) {
Integer userCoins = user.getCoins() != null ? user.getCoins() : 0;
if (userCoins < amount) {
return null;
}
user.setCoins(user.getCoins() - amount);
user.setCoins(userCoins - amount);
userInfoRepository.save(user);
CoinConsumeRecord record = new CoinConsumeRecord();