release: 积分返还bug修复

release-2024-04-25
huangyw 1 month ago
parent fb440653d6
commit c74477f13a

@ -317,6 +317,14 @@ public class LotteryService {
// 返还用户积分 放到MQ队列 // 返还用户积分 放到MQ队列
lotteryUserDao.findByLotteryId(id).forEach(lotteryUser -> { lotteryUserDao.findByLotteryId(id).forEach(lotteryUser -> {
Integer point = lottery.getPoint();
UserInfo userInfo = userInfoDao.findById(lotteryUser.getUserId()).get();
// 永久会员
if (Objects.equals(userInfo.getVipStatus(), UserVipStatusEnum.LIFE.getCode())) {
// 向下取整
point = (int) Math.floor(point * envConfig.getPermanentMemberDiscount());
}
UserPointLog userPointLog = UserPointLog.builder() UserPointLog userPointLog = UserPointLog.builder()
.id(String.valueOf(idWorker.nextId())) .id(String.valueOf(idWorker.nextId()))
.type(PointEnums.TASK_POINT_TYPE_ADD.getCode()) .type(PointEnums.TASK_POINT_TYPE_ADD.getCode())
@ -324,7 +332,7 @@ public class LotteryService {
.taskPointId(TaskPointIdConstants.LOTTERY_RETURNS) .taskPointId(TaskPointIdConstants.LOTTERY_RETURNS)
.description(POINTS_WILL_BE_RETURNED) .description(POINTS_WILL_BE_RETURNED)
.userId(lotteryUser.getUserId()) .userId(lotteryUser.getUserId())
.score(lottery.getPoint()) .score(point)
.build(); .build();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();

@ -215,8 +215,10 @@ public class TaskPointService {
public TaskPoint getTaskPoint(String id) { public TaskPoint getTaskPoint(String id) {
TaskPoint taskPoint = (TaskPoint) redisTemplate.opsForValue().get(TASK_POINT + id); TaskPoint taskPoint = (TaskPoint) redisTemplate.opsForValue().get(TASK_POINT + id);
if(taskPoint == null) { if(taskPoint == null) {
taskPoint = taskPointDao.findById(id).get(); taskPoint = taskPointDao.findById(id).orElse(null);
redisTemplate.opsForValue().set(TASK_POINT + id, taskPoint); if(taskPoint != null) {
redisTemplate.opsForValue().set(TASK_POINT + id, taskPoint);
}
} }
return taskPoint; return taskPoint;
} }

@ -1,6 +1,7 @@
package com.luoo.user.service; package com.luoo.user.service;
import api.PageResult; import api.PageResult;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.luoo.user.dao.LotteryUserDao; import com.luoo.user.dao.LotteryUserDao;
import com.luoo.user.dao.TaskPointDao; import com.luoo.user.dao.TaskPointDao;
@ -185,12 +186,15 @@ public class UserPointLogService {
if (taskPointId != null) { if (taskPointId != null) {
TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId); TaskPoint taskPoint = taskPointService.getTaskPoint(taskPointId);
if (taskPoint == null) {
return;
}
// 如果不存在于数据库,就是后台控制的积分,如取消抽奖的返还的积分
// 积分
Integer score = taskPoint == null ? userPointLog.getScore() : taskPoint.getScore();
// 获取积分任务类型 // 获取积分任务类型
Integer type = taskPoint.getType(); Integer type = taskPoint == null ? userPointLog.getType() : taskPoint.getType();
// 描述
String description = taskPoint == null ? userPointLog.getDescription() : taskPoint.getDescription();
// 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分 // 对于新手任务,只允许完成一次,如果用户已经完成过,则直接返回,不重复添加积分
if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) { if (Objects.equals(type, PointEnums.TASK_TYPE_NEW.getCode())) {
@ -201,21 +205,23 @@ public class UserPointLogService {
} }
} }
userPointLog.setScore(taskPoint.getScore()); userPointLog.setScore(score);
userPointLog.setDescription(taskPoint.getDescription()); userPointLog.setDescription(description);
// 保存用户积分记录 // 保存用户积分记录
userPointLogDao.save(userPointLog); userPointLogDao.save(userPointLog);
log.info("用户 {} 添加积分记录 {} 成功", userPointLog.getUserId(), userPointLog.getId()); log.info("用户 {} 添加积分记录 {} 成功", userPointLog.getUserId(), userPointLog.getId());
} }
// 如果id不存在按传入的增加积分如取消抽奖返还用户积分
// 更新用户积分,获取用户信息并累加积分得分 // 更新用户积分,获取用户信息并累加积分得分
// 对用户进行积分计算 // 对用户进行积分计算
UserInfo userInfo = userInfoDao.findById(userPointLog.getUserId()).get(); UserInfo userInfo = userInfoDao.findById(userPointLog.getUserId()).get();
Integer point = userInfo.getPoint() == null ? 0 : userInfo.getPoint(); Integer point = 0;
if (ObjectUtil.equals(PointEnums.TASK_POINT_TYPE_ADD.getCode(), userPointLog.getType())) {
point += userInfo.getPoint() == null ? 0 : userInfo.getPoint();
} else {
point -= userInfo.getPoint() == null ? 0 : userInfo.getPoint();
}
point += userPointLog.getScore(); point += userPointLog.getScore();
userInfo.setPoint(point); userInfo.setPoint(point);
// 更新用户积分信息 // 更新用户积分信息

@ -91,6 +91,8 @@ public class LotteryPCVO implements Serializable {
@ApiModelProperty(value = "抽奖物品价格") @ApiModelProperty(value = "抽奖物品价格")
private BigDecimal price; private BigDecimal price;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "发布时间") @ApiModelProperty(value = "发布时间")
private LocalDateTime publishTime; private LocalDateTime publishTime;

Loading…
Cancel
Save