diff --git a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java index 682cfd4..467f0a2 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/LotteryService.java @@ -317,6 +317,14 @@ public class LotteryService { // 返还用户积分 放到MQ队列 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() .id(String.valueOf(idWorker.nextId())) .type(PointEnums.TASK_POINT_TYPE_ADD.getCode()) @@ -324,7 +332,7 @@ public class LotteryService { .taskPointId(TaskPointIdConstants.LOTTERY_RETURNS) .description(POINTS_WILL_BE_RETURNED) .userId(lotteryUser.getUserId()) - .score(lottery.getPoint()) + .score(point) .build(); ObjectMapper objectMapper = new ObjectMapper(); diff --git a/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java b/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java index c70e757..1ba868c 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/TaskPointService.java @@ -215,8 +215,10 @@ public class TaskPointService { public TaskPoint getTaskPoint(String id) { TaskPoint taskPoint = (TaskPoint) redisTemplate.opsForValue().get(TASK_POINT + id); if(taskPoint == null) { - taskPoint = taskPointDao.findById(id).get(); - redisTemplate.opsForValue().set(TASK_POINT + id, taskPoint); + taskPoint = taskPointDao.findById(id).orElse(null); + if(taskPoint != null) { + redisTemplate.opsForValue().set(TASK_POINT + id, taskPoint); + } } return taskPoint; } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java index 1cc9fe9..5ba6ab9 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserPointLogService.java @@ -1,6 +1,7 @@ package com.luoo.user.service; import api.PageResult; +import cn.hutool.core.util.ObjectUtil; import com.fasterxml.jackson.databind.ObjectMapper; import com.luoo.user.dao.LotteryUserDao; import com.luoo.user.dao.TaskPointDao; @@ -185,12 +186,15 @@ public class UserPointLogService { if (taskPointId != null) { 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())) { @@ -201,21 +205,23 @@ public class UserPointLogService { } } - userPointLog.setScore(taskPoint.getScore()); - userPointLog.setDescription(taskPoint.getDescription()); + userPointLog.setScore(score); + userPointLog.setDescription(description); // 保存用户积分记录 userPointLogDao.save(userPointLog); log.info("用户 {} 添加积分记录 {} 成功", userPointLog.getUserId(), userPointLog.getId()); } - // 如果id不存在,按传入的增加积分,如取消抽奖返还用户积分 - - // 更新用户积分,获取用户信息并累加积分得分 // 对用户进行积分计算 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(); userInfo.setPoint(point); // 更新用户积分信息 diff --git a/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryPCVO.java b/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryPCVO.java index ac859e0..b1c1cb0 100644 --- a/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryPCVO.java +++ b/luoo_user/src/main/java/com/luoo/user/vo/point/LotteryPCVO.java @@ -91,6 +91,8 @@ public class LotteryPCVO implements Serializable { @ApiModelProperty(value = "抽奖物品价格") private BigDecimal price; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "发布时间") private LocalDateTime publishTime;