| 
					
				 | 
			
			
				@@ -3187,40 +3187,12 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         VipGroupCategory vipGroupCategory = vipGroupCategoryService.get(vipGroup.getVipGroupCategoryId().intValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Map<String, BigDecimal> result = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        BigDecimal bigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<StudentCourseInfoDto> userCourseInfos = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //是否关联活动 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        if (vipGroup.getVipGroupActivityId() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            ActivityUserMapper activityUserMapper = activityUserMapperService.findByStudentId(vipGroupId, studentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            if (activityUserMapper != null && !activityUserMapper.getReturnFee()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                if (Objects.nonNull(activityUserMapper.getVipGroupId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    VipGroup group = vipGroupDao.get(vipGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    vipGroupCategory = vipGroupCategoryService.get(group.getVipGroupCategoryId().intValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    userCourseInfos.addAll(courseScheduleDao.findUserCourseInfos(GroupType.VIP, activityUserMapper.getVipGroupId(), studentId, null)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                if (Objects.nonNull(activityUserMapper.getGiveVipGroupId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    userCourseInfos.addAll(courseScheduleDao.findUserCourseInfos(GroupType.VIP, activityUserMapper.getGiveVipGroupId(), studentId, null)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                if (Objects.nonNull(activityUserMapper.getPracticeGroupId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    vipGroupCategory = vipGroupCategoryService.get(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    userCourseInfos.addAll(courseScheduleDao.findUserCourseInfos(GroupType.PRACTICE, activityUserMapper.getPracticeGroupId(), studentId, null)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                if (Objects.nonNull(activityUserMapper.getGivePracticeGroupId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                    userCourseInfos.addAll(courseScheduleDao.findUserCourseInfos(GroupType.PRACTICE, activityUserMapper.getGivePracticeGroupId(), studentId, null)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                userCourseInfos.removeAll(Collections.singleton(null)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                userCourseInfos = courseScheduleDao.findUserCourseInfos(GroupType.VIP, vipGroupId.toString(), studentId, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            userCourseInfos = courseScheduleDao.findUserCourseInfos(GroupType.VIP, vipGroupId.toString(), studentId, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BigDecimal bigDecimal = ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<StudentCourseInfoDto> userCourseInfos  = courseScheduleDao.findUserCourseInfos(GroupType.VIP, vipGroupId.toString(), studentId, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (CollectionUtils.isEmpty(userCourseInfos) && vipGroup.getStatus().equals(VipGroupStatusEnum.APPLYING)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.findByStudentVipGroup(vipGroupId, studentId, DealStatusEnum.SUCCESS.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (Objects.isNull(studentPaymentOrder)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                bigDecimal = ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Objects.nonNull(studentPaymentOrder)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 bigDecimal = studentPaymentOrder.getActualAmount().add(studentPaymentOrder.getBalancePaymentAmount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             result.put("suplusCourseOriginalFee", bigDecimal); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3236,24 +3208,17 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             bigDecimal = allPrice.subtract(historyPrice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (bigDecimal.compareTo(ZERO) < 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                bigDecimal = ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (overNum == userCourseInfos.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (bigDecimal.compareTo(ZERO) < 0 || overNum == userCourseInfos.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 bigDecimal = ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             result.put("suplusCourseOriginalFee", allPrice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            bigDecimal = new BigDecimal(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             result.put("suplusCourseOriginalFee", bigDecimal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ClassGroup classGroup = classGroupDao.findByVipGroup(vipGroupId, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (Objects.isNull(classGroup)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new BizException("未找到对应班级"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (Objects.isNull(bigDecimal)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            bigDecimal = new BigDecimal(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         bigDecimal = sysUserCashAccountLogService.vipReturnFeeCharges(bigDecimal, vipGroupCategory == null ? 0 : vipGroupCategory.getStudentNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //		if(vipGroupCategory == null || vipGroupCategory.getStudentNum() <= 1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //            bigDecimal = bigDecimal.multiply(new BigDecimal(0.8)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_HALF_UP); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3948,10 +3913,26 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 surplusCoursesPrice = surplusCoursesPrice.multiply(discount).setScale(0, BigDecimal.ROUND_CEILING); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            sysUserCashAccountService.subtractFromCourseBalanceAndBalance(studentId, surplusCoursesPrice.setScale(0, BigDecimal.ROUND_CEILING), PlatformCashAccountDetailTypeEnum.PAY_FEE, "后台添加学员金额扣减", vipGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            sysUserCashAccountService.subtractFromCourseBalanceAndBalance(studentId, surplusCoursesPrice.setScale(0, BigDecimal.ROUND_CEILING), PlatformCashAccountDetailTypeEnum.PAY_FEE, "后台添加学员金额扣减", vipGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //获取账户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SysUserCashAccount cashAccount = sysUserCashAccountService.getLocked(studentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (cashAccount == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new BizException("用户[{}]现金账户不存在", studentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal courseBalance = cashAccount.getCourseBalance(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //获取学员排课资格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List studentIdList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentIdList.add(studentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //获取学员付费排课资格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<ActivityUserMapper> activityUserMappers = activityUserMapperService.getDao().findByStudents(studentIdList,vipGroup.getVipGroupCategoryId(),vipGroup.getSingleClassMinutes()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //获取学员赠送排课资格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<ActivityUserMapper> freeActivityUserMappers = activityUserMapperService.getDao().findByStudents1(studentIdList,vipGroup.getVipGroupCategoryId(),vipGroup.getSingleClassMinutes()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int j = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int a = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //实际支付金额,去除优惠券 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             BigDecimal divide = ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             BigDecimal firstAmount = ZERO; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3963,11 +3944,6 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (int i = 0; i < surplusCourses.size(); i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 CourseSchedule vipGroupCourseSchedule = surplusCourses.get(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                courseScheduleStudentPayment.setGroupType(GroupType.VIP); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                courseScheduleStudentPayment.setMusicGroupId(vipGroupId.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                courseScheduleStudentPayment.setClassGroupId(vipGroupCourseSchedule.getClassGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                courseScheduleStudentPayment.setCourseScheduleId(vipGroupCourseSchedule.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                courseScheduleStudentPayment.setUserId(studentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (i == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     courseScheduleStudentPayment.setExpectPrice(firstAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     courseScheduleStudentPayment.setActualPrice(firstAmount); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3975,6 +3951,19 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     courseScheduleStudentPayment.setExpectPrice(divide); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     courseScheduleStudentPayment.setActualPrice(divide); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BigDecimal actualPrice = courseScheduleStudentPayment.getActualPrice(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //按课扣除课程余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if(courseBalance.compareTo(actualPrice) >= 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    courseBalance = courseBalance.subtract(actualPrice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    //扣除排课资格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    courseScheduleStudentPayment.setActualPrice(activityUserMapperService.use(activityUserMappers,freeActivityUserMappers,j,a,vipGroup.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                courseScheduleStudentPayment.setGroupType(GroupType.VIP); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                courseScheduleStudentPayment.setMusicGroupId(vipGroupId.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                courseScheduleStudentPayment.setClassGroupId(vipGroupCourseSchedule.getClassGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                courseScheduleStudentPayment.setCourseScheduleId(vipGroupCourseSchedule.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                courseScheduleStudentPayment.setUserId(studentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (vipGroupCourseSchedule.getTeachMode().equals(TeachModeEnum.OFFLINE)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     courseScheduleStudentPayment.setOriginalPrice(vipGroup.getOfflineClassesUnitPrice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else if (vipGroupCourseSchedule.getTeachMode().equals(TeachModeEnum.ONLINE)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -3986,6 +3975,15 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 courseScheduleStudentPayments.add(courseScheduleStudentPayment); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //扣余额,如果余额不足,那么扣排课资格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(cashAccount.getCourseBalance().compareTo(courseBalance) != 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sysUserCashAccountService.appendCourseBalance(studentId, cashAccount.getCourseBalance().subtract(courseBalance).negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "vip课加学员扣除课程余额"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //更新资格 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            activityUserMappers.addAll(freeActivityUserMappers); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(!CollectionUtils.isEmpty(activityUserMappers)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                activityUserMapperService.getDao().batchUpdate(activityUserMappers); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //创建班级学生关联记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ClassGroupStudentMapper classGroupStudentMapper; 
			 |