Procházet zdrojové kódy

1、教务端课程交换
2、vip课退课费用

Joburgess před 5 roky
rodič
revize
372ff25f86

+ 15 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleDao.java

@@ -827,6 +827,21 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
                                                          @Param("userId") Integer userId);
 
     /**
+     * @describe 获取学生的课程信息
+     * @author Joburgess
+     * @date 2020/1/15
+     * @param groupType: 团体类型
+     * @param groupId: 团体编号
+     * @param userId: 用户编号
+     * @param type: 查询类型:不传查全部,'history'已消耗的,'surplus'剩余的
+     * @return java.util.List<com.ym.mec.biz.dal.dto.StudentCourseInfoDto>
+     */
+    List<StudentCourseInfoDto> findUserCourseInfos(@Param("groupType") GroupType groupType,
+                                                   @Param("groupId") String groupId,
+                                                   @Param("userId") Integer userId,
+                                                   @Param("type") String type);
+
+    /**
      * @describe 获取指定乐团下课程开始时间
      * @author Joburgess
      * @date 2019/12/19

+ 56 - 17
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -1260,7 +1260,35 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		if(surplusCourses<=0){
 			throw new BizException("此vip课程没有剩余排课");
 		}
-		BigDecimal surplusCourseFee = studentPaymentOrderDao.sumSurplusCourseFee(vipGroup.getId().toString(), userId);
+		Date now=new Date();
+        BigDecimal surplusCourseFee;
+        List<StudentCourseInfoDto> userCourseInfos = courseScheduleDao.findUserCourseInfos(GroupType.VIP, vipGroupId.toString(), userId, null);
+        if(CollectionUtils.isEmpty(userCourseInfos)&&vipGroup.getStatus().equals(VipGroupStatusEnum.APPLYING)){
+            if(Objects.isNull(studentPaymentOrder)){
+                surplusCourseFee=new BigDecimal(0);
+            }else{
+                surplusCourseFee=studentPaymentOrder.getActualAmount();
+            }
+        }else if(!CollectionUtils.isEmpty(userCourseInfos)){
+            BigDecimal historyPrice=new BigDecimal(0);
+            BigDecimal allPrice=new BigDecimal(0);
+            for (StudentCourseInfoDto userCourseInfo : userCourseInfos) {
+                allPrice=allPrice.add(userCourseInfo.getExpectPrice());
+                if(now.after(userCourseInfo.getStartClassTime())){
+                    historyPrice=historyPrice.add(userCourseInfo.getTeachMode().equals(TeachModeEnum.ONLINE)?vipGroup.getOnlineClassesUnitPrice():vipGroup.getOfflineClassesUnitPrice());
+                }
+            }
+            surplusCourseFee=allPrice.subtract(historyPrice);
+            if(surplusCourseFee.longValue()<0){
+                surplusCourseFee=new BigDecimal(0);
+            }
+        }else{
+            surplusCourseFee=new BigDecimal(0);
+        }
+        if(Objects.isNull(surplusCourseFee)){
+            surplusCourseFee = new BigDecimal(0);
+        }
+        surplusCourseFee = surplusCourseFee.multiply(new BigDecimal(0.8)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_HALF_UP);
 		studentApplyRefunds.setExpectAmount(surplusCourseFee);
 		studentApplyRefunds.setStatus(StudentApplyRefundsStatus.ING);
 		String orderNo=StringUtils.join(new String[]{userId.toString(),String.valueOf(System.currentTimeMillis())});
@@ -1619,26 +1647,37 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		if(vipGroup.getStatus().equals(VipGroupStatusEnum.CANCEL)){
 			throw new BizException("不能对已停止的课程进行退课操作");
 		}
-		Map<String,BigDecimal> result=new HashMap<>();
-		if(vipGroup.getStatus().equals(VipGroupStatusEnum.APPLYING)){
-			StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.findByStudentVipGroup(vipGroupId, studentId, DealStatusEnum.SUCCESS.getCode());
-			if(Objects.isNull(studentPaymentOrder)){
-				BigDecimal surplusCourseFee = studentPaymentOrderDao.sumSurplusCourseFee(vipGroupId.toString(), studentId);
-				if(Objects.isNull(surplusCourseFee)){
-					result.put("suplusCourseFee",new BigDecimal(0));
-				}else{
-					result.put("suplusCourseFee",surplusCourseFee);
-				}
-			}else{
-				result.put("suplusCourseFee",studentPaymentOrder.getActualAmount());
-			}
-			return result;
-		}
+		Date now = new Date();
+        BigDecimal bigDecimal;
+        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=new BigDecimal(0);
+            }else{
+                bigDecimal=studentPaymentOrder.getActualAmount();
+            }
+        }else if(!CollectionUtils.isEmpty(userCourseInfos)){
+            BigDecimal historyPrice=new BigDecimal(0);
+            BigDecimal allPrice=new BigDecimal(0);
+            for (StudentCourseInfoDto userCourseInfo : userCourseInfos) {
+                allPrice=allPrice.add(userCourseInfo.getExpectPrice());
+                if(now.after(userCourseInfo.getStartClassTime())){
+                    historyPrice=historyPrice.add(userCourseInfo.getTeachMode().equals(TeachModeEnum.ONLINE)?vipGroup.getOnlineClassesUnitPrice():vipGroup.getOfflineClassesUnitPrice());
+                }
+            }
+            bigDecimal=allPrice.subtract(historyPrice);
+            if(bigDecimal.longValue()<0){
+                bigDecimal=new BigDecimal(0);
+            }
+        }else{
+		    bigDecimal=new BigDecimal(0);
+        }
+        Map<String,BigDecimal> result=new HashMap<>();
 		ClassGroup classGroup = classGroupDao.findByVipGroup(vipGroupId, null);
 		if(Objects.isNull(classGroup)){
 			throw new BizException("未找到对应班级");
 		}
-		BigDecimal bigDecimal = courseScheduleStudentPaymentDao.countSurplusCourseFee(classGroup.getId(), studentId);
 		if(Objects.isNull(bigDecimal)){
 			bigDecimal = new BigDecimal(0);
 		}

+ 29 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -1850,6 +1850,35 @@
             AND cs.music_group_id_ = #{groupId}
             AND cssp.user_id_=#{userId}
     </select>
+
+    <select id="findUserCourseInfos" resultMap="StudentCourseInfoDto">
+        SELECT
+            cs.id_,
+            cs.music_group_id_,
+            cs.class_group_id_,
+            cs.status_,
+            cs.class_date_,
+            cs.start_class_time_,
+            cs.end_class_time_,
+            cs.actual_teacher_id_,
+            cs.teach_mode_,
+            cssp.expect_price_
+        FROM
+            course_schedule cs
+            LEFT JOIN course_schedule_student_payment cssp ON cs.id_ = cssp.course_schedule_id_
+        WHERE
+            (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
+            AND cs.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+            AND cs.music_group_id_ = #{groupId}
+            AND cssp.user_id_=#{userId}
+            <if test="type=='history'">
+                AND CONCAT( cs.class_date_, ' ', cs.end_class_time_ ) &lt;= NOW()
+            </if>
+            <if test="type=='surplus'">
+                AND CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) &gt; NOW()
+            </if>
+    </select>
+
     <select id="getMinCourseTime" resultType="java.util.Date">
         SELECT MIN(CONCAT(class_date_,' ',start_class_time_))
         FROM course_schedule