| | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | UserPointVO userPointVO = new UserPointVO(); |
| | | userPointVO.setTotalPoint(appUser.getTotalPoint()); |
| | | userPointVO.setConsumePoint(appUser.getLavePoint()); |
| | | userPointVO.setConsumePoint(appUser.getAvailablePoint()); |
| | | userPointVO.setShopPoint(appUser.getShopPoint()); |
| | | userPointVO.setSharePoint(appUser.getSharePoint()); |
| | | userPointVO.setPullNewPoint(appUser.getTotalInvitePoint()); |
| | |
| | | List<UserPoint> userPointList = list(new LambdaQueryWrapper<UserPoint>() |
| | | .between(startTime != null, UserPoint::getCreateTime, startTime, endTime) |
| | | .eq(type != null, UserPoint::getType, type) |
| | | .eq(UserPoint::getAppUserId, userId)); |
| | | .eq(UserPoint::getAppUserId, userId).orderByDesc(UserPoint::getCreateTime)); |
| | | if (CollectionUtil.isNotEmpty(userPointList)) { |
| | | return userPointList.stream().map(p -> { |
| | | UserPointDetailVO userPointDetailVO = new UserPointDetailVO(); |
| | | userPointDetailVO.setType(p.getType()); |
| | | userPointDetailVO.setVariablePoint(p.getVariablePoint()); |
| | | userPointDetailVO.setCreateTime(p.getCreateTime()); |
| | | String format = p.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | userPointDetailVO.setCreateTime(format); |
| | | return userPointDetailVO; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | |
| | | throw new ServiceException("积分设置未找到"); |
| | | } |
| | | // 可转赠积分总数 |
| | | long adjustedPoint = getAdjustedPoint(pointSetting, appUser); |
| | | long adjustedPoint = appUser.getAvailablePoint(); |
| | | |
| | | if (point.compareTo(new BigDecimal(adjustedPoint)) > 0) { |
| | | throw new ServiceException("转赠积分不足"); |
| | |
| | | appUserService.updateById(appUser); |
| | | log.info("积分转赠完成,用户ID: {}, 新积分: {}", appUserForPhoe.getId(), appUserForPhoe.getLavePoint()); |
| | | } |
| | | |
| | | /** |
| | | * 获取可转赠积分 |
| | | * @param pointSetting 积分设置 |
| | | * @param appUser 用户 |
| | | */ |
| | | private long getAdjustedPoint(PointSetting pointSetting, AppUser appUser) { |
| | | if (pointSetting == null || appUser == null) { |
| | | throw new ServiceException("pointSetting和appUser不能为空"); |
| | | } |
| | | |
| | | long transferPoint = 0; |
| | | |
| | | transferPoint += calculatePoint(pointSetting.getBuyPointGift(), appUser.getShopPoint(), pointSetting.getBuyPoint()); |
| | | transferPoint += calculatePoint(pointSetting.getSharePointGift(), appUser.getSharePoint(), pointSetting.getSharePoint()); |
| | | transferPoint += calculatePoint(pointSetting.getShopSharePointGift(), appUser.getShopSharePoint(), pointSetting.getShopSharePoint()); |
| | | transferPoint += calculatePoint(pointSetting.getShopPointGift(), appUser.getShopAchievementPoint(), pointSetting.getShopPoint()); |
| | | transferPoint += calculatePoint(pointSetting.getPersonPointGift(), appUser.getTotalPerformancePoint(), pointSetting.getPersonPoint()); |
| | | transferPoint += calculatePoint(pointSetting.getGetNewPointGift(), appUser.getTotalInvitePoint(), pointSetting.getGetNewPoint()); |
| | | transferPoint += calculatePoint(pointSetting.getGetRegisPointGift(), appUser.getTotalRegisterPoint(), pointSetting.getRegisPoint()); |
| | | transferPoint += calculatePoint(pointSetting.getWorkPointGift(), appUser.getTotalSharePoint() + appUser.getTotalSignPoint() + appUser.getTotalHourPoint(), pointSetting.getWorkPoint()); |
| | | |
| | | return transferPoint; |
| | | } |
| | | |
| | | private long calculatePoint(Integer settingValue, double userValue, double pointValue) { |
| | | if (settingValue == 1) { |
| | | try { |
| | | double result = userValue * (pointValue / 100.0); |
| | | return Math.round(result); |
| | | } catch (ArithmeticException e) { |
| | | return 0; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |