|  | @@ -2479,37 +2479,6 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public void updateVipGroupStudentNumAndStatus(Long vipGroupId, ClassGroup classGroup, Integer num, boolean updateVipStatus) {
 | 
	
		
			
				|  |  | -        VipGroup vipGroup = vipGroupDao.get(vipGroupId);
 | 
	
		
			
				|  |  | -        if (Objects.isNull(vipGroup)) {
 | 
	
		
			
				|  |  | -            throw new BizException("指定的vip课程不存在");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (Objects.isNull(classGroup)) {
 | 
	
		
			
				|  |  | -            throw new BizException("未找到关联班级");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (classGroup.getStudentNum() + num < 0) {
 | 
	
		
			
				|  |  | -            classGroup.setStudentNum(0);
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            classGroup.setStudentNum(classGroup.getStudentNum() + num);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        Integer studentPaymentNum = studentPaymentOrderDao.countStudentPaymentNum(vipGroupId.toString());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        if (studentPaymentNum.equals(classGroup.getExpectStudentNum()) && updateVipStatus) {
 | 
	
		
			
				|  |  | -            classGroup.setStudentNum(studentPaymentNum);
 | 
	
		
			
				|  |  | -            classGroup.setDelFlag(0);
 | 
	
		
			
				|  |  | -            classGroupDao.update(classGroup);
 | 
	
		
			
				|  |  | -            createVipGroupCourseScheInfo(vipGroupId, classGroup);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (num != 0 || updateVipStatus) {
 | 
	
		
			
				|  |  | -            int i = courseScheduleDao.countVipGroupCourses(vipGroupId.intValue(), "VIP");
 | 
	
		
			
				|  |  | -            classGroup.setTotalClassTimes(i);
 | 
	
		
			
				|  |  | -            classGroupDao.update(classGroup);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  | -    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void createVipGroupCourseScheInfo(Long vipGroupId, ClassGroup classGroup) {
 | 
	
		
			
				|  |  |          VipGroup vipGroup = vipGroupDao.get(vipGroupId);
 | 
	
		
			
				|  |  |          List<CourseSchedule> courseSchedules = JSON.parseArray(vipGroup.getCourseSchedulesJson(), CourseSchedule.class);
 | 
	
	
		
			
				|  | @@ -3673,6 +3642,36 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Map<String, BigDecimal> getStudentSurplusCourseFee1(SurplusCourseFeeDto feeDto) {
 | 
	
		
			
				|  |  | +        //获取当前课程组关联的活动
 | 
	
		
			
				|  |  | +        Set<String> ignoreGroupId = new HashSet<>();
 | 
	
		
			
				|  |  | +        Set<Integer> ignoreActivityIds = new HashSet<>();
 | 
	
		
			
				|  |  | +        this.studentSurplusCourseFeeTree(feeDto,ignoreGroupId,ignoreActivityIds);
 | 
	
		
			
				|  |  | +        //再通过活动编号获取锁关联的课程组、会员
 | 
	
		
			
				|  |  | +        //计算出需要退的金额
 | 
	
		
			
				|  |  | +        return null;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public void studentSurplusCourseFeeTree(SurplusCourseFeeDto feeDto,Set<String> ignoreGroupId,Set<Integer> ignoreActivityIds){
 | 
	
		
			
				|  |  | +        String join = StringUtils.join(ignoreGroupId, ",");
 | 
	
		
			
				|  |  | +        feeDto.setIgnoreGroupId(join);
 | 
	
		
			
				|  |  | +        //获取课程组关联的活动
 | 
	
		
			
				|  |  | +        List<SurplusCourseFeeDto> surplusCourseFeeDtos = courseScheduleStudentPaymentDao.queryActivityUserMapperId(feeDto);
 | 
	
		
			
				|  |  | +        if (!CollectionUtils.isEmpty(surplusCourseFeeDtos)){
 | 
	
		
			
				|  |  | +            ignoreActivityIds.addAll(surplusCourseFeeDtos.stream().map(e -> e.getActivityUserMapperId()).collect(Collectors.toSet()));
 | 
	
		
			
				|  |  | +            for (SurplusCourseFeeDto surplusCourseFeeDto : surplusCourseFeeDtos) {
 | 
	
		
			
				|  |  | +                surplusCourseFeeDto.setIgnoreGroupId(join);
 | 
	
		
			
				|  |  | +                //获取活动关联的课程组
 | 
	
		
			
				|  |  | +                List<SurplusCourseFeeDto> feeDtos = courseScheduleStudentPaymentDao.queryGroupIdByActivity(surplusCourseFeeDto);
 | 
	
		
			
				|  |  | +                if(!CollectionUtils.isEmpty(feeDtos)){
 | 
	
		
			
				|  |  | +                    ignoreGroupId.addAll(feeDtos.stream().map(e -> e.getGroupId()).collect(Collectors.toSet()));
 | 
	
		
			
				|  |  | +                    feeDtos.forEach(e->this.studentSurplusCourseFeeTree(e,ignoreGroupId,ignoreActivityIds));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public HttpResponseResult applyRefundAudit(Long id, StudentApplyRefundsStatus status, String remark, BigDecimal amount, boolean confirmReturnActivityGive) {
 | 
	
	
		
			
				|  | @@ -3980,68 +3979,6 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public boolean awardedMonthlyRewards() {
 | 
	
		
			
				|  |  | -        //获取上个月的时间
 | 
	
		
			
				|  |  | -        Date months = DateUtil.addMonths(new Date(), -1);
 | 
	
		
			
				|  |  | -        String firstDayOfMonth = DateUtil.format(DateUtil.getFirstDayOfMonth(months), DateUtil.ISO_EXPANDED_DATE_FORMAT);
 | 
	
		
			
				|  |  | -        String lastDayOfMonth = DateUtil.format(DateUtil.getLastDayOfMonth(months), DateUtil.ISO_EXPANDED_DATE_FORMAT);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        List<TaskRewardsRulesDto> rewardsRulesDtos = courseScheduleRewardsRulesService.queryVipGroupTeacherClassTimesByMonth(firstDayOfMonth, lastDayOfMonth);
 | 
	
		
			
				|  |  | -        if (rewardsRulesDtos != null && rewardsRulesDtos.size() > 0) {
 | 
	
		
			
				|  |  | -            List<Integer> activeIds = rewardsRulesDtos.stream().map(e -> e.getActiveId()).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -            List<CourseScheduleRewardsRules> rewardsRules = courseScheduleRewardsRulesService.findByIds(activeIds);
 | 
	
		
			
				|  |  | -            Map<Integer, List<CourseScheduleRewardsRules>> integerListMap = rewardsRules.stream().collect(Collectors.groupingBy(CourseScheduleRewardsRules::getId));
 | 
	
		
			
				|  |  | -            String currentMonth = DateUtil.format(new Date(), DateUtil.ISO_YEAR_MONTH_FORMAT);
 | 
	
		
			
				|  |  | -            rewardsRulesDtos.forEach(e -> {
 | 
	
		
			
				|  |  | -                //当前用户是否已经发放过上月奖励
 | 
	
		
			
				|  |  | -                Integer num = sysUserCashAccountDetailDao.countByTypeAndTime(currentMonth, e.getTeacherId(), e.getActiveId());
 | 
	
		
			
				|  |  | -                if (num == null || num == 0) {
 | 
	
		
			
				|  |  | -                    CourseScheduleRewardsRules rewardsRule = integerListMap.get(e.getActiveId()).get(0);
 | 
	
		
			
				|  |  | -                    List<RewardsRulesJsonDto> rulesJsonDtos = JSONObject.parseArray(rewardsRule.getRewardsRulesJson(), RewardsRulesJsonDto.class);
 | 
	
		
			
				|  |  | -                    BigDecimal money = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | -                    //STAIR 阶梯, PER 累计, TOTAL
 | 
	
		
			
				|  |  | -                    RewardsRulesJsonDto dto;
 | 
	
		
			
				|  |  | -                    int times = e.getTimes();
 | 
	
		
			
				|  |  | -                    switch (rewardsRule.getRewardMode()) {
 | 
	
		
			
				|  |  | -                        case STAIR:
 | 
	
		
			
				|  |  | -                            for (int i = 0; i < rulesJsonDtos.size(); i++) {
 | 
	
		
			
				|  |  | -                                dto = rulesJsonDtos.get(i);
 | 
	
		
			
				|  |  | -                                if (e.getTimes() >= dto.getMin()) {
 | 
	
		
			
				|  |  | -                                    //最后一个梯度
 | 
	
		
			
				|  |  | -                                    if (rulesJsonDtos.size() - 1 == i) {
 | 
	
		
			
				|  |  | -                                        money = money.add(dto.getMoney().multiply(new BigDecimal(times)));
 | 
	
		
			
				|  |  | -                                    } else if (e.getTimes() >= dto.getMax()) {
 | 
	
		
			
				|  |  | -                                        times = Math.abs(dto.getMax() - times);
 | 
	
		
			
				|  |  | -                                        money = money.add(dto.getMoney().multiply(new BigDecimal(dto.getMax() - dto.getMin() + 1)));
 | 
	
		
			
				|  |  | -                                    } else {
 | 
	
		
			
				|  |  | -                                        money = money.add(dto.getMoney().multiply(new BigDecimal(times)));
 | 
	
		
			
				|  |  | -                                    }
 | 
	
		
			
				|  |  | -                                }
 | 
	
		
			
				|  |  | -                            }
 | 
	
		
			
				|  |  | -                            break;
 | 
	
		
			
				|  |  | -                        case PER:
 | 
	
		
			
				|  |  | -                            for (int i = 0; i < rulesJsonDtos.size(); i++) {
 | 
	
		
			
				|  |  | -                                dto = rulesJsonDtos.get(i);
 | 
	
		
			
				|  |  | -                                if (e.getTimes() >= dto.getMin()) {
 | 
	
		
			
				|  |  | -                                    money = dto.getMoney().multiply(new BigDecimal(times));
 | 
	
		
			
				|  |  | -                                }
 | 
	
		
			
				|  |  | -                            }
 | 
	
		
			
				|  |  | -                            break;
 | 
	
		
			
				|  |  | -                        case TOTAL:
 | 
	
		
			
				|  |  | -                            break;
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    if (money.doubleValue() > 0) {
 | 
	
		
			
				|  |  | -                        sysUserCashAccountDetailService.addCashAccountDetail(e.getTeacherId(), money, "", SysUserCashAccountDetailService.ORGAN,
 | 
	
		
			
				|  |  | -                                PlatformCashAccountDetailTypeEnum.REWARDS, null, DealStatusEnum.SUCCESS, "分部奖励", e.getActiveId().toString());
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            });
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return true;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  |      public List<School> querySchoolByUserId(Integer userId) {
 | 
	
		
			
				|  |  |          return vipGroupDao.querySchoolByUserId(userId);
 | 
	
		
			
				|  |  |      }
 |