Browse Source

活动排课

zouxuan 3 years ago
parent
commit
c331960b02

+ 0 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleStudentPaymentService.java

@@ -20,9 +20,6 @@ public interface CourseScheduleStudentPaymentService extends BaseService<Long, C
 	 */
 	int createCourseScheduleStudentPaymentForVipGroup(Long vipGroupId, Integer userId);
 
-	int createCourseScheduleStudentPaymentForPracticeGroup(Long practiceGroupId, Integer userId);
-
-
 	/**
 	 * 删除学生对应的课程
 	 * @param userId

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ContractServiceImpl.java

@@ -779,6 +779,7 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 	}
 
 	@Override
+	@Async
 	public boolean transferPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
 		if(true){
 			 transferProduceContract(userId, null, null);

+ 0 - 74
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java

@@ -158,80 +158,6 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 		return courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
 	}
 
-	@Override
-	public int createCourseScheduleStudentPaymentForPracticeGroup(Long vipGroupId, Integer userId) {
-		VipGroup vipGroup = vipGroupDao.get(vipGroupId);
-
-		if(Objects.isNull(vipGroup)){
-			throw new BizException("未找到相关vip课程");
-		}
-
-		VipGroupDefaultClassesUnitPrice vipGroupDefaultClassesUnitPrice = vipGroupDefaultClassesUnitPriceDao.getByVipGroup(vipGroupId);
-		if(Objects.isNull(vipGroupDefaultClassesUnitPrice)){
-			throw new BizException("课程单价设置错误");
-		}
-
-		//获取活动信息
-		VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupActivityId());
-
-		List<CourseSchedule> vipGroupCourseSchedules=courseScheduleDao.findGroupCourseSchedules(vipGroupId.toString(),GroupType.VIP.getCode());
-
-		if(CollectionUtils.isEmpty(vipGroupCourseSchedules)){
-			throw new BizException("未获取到排课信息");
-		}
-
-		int giveClassTimes=0;
-//        if(vipGroup.getStatus().equals(VipGroupStatusEnum.APPLYING)
-//                &&Objects.nonNull(vipGroupActivity)
-//                &&vipGroupActivity.getType().equals(VipGroupActivityTypeEnum.GIVE_CLASS)
-//                &&vipGroupCourseSchedules.size() >= Integer.parseInt(vipGroupActivity.getAttribute1())){
-//            giveClassTimes = Integer.parseInt(vipGroupActivity.getAttribute2());
-//        }
-
-		StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDaop.findByStudentVipGroup(vipGroupId, userId, DealStatusEnum.SUCCESS.getCode());
-		BigDecimal couponFee = new BigDecimal(0);
-		if(Objects.nonNull(studentPaymentOrder)){
-			couponFee = studentPaymentOrder.getCouponRemitFee().divide(new BigDecimal(vipGroupCourseSchedules.size()-giveClassTimes), CommonConstants.DECIMAL_PLACE);
-		}
-
-		List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
-		Map<TeachModeEnum, List<CourseSchedule>> courseScheduleGroupByTeachMode = vipGroupCourseSchedules.stream().collect(Collectors.groupingBy(CourseSchedule::getTeachMode));
-		for(TeachModeEnum teachModeEnum:courseScheduleGroupByTeachMode.keySet()){
-			List<CourseSchedule> courseSchedules = courseScheduleGroupByTeachMode.get(teachModeEnum)
-					.stream()
-					.sorted(Comparator.comparing(CourseSchedule::getStartClassTime)).collect(Collectors.toList());
-			for(int i=0;i<courseSchedules.size();i++) {
-				//创建学生课程应缴费记录
-				CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
-				courseScheduleStudentPayment.setUserId(userId);
-	            courseScheduleStudentPayment.setGroupType(courseSchedules.get(i).getGroupType());
-	            courseScheduleStudentPayment.setMusicGroupId(courseSchedules.get(i).getMusicGroupId());
-				courseScheduleStudentPayment.setCourseScheduleId(courseSchedules.get(i).getId());
-				courseScheduleStudentPayment.setClassGroupId(courseSchedules.get(i).getClassGroupId());
-
-				if (teachModeEnum == TeachModeEnum.ONLINE) {
-					//学生线上单节课应缴费计算
-					courseScheduleStudentPayment.setExpectPrice(
-							vipGroup.getOnlineClassesUnitPrice().multiply(vipGroupActivity.getDiscount())
-									.divide(new BigDecimal(100), CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_HALF_UP)
-									.subtract(couponFee)
-					);
-				}else{
-					//学生线下单节课应缴费计算
-					courseScheduleStudentPayment.setExpectPrice(
-							vipGroup.getOfflineClassesUnitPrice().multiply(vipGroupActivity.getDiscount())
-									.divide(new BigDecimal(100), CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_HALF_UP)
-									.subtract(couponFee)
-					);
-				}
-                courseScheduleStudentPayment.setOriginalPrice(TeachModeEnum.ONLINE.equals(teachModeEnum)?vipGroupDefaultClassesUnitPrice.getOnlineClassesUnitPrice():vipGroupDefaultClassesUnitPrice.getOfflineClassesUnitPrice());
-				courseScheduleStudentPayment.setActualPrice(courseScheduleStudentPayment.getExpectPrice());
-				courseScheduleStudentPayments.add(courseScheduleStudentPayment);
-			}
-		}
-		return courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
-	}
-
     @Override
     public int deleteStudentCourseSchedule(Integer userId, List<CourseSchedule> courseScheduleList) {
 		if(courseScheduleList.size() == 0){

+ 35 - 63
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PracticeGroupServiceImpl.java

@@ -47,6 +47,7 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import static com.ym.mec.biz.dal.enums.SignInStatusEnum.*;
+import static java.math.BigDecimal.ROUND_DOWN;
 
 @Service
 public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGroup> implements PracticeGroupService {
@@ -3064,11 +3065,11 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         if(teacherDefaultSalary == null){
         	throw new BizException("请设置教师课酬");
         }
-        BigDecimal studentSingleCourseCost = amount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
+        BigDecimal studentSingleCourseCost = amount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
 
         BigDecimal oneMonthOriginalPrice=practiceGroupBuyParams.getDrillTimesOnWeek()==1?practiceGroupSellPrice.getOnceOriginalPrice():practiceGroupSellPrice.getTwiceOriginalPrice();
         BigDecimal originalAmount = oneMonthOriginalPrice.multiply(new BigDecimal(practiceGroupBuyParams.getBuyMonths()));
-        BigDecimal studentSingleCourseOriginalCost=originalAmount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
+        BigDecimal studentSingleCourseOriginalCost=originalAmount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
 
         for (CourseSchedule courseSchedule : practiceCourses) {
             //课程与老师薪水表
@@ -3512,11 +3513,11 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         if(teacherDefaultSalary == null){
             throw new BizException("请设置教师课酬");
         }
-        BigDecimal studentSingleCourseCost = amount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
+        BigDecimal studentSingleCourseCost = amount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
 
         BigDecimal oneMonthOriginalPrice=practiceGroupBuyParams.getDrillTimesOnWeek()==1?practiceGroupSellPrice.getOnceOriginalPrice():practiceGroupSellPrice.getTwiceOriginalPrice();
         BigDecimal originalAmount = oneMonthOriginalPrice.multiply(new BigDecimal(practiceGroupBuyParams.getBuyMonths()));
-        BigDecimal studentSingleCourseOriginalCost=originalAmount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
+        BigDecimal studentSingleCourseOriginalCost=originalAmount.divide(new BigDecimal(practiceCourses.size()), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
 
         for (CourseSchedule courseSchedule : practiceCourses) {
             //课程与老师薪水表
@@ -3711,9 +3712,10 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
                     practiceGroup.getId(),order.getActivityBuyNum());
             practiceGroup.setActivityUserMapperId(activityUserMapperId);
             if(classGroup.getDelFlag() == 1){
-                updatePracticeGroupStudentNumAndStatus(practiceGroup, classGroup);
+                updatePracticeGroupStudentNumAndStatus(practiceGroup, classGroup,order);
+            }else {
+                courseScheduleDao.updateGroupCourseLock(order.getMusicGroupId(), GroupType.PRACTICE, 0);
             }
-            courseScheduleDao.updateGroupCourseLock(order.getMusicGroupId(), GroupType.PRACTICE, 0);
         } else {
             if (Objects.nonNull(order.getBalancePaymentAmount()) && order.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
                 sysUserCashAccountService.updateBalance(order.getUserId(), order.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "网管课支付失败,退还余额");
@@ -3785,7 +3787,6 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         } catch (Exception e) {
             LOGGER.error(MessageFormatter.arrayFormat("网管课[{}]购买协议错误:{}", order.getMusicGroupId(), e.getMessage()), e);
         }
-
         try {
             teacherCourseRewardService.addConvertReward(practiceGroup.getStudentId(), practiceGroup.getUserId());
         } catch (Exception e) {
@@ -3851,7 +3852,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         imUserFriendService.refreshGroupImUserFriend(practiceGroup.getId().toString(),GroupType.PRACTICE);
     }
 
-    private void updatePracticeGroupStudentNumAndStatus(PracticeGroup practiceGroup, ClassGroup classGroup) {
+    private void updatePracticeGroupStudentNumAndStatus(PracticeGroup practiceGroup, ClassGroup classGroup,StudentPaymentOrder order) {
         classGroup.setStudentNum(1);
         classGroup.setDelFlag(0);
         classGroupDao.update(classGroup);
@@ -3861,6 +3862,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         if(courseNum == 0){
             courseScheduleService.batchAddCourseSchedule(courseSchedules);
         }
+
         ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
         classGroupStudentMapper.setClassGroupId(classGroup.getId());
         classGroupStudentMapper.setGroupType(GroupType.PRACTICE);
@@ -3868,77 +3870,47 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         classGroupStudentMapper.setMusicGroupId(practiceGroup.getId().toString());
         classGroupStudentMapper.setUserId(practiceGroup.getStudentId());
         classGroupStudentMapperDao.insert(classGroupStudentMapper);
+
+        List<TeacherAttendance> teacherAttendances = new ArrayList<>();
         List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
-        courseSchedules.forEach(e->{
-            CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
-            courseScheduleStudentPayment.setGroupType(GroupType.PRACTICE);
-            courseScheduleStudentPayment.setMusicGroupId(practiceGroup.getId().toString());
-            courseScheduleStudentPayment.setCourseScheduleId(e.getId());
-            courseScheduleStudentPayment.setUserId(practiceGroup.getStudentId());
-            courseScheduleStudentPayment.setExpectPrice(BigDecimal.ZERO);
-            courseScheduleStudentPayment.setActualPrice(BigDecimal.ZERO);
-            courseScheduleStudentPayment.setOriginalPrice(BigDecimal.ZERO);
-            courseScheduleStudentPayment.setClassGroupId(classGroup.getId());
-            courseScheduleStudentPayments.add(courseScheduleStudentPayment);
-        });
-        for (CourseSchedule courseSchedule : courseSchedules) {
-            //课程与老师薪水表
-            CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
-            courseScheduleTeacherSalary.setCourseScheduleId(courseSchedule.getId());
-            courseScheduleTeacherSalary.setGroupType(GroupType.PRACTICE);
-            courseScheduleTeacherSalary.setMusicGroupId(practiceGroupBuyParams.getId().toString());
-            courseScheduleTeacherSalary.setTeacherRole(classGroupTeacherMapper.getTeacherRole());
-            courseScheduleTeacherSalary.setUserId(practiceGroupBuyParams.getUserId());
-            courseScheduleTeacherSalary.setExpectSalary(teacherDefaultSalary);
-            courseScheduleTeacherSalary.setCreateTime(now);
-            courseScheduleTeacherSalary.setUpdateTime(now);
-            courseScheduleTeacherSalary.setClassGroupId(classGroup.getId());
-            courseScheduleTeacherSalaries.add(courseScheduleTeacherSalary);
 
+        PracticeGroupSellPrice practiceGroupSellPrice = practiceGroupSellPriceDao.get(practiceGroup.getOrganId());
+        BigDecimal singleClassMinutesPrice = practiceGroupSellPrice.getSingleClassMinutesPrice();
+        //实际支付金额,去除优惠券
+        BigDecimal actualPrice = order.getExpectAmount().subtract(order.getCouponRemitFee());
+        BigDecimal divide = actualPrice.divide(new BigDecimal(courseSchedules.size()), ROUND_DOWN);
+        BigDecimal firstAmount = actualPrice.subtract(divide.multiply(new BigDecimal(courseSchedules.size()))).add(divide);
+
+        for (int i = 0; i < courseSchedules.size(); i++) {
+            CourseSchedule courseSchedule = courseSchedules.get(i);
             //学生缴费记录
             CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
             courseScheduleStudentPayment.setGroupType(GroupType.PRACTICE);
-            courseScheduleStudentPayment.setMusicGroupId(practiceGroupBuyParams.getId().toString());
+            courseScheduleStudentPayment.setMusicGroupId(practiceGroup.getId().toString());
             courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
-            courseScheduleStudentPayment.setUserId(practiceGroupBuyParams.getStudentId());
-            courseScheduleStudentPayment.setExpectPrice(studentSingleCourseCost);
-            courseScheduleStudentPayment.setActualPrice(studentSingleCourseCost);
-            courseScheduleStudentPayment.setOriginalPrice(studentSingleCourseOriginalCost);
+            courseScheduleStudentPayment.setUserId(practiceGroup.getStudentId());
+            if(i == 0){
+                courseScheduleStudentPayment.setExpectPrice(firstAmount);
+                courseScheduleStudentPayment.setActualPrice(firstAmount);
+            }else {
+                courseScheduleStudentPayment.setExpectPrice(divide);
+                courseScheduleStudentPayment.setActualPrice(divide);
+            }
+            courseScheduleStudentPayment.setOriginalPrice(singleClassMinutesPrice);
             courseScheduleStudentPayment.setClassGroupId(classGroup.getId());
-            courseScheduleStudentPayment.setCreateTime(now);
-            courseScheduleStudentPayment.setUpdateTime(now);
             courseScheduleStudentPayments.add(courseScheduleStudentPayment);
 
             //教师签到记录
             TeacherAttendance teacherAttendance = new TeacherAttendance();
-            teacherAttendance.setMusicGroupId(practiceGroupBuyParams.getId().toString());
-            teacherAttendance.setTeacherId(practiceGroupBuyParams.getUserId());
+            teacherAttendance.setMusicGroupId(practiceGroup.getId().toString());
+            teacherAttendance.setTeacherId(practiceGroup.getStudentId());
             teacherAttendance.setClassGroupId(classGroup.getId());
             teacherAttendance.setGroupType(GroupType.PRACTICE);
             teacherAttendance.setCourseScheduleId(courseSchedule.getId());
-            teacherAttendance.setCreateTime(now);
             teacherAttendances.add(teacherAttendance);
         }
-        courseScheduleTeacherSalaryDao.batchInsert(courseScheduleTeacherSalaries);
         courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
         teacherAttendanceDao.batchInsert(teacherAttendances);
-
-        courseScheduleStudentPaymentService.createCourseScheduleStudentPaymentForPracticeGroup(practiceGroup.getId(),classGroupStudentMapper.getUserId());
-        studentDao.updateStudentServiceTag(classGroupStudentMapper.getUserId(), null, YesOrNoEnum.YES.getCode());
-
-        Map<Integer,String> userRoleMap = new HashMap<Integer, String>();
-        userRoleMap.put(classGroupStudentMapper.getUserId(),null);
-        if(Objects.nonNull(practiceGroup.getEducationalTeacherId())){
-            userRoleMap.put(practiceGroup.getEducationalTeacherId(),"乐团主管");
-        }
-        userRoleMap.put(practiceGroup.getUserId(),"指导老师");
-        try {
-            imGroupService.create(classGroup.getId().longValue(), null, classGroup.getName(), classGroup.getName(), practiceGroup.getName(), null, null, GroupType.VIP.getCode());
-            imGroupMemberService.join(classGroup.getId().longValue(), userRoleMap);
-            imUserFriendService.refreshGroupImUserFriend(classGroup.getMusicGroupId(),classGroup.getGroupType());
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
     }
 
     @Override
@@ -4632,7 +4604,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
                 throw new BizException("课酬结算方案错误");
             }
             salarySettlement = vipGroupSalarySettlementDto.getPracticeSalarySettlement();
-            totalPrice = totalPrice.multiply(vipGroupActivity.getDiscount()).divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
+            totalPrice = totalPrice.multiply(vipGroupActivity.getDiscount()).divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
         }
         //教师课酬线上单课酬计算
         teacherDefaultSalary = teacherDefaultPracticeGroupSalary.getMainTeacherSalary();
@@ -5326,7 +5298,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
                 default:
                     throw new BizException("错误的会员周期");
             }
-            activityFee = activityFee.multiply(activity.getDiscount()).divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
+            activityFee = activityFee.multiply(activity.getDiscount()).divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, ROUND_DOWN);
         }
         //计算订单金额
         StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(practiceGroupBuyParams.getCouponIdList(), activityFee, true);

+ 13 - 13
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupActivityServiceImpl.java

@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 import static com.ym.mec.biz.dal.enums.SalarySettlementTypeEnum.TEACHER_DEFAULT;
 
@@ -87,26 +88,25 @@ public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGro
 	private ActivityApplyStudentType getApplyToStudentType(String applyToStudentType){
 		ActivityApplyStudentType activityApplyStudentType = new ActivityApplyStudentType();
 		if(StringUtils.isNotEmpty(applyToStudentType)){
+			List<Integer> collect = Arrays.stream(applyToStudentType.split(",")).mapToInt(Integer::valueOf).boxed().collect(Collectors.toList());
 			//0:老用户;1:新用户,2会员,3非会员
-			if(applyToStudentType.contains("0") && applyToStudentType.contains("1")){
-				applyToStudentType.replace("0","");
-				applyToStudentType.replace("1","");
-			}
-			if(applyToStudentType.contains("3") && applyToStudentType.contains("2")){
-				applyToStudentType.replace("2","");
-				applyToStudentType.replace("3","");
-			}
-			if(StringUtils.isNotEmpty(applyToStudentType)){
-				if(applyToStudentType.contains("0")){
+			if(collect.contains(0) && collect.contains(1)){
+				activityApplyStudentType.setNewStudent(-1);
+			}else {
+				if(collect.contains(0)){
 					activityApplyStudentType.setNewStudent(0);
 				}
-				if(applyToStudentType.contains("1")){
+				if(collect.contains(1)){
 					activityApplyStudentType.setNewStudent(1);
 				}
-				if(applyToStudentType.contains("2")){
+			}
+			if(collect.contains(2) && collect.contains(3)){
+				activityApplyStudentType.setMemberFlag(-1);
+			}else {
+				if(collect.contains(2)){
 					activityApplyStudentType.setMemberFlag(1);
 				}
-				if(applyToStudentType.contains("3")){
+				if(collect.contains(3)){
 					activityApplyStudentType.setMemberFlag(0);
 				}
 			}