fix登录,积分
This commit is contained in:
@@ -24,7 +24,7 @@ public interface IPointsService {
|
||||
/**
|
||||
* 扣除积分
|
||||
*/
|
||||
boolean subPoints(Long userId, Long amount, String type, String bizNo, Long operatorId, String remark);
|
||||
void subPoints(Long userId, Long amount, String type, String bizNo, Long operatorId, String remark);
|
||||
|
||||
/**
|
||||
* 获取用户积分
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface IUserService extends IService<User> {
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
String login(String username, String password);
|
||||
Long login(String username, String password);
|
||||
|
||||
/**
|
||||
* 获取当前登录用户
|
||||
|
||||
@@ -95,11 +95,9 @@ public class BetServiceImpl implements IBetService {
|
||||
BigDecimal odds = getOdds(playType);
|
||||
|
||||
// 扣减积分
|
||||
boolean success = pointsService.subPoints(userId, betAmount.longValue(),
|
||||
pointsService.subPoints(userId, betAmount.longValue(),
|
||||
IPointsService.TYPE_BET, null, null, "游戏下注");
|
||||
if (!success) {
|
||||
throw new RuntimeException("余额不足");
|
||||
}
|
||||
|
||||
|
||||
// 创建注单
|
||||
BetOrder bet = new BetOrder();
|
||||
|
||||
@@ -62,13 +62,13 @@ public class PointsServiceImpl implements IPointsService {
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean subPoints(Long userId, Long amount, String type, String bizNo, Long operatorId, String remark) {
|
||||
public void subPoints(Long userId, Long amount, String type, String bizNo, Long operatorId, String remark) {
|
||||
User user = userMapper.selectById(userId);
|
||||
if (user == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
if (user.getPoints() < amount) {
|
||||
return false;
|
||||
throw new RuntimeException("余额不足");
|
||||
}
|
||||
|
||||
Long before = user.getPoints();
|
||||
@@ -76,7 +76,7 @@ public class PointsServiceImpl implements IPointsService {
|
||||
// 原子扣除积分(SQL层保证余额充足才扣)
|
||||
int rows = userMapper.subPoints(userId, amount);
|
||||
if (rows == 0) {
|
||||
return false;
|
||||
throw new RuntimeException("积分扣除失败");
|
||||
}
|
||||
|
||||
Long after = before - amount;
|
||||
@@ -93,7 +93,6 @@ public class PointsServiceImpl implements IPointsService {
|
||||
flow.setRemark(remark);
|
||||
pointsFlowMapper.insert(flow);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,11 +61,9 @@ public class RedPacketServiceImpl implements IRedPacketService {
|
||||
}
|
||||
|
||||
// 扣积分
|
||||
boolean success = pointsService.subPoints(userId, totalAmount.longValue(),
|
||||
pointsService.subPoints(userId, totalAmount.longValue(),
|
||||
IPointsService.TYPE_RP_SEND, null, null, "发送红包");
|
||||
if (!success) {
|
||||
throw new RuntimeException("余额不足");
|
||||
}
|
||||
|
||||
|
||||
// 创建红包
|
||||
RedPacket rp = new RedPacket();
|
||||
@@ -275,7 +273,8 @@ public class RedPacketServiceImpl implements IRedPacketService {
|
||||
|
||||
try {
|
||||
List<BigDecimal> amounts = objectMapper.readValue(rp.getShareAmounts(),
|
||||
new TypeReference<List<BigDecimal>>() {});
|
||||
new TypeReference<List<BigDecimal>>() {
|
||||
});
|
||||
if (amounts.isEmpty()) {
|
||||
return calculateReceiveAmount(rp);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
* 用户登录
|
||||
*/
|
||||
@Override
|
||||
public String login(String username, String password) {
|
||||
public Long login(String username, String password) {
|
||||
User user = getByUsername(username);
|
||||
if (user == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
@@ -86,7 +86,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
if (!passwordUtil.matches(password, user.getPassword())) {
|
||||
throw new RuntimeException("密码错误");
|
||||
}
|
||||
return jwtUtil.generateToken(user.getId(), user.getUsername());
|
||||
return user.getId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user