Joburgess 5 years ago
parent
commit
4a36149af6

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleStudentPaymentDao.java

@@ -6,6 +6,7 @@ import com.ym.mec.biz.dal.entity.CourseScheduleStudentPayment;
 import com.ym.mec.common.dal.BaseDAO;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -55,4 +56,15 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
      */
     List<StudentAttendanceStatisticsResponse> findStudentByClassGroup(Map<String,Object> params);
     int countStudentByClassGroup(Map<String,Object> params);
+
+    /**
+     * @describe 统计学生剩余课时的费用
+     * @author Joburgess
+     * @date 2019/11/15
+     * @param classGroupId: 班级编号
+     * @param userId: 学生编号
+     * @return java.math.BigDecimal
+     */
+    BigDecimal countSurplusCourseFee(@Param("classGroupId") Integer classGroupId,
+                                     @Param("userId") Integer userId);
 }

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

@@ -199,6 +199,26 @@ public interface VipGroupService extends BaseService<Long, VipGroup> {
 	 */
 	void applyRefund(Long vipGroupId, Integer studentId);
 
+	/**
+	 * @describe 给指定学生退课
+	 * @author Joburgess
+	 * @date 2019/11/15
+	 * @param vipGroupId: vip课程
+	 * @param studentId: 学生编号
+	 * @return void
+	 */
+	void applyRefundForStudent(Long vipGroupId, Integer studentId, BigDecimal amount);
+
+	/**
+	 * @describe 获取指定学生的剩余课时费用
+	 * @author Joburgess
+	 * @date 2019/11/15
+	 * @param vipGroupId: VIP课编号
+	 * @param studentId: 学生编号
+	 * @return java.util.Map<java.lang.String,java.math.BigDecimal>
+	 */
+	Map<String,BigDecimal> getStudentSurplusCourseFee(Long vipGroupId, Integer studentId);
+
     /**
      * @Author: Joburgess
      * @Date: 2019/10/3

+ 59 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -978,6 +978,65 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		studentApplyRefundsDao.insert(studentApplyRefunds);
 	}
 
+	@Override
+	public void applyRefundForStudent(Long vipGroupId, Integer studentId, BigDecimal amount) {
+		if(Objects.isNull(vipGroupId)||Objects.isNull(studentId)){
+			throw new BizException("请指定小课与学生");
+		}
+		if(Objects.isNull(amount)){
+			throw new BizException("请确定退费金额");
+		}
+		VipGroup vipGroup=vipGroupDao.get(vipGroupId);
+		if(Objects.isNull(vipGroup)){
+			throw new BizException("指定的课程不存在");
+		}
+		ClassGroup classGroup = classGroupDao.findByVipGroup(vipGroupId, null);
+		sysUserCashAccountService.updateBalance(studentId, amount);
+		SysUserCashAccount sysUserCashAccount = sysUserCashAccountService.get(studentId);
+		SysUserCashAccountDetail sysUserCashAccountDetail = new SysUserCashAccountDetail();
+		sysUserCashAccountDetail.setUserId(studentId);
+		sysUserCashAccountDetail.setType(PlatformCashAccountDetailTypeEnum.REFUNDS);
+		sysUserCashAccountDetail.setStatus(DealStatusEnum.SUCCESS);
+		sysUserCashAccountDetail.setAmount(amount);
+		sysUserCashAccountDetail.setBalance(sysUserCashAccount.getBalance());
+		sysUserCashAccountDetail.setAttribute(studentId.toString());
+		sysUserCashAccountDetailDao.insert(sysUserCashAccountDetail);
+
+		ClassGroupStudentMapper classStudentMapperByUserIdAndClassGroupId = classGroupStudentMapperDao.query(classGroup.getId(),
+				studentId);
+
+		classStudentMapperByUserIdAndClassGroupId.setStatus(ClassGroupStudentStatusEnum.QUIT);
+		classGroupStudentMapperDao.update(classStudentMapperByUserIdAndClassGroupId);
+
+		//学员退出班级群
+		ImGroupMember[] imGroupMembers = new ImGroupMember[]{new ImGroupMember(studentId.toString())};
+		imFeignService.groupJoin(new ImGroupModel(classGroup.getId().toString(), imGroupMembers, null));
+	}
+
+	@Override
+	public Map<String, BigDecimal> getStudentSurplusCourseFee(Long vipGroupId, Integer studentId) {
+		if(Objects.isNull(vipGroupId)||Objects.isNull(studentId)){
+			throw new BizException("请指定课程和学生");
+		}
+		VipGroup vipGroup = vipGroupDao.get(vipGroupId);
+		if(Objects.isNull(vipGroup)){
+			throw new BizException("未找到指定vip课");
+		}
+		Map<String,BigDecimal> result=new HashMap<>();
+		if(vipGroup.getStatus().equals(VipGroupStatusEnum.APPLYING)){
+			StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.findByStudentVipGroup(vipGroupId, studentId, DealStatusEnum.SUCCESS.getCode());
+			result.put("suplusCourseFee",studentPaymentOrder.getActualAmount());
+			return result;
+		}
+		ClassGroup classGroup = classGroupDao.findByVipGroup(vipGroupId, null);
+		if(Objects.isNull(classGroup)){
+			throw new BizException("为找到对应班级");
+		}
+		BigDecimal bigDecimal = courseScheduleStudentPaymentDao.countSurplusCourseFee(classGroup.getId(), studentId);
+		result.put("suplusCourseFee",Objects.isNull(bigDecimal)?new BigDecimal(0):bigDecimal);
+		return result;
+	}
+
 	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void applyRefundAudit(Long id, StudentApplyRefundsStatus status, String remark,BigDecimal amount) {

+ 12 - 1
mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml

@@ -132,8 +132,19 @@
 		WHERE
 			cs.class_group_id_ = #{classGroupId}
 	</select>
+    <select id="countSurplusCourseFee" resultType="java.math.BigDecimal">
+		SELECT
+			SUM(expect_price_)
+		FROM
+			course_schedule_student_payment cssp
+			LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
+		WHERE
+			cssp.user_id_ = #{userId}
+			AND cs.status_ = 'NOT_START'
+			AND cs.class_group_id_ = #{classGroupId}
+    </select>
 
-	<delete id="deleteStudentCourseSchedule">
+    <delete id="deleteStudentCourseSchedule">
 		DELETE FROM course_schedule_student_payment WHERE user_id_ = #{userId} AND course_schedule_id_ IN
 		<foreach collection="courseScheduleList" item="courseSchedule" index="index" open="(" close=")" separator=",">
 			#{courseSchedule.id}

+ 8 - 2
mec-web/src/main/java/com/ym/mec/web/controller/VipGroupManageController.java

@@ -112,8 +112,8 @@ public class VipGroupManageController extends BaseController {
     @ApiOperation(value = "退课申请")
     @PostMapping("/applyRefundForStudent")
     @PreAuthorize("@pcs.hasPermissions('vipGroupManage/applyRefundForStudent')")
-    public Object applyRefundForStudent(Long vipGroupId,Integer studentId){
-        vipGroupService.applyRefund(vipGroupId,studentId);
+    public Object applyRefundForStudent(Long vipGroupId,Integer studentId, BigDecimal amount){
+        vipGroupService.applyRefundForStudent(vipGroupId,studentId,amount);
         return succeed();
     }
 
@@ -245,4 +245,10 @@ public class VipGroupManageController extends BaseController {
         vipGroupService.appendVipGroupCourseSchedules(vipGroupApplyDto);
         return succeed();
     }
+
+    @ApiOperation(value = "获取学生指定vip课的剩余课时费用")
+    @GetMapping(value = "/getStudentSurplusCourseFee")
+    public Object getStudentSurplusCourseFee(Long vipGroupId, Integer studentId){
+        return succeed(vipGroupService.getStudentSurplusCourseFee(vipGroupId,studentId));
+    }
 }