Ver código fonte

feat:课酬调整变更

Joburgess 4 anos atrás
pai
commit
fd2b5feb1c

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/VipGroupDao.java

@@ -365,4 +365,15 @@ public interface VipGroupDao extends BaseDAO<Long, VipGroup> {
      * @return
      */
     List<Map<Long, String>> queryEduNameMapByCourseId(@Param("courseIds") List<Long> courseIds);
+
+    /**
+     * @describe 统计学员在指定活动上关联的次数
+     * @author Joburgess
+     * @date 2021/5/17 0017
+     * @param vipGroupActivityId:
+     * @param studentId:
+     * @return int
+     */
+    int countStudentUserActivityNum(@Param("vipGroupActivityId") Integer vipGroupActivityId,
+                                    @Param("studentId") Integer studentId);
 }

+ 35 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -198,10 +198,6 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
         String studentIds=vipGroup.getStudentIds();
 		List<String> studentIdList=new ArrayList<>();
 
-        if(StringUtils.isNotBlank(studentIds)){
-			studentIdList = Arrays.asList(studentIds.split(","));
-		}
-
         Date now=new Date();
 
 		VipGroupApplyBaseInfoDto vipGroupApplyBaseInfoDto=vipGroup.getVipGroupApplyBaseInfo();
@@ -243,6 +239,15 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 
 		//获取活动信息
 		VipGroupActivity vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupApplyBaseInfo().getVipGroupActivityId());
+		if(Objects.nonNull(vipGroupActivity)&&Objects.nonNull(vipGroupActivity.getStudentMaxUsedTimes())&&StringUtils.isNotBlank(studentIds)){
+			studentIdList = Arrays.asList(studentIds.split(","));
+			for (String studentIdStr : studentIdList) {
+				int useNum = vipGroupDao.countStudentUserActivityNum(vipGroup.getVipGroupApplyBaseInfo().getVipGroupActivityId(), Integer.valueOf(studentIdStr));
+				if(useNum>=vipGroupActivity.getStudentMaxUsedTimes()){
+					throw new BizException("创建失败:当前活动可购买次数为{}次", vipGroupActivity.getStudentMaxUsedTimes());
+				}
+			}
+		}
 		//判断课程安排是否超出范围
 		if(Objects.nonNull(vipGroupActivity)&&(Objects.nonNull(vipGroupActivity.getCoursesEndTime())||Objects.nonNull(vipGroupActivity.getCoursesStartTime()))){
 			if(latestCourseSchedule.getEndClassTime().after(vipGroupActivity.getCoursesEndTime())
@@ -1492,7 +1497,6 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 
         VipGroup vipGroup = vipGroupDao.get(vipGroupBuyParams.getVipGroupId());
 
-
 		if(classGroup.getStudentNum()>0&&(VipGroupStatusEnum.APPLYING.equals(vipGroup.getStatus()))){
 			int i = studentPaymentOrderDao.countGroupOrderWithoutFailed(vipGroupBuyParams.getVipGroupId().toString(), GroupType.VIP);
 			if(i<=0){
@@ -1500,6 +1504,18 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 			}
 		}
 
+		VipGroupActivity vipGroupActivity = null;
+		if(Objects.nonNull(vipGroup.getVipGroupActivityId())){
+			vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupActivityId().intValue());
+		}
+
+		if(Objects.nonNull(vipGroupActivity)&&Objects.nonNull(vipGroupActivity.getStudentMaxUsedTimes())){
+			int useNum = vipGroupDao.countStudentUserActivityNum(vipGroup.getVipGroupActivityId(), Integer.valueOf(user.getId()));
+			if(useNum>=vipGroupActivity.getStudentMaxUsedTimes()){
+				throw new BizException("创建失败:当前活动可购买次数为{}次", vipGroupActivity.getStudentMaxUsedTimes());
+			}
+		}
+
 		if(vipGroup.getPaymentExpireDate().before(date)){
 			throw new BizException("该课程已结束报名!");
 		}
@@ -2885,6 +2901,20 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 			throw new BizException("选择的学生中存在此课程中已存在的学生");
 		}
 
+		VipGroupActivity vipGroupActivity = null;
+		if(Objects.nonNull(vipGroup.getVipGroupActivityId())){
+			vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupActivityId().intValue());
+		}
+
+		if(Objects.nonNull(vipGroupActivity)&&Objects.nonNull(vipGroupActivity.getStudentMaxUsedTimes())&&!CollectionUtils.isEmpty(studentIds)){
+			for (Integer studentId : studentIds) {
+				int useNum = vipGroupDao.countStudentUserActivityNum(vipGroup.getVipGroupActivityId(), Integer.valueOf(studentId));
+				if(useNum>=vipGroupActivity.getStudentMaxUsedTimes()){
+					throw new BizException("创建失败:当前活动可购买次数为{}次", vipGroupActivity.getStudentMaxUsedTimes());
+				}
+			}
+		}
+
 		Date now=new Date();
         Map<Integer,String> userRoleMap = new HashMap<Integer, String>();
 
@@ -2965,11 +2995,6 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 			return;
 		}
 
-		VipGroupActivity vipGroupActivity = null;
-		if(Objects.nonNull(vipGroup.getVipGroupActivityId())){
-			vipGroupActivity = vipGroupActivityDao.get(vipGroup.getVipGroupActivityId().intValue());
-		}
-
 		BigDecimal surplusCoursesPrice=new BigDecimal(0);
 		boolean hasGiveClass=false;
 		int onlineCourseTimes=0,

+ 7 - 0
mec-biz/src/main/resources/config/mybatis/VipGroupMapper.xml

@@ -1037,4 +1037,11 @@
         </foreach>
         AND vg.educational_teacher_id_ IS NOT NULL
     </select>
+    <select id="countStudentUserActivityNum" resultType="int">
+        SELECT COUNT(DISTINCT vg.id_)
+        FROM vip_group vg
+        LEFT JOIN class_group_student_mapper cgsm ON vg.id_=cgsm.music_group_id_ AND cgsm.group_type_='VIP'
+        WHERE vg.vip_group_activity_id_=#{vipGroupActivityId}
+            AND ((vg.group_status_=1 AND FIND_IN_SET(#{studentId}, vg.student_id_list_)) OR cgsm.user_id_=#{studentId});
+    </select>
 </mapper>