|
|
@ -204,46 +204,37 @@ public class UserPointLogService {
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void executeDraw(DrawDTO drawDTO) {
|
|
|
|
public void executeDraw(DrawDTO drawDTO) {
|
|
|
|
|
|
|
|
|
|
|
|
String taskPointId = drawDTO.getTaskPointId();
|
|
|
|
// 调整用户积分
|
|
|
|
if (taskPointId != null) {
|
|
|
|
UserInfo userInfo = userInfoDao.findById(drawDTO.getUserId()).get();
|
|
|
|
TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
|
|
|
|
int point = userInfo.getPoint() == null ? 0 : userInfo.getPoint();
|
|
|
|
if(taskPoint == null) {
|
|
|
|
if(point < drawDTO.getScore()) {
|
|
|
|
return ;
|
|
|
|
throw new BizException(ErrorConstants.POINT_NOT_ENOUGH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
userInfo.setPoint(point - drawDTO.getScore());
|
|
|
|
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
|
|
|
|
|
|
|
|
// 调整用户积分
|
|
|
|
UserPointLog userPointLog = UserPointLog.builder()
|
|
|
|
UserInfo userInfo = userInfoDao.findById(drawDTO.getUserId()).get();
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
int point = userInfo.getPoint() == null ? 0 : userInfo.getPoint();
|
|
|
|
.type(PointEnums.TASK_POINT_TYPE_REDUCE.getCode())
|
|
|
|
if(point < taskPoint.getScore()) {
|
|
|
|
.createUser(drawDTO.getUserId())
|
|
|
|
throw new BizException(ErrorConstants.POINT_NOT_ENOUGH);
|
|
|
|
.description(LOTTERY_POINTS_TYPE)
|
|
|
|
}
|
|
|
|
.userId(drawDTO.getUserId())
|
|
|
|
userInfo.setPoint(point - taskPoint.getScore());
|
|
|
|
.score(drawDTO.getScore())
|
|
|
|
userInfoDao.save(userInfo);
|
|
|
|
.build();
|
|
|
|
|
|
|
|
userPointLogDao.save(userPointLog);
|
|
|
|
UserPointLog userPointLog = UserPointLog.builder()
|
|
|
|
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
|
|
|
|
.type(PointEnums.TASK_POINT_TYPE_REDUCE.getCode())
|
|
|
|
|
|
|
|
.createUser(drawDTO.getUserId())
|
|
|
|
|
|
|
|
.taskPointId(null)
|
|
|
|
|
|
|
|
.description(LOTTERY_POINTS_TYPE)
|
|
|
|
|
|
|
|
.userId(drawDTO.getUserId())
|
|
|
|
|
|
|
|
.score(point)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
userPointLogDao.save(userPointLog);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 确保先扣除积分,再报名成功
|
|
|
|
// 确保先扣除积分,再报名成功
|
|
|
|
// 抽奖报名成功
|
|
|
|
// 抽奖报名成功
|
|
|
|
LotteryUser lotteryUser = LotteryUser.builder()
|
|
|
|
LotteryUser lotteryUser = LotteryUser.builder()
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
.id(String.valueOf(idWorker.nextId()))
|
|
|
|
.lotteryId(drawDTO.getLotteryId())
|
|
|
|
.lotteryId(drawDTO.getLotteryId())
|
|
|
|
.regionId(drawDTO.getRegionId())
|
|
|
|
.regionId(drawDTO.getRegionId())
|
|
|
|
.userId(drawDTO.getUserId())
|
|
|
|
.userId(drawDTO.getUserId())
|
|
|
|
.createUser(drawDTO.getUserId())
|
|
|
|
.createUser(drawDTO.getUserId())
|
|
|
|
.updateUser(drawDTO.getUserId())
|
|
|
|
.updateUser(drawDTO.getUserId())
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
lotteryUserDao.save(lotteryUser);
|
|
|
|
lotteryUserDao.save(lotteryUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|