Procházet zdrojové kódy

活动排课,资格管理

zouxuan před 2 roky
rodič
revize
a71ca8a98e

+ 44 - 33
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ActivityUserMapperServiceImpl.java

@@ -89,6 +89,12 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 	private TeacherService teacherService;
 	@Autowired
 	private PracticeGroupSellPriceDao practiceGroupSellPriceDao;
+	@Autowired
+	private ImGroupService imGroupService;
+	@Autowired
+	private ImGroupMemberService imGroupMemberService;
+	@Autowired
+	private ImUserFriendService imUserFriendService;
 
 	@Override
 	public BaseDAO<Integer, ActivityUserMapper> getDAO() {
@@ -654,14 +660,14 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 			courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
 			studentDao.updateStudentServiceTag(null, studentIdList, YesOrNoEnum.YES.getCode());
 		}
-//		try {
-//			imGroupService.create(classGroup.getId().toString(), null, classGroup.getName(), classGroup.getName(),
-//					applyBaseInfo.getName(), null, null, GroupType.VIP.getCode(), ImGroup.GroupTypeEnum.VIP);
-//			imGroupMemberService.join(classGroup.getId().toString(), userRoleMap);
-//			imUserFriendService.refreshGroupImUserFriend(classGroup.getMusicGroupId(), classGroup.getGroupType());
-//		} catch (Exception e) {
-//			e.printStackTrace();
-//		}
+		try {
+			imGroupService.create(classGroup.getId().toString(), null, classGroup.getName(), classGroup.getName(),
+					applyBaseInfo.getName(), null, null, GroupType.VIP.getCode(), ImGroup.GroupTypeEnum.VIP);
+			imGroupMemberService.join(classGroup.getId().toString(), userRoleMap);
+			imUserFriendService.refreshGroupImUserFriend(classGroup.getMusicGroupId(), classGroup.getGroupType());
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
 		return BaseController.succeed(applyBaseInfo.getAuditStatus().getCode());
     }
 
@@ -803,18 +809,7 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 	}
 
 	private void modifyGroupId(ActivityUserMapper activityUserMapper,Long groupId){
-		if(activityUserMapper.getVipFlag() != 0 || activityUserMapper.getGiveVipFlag() != 0){
-			if(StringUtils.isEmpty(activityUserMapper.getVipGroupId())){
-				activityUserMapper.setVipGroupId(groupId.toString());
-			}else {
-				String[] split = activityUserMapper.getVipGroupId().split(",");
-				List<String> idList = Arrays.stream(split).collect(Collectors.toList());
-				if(!idList.contains(groupId.toString())){
-					activityUserMapper.setVipGroupId(activityUserMapper.getVipGroupId()+","+groupId);
-				}
-			}
-			activityUserMapper.setVipFlag(2);
-		}else {
+		if(activityUserMapper.getCategoryId() == null){
 			if(StringUtils.isEmpty(activityUserMapper.getPracticeGroupId())){
 				activityUserMapper.setPracticeGroupId(groupId.toString());
 			}else {
@@ -826,21 +821,21 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 			}
 			//虽然还有剩余价值,但是这里处理为已排课,不再考虑退费问题
 			activityUserMapper.setPracticeFlag(2);
-		}
-	}
-	private void modifyGiveGroupId(ActivityUserMapper activityUserMapper,Long groupId){
-		if(activityUserMapper.getVipFlag() != 0 || activityUserMapper.getGiveVipFlag() != 0){
-			if(StringUtils.isEmpty(activityUserMapper.getGiveVipGroupId())){
-				activityUserMapper.setGiveVipGroupId(groupId.toString());
+		}else {
+			if(StringUtils.isEmpty(activityUserMapper.getVipGroupId())){
+				activityUserMapper.setVipGroupId(groupId.toString());
 			}else {
-				String[] split = activityUserMapper.getGiveVipGroupId().split(",");
+				String[] split = activityUserMapper.getVipGroupId().split(",");
 				List<String> idList = Arrays.stream(split).collect(Collectors.toList());
 				if(!idList.contains(groupId.toString())){
-					activityUserMapper.setGiveVipGroupId(activityUserMapper.getGiveVipGroupId()+","+groupId);
+					activityUserMapper.setVipGroupId(activityUserMapper.getVipGroupId()+","+groupId);
 				}
 			}
-			activityUserMapper.setGiveVipFlag(2);
-		}else {
+			activityUserMapper.setVipFlag(2);
+		}
+	}
+	private void modifyGiveGroupId(ActivityUserMapper activityUserMapper,Long groupId){
+		if(activityUserMapper.getGiveCategoryId() == null){
 			if(StringUtils.isEmpty(activityUserMapper.getGivePracticeGroupId())){
 				activityUserMapper.setGivePracticeGroupId(groupId.toString());
 			}else {
@@ -852,6 +847,17 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 			}
 			//虽然还有剩余价值,但是这里处理为已排课,不再考虑退费问题
 			activityUserMapper.setGivePracticeFlag(2);
+		}else {
+			if(StringUtils.isEmpty(activityUserMapper.getGiveVipGroupId())){
+				activityUserMapper.setGiveVipGroupId(groupId.toString());
+			}else {
+				String[] split = activityUserMapper.getGiveVipGroupId().split(",");
+				List<String> idList = Arrays.stream(split).collect(Collectors.toList());
+				if(!idList.contains(groupId.toString())){
+					activityUserMapper.setGiveVipGroupId(activityUserMapper.getGiveVipGroupId()+","+groupId);
+				}
+			}
+			activityUserMapper.setGiveVipFlag(2);
 		}
 	}
 
@@ -1047,7 +1053,14 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 		activityUserMapper.setSingleCourseTime(singleClassMinutes);
 		activityUserMapper.setTotalCourseNum(studentPayments.size());
 		activityUserMapper.setSubCourseNum(studentPayments.size());
-		activityUserMapper.setVipFlag(1);
+		if(Objects.nonNull(categoryId)){
+			activityUserMapper.setVipFlag(1);
+			activityUserMapper.setCategoryId(categoryId);
+			activityUserMapper.setAddMemo("学员休学转化排课资格");
+		}else {
+			activityUserMapper.setPracticeFlag(1);
+			activityUserMapper.setAddMemo("网管课关闭转化排课资格");
+		}
 		BigDecimal reduce = studentPayments.stream().map(e -> e.getActualPrice()).reduce(ZERO, BigDecimal::add);
 		activityUserMapper.setActualPrice(reduce);
 		activityUserMapper.setSubNoCoursePrice(reduce);
@@ -1055,8 +1068,6 @@ public class ActivityUserMapperServiceImpl extends BaseServiceImpl<Integer, Acti
 		activityUserMapper.setTenantId(student.getTenantId());
 		activityUserMapper.setTeacherId(student.getTeacherId());
 		activityUserMapper.setUserId(studentId);
-		activityUserMapper.setAddMemo("学员休学转化排课资格");
-		activityUserMapper.setCategoryId(categoryId);
 		activityUserMapperDao.insert(activityUserMapper);
 	}
 

+ 8 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GroupClassServiceImpl.java

@@ -47,8 +47,6 @@ public class GroupClassServiceImpl implements GroupClassService {
     @Autowired
     private CourseScheduleDao courseScheduleDao;
     @Autowired
-    private CourseScheduleService courseScheduleService;
-    @Autowired
     private CourseScheduleTeacherSalaryDao courseScheduleTeacherSalaryDao;
     @Autowired
     private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
@@ -67,22 +65,10 @@ public class GroupClassServiceImpl implements GroupClassService {
     @Autowired
     private SysTenantAccountService sysTenantAccountService;
     @Autowired
-    private ActivityUserMapperDao activityUserMapperDao;
-    @Autowired
-    private CloudTeacherOrderDao cloudTeacherOrderDao;
-    @Autowired
-    private VipGroupActivityDao vipGroupActivityDao;
+    private ActivityUserMapperService activityUserMapperService;
     @Autowired
     private StudentDao studentDao;
     @Autowired
-    private VipGroupDao vipGroupDao;
-    @Autowired
-    private VipGroupCategoryDao vipGroupCategoryDao;
-    @Autowired
-    private VipGroupService vipGroupService;
-    @Autowired
-    private ImGroupMemberService imGroupMemberService;
-    @Autowired
     private PracticeGroupService practiceGroupService;
 
     private final static Logger LOGGER = LoggerFactory.getLogger(GroupClassServiceImpl.class);
@@ -190,6 +176,13 @@ public class GroupClassServiceImpl implements GroupClassService {
                 sysUserCashAccountLog.setComment("后台关闭网管课");
                 sysUserCashAccountLogDao.insert(sysUserCashAccountLog);
             }
+            ClassGroup classGroup = classGroupDao.findByMusicGroupAndType(groupId.toString(),"PRACTICE");
+            if(Objects.nonNull(classGroup)){
+                List<CourseScheduleStudentPayment> payments = courseScheduleStudentPaymentDao.findNotStartCourseStudentPaymentsWithClassGroupAndStudent(classGroup.getId(), practiceGroup.getStudentId());
+                if(!CollectionUtils.isEmpty(payments)){
+                    activityUserMapperService.subCourseConvert(payments,practiceGroup.getStudentId(),practiceGroup.getSingleClassMinutes(),null);
+                }
+            }
             cleanGroupInfo(groupId.toString(), GroupType.PRACTICE);
             practiceGroup.setMemo("后台关闭网管课");
             practiceGroup.setGroupStatus(GroupStatusEnum.CANCEL);

+ 43 - 45
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

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