Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master_teacherSalary_2020-12-11' into master_teacherSalary_2020-12-11

zouxuan 4 anni fa
parent
commit
ed0b9a7e48

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/VipGroupService.java

@@ -182,6 +182,17 @@ public interface VipGroupService extends BaseService<Long, VipGroup> {
                                                      BigDecimal onlineClassesUnitPrice,
                                                      BigDecimal offlineClassesUnitPrice);
 
+    /**
+     * @describe 计算vip课程购买总价,及老师课酬-只是学生人数统计方式不同
+     * @author Joburgess
+     * @date 2019/10/23
+     * @param vipGroup: vip课程
+     * @param teacherId: 要计算课酬的老师的编号
+     * @return java.util.Map
+     */
+    <K extends VipGroup> Map<String, BigDecimal> countVipGroupCoursePredictFee(K vipGroup,
+                                                                         Integer teacherId,
+                                                                               Long courseId);
 
 
     /**

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

@@ -311,7 +311,7 @@ public class CourseScheduleTeacherSalaryServiceImpl extends BaseServiceImpl<Long
             }else{
                 //按照活动重新计算课酬
                 VipGroup vipGroup = vipGroupService.get(Long.valueOf(ts.getMusicGroupId()));
-                Map<String, BigDecimal> teachModeSalaryMap = vipGroupService.countVipGroupPredictFee(vipGroup, ts.getUserId(), null, null);
+                Map<String, BigDecimal> teachModeSalaryMap = vipGroupService.countVipGroupCoursePredictFee(vipGroup, ts.getUserId(), ts.getCourseScheduleId());
                 if(TeachModeEnum.ONLINE.equals(ts.getTeachMode())&&teachModeSalaryMap.containsKey("onlineTeacherSalary")){
                     ts.setExpectSalary(teachModeSalaryMap.get("onlineTeacherSalary"));
                 }else if(TeachModeEnum.OFFLINE.equals(ts.getTeachMode())&&teachModeSalaryMap.containsKey("offlineTeacherSalary")){
@@ -426,10 +426,6 @@ public class CourseScheduleTeacherSalaryServiceImpl extends BaseServiceImpl<Long
             //当前课酬对应的课程信息
             CourseSchedule courseSchedule = courseScheduleIdMap.get(courseScheduleTeacherSalary.getCourseScheduleId());
 
-            if(CourseSchedule.CourseScheduleType.HIGH.equals(courseSchedule.getType())){
-                courseSchedule.setType(CourseSchedule.CourseScheduleType.HIGH_ONLINE);
-            }
-
             //教师课酬
             BigDecimal teacherSalary = new BigDecimal(0);
 
@@ -459,6 +455,8 @@ public class CourseScheduleTeacherSalaryServiceImpl extends BaseServiceImpl<Long
                 if(Objects.isNull(teacherSalary)){
                     teacherSalary = BigDecimal.ZERO;
                 }
+            }else if(CourseSchedule.CourseScheduleType.HIGH.equals(courseSchedule.getType())){
+
             }else{
                 teacherSalary=courseScheduleTeacherSalary.getExpectSalary();
             }
@@ -483,8 +481,8 @@ public class CourseScheduleTeacherSalaryServiceImpl extends BaseServiceImpl<Long
                 }
             }
 
-            if(CollectionUtils.isEmpty(courseTeacherAttendances)){
-                //无签到记录扣除全部课酬
+            if(CollectionUtils.isEmpty(courseTeacherAttendances)||!isCallName){
+                //无签到记录或者未点名扣除全部课酬
                 deductCost = deductCost.add(teacherSalary);
                 deductReasons.add("无签到记录扣除全部课酬");
             }else{
@@ -511,17 +509,12 @@ public class CourseScheduleTeacherSalaryServiceImpl extends BaseServiceImpl<Long
                     }
                 }
 
-                if(!isCallName){
-                    //未点名扣除一半课酬
-                    deductCost = deductCost.add(teacherSalary.divide(new BigDecimal(2)));
-                    deductReasons.add("未点名扣除一半课酬");
-                }else if((Objects.isNull(teacherAttendance.getSignOutStatus())||YesOrNoEnum.NO.equals(teacherAttendance.getSignOutStatus()))&&isCallName){
+                if((Objects.isNull(teacherAttendance.getSignOutStatus())||YesOrNoEnum.NO.equals(teacherAttendance.getSignOutStatus()))&&isCallName){
                     //异常签退或者未签退,但是正常点名扣除50元课酬
                     deductCost = deductCost.add(new BigDecimal(50));
                     deductReasons.add("异常签退或者未签退,但是正常点名扣除50元课酬");
                 }
 
-
             }
 
             BigDecimal finalSalary = teacherSalary.subtract(deductCost).setScale(BigDecimal.ZERO.intValue(), BigDecimal.ROUND_HALF_UP);

+ 182 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -1081,7 +1081,6 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 
 		results.put("totalPrice",totalPrice.setScale(0,BigDecimal.ROUND_CEILING));
 
-
 		int normalStudentNum = 0;
 		if(Objects.nonNull(vipGroup.getId())){
 			normalStudentNum = classGroupStudentMapperDao.countGroupNormalStudentNum(GroupType.VIP, vipGroup.getId().toString());
@@ -1181,6 +1180,188 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
     }
 
 	@Override
+	public <K extends VipGroup> Map<String,BigDecimal> countVipGroupCoursePredictFee(K vipGroup,
+																			   Integer teacherId,
+																					 Long courseId){
+
+		if(Objects.isNull(teacherId)){
+			throw new BizException("请指定教师");
+		}
+
+		if(Objects.isNull(vipGroup.getVipGroupCategoryId())){
+			throw new BizException("请指定课程形式");
+		}
+
+		VipGroupCategory vipGroupCategory = vipGroupCategoryDao.get(vipGroup.getVipGroupCategoryId().intValue());
+		if(Objects.isNull(vipGroupCategory)){
+			throw new BizException("未找到课程形式");
+		}
+
+		TeacherDefaultVipGroupSalary teacherDefaultVipGroupSalary = teacherDefaultVipGroupSalaryDao.findByTeacherAndCategory(teacherId,
+				vipGroup.getVipGroupCategoryId());
+
+		if(Objects.isNull(teacherDefaultVipGroupSalary)){
+			throw new BizException("请设置教师课酬");
+		}
+
+		if(Objects.isNull(vipGroup.getVipGroupActivityId())){
+			throw new BizException("请指定活动方案");
+		}
+
+		VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupActivityId().intValue());
+
+		if(Objects.isNull(vipGroupActivity)){
+			throw new BizException("指定的活动方案不存在");
+		}
+
+		VipGroupSalarySettlementDto vipGroupSalarySettlementDto = JSON.parseObject(vipGroupActivity.getSalarySettlementJson(), VipGroupSalarySettlementDto.class);
+
+		if(Objects.isNull(vipGroupSalarySettlementDto)){
+			throw new BizException("课酬结算方案错误");
+		}
+
+		Map<String,BigDecimal> results=new HashMap<>(1);
+
+		BigDecimal offlineClassNum=new BigDecimal(vipGroup.getOfflineClassesNum());
+		BigDecimal onlineClassNum=new BigDecimal(vipGroup.getOnlineClassesNum());
+		BigDecimal onlineClassesUnitPrice=vipGroup.getOnlineClassesUnitPrice();
+		if(Objects.isNull(onlineClassesUnitPrice)){
+			onlineClassesUnitPrice = BigDecimal.ZERO;
+		}
+		BigDecimal onlineVipGroupCharge = onlineClassesUnitPrice.multiply(onlineClassNum);
+		BigDecimal offlineClassesUnitPrice=vipGroup.getOfflineClassesUnitPrice();
+		if(Objects.isNull(offlineClassesUnitPrice)){
+			offlineClassesUnitPrice = BigDecimal.ZERO;
+		}
+		BigDecimal offlineVipGroupCharge = offlineClassesUnitPrice.multiply(offlineClassNum);
+		BigDecimal totalClassNum=offlineClassNum.add(onlineClassNum);
+		BigDecimal teacherOnlineSalary=null,teacherOfflineSalary=null;
+
+		if(Objects.isNull(vipGroupActivity.getType())){
+			throw new BizException("此活动未设置活动类型");
+		}
+
+		//课程购买费用计算
+		BigDecimal totalPrice;
+		switch (vipGroupActivity.getType()){
+			case BASE_ACTIVITY:
+				totalPrice=onlineVipGroupCharge.add(offlineVipGroupCharge);
+				break;
+			case DISCOUNT:
+				BigDecimal discount=new BigDecimal(vipGroupActivity.getAttribute1());
+				totalPrice=onlineVipGroupCharge.add(offlineVipGroupCharge);
+				totalPrice=totalPrice.multiply(discount).divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
+				break;
+			case GIVE_CLASS:
+				if(totalClassNum.compareTo(new BigDecimal(vipGroupActivity.getAttribute1()))<0){
+
+				}else if(vipGroup.getGiveTeachMode()==TeachModeEnum.OFFLINE){
+					if(totalClassNum.compareTo(new BigDecimal(vipGroupActivity.getAttribute1()))>-1){
+						offlineClassNum=offlineClassNum.subtract(new BigDecimal(vipGroupActivity.getAttribute2()));
+					}
+					offlineVipGroupCharge = offlineClassesUnitPrice.multiply(offlineClassNum);
+				}else if(vipGroup.getGiveTeachMode()==TeachModeEnum.ONLINE){
+					if(totalClassNum.compareTo(new BigDecimal(vipGroupActivity.getAttribute1()))>-1){
+						onlineClassNum=onlineClassNum.subtract(new BigDecimal(vipGroupActivity.getAttribute2()));
+					}
+					onlineVipGroupCharge = onlineClassesUnitPrice.multiply(onlineClassNum);
+				}else{
+					throw new BizException("请指定赠送课程类型!");
+				}
+				totalPrice=onlineVipGroupCharge.add(offlineVipGroupCharge);
+				break;
+			default:
+				throw new BizException("活动类型错误!");
+		}
+
+		results.put("totalPrice",totalPrice.setScale(0,BigDecimal.ROUND_CEILING));
+
+		int normalStudentNum = 0;
+		if(Objects.nonNull(vipGroup.getId())){
+			normalStudentNum = courseScheduleStudentPaymentDao.countStudentNum(courseId.intValue());
+		}
+
+		//教师课酬线上单课酬计算
+		if(Objects.nonNull(vipGroupSalarySettlementDto.getOnlineSalarySettlement())){
+			if(Objects.isNull(teacherOnlineSalary)){
+				switch (vipGroupSalarySettlementDto.getOnlineSalarySettlement().getSalarySettlementType()){
+					case TEACHER_DEFAULT:
+						if(Objects.isNull(teacherDefaultVipGroupSalary)||Objects.isNull(teacherDefaultVipGroupSalary.getOfflineClassesSalary())){
+							teacherOnlineSalary=new BigDecimal(0);
+						}else{
+							teacherOnlineSalary=teacherDefaultVipGroupSalary.getOfflineClassesSalary();
+						}
+						results.put("onlineTeacherSalary",teacherOnlineSalary.setScale(0, BigDecimal.ROUND_HALF_UP));
+						break;
+					case RATIO_DISCOUNT:
+						results.put("onlineTeacherSalary",totalPrice.multiply(new BigDecimal(vipGroupCategory.getStudentNum()))
+								.divide(totalClassNum, CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN)
+								.multiply(vipGroupSalarySettlementDto.getOnlineSalarySettlement().getSettlementValue())
+								.divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN)
+								.setScale(0,BigDecimal.ROUND_HALF_UP));
+
+						break;
+					case FIXED_SALARY:
+						results.put("onlineTeacherSalary",vipGroupSalarySettlementDto.getOnlineSalarySettlement().getSettlementValue().setScale(0, BigDecimal.ROUND_HALF_UP));
+						break;
+					default:
+						throw new BizException("未指定课酬结算标准!");
+				}
+
+			}
+		}
+
+		//教师线下单课酬计算
+		if(Objects.nonNull(vipGroupSalarySettlementDto.getOfflineSalarySettlement())){
+			if(Objects.isNull(teacherOfflineSalary)){
+				switch (vipGroupSalarySettlementDto.getOfflineSalarySettlement().getSalarySettlementType()){
+					case TEACHER_DEFAULT:
+						if(Objects.isNull(teacherDefaultVipGroupSalary)||Objects.isNull(teacherDefaultVipGroupSalary.getOfflineClassesSalary())){
+							teacherOfflineSalary=new BigDecimal(0);
+						}else{
+							teacherOfflineSalary=teacherDefaultVipGroupSalary.getOfflineClassesSalary();
+						}
+						results.put("offlineTeacherSalary",teacherOfflineSalary.setScale(0, BigDecimal.ROUND_HALF_UP));
+						break;
+					case RATIO_DISCOUNT:
+						results.put("offlineTeacherSalary",totalPrice.multiply(new BigDecimal(vipGroupCategory.getStudentNum())).divide(totalClassNum, CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(vipGroupSalarySettlementDto.getOfflineSalarySettlement().getSettlementValue()).divide(new BigDecimal(100), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).setScale(0,BigDecimal.ROUND_HALF_UP));
+
+						break;
+					case FIXED_SALARY:
+						results.put("offlineTeacherSalary",vipGroupSalarySettlementDto.getOfflineSalarySettlement().getSettlementValue().setScale(0, BigDecimal.ROUND_HALF_UP));
+						break;
+					default:
+						throw new BizException("未指定课酬结算标准!");
+				}
+			}
+		}
+
+		BigDecimal ots = results.get("onlineTeacherSalary");
+		if(Objects.isNull(ots)){
+			ots = teacherDefaultVipGroupSalary.getOfflineClassesSalary();
+		}
+		if(Objects.isNull(ots)){
+			ots = BigDecimal.ZERO;
+		}
+		BigDecimal ofts = results.get("offlineTeacherSalary");
+		if(Objects.isNull(ofts)){
+			ofts = teacherDefaultVipGroupSalary.getOfflineClassesSalary();
+		}
+		if(Objects.isNull(ofts)){
+			ofts = BigDecimal.ZERO;
+		}
+		if(Objects.nonNull(vipGroup.getStatus())&&normalStudentNum!=vipGroupCategory.getStudentNum()){
+			ots = ots.divide(new BigDecimal(vipGroupCategory.getStudentNum()),CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(normalStudentNum)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_HALF_UP);
+			ofts = ofts.divide(new BigDecimal(vipGroupCategory.getStudentNum()),CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(normalStudentNum)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_HALF_UP);
+		}
+
+		results.put("onlineTeacherSalary", ots);
+		results.put("offlineTeacherSalary", ofts);
+
+		return results;
+	}
+
+	@Override
 	public void enableBuyVipGroup(Integer vipGroupId, Integer userId) {
 		if (Objects.isNull(vipGroupId)){
 			throw new BizException("请指定VIP课");