| | |
| | | package cc.mrbird.febs.mall.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.configure.FebsConfigure; |
| | | import cc.mrbird.febs.common.enumerates.*; |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.common.utils.MallUtils; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.service.AsyncService; |
| | |
| | | private final MallMemberCouponMapper mallMemberCouponMapper; |
| | | private final RunVipMapper runVipMapper; |
| | | private final MallMemberWalletMapper mallMemberWalletMapper; |
| | | private final RunNodeSetMapper runNodeSetMapper; |
| | | private final MallChargeMapper mallChargeMapper; |
| | | private final IMallMoneyFlowService mallMoneyFlowService; |
| | | |
| | | private final AsyncService asyncService; |
| | | private final FebsConfigure febsConfigure; |
| | | private final RunVipGrowMapper runVipGrowMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新会员等级,将所有等级过期的会员等级重置为最低等级 |
| | | * 查询 RunVip 表中按顺序号升序排列的第一条记录,获取最低会员等级。 |
| | | * 构建查询条件,查询 MallMember 表中会员等级过期且当前等级不是最低等级的用户。 |
| | | * 如果查询结果不为空,遍历每个用户,调用 updateLevel 方法将会员等级更新为最低等级。 |
| | | * 处理完所有用户后,结束方法 |
| | | */ |
| | | @Override |
| | | public void updateMemberLevel() { |
| | | mallMemberWalletMapper.updateScore(); |
| | | List<RunVip> runVips = runVipMapper.selectList(new LambdaQueryWrapper<RunVip>().orderByAsc(RunVip :: getOrderNumber)); |
| | | RunVip runVip = runVips.get(0); |
| | | |
| | | //获取过期时间小于等于当前时间,并且会员等级不是最小等级游客的所有用户 |
| | | LambdaQueryWrapper<MallMember> mallMemberLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | mallMemberLambdaQueryWrapper.le(MallMember :: getVipLevelTime,DateUtil.date()); |
| | | mallMemberLambdaQueryWrapper.ne(MallMember :: getLevel,runVip.getVipCode()); |
| | | List<MallMember> mallMembers = mallMemberMapper.selectList(mallMemberLambdaQueryWrapper); |
| | | if(CollUtil.isNotEmpty(mallMembers)){ |
| | | mallMembers.forEach( |
| | | item -> { |
| | | mallMemberMapper.updateVipLevelTimeAndLevel(item.getId(),item.getVipLevelTime(),item.getLevel()); |
| | | } |
| | | ); |
| | | // 更新会员等级的逻辑 |
| | | try { |
| | | List<RunVip> runVips = runVipMapper.selectList(new LambdaQueryWrapper<RunVip>().orderByAsc(RunVip::getOrderNumber)); |
| | | RunVip runVip = runVips.get(0); |
| | | |
| | | // 获取过期时间小于等于当前时间,并且会员等级不是最小等级游客的所有用户 |
| | | LambdaQueryWrapper<MallMember> mallMemberLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | mallMemberLambdaQueryWrapper.le(MallMember::getVipLevelTime, DateUtil.date()); |
| | | mallMemberLambdaQueryWrapper.ne(MallMember::getLevel, runVip.getVipCode()); |
| | | List<MallMember> mallMembers = mallMemberMapper.selectList(mallMemberLambdaQueryWrapper); |
| | | if (CollUtil.isNotEmpty(mallMembers)) { |
| | | mallMembers.forEach( |
| | | item -> { |
| | | try { |
| | | mallMemberMapper.updateLevel(item.getId(), runVip.getVipCode()); |
| | | } catch (Exception e) { |
| | | log.error("Error updating member level for user {}: ", item.getId(), e); |
| | | } |
| | | } |
| | | ); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("Error fetching or updating VIP levels: ", e); |
| | | } |
| | | } |
| | | |
| | |
| | | System.out.println(DateUtil.compare(DateUtil.date(),lastDateTime) > 0); |
| | | System.out.println(DateUtil.parseTime(DateUtil.date().toTimeStr())); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取全部会员 |
| | |
| | | if(DateUtil.compare(nowTime,startTime) < 0 || DateUtil.compare(nowTime,endTime) > 0){ |
| | | return; |
| | | } |
| | | int hour = DateUtil.hour(nowTime,true); |
| | | boolean flag = isDivisibleByTwo(hour); |
| | | |
| | | int C1 = Integer.parseInt(String.valueOf(DateUtil.between(startTime, endTime, DateUnit.HOUR))); |
| | | |
| | | List<RunVip> runVips = runVipMapper.selectList(null); |
| | | Map<String, RunVip> runVipMap = runVips.stream() |
| | | .collect(Collectors.toMap(RunVip::getVipCode, runVip -> runVip)); |
| | | List<MallMember> mallMembers = mallMemberMapper.selectList(null); |
| | | if(CollUtil.isNotEmpty(mallMembers)){ |
| | | /** |
| | | * 释放规则 |
| | | * 当前时间的小时 H1 / 2,整除时 |
| | | * 每个会员等级每日总释放量 T1 / 总时间间隔 C1 = 每次释放量上限 V1 |
| | | * 每次释放量上线 V1 / 2 = 每次释放量下限 V2 |
| | | * 每次释放量 V3 = 随机 [V2,V1) |
| | | * 当前时间的小时 H1 / 2,不整除时 |
| | | * 每个会员等级每日总释放量 T1 / 总时间间隔 C1 = 每次释放量下限 V1 |
| | | * 如果上一次有释放 |
| | | * 每次释放量上限 V2 = 每次释放量上限 V1 + (每次释放量上限 V1 - 上一次释放的数量 U1) |
| | | * 如果上一次没有释放 |
| | | * 每次释放量上限 V2 = 每次释放量上限 V1 * 2 |
| | | * 每次释放量 V3 = 随机 [V1,U2) |
| | | */ |
| | | int hour = DateUtil.hour(nowTime,true); |
| | | boolean flag = isDivisibleByTwo(hour); |
| | | |
| | | int C1 = Integer.parseInt(String.valueOf(DateUtil.between(startTime, endTime, DateUnit.HOUR))); |
| | | for (MallMember item : mallMembers) { |
| | | RunVip runVip = runVipMap.get(item.getLevel()); |
| | | if(ObjectUtil.isEmpty(runVip)){ |
| | | //未匹配到,直接跳过 |
| | | continue; |
| | | } |
| | | //每次释放的碳积分 |
| | | //每一个等级每日释放最大值 |
| | | BigDecimal T1 = new BigDecimal(runVip.getGrowthCnt()); |
| | | BigDecimal V1 = T1.divide(new BigDecimal(C1), 0, RoundingMode.DOWN); |
| | | BigDecimal V2 = BigDecimal.ZERO; |
| | | BigDecimal V3 = BigDecimal.ZERO; |
| | | BigDecimal V1 = T1.divide(new BigDecimal(C1), 2, BigDecimal.ROUND_DOWN); |
| | | if (flag) { |
| | | BigDecimal V2 = V1.divide(new BigDecimal("2"), 2, BigDecimal.ROUND_DOWN); |
| | | V3 = RandomUtil.randomBigDecimal(V2,V1); |
| | | V2 = V1.divide(new BigDecimal("2"), 0, RoundingMode.DOWN); |
| | | if(V1.intValue() <= V2.intValue()){ |
| | | V3 = new BigDecimal(RandomUtil.randomInt(V1.intValue(),V2.intValue()+1)).setScale(0,RoundingMode.DOWN); |
| | | }else{ |
| | | V3 = new BigDecimal(RandomUtil.randomInt(V2.intValue(),V1.intValue())).setScale(0,RoundingMode.DOWN); |
| | | } |
| | | }else{ |
| | | List<MallMoneyFlow> mallMoneyFlows = mallMoneyFlowMapper.selectList( |
| | | new LambdaQueryWrapper<MallMoneyFlow>() |
| | |
| | | .last("LIMIT 1") |
| | | ); |
| | | if(CollUtil.isNotEmpty(mallMoneyFlows)){ |
| | | V3 = V1.add(V1.subtract(mallMoneyFlows.get(0).getAmount())); |
| | | BigDecimal U1 = mallMoneyFlows.get(0).getAmount().setScale(0,RoundingMode.DOWN); |
| | | V2 = V1.add(V1.subtract(U1)).setScale(0,RoundingMode.DOWN); |
| | | }else{ |
| | | V3 = RandomUtil.randomBigDecimal(V1,V1.multiply(new BigDecimal("2"))); |
| | | V2 = V1.multiply(new BigDecimal("2")).setScale(0,RoundingMode.DOWN); |
| | | } |
| | | if(V1.intValue() < V2.intValue()){ |
| | | V3 = new BigDecimal(RandomUtil.randomInt(V1.intValue(),V2.intValue())).setScale(0,RoundingMode.DOWN); |
| | | }else if(V1.intValue() == V2.intValue()){ |
| | | V3 = new BigDecimal(RandomUtil.randomInt(V1.intValue(),V2.intValue()+1)).setScale(0,RoundingMode.DOWN); |
| | | }else{ |
| | | V3 = new BigDecimal(RandomUtil.randomInt(V2.intValue(),V1.intValue())).setScale(0,RoundingMode.DOWN); |
| | | } |
| | | } |
| | | V3 = V3.setScale(0,BigDecimal.ROUND_DOWN); |
| | | //会员权益的收益 |
| | | RunVipGrow runVipGrow = runVipGrowMapper.selectList( |
| | | new LambdaQueryWrapper<RunVipGrow>() |
| | | .eq(RunVipGrow::getMemberId, item.getId()) |
| | | .eq(RunVipGrow::getLevelNow, runVip.getVipCode()) |
| | | .orderByDesc(RunVipGrow::getId) |
| | | ).stream().findFirst().orElse(null); |
| | | if(null != runVipGrow){ |
| | | BigDecimal amountNow = runVipGrow.getAmountNow(); |
| | | RunVip runVipNext = runVips.stream().filter(vipItem -> vipItem.getOrderNumber() == runVip.getOrderNumber() + 1).findFirst().orElse(null); |
| | | if(runVipNext != null){ |
| | | |
| | | BigDecimal presentPrice = runVip.getPresentPrice(); |
| | | amountNow = amountNow.subtract(presentPrice); |
| | | |
| | | BigDecimal presentPriceNext = runVipNext.getPresentPrice(); |
| | | BigDecimal subtract = presentPriceNext.subtract(presentPrice); |
| | | |
| | | BigDecimal divide = amountNow.divide(subtract, 4, RoundingMode.DOWN); |
| | | |
| | | Integer growthCnt = runVip.getGrowthCnt(); |
| | | Integer growthCntNext = runVipNext.getGrowthCnt(); |
| | | int growthNum = growthCntNext - growthCnt; |
| | | |
| | | BigDecimal growthAmountTotal = divide.multiply(new BigDecimal(growthNum)); |
| | | BigDecimal growthAmount = growthAmountTotal.divide(new BigDecimal(C1), 0, RoundingMode.DOWN); |
| | | if(growthAmount.intValue() > 0){ |
| | | V3 = V3.add(growthAmount); |
| | | } |
| | | } |
| | | } |
| | | //更新钱包数据 |
| | | if(V3.intValue() <= 0){ |
| | | continue; |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateMemberCoin() { |
| | | try { |
| | | // 操作时间 |
| | | DateTime operationDate = DateUtil.parseDate(DateUtil.today()); |
| | | |
| | | // 获取会员等级 |
| | | List<RunVip> runVips = runVipMapper.selectList(null); |
| | | if (CollUtil.isEmpty(runVips)) { |
| | | log.error("未找到任何会员等级"); |
| | | return; |
| | | } |
| | | Map<String, RunVip> runVipMap = runVips.stream() |
| | | .collect(Collectors.toMap(RunVip::getVipCode, runVip -> runVip)); |
| | | |
| | | // 获取最低级别的会员等级 |
| | | Optional<RunVip> optionalRunVip = runVips.stream().min(Comparator.comparingInt(RunVip::getOrderNumber)); |
| | | RunVip minRunVip = optionalRunVip.orElse(null); |
| | | if (minRunVip == null) { |
| | | log.error("最低级别的会员等级未找到"); |
| | | return; |
| | | } |
| | | |
| | | // 获取全部等级不是游客的用户,返回一个set集合 |
| | | List<MallMember> mallMembers = mallMemberMapper.selectList( |
| | | new LambdaQueryWrapper<MallMember>() |
| | | .select(MallMember::getId, MallMember::getLevel, MallMember::getInviteId, MallMember::getReferrerId) |
| | | .ne(MallMember::getLevel,minRunVip.getVipCode()) |
| | | ); |
| | | if (CollUtil.isEmpty(mallMembers)) { |
| | | log.info("没有符合条件的会员"); |
| | | return; |
| | | } |
| | | |
| | | Set<Long> memberIds = mallMembers.stream() |
| | | .map(MallMember::getId) |
| | | .collect(Collectors.toSet()); |
| | | if (CollUtil.isEmpty(memberIds)) { |
| | | log.info("没有有效的会员ID"); |
| | | return; |
| | | } |
| | | |
| | | |
| | | // 构建成员ID到MallMember对象的映射 |
| | | Map<Long, MallMember> memberMap = mallMembers.stream() |
| | | .collect(Collectors.toMap(MallMember::getId, member -> member)); |
| | | // 缓存直推成员 |
| | | Map<String, Set<MallMember>> directMembersCache = mallMembers.stream() |
| | | .filter(member -> StrUtil.isNotBlank(member.getReferrerId())) |
| | | .collect(Collectors.groupingBy(MallMember::getReferrerId, Collectors.toSet())); |
| | | |
| | | |
| | | for (Long memberId : memberIds) { |
| | | MallMember mallMember = memberMap.get(memberId); |
| | | if (mallMember == null || minRunVip.getVipCode().equals(mallMember.getLevel())) { |
| | | continue; |
| | | } |
| | | |
| | | // 获取所有购买了会员等级的直推成员 |
| | | Set<MallMember> directMembers = directMembersCache.get(mallMember.getInviteId()); |
| | | if (CollUtil.isEmpty(directMembers)) { |
| | | continue; |
| | | } |
| | | |
| | | RunVip memberRunVip = runVipMap.get(mallMember.getLevel()); |
| | | if (memberRunVip == null) { |
| | | log.warn("会员等级 {} 不存在", mallMember.getLevel()); |
| | | continue; |
| | | } |
| | | for (MallMember item : directMembers) { |
| | | BigDecimal realScore = calculateDirectScore(memberRunVip, item, operationDate, runVipMap); |
| | | if(BigDecimal.ZERO.compareTo(realScore) >= 0){ |
| | | return; |
| | | } |
| | | walletService.addScore(realScore, memberId); |
| | | String orderNo = MallUtils.getOrderNum("ZLS"); |
| | | mallMoneyFlowService.runVipMoneyFlowAdd( |
| | | memberId, |
| | | item.getId(), |
| | | orderNo, |
| | | FlowTypeEnum.SCORE.getValue(), |
| | | RunVipMoneyFlowTypeEnum.DIRECT_SCORE.getValue(), |
| | | realScore, |
| | | StrUtil.format(RunVipMoneyFlowTypeEnum.DIRECT_SCORE.getDescription(), realScore), |
| | | YesOrNoEnum.YES.getValue() |
| | | ); |
| | | // CompletableFuture.runAsync(() -> { |
| | | // BigDecimal realScore = calculateDirectScore(memberRunVip, item, operationDate, runVipMap); |
| | | // if(BigDecimal.ZERO.compareTo(realScore) >= 0){ |
| | | // return; |
| | | // } |
| | | // walletService.addScore(realScore, memberId); |
| | | // String orderNo = MallUtils.getOrderNum("ZLS"); |
| | | // mallMoneyFlowService.runVipMoneyFlowAdd( |
| | | // memberId, |
| | | // item.getId(), |
| | | // orderNo, |
| | | // FlowTypeEnum.SCORE.getValue(), |
| | | // RunVipMoneyFlowTypeEnum.DIRECT_SCORE.getValue(), |
| | | // realScore, |
| | | // StrUtil.format(RunVipMoneyFlowTypeEnum.DIRECT_SCORE.getDescription(), realScore), |
| | | // YesOrNoEnum.YES.getValue() |
| | | // ); |
| | | // },febsConfigure.asyncThreadPoolTaskExecutor()); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("更新会员积分时发生异常", e); |
| | | throw new RuntimeException("更新会员积分时发生异常", e); // 根据业务需求选择是否抛出异常 |
| | | } |
| | | } |
| | | |
| | | |
| | | private BigDecimal calculateDirectScore(RunVip memberRunVip, MallMember directMember, Date operationDate, Map<String, RunVip> runVipMap) { |
| | | // 实际助力 |
| | | BigDecimal realScore = BigDecimal.ZERO; |
| | | |
| | | try { |
| | | RunVip directRunVip = runVipMap.get(directMember.getLevel()); |
| | | if (directRunVip == null) { |
| | | return realScore; |
| | | } |
| | | // 获取每一个会员的前一日碳积分总和 |
| | | LambdaQueryWrapper<MallMoneyFlow> mallMoneyFlowLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | mallMoneyFlowLambdaQueryWrapper.ge(MallMoneyFlow::getCreatedTime, DateUtil.offsetDay(operationDate, -1)); |
| | | mallMoneyFlowLambdaQueryWrapper.lt(MallMoneyFlow::getCreatedTime, operationDate); |
| | | mallMoneyFlowLambdaQueryWrapper.eq(MallMoneyFlow::getFlowType, FlowTypeEnum.SCORE.getValue()); |
| | | mallMoneyFlowLambdaQueryWrapper.eq(MallMoneyFlow::getType, RunVipMoneyFlowTypeEnum.GET_SCORE.getValue()); |
| | | mallMoneyFlowLambdaQueryWrapper.eq(MallMoneyFlow::getMemberId, directMember.getId()); |
| | | |
| | | List<MallMoneyFlow> mallMoneyFlows = mallMoneyFlowMapper.selectList(mallMoneyFlowLambdaQueryWrapper); |
| | | if (CollUtil.isEmpty(mallMoneyFlows)) { |
| | | return realScore; |
| | | } |
| | | |
| | | // 如果直推小于会员本身的会员等级,则全部助力 |
| | | if (memberRunVip.getOrderNumber() >= directRunVip.getOrderNumber()) { |
| | | BigDecimal rebatePercent = directRunVip.getRebatePercent(); |
| | | BigDecimal totalScore = mallMoneyFlows.stream() |
| | | .map(MallMoneyFlow::getAmount) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | realScore = totalScore.multiply(rebatePercent).setScale(0, RoundingMode.DOWN); |
| | | } else { |
| | | Integer growthCnt = memberRunVip.getGrowthCnt(); |
| | | if (growthCnt == null || growthCnt <= 0) { |
| | | return realScore; |
| | | } |
| | | BigDecimal rebatePercent1 = memberRunVip.getRebatePercent(); |
| | | if (rebatePercent1 == null || rebatePercent1.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return realScore; |
| | | } |
| | | realScore = new BigDecimal(growthCnt).multiply(rebatePercent1).setScale(0, RoundingMode.DOWN); |
| | | } |
| | | } catch (Exception e) { |
| | | // 记录日志并返回默认值 |
| | | log.error("Error calculating direct score", e); |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | return realScore; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public boolean isDivisibleByTwo(int number) { |
| | | return number % 2 == 0; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 更新会员钱包中的积分,将所有积分大于0的会员钱包积分清零 |
| | | * 初始化最大尝试次数 maxAttempts 和当前尝试次数 attemptCount。 |
| | | * 使用 while 循环,每次查询1000条积分大于0的会员钱包记录。 |
| | | * 如果查询结果为空,设置标志位 flag 为 false,退出循环。 |
| | | * 否则,提取记录ID并调用 updateScore 方法将积分更新为0。 |
| | | * 增加尝试次数,继续下一次循环,直到达到最大尝试次数或查询结果为空。 |
| | | */ |
| | | @Override |
| | | public void updateMemberScore() { |
| | | // 更新会员钱包积分的逻辑 |
| | | int maxAttempts = 100; // 最大尝试次数 |
| | | int attemptCount = 0; |
| | | boolean flag = true; |
| | | while (flag && attemptCount < maxAttempts) { |
| | | try { |
| | | Page<MallMemberWallet> page = new Page<>(0, 1000); |
| | | IPage<MallMemberWallet> result = mallMemberWalletMapper.selectPage( |
| | | page, |
| | | new LambdaQueryWrapper<MallMemberWallet>() |
| | | .gt(MallMemberWallet::getScore, 0) |
| | | ); |
| | | List<MallMemberWallet> mallMemberWallets = result.getRecords(); |
| | | if (CollUtil.isEmpty(mallMemberWallets)) { |
| | | flag = false; |
| | | } else { |
| | | List<Long> ids = mallMemberWallets.stream().map(MallMemberWallet::getId).collect(Collectors.toList()); |
| | | mallMemberWalletMapper.updateScore(ids); |
| | | } |
| | | attemptCount++; |
| | | } catch (Exception e) { |
| | | log.error("Error updating member level: ", e); |
| | | flag = false; // 发生异常时退出循环 |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateNodeScore() { |
| | | /** |
| | | * 获取全部的节点 |
| | | */ |
| | | List<MallMember> mallMembers = mallMemberMapper.selectList( |
| | | new LambdaQueryWrapper<MallMember>() |
| | | .eq(MallMember::getDirector, YesOrNoEnum.YES.getValue()) |
| | | ); |
| | | if(CollUtil.isEmpty(mallMembers)){ |
| | | return; |
| | | } |
| | | //获取节点设置 |
| | | List<RunNodeSet> runNodeSets = runNodeSetMapper.selectList(null); |
| | | |
| | | //获取节点设置runNodeSets中orderNumber最小的节点 |
| | | RunNodeSet minRunNodeSet = runNodeSets.stream().min(Comparator.comparingInt(RunNodeSet::getOrderNumber)).orElse(null); |
| | | if(null == minRunNodeSet){ |
| | | return; |
| | | } |
| | | |
| | | DateTime endTime = DateUtil.date(); |
| | | for (MallMember item : mallMembers) { |
| | | //获取总业绩 |
| | | BigDecimal achieve = getDirectAchieve(item.getInviteId(),item.getDirectorTime(),endTime); |
| | | //判断总业绩是否小于最小业绩 |
| | | if(minRunNodeSet.getMinAchieve().compareTo(achieve) > 0){ |
| | | item.setDirector(YesOrNoEnum.NO.getValue()); |
| | | mallMemberMapper.updateById(item); |
| | | continue; |
| | | } |
| | | BigDecimal nodePercent = getNodePercent(runNodeSets, achieve); |
| | | if(BigDecimal.ZERO.compareTo(nodePercent) >= 0){ |
| | | continue; |
| | | } |
| | | asyncService.releaseNodeCoin(achieve,nodePercent,item.getId()); |
| | | item.setDirectorTime(endTime); |
| | | mallMemberMapper.updateById(item); |
| | | } |
| | | } |
| | | |
| | | private BigDecimal getDirectAchieve(String inviteId,Date startTime,Date endTime) { |
| | | |
| | | try { |
| | | // 获取直推成员和团队成员的ID集合 |
| | | Set<Long> memberIds = getTeamMemberIds(inviteId); |
| | | |
| | | if (CollUtil.isEmpty(memberIds)) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | // 获取团队业绩(不包含本人业绩) |
| | | List<MallCharge> mallCharges = mallChargeMapper.selectList( |
| | | new LambdaQueryWrapper<MallCharge>() |
| | | .in(MallCharge::getMemberId, memberIds) |
| | | .eq(MallCharge::getState, YesOrNoEnum.YES.getValue()) |
| | | .ge(MallCharge::getCreatedTime, startTime) |
| | | .lt(MallCharge::getCreatedTime, endTime) |
| | | ); |
| | | |
| | | if (CollUtil.isEmpty(mallCharges)) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | return mallCharges.stream() |
| | | .map(MallCharge::getAmount) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } catch (Exception e) { |
| | | // 异常处理 |
| | | log.error("Error occurred while calculating direct achieve for member: {}", inviteId, e); |
| | | return BigDecimal.ZERO; |
| | | } |
| | | } |
| | | |
| | | private Set<Long> getTeamMemberIds(String inviteId) { |
| | | Set<Long> memberIds = new HashSet<>(); |
| | | // 获取直推成员 |
| | | List<MallMember> directMembers = mallMemberMapper.selectList( |
| | | new LambdaQueryWrapper<MallMember>() |
| | | .eq(MallMember::getReferrerId, inviteId) |
| | | ); |
| | | if(CollUtil.isEmpty(directMembers)){ |
| | | return memberIds; |
| | | } |
| | | memberIds.addAll(directMembers.stream().map(MallMember::getId).collect(Collectors.toSet())); |
| | | |
| | | // 获取团队成员 |
| | | List<MallMember> teamMembers = mallMemberMapper.selectList( |
| | | new LambdaQueryWrapper<MallMember>() |
| | | .in(MallMember::getReferrerId, directMembers.stream().map(MallMember::getInviteId).collect(Collectors.toSet())) |
| | | ); |
| | | |
| | | if(CollUtil.isEmpty(teamMembers)){ |
| | | return memberIds; |
| | | } |
| | | memberIds.addAll(teamMembers.stream().map(MallMember::getId).collect(Collectors.toSet())); |
| | | |
| | | return memberIds; |
| | | } |
| | | |
| | | |
| | | private BigDecimal getNodePercent(List<RunNodeSet> runNodeSets, BigDecimal directAchieve) { |
| | | BigDecimal percent = BigDecimal.ZERO; |
| | | //获取directAchieve在runNodeSets中哪一个位置 |
| | | for(RunNodeSet item : runNodeSets){ |
| | | BigDecimal minAchieve = item.getMinAchieve(); |
| | | BigDecimal maxAchieve = item.getMaxAchieve(); |
| | | BigDecimal nodePercent = new BigDecimal(item.getNodePercent()); |
| | | if(directAchieve.compareTo(minAchieve) >= 0 && directAchieve.compareTo(maxAchieve) < 0){ |
| | | percent = nodePercent; |
| | | break; |
| | | } |
| | | } |
| | | return percent; |
| | | } |
| | | } |