| | |
| | | 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 |