From e41a2c93c1d366da245ffe2ecc0c9d4457e4457d Mon Sep 17 00:00:00 2001 From: phpcjl <phpcjl@gmail.com> Date: 星期五, 13 十二月 2024 18:21:21 +0800 Subject: [PATCH] 用户积分统计 --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java | 54 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 44 insertions(+), 10 deletions(-) diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java index db675e1..c4da661 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java @@ -12,6 +12,7 @@ import com.ruoyi.account.service.UserPointService; import com.ruoyi.account.service.VipSettingService; import com.ruoyi.account.vo.UserPointDetailVO; +import com.ruoyi.account.vo.UserPointStatistics; import com.ruoyi.account.vo.UserPointVO; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.PhoneNumberValidator; @@ -51,26 +52,26 @@ private VipSettingService vipSettingService; @Resource private PointSettingService pointSettingService; + @Resource + private UserPointMapper userPointMapper; @Override public UserPointVO getUserPoint(Long userId) { AppUser appUser = appUserService.getById(userId); List<UserPoint> userPointList = this.baseMapper.findLatestUserPointByTypeForUser(userId); - Map<Integer, Integer> userBalanceMap = userPointList.stream() .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance)); VipSetting vipSetting = vipSettingService.getVipSettingByUserId(userId); - Integer lavePoint = appUser.getLavePoint(); UserPointVO userPointVO = new UserPointVO(); - userPointVO.setTotalPoint(lavePoint); -// userPointVO.setConsumePoint(lavePoint); - userPointVO.setShopPoint(userBalanceMap.get(PointChangeType.CONSUME.getCode())); - userPointVO.setSharePoint(userBalanceMap.get(PointChangeType.COMMISSION_RETURN.getCode())); + userPointVO.setTotalPoint(appUser.getTotalPoint()); + userPointVO.setConsumePoint(appUser.getLavePoint()); + userPointVO.setShopPoint(appUser.getShopPoint()); + userPointVO.setSharePoint(appUser.getSharePoint()); userPointVO.setPullNewPoint(userBalanceMap.get(PointChangeType.NEW_USER_REFERRAL.getCode())); userPointVO.setShopAchievementPoint(userBalanceMap.get(PointChangeType.STORE_PERFORMANCE.getCode())); userPointVO.setShopSharePoint(userBalanceMap.get(PointChangeType.STORE_COMMISSION_RETURN.getCode())); - userPointVO.setGiftPoint(vipSetting.getVipGiftRole()); + userPointVO.setGiftPoint(vipSetting.getVipGiftRole() == 1 && vipSetting.getId() == 1 ? 1 : 0); return userPointVO; } @@ -107,7 +108,7 @@ if (vipSetting == null) { throw new ServiceException("VIP 设置未找到"); } - if (vipSetting.getVipGiftRole() == 0) { + if (vipSetting.getId() == 0 && vipSetting.getVipGiftRole() == 0) { throw new ServiceException("转赠积分权限未开启"); } @@ -123,8 +124,9 @@ } Integer buyPointOpen = pointSetting.getBuyPointOpen(); - List<UserPoint> userPointList = list(new LambdaQueryWrapper<UserPoint>() - .eq(UserPoint::getAppUserId, userid)); + UserPoint userPoint = new UserPoint(); + userPoint.setAppUserId(userid); + List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint); Map<Integer, Integer> userBalanceMap = userPointList.stream() .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance)); @@ -157,4 +159,36 @@ private int getAdjustedPoint(Map<Integer, Integer> userBalanceMap, int pointTypeCode, boolean isOpen) { return isOpen ? 0 : Optional.ofNullable(userBalanceMap.get(pointTypeCode)).orElse(0); } + + @Override + public UserPointStatistics getStatistics(UserPoint userPoint) { + LoginUser loginUser = tokenService.getLoginUser(); + userPoint.setAppUserId(loginUser.getUserid()); + List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint); + Map<Integer, Integer> userBalanceMap = userPointList.stream() + .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance)); + + Integer consumePoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.CONSUME.getCode())).orElse(0); + Integer sharePoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.COMMISSION_RETURN.getCode())).orElse(0); + Integer pullNewPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.NEW_USER_REFERRAL.getCode())).orElse(0); + Integer registerPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.REGISTRATION.getCode())).orElse(0); + Integer workPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.WORK_PERFORMANCE.getCode())).orElse(0); + Integer shopAchievementPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.TECHNICIAN_PERFORMANCE.getCode())).orElse(0); + Integer exchangeGoodsPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.EXCHANGE_GOODS.getCode())).orElse(0); + Integer storeAchievementPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.STORE_PERFORMANCE.getCode())).orElse(0); + Integer storeCommissionPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.STORE_COMMISSION_RETURN.getCode())).orElse(0); + Integer transferPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.TRANSFER_POINTS.getCode())).orElse(0); + Integer totalPoint = consumePoint + sharePoint + pullNewPoint + registerPoint + workPoint + shopAchievementPoint + exchangeGoodsPoint + storeAchievementPoint + storeCommissionPoint + transferPoint; + + + UserPointStatistics userPointStatistics = new UserPointStatistics(); + userPointStatistics.setTotalPoint(totalPoint); + userPointStatistics.setConsumePoint(consumePoint); + userPointStatistics.setSharePoint(sharePoint); + userPointStatistics.setPullNewPoint(pullNewPoint); + userPointStatistics.setRegisterPoint(registerPoint); + userPointStatistics.setWorkPoint(workPoint); + userPointStatistics.setShopAchievementPoint(shopAchievementPoint); + return userPointStatistics; + } } -- Gitblit v1.7.1