Browse Source

活动排课

zouxuan 4 years ago
parent
commit
21c6485895

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/ActivityUserMapperDao.java

@@ -21,4 +21,14 @@ public interface ActivityUserMapperDao extends BaseDAO<Integer, ActivityUserMapp
     * @date 2021/10/11 16:31
     */
     List<ActivityUserMapper> findByStudentIdList(@Param("activityId") Integer activityId, @Param("studentIds") String studentIds, @Param("type") String type);
+
+    /**
+    * @description: 获取学员购买的活动次数
+     * @param activityId
+     * @param userId
+    * @return int
+    * @author zx
+    * @date 2021/10/12 18:22
+    */
+    int countActivityBuyNum(@Param("activityId") Integer activityId, @Param("userId") Integer userId);
 }

+ 84 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/PracticeGroupBuyParamsDto.java

@@ -0,0 +1,84 @@
+package com.ym.mec.biz.dal.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.List;
+
+public class PracticeGroupBuyParamsDto {
+
+    @ApiModelProperty(value = "课程组ID")
+    private Long practiceGroupId;
+
+    @ApiModelProperty(value = "付款渠道")
+    private String paymentChannel;
+
+    @ApiModelProperty(value = "业务渠道")
+    private String paymentBusinessChannel;
+
+    @ApiModelProperty(value = "是否使用账户余额支付")
+    private boolean isUseBalancePayment;
+
+    @ApiModelProperty(value = "是否重新支付")
+    private boolean isRepeatPay;
+
+    @ApiModelProperty(value = "优惠券列表", required = false)
+    private List<Integer> couponIdList;
+
+    public Long getPracticeGroupId() {
+        return practiceGroupId;
+    }
+
+    public void setPracticeGroupId(Long practiceGroupId) {
+        this.practiceGroupId = practiceGroupId;
+    }
+
+    public List<Integer> getCouponIdList() {
+        return couponIdList;
+    }
+
+    public void setCouponIdList(List<Integer> couponIdList) {
+        this.couponIdList = couponIdList;
+    }
+
+    public boolean isRepeatPay() {
+        return isRepeatPay;
+    }
+
+    public void setRepeatPay(boolean repeatPay) {
+        isRepeatPay = repeatPay;
+    }
+
+    public boolean isUseBalancePayment() {
+        return isUseBalancePayment;
+    }
+
+    public void setUseBalancePayment(boolean useBalancePayment) {
+        isUseBalancePayment = useBalancePayment;
+    }
+
+    private Integer userId;
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
+    public String getPaymentChannel() {
+        return paymentChannel;
+    }
+
+    public void setPaymentChannel(String paymentChannel) {
+        this.paymentChannel = paymentChannel;
+    }
+
+    public String getPaymentBusinessChannel() {
+        return paymentBusinessChannel;
+    }
+
+    public void setPaymentBusinessChannel(String paymentBusinessChannel) {
+        this.paymentBusinessChannel = paymentBusinessChannel;
+    }
+}

+ 51 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/ActivityUserMapper.java

@@ -27,13 +27,63 @@ public class ActivityUserMapper {
 	
 	/**  */
 	private Integer givePracticeFlag = 0;
+
+	private Long paymentOrderId;
+
+	private Long vipGroupId;
+
+	private Long giveVipGroupId;
+
+	private Long practiceGroupId;
+
+	private Long givePracticeGroupId;
 	
 	/**  */
 	private java.util.Date createTime;
 	
 	/**  */
 	private java.util.Date updateTime;
-	
+
+	public Long getVipGroupId() {
+		return vipGroupId;
+	}
+
+	public void setVipGroupId(Long vipGroupId) {
+		this.vipGroupId = vipGroupId;
+	}
+
+	public Long getGiveVipGroupId() {
+		return giveVipGroupId;
+	}
+
+	public void setGiveVipGroupId(Long giveVipGroupId) {
+		this.giveVipGroupId = giveVipGroupId;
+	}
+
+	public Long getPracticeGroupId() {
+		return practiceGroupId;
+	}
+
+	public void setPracticeGroupId(Long practiceGroupId) {
+		this.practiceGroupId = practiceGroupId;
+	}
+
+	public Long getGivePracticeGroupId() {
+		return givePracticeGroupId;
+	}
+
+	public void setGivePracticeGroupId(Long givePracticeGroupId) {
+		this.givePracticeGroupId = givePracticeGroupId;
+	}
+
+	public Long getPaymentOrderId() {
+		return paymentOrderId;
+	}
+
+	public void setPaymentOrderId(Long paymentOrderId) {
+		this.paymentOrderId = paymentOrderId;
+	}
+
 	public void setId(Integer id){
 		this.id = id;
 	}

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/PracticeGroup.java

@@ -87,9 +87,20 @@ public class PracticeGroup {
 	@ApiModelProperty(value = "课时总数")
 	private Integer allCourseNum;
 
+	@ApiModelProperty(value = "学员购买的活动已课程关联")
+	private Integer activityUserMapperId;
+
 	@ApiModelProperty(value = "总金额",required = false)
 	private BigDecimal totalPrice = BigDecimal.ZERO;
 
+	public Integer getActivityUserMapperId() {
+		return activityUserMapperId;
+	}
+
+	public void setActivityUserMapperId(Integer activityUserMapperId) {
+		this.activityUserMapperId = activityUserMapperId;
+	}
+
 	public BigDecimal getTotalPrice() {
 		return totalPrice;
 	}

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/VipGroup.java

@@ -141,6 +141,17 @@ public class VipGroup {
 
 	private int enableDelete;
 
+	@ApiModelProperty(value = "学员购买的活动明细id")
+	private Integer activityUserMapperId;
+
+	public Integer getActivityUserMapperId() {
+		return activityUserMapperId;
+	}
+
+	public void setActivityUserMapperId(Integer activityUserMapperId) {
+		this.activityUserMapperId = activityUserMapperId;
+	}
+
 	public Integer getEnableDelete() {
 		return enableDelete;
 	}

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/PracticeGroupService.java

@@ -343,4 +343,13 @@ public interface PracticeGroupService extends BaseService<Long, PracticeGroup> {
     * @date 2021/10/11 19:17
     */
     Object createActivityPracticeGroup(PracticeGroupApplyDto practiceGroupApplyDto);
+
+    /**
+    * @description: 购买指导老师创建的网管课
+     * @param practiceGroupBuyParams
+    * @return java.lang.Object
+    * @author zx
+    * @date 2021/10/12 18:09
+    */
+    Object buyTeacherPracticeGroup(PracticeGroupBuyParamsDto practiceGroupBuyParams) throws Exception;
 }

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

@@ -203,11 +203,11 @@ public interface StudentPaymentOrderService extends BaseService<Long, StudentPay
     /**
     * @description: 活动赠送课程,或者会员
      * @param vipGroupActivityId
- * @param userId
- * @param paymentOrderId
+     * @param userId
+     * @param paymentOrderId
     * @return void
     * @author zx
     * @date 2021/10/11 10:36
     */
-    void activityGive(Integer vipGroupActivityId,Integer userId,Long paymentOrderId);
+    Integer activityGive(Integer vipGroupActivityId,Integer userId,Long paymentOrderId,Long vipGroupId,Long practiceGroupId);
 }

+ 138 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PracticeGroupServiceImpl.java

@@ -35,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.util.CollectionUtils;
@@ -3687,7 +3688,8 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         }
         PracticeGroup practiceGroup = practiceGroupDao.get(Long.valueOf(order.getMusicGroupId()));
         if (order.getStatus().equals(DealStatusEnum.SUCCESS)) {
-            studentPaymentOrderService.activityGive(practiceGroup.getVipGroupActivityId(),order.getUserId(),order.getId());
+            Integer activityUserMapperId = studentPaymentOrderService.activityGive(practiceGroup.getVipGroupActivityId(), order.getUserId(), order.getId(), null, practiceGroup.getId());
+            practiceGroup.setActivityUserMapperId(activityUserMapperId);
             courseScheduleDao.updateGroupCourseLock(order.getMusicGroupId(), GroupType.PRACTICE, 0);
         } else {
             if (Objects.nonNull(order.getBalancePaymentAmount()) && order.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
@@ -4736,4 +4738,139 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
         courseScheduleService.checkNewCourseSchedules(courseSchedules, false,false);
         return BaseController.succeed(applyBaseInfo.getAuditStatus().getCode());
     }
+
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+    public Object buyTeacherPracticeGroup(PracticeGroupBuyParamsDto practiceGroupBuyParams) throws Exception {
+        SysUser user = sysUserFeignService.queryUserInfo();
+        if(user == null){
+            throw new BizException("用户信息获取失败");
+        }
+        ClassGroup classGroup = classGroupDao.findByMusicGroupAndType(practiceGroupBuyParams.getPracticeGroupId().toString(),ClassGroupTypeEnum.PRACTICE.getCode());
+
+        classGroup = classGroupDao.lockClassGroup(classGroup.getId());
+
+        if(Objects.isNull(classGroup)){
+            throw new BizException("课程信息错误");
+        }
+
+        Date date=new Date();
+
+        PracticeGroup practiceGroup = practiceGroupDao.get(practiceGroupBuyParams.getPracticeGroupId());
+
+        if(classGroup.getStudentNum() > 0){
+            int i = studentPaymentOrderDao.countGroupOrderWithoutFailed(practiceGroupBuyParams.getPracticeGroupId().toString(),GroupType.PRACTICE);
+            if(i <= 0){
+                throw new BizException("该课程已经无法通过购买加入,请联系教务老师!");
+            }
+        }
+
+        VipGroupActivity vipGroupActivity = null;
+        if(Objects.nonNull(practiceGroup.getVipGroupActivityId())){
+            vipGroupActivity = vipGroupActivityDao.get(practiceGroup.getVipGroupActivityId().intValue());
+        }
+
+        if(Objects.nonNull(vipGroupActivity) && Objects.nonNull(vipGroupActivity.getStudentMaxUsedTimes()) && vipGroupActivity.getStudentMaxUsedTimes() != -1){
+            int useNum = activityUserMapperDao.countActivityBuyNum(vipGroupActivity.getId(),user.getId());
+            if(useNum >= vipGroupActivity.getStudentMaxUsedTimes()){
+                throw new BizException("您已超过该活动购买次数限制", vipGroupActivity.getStudentMaxUsedTimes());
+            }
+        }
+
+        if(practiceGroup.getPaymentExpireDate().before(date)){
+            throw new BizException("该课程已结束报名!");
+        }
+        if(practiceGroup.getStudentId() != user.getId()){
+            throw new BizException("您无法购买此课程");
+        }
+
+        List<CourseSchedule> courseSchedules = JSON.parseArray(practiceGroup.getCourseScheduleJson(),CourseSchedule.class);
+        courseScheduleService.checkNewCourseSchedules(courseSchedules,false,false);
+
+        StudentPaymentOrder studentPaymentOrder=sysCouponCodeService.use(practiceGroupBuyParams.getCouponIdList(),practiceGroup.getTotalPrice(),true);
+        studentPaymentOrder.setUserId(user.getId());
+        studentPaymentOrder.setGroupType(GroupType.PRACTICE);
+        String orderNo = idGeneratorService.generatorId("payment") + "";
+        studentPaymentOrder.setOrderNo(orderNo);
+        studentPaymentOrder.setStatus(DealStatusEnum.ING);
+        studentPaymentOrder.setType(OrderTypeEnum.PRACTICE_GROUP_BUY);
+        studentPaymentOrder.setMusicGroupId(practiceGroup.getId().toString());
+        studentPaymentOrder.setClassGroupId(classGroup.getId());
+        studentPaymentOrder.setOrganId(practiceGroup.getOrganId());
+        studentPaymentOrder.setVersion(0);
+        studentPaymentOrderDao.insert(studentPaymentOrder);
+
+        BigDecimal amount=studentPaymentOrder.getActualAmount();
+        BigDecimal balance = BigDecimal.ZERO;
+        if(practiceGroupBuyParams.isUseBalancePayment() || amount.doubleValue() == 0){
+            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(user.getId());
+            if(userCashAccount == null){
+                throw new BizException("用户账户找不到");
+            }
+            studentPaymentOrder.setPaymentChannel("BALANCE");
+            if(userCashAccount.getBalance().subtract(amount).doubleValue() >= 0){
+                studentPaymentRouteOrderService.addRouteOrder(orderNo, practiceGroup.getOrganId(), practiceGroup.getTotalPrice());
+                // 更新订单信息
+                studentPaymentOrder.setActualAmount(new BigDecimal(0));
+                studentPaymentOrder.setBalancePaymentAmount(amount);
+                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
+                studentPaymentOrder.setUpdateTime(date);
+                studentPaymentOrder.setOrganId(practiceGroup.getOrganId());
+                studentPaymentOrder.setRoutingOrganId(practiceGroup.getOrganId());
+
+                this.orderCallback(studentPaymentOrder);
+
+                sysUserCashAccountService.updateBalance(user.getId(), amount.negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,"网管课购买");
+
+                Map<String,Object> result=new HashMap<>();
+                result.put("orderNo",studentPaymentOrder.getOrderNo());
+
+                return result;
+            }else{
+                if (userCashAccount.getBalance().doubleValue() > 0) {
+                    balance = userCashAccount.getBalance();
+                    sysUserCashAccountService.updateBalance(user.getId(), balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "网管课购买");
+                    amount = amount.subtract(userCashAccount.getBalance());
+                    studentPaymentOrder.setActualAmount(amount);
+                    studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
+                } else {
+                    studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
+                }
+            }
+        }
+        if(!"36".equals(user.getOrganId())){
+            try {
+                contractService.register(user.getId(),user.getRealName(),user.getIdCardNo(),user.getPhone());
+            } catch (Exception e) {
+                LOGGER.error("[{}]小课购买协议生成错误:{}", practiceGroup.getId(), e.getCause());
+            }
+        }
+
+        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
+        //分类费用 course,instrument,accessories,other
+        Map<String, BigDecimal> classFee = new HashMap<>();
+        classFee.put("course",amount);
+        classFee.put("instrument",BigDecimal.ZERO);
+        classFee.put("accessories",BigDecimal.ZERO);
+        classFee.put("other",BigDecimal.ZERO);
+        Map<String,Object> payMap = payService.getPayMap(
+                amount,
+                balance,
+                orderNo,
+                baseApiUrl+"/api-student/studentOrder/notify",
+                baseApiUrl+"/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
+                "网管课购买",
+                practiceGroup.getName(),
+                practiceGroup.getOrganId(),
+                "practiceBuy"
+        );
+
+        studentPaymentOrder.setOrganId(practiceGroup.getOrganId());
+        studentPaymentOrder.setRoutingOrganId(practiceGroup.getOrganId());
+        studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
+        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
+        studentPaymentOrder.setUpdateTime(date);
+        studentPaymentOrderService.update(studentPaymentOrder);
+        return payMap;
+    }
 }

+ 18 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -105,6 +105,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     @Autowired
     private VipGroupActivityDao vipGroupActivityDao;
     @Autowired
+    private ActivityUserMapperDao activityUserMapperDao;
+    @Autowired
     private StudentService studentService;
 
     @Override
@@ -666,7 +668,6 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
 		if (StringUtils.isBlank(transNo)) {
 			return PayStatus.FAILED;
 		}
-
 		if (StringUtils.equals(paymentChannel, "ADAPAY")) {
 			Map<String, Object> payment = Payment.queryPayment(transNo);
 			String status = (String) payment.get("status");
@@ -712,9 +713,21 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    public void activityGive(Integer vipGroupActivityId, Integer userId, Long paymentOrderId) {
+    @Transactional(rollbackFor = Exception.class)
+    public Integer activityGive(Integer vipGroupActivityId, Integer userId, Long paymentOrderId,Long vipGroupId,Long practiceGroupId) {
+        Integer activityUserMapperId = null;
         if(vipGroupActivityId != null){
             ActivityUserMapper activityUserMapper = new ActivityUserMapper();
+            activityUserMapper.setVipGroupId(vipGroupId);
+            activityUserMapper.setPracticeGroupId(practiceGroupId);
+            activityUserMapper.setPaymentOrderId(paymentOrderId);
+            activityUserMapper.setUserId(userId);
+            activityUserMapper.setActivityId(vipGroupActivityId);
+            if(vipGroupId != null){
+                activityUserMapper.setVipFlag(2);
+            }else {
+                activityUserMapper.setPracticeFlag(2);
+            }
             VipGroupActivity activity = vipGroupActivityDao.get(vipGroupActivityId);
             //是否赠送课程
             if(activity.getGiveCourseNum() > 0){
@@ -724,6 +737,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                     activityUserMapper.setGivePracticeFlag(1);
                 }
             }
+            activityUserMapperDao.insert(activityUserMapper);
+            activityUserMapperId = activityUserMapper.getId();
             //是否赠送会员(会员立即生效)
             if(activity.getMemberTime() > 0){
                 Date now = new Date();
@@ -802,5 +817,6 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 studentService.updateMemberRank(cloudTeacherOrder, periodEnum);
             }
         }
+        return activityUserMapperId;
     }
 }

+ 3 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -2842,8 +2842,9 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		}
 		VipGroup vipGroup = vipGroupDao.get(vipGroupId);
 		try {
-			studentPaymentOrderService.activityGive(vipGroup.getVipGroupActivityId(),userId,studentPaymentOrder.getId());
-			if(classGroup.getDelFlag()==1){
+			Integer activityUserMapperId = studentPaymentOrderService.activityGive(vipGroup.getVipGroupActivityId(), userId, studentPaymentOrder.getId(), vipGroupId, null);
+			vipGroup.setActivityUserMapperId(activityUserMapperId);
+			if(classGroup.getDelFlag() == 1){
 				updateVipGroupStudentNumAndStatus(vipGroupId, classGroup,0,true);
 			}
 		} catch (Exception e) {

+ 52 - 24
mec-biz/src/main/resources/config/mybatis/ActivityUserMapperMapper.xml

@@ -14,6 +14,11 @@
 		<result column="give_vip_flag_" property="giveVipFlag" />
 		<result column="practice_flag_" property="practiceFlag" />
 		<result column="give_practice_flag_" property="givePracticeFlag" />
+		<result column="payment_order_id_" property="paymentOrderId" />
+		<result column="vip_group_id_" property="vipGroupId" />
+		<result column="give_vip_group_id_" property="giveVipGroupId" />
+		<result column="practice_group_id_" property="practiceGroupId" />
+		<result column="give_practice_group_id_" property="givePracticeGroupId" />
 		<result column="create_time_" property="createTime" />
 		<result column="update_time_" property="updateTime" />
 	</resultMap>
@@ -31,34 +36,52 @@
 	<!-- 向数据库增加一条记录 -->
 	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ActivityUserMapper" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
 		INSERT INTO activity_user_mapper (activity_id_,user_id_,vip_flag_,give_vip_flag_,
-		                                  practice_flag_,give_practice_flag_,create_time_,update_time_)
+		                                  practice_flag_,give_practice_flag_,create_time_,update_time_,payment_order_id_,
+										  vip_group_id_,give_vip_group_id_,practice_group_id_,give_practice_group_id_)
 		                                  VALUES(#{activityId},#{userId},#{vipFlag},#{giveVipFlag},#{practiceFlag},
-		                                         #{givePracticeFlag},NOW(),NOW())
+		                                         #{givePracticeFlag},NOW(),NOW(),#{paymentOrderId},#{vipGroupId},
+		                                         #{giveVipGroupId},#{practiceGroupId},#{givePracticeGroupId})
 	</insert>
 	
 	<!-- 根据主键查询一条记录 -->
 	<update id="update" parameterType="com.ym.mec.biz.dal.entity.ActivityUserMapper">
-		UPDATE activity_user_mapper <set>
-		<if test="userId != null">
-		user_id_ = #{userId},
-		</if>
-		<if test="givePracticeFlag != null">
-		give_practice_flag_ = #{givePracticeFlag},
-		</if>
-		<if test="giveVipFlag != null">
-		give_vip_flag_ = #{giveVipFlag},
-		</if>
-		<if test="vipFlag != null">
-		vip_flag_ = #{vipFlag},
-		</if>
-		<if test="activityId != null">
-		activity_id_ = #{activityId},
-		</if>
-		<if test="practiceFlag != null">
-		practice_flag_ = #{practiceFlag},
-		</if>
-		update_time_ = NOW()
-	</set> WHERE id_ = #{id}
+		UPDATE activity_user_mapper
+		<set>
+			<if test="vipGroupId != null">
+				vip_group_id_ = #{vipGroupId},
+			</if>
+			<if test="giveVipGroupId != null">
+				give_vip_group_id_ = #{giveVipGroupId},
+			</if>
+			<if test="practiceGroupId != null">
+				practice_group_id_ = #{practiceGroupId},
+			</if>
+			<if test="givePracticeGroupId != null">
+				give_practice_group_id_ = #{givePracticeGroupId},
+			</if>
+			<if test="paymentOrderId != null">
+				payment_order_id_ = #{paymentOrderId},
+			</if>
+			<if test="userId != null">
+				user_id_ = #{userId},
+			</if>
+			<if test="givePracticeFlag != null">
+				give_practice_flag_ = #{givePracticeFlag},
+			</if>
+			<if test="giveVipFlag != null">
+				give_vip_flag_ = #{giveVipFlag},
+			</if>
+			<if test="vipFlag != null">
+				vip_flag_ = #{vipFlag},
+			</if>
+			<if test="activityId != null">
+				activity_id_ = #{activityId},
+			</if>
+			<if test="practiceFlag != null">
+				practice_flag_ = #{practiceFlag},
+			</if>
+			update_time_ = NOW()
+		</set>WHERE id_ = #{id}
 	</update>
 	
 	<!-- 根据主键删除一条记录 -->
@@ -68,7 +91,8 @@
 	
 	<!-- 分页查询 -->
 	<select id="queryPage" resultMap="ActivityUserMapper" parameterType="map">
-		SELECT * FROM activity_user_mapper ORDER BY id_ <include refid="global.limit"/>
+		SELECT * FROM activity_user_mapper ORDER BY id_
+		<include refid="global.limit"/>
 	</select>
 	
 	<!-- 查询当前表的总记录数 -->
@@ -92,4 +116,8 @@
 		</if>
 		GROUP BY user_id_
 	</select>
+	<select id="countActivityBuyNum" resultType="java.lang.Integer">
+		SELECT count(id_) FROM activity_user_mapper
+		WHERE activity_id_ = #{activityId} AND user_id_ = #{userId}
+	</select>
 </mapper>

+ 8 - 4
mec-biz/src/main/resources/config/mybatis/PracticeGroupMapper.xml

@@ -33,6 +33,7 @@
         <result column="registration_start_time_" property="registrationStartTime"/>
         <result column="course_num_" property="allCourseNum"/>
         <result column="total_price_" property="totalPrice"/>
+        <result column="activity_user_mapper_id_" property="activityUserMapperId"/>
     </resultMap>
 
     <resultMap id="PracticeCourseDto" type="com.ym.mec.biz.dal.dto.PracticeCourseDto" extends="PracticeGroup">
@@ -71,6 +72,9 @@
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.PracticeGroup">
         UPDATE practice_group
         <set>
+            <if test="activityUserMapperId != null">
+                activity_user_mapper_id_ = #{activityUserMapperId},
+            </if>
             <if test="totalPrice != null">
                 total_price_ = #{totalPrice},
             </if>
@@ -157,15 +161,15 @@
     <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.PracticeGroup" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
         INSERT INTO practice_group
-        (id_,name_,type_,subject_id_,user_id_,student_id_,single_class_minutes_,
+        (name_,type_,subject_id_,user_id_,student_id_,single_class_minutes_,
          organ_id_,courses_start_date_,courses_expire_date_,create_time_,update_time_,
          memo_,buy_months_,drill_times_on_week_,drill_times_json_,group_status_,
-         be_renew_group_id_,educational_teacher_id_,payment_expire_date_,registration_start_time_,course_num_,total_price_)
-        VALUES(#{id},#{name},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+         be_renew_group_id_,educational_teacher_id_,payment_expire_date_,registration_start_time_,course_num_,total_price_,activity_user_mapper_id_)
+        VALUES(#{name},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
                #{subjectId},#{userId},#{studentId},#{singleClassMinutes},#{organId},#{coursesStartDate},
                #{coursesExpireDate},NOW(),NOW(),#{memo},#{buyMonths},#{drillTimesOnWeek},#{drillTimesJson},
                #{groupStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{beRenewGroupId},
-               #{educationalTeacherId},#{paymentExpireDate},#{registrationStartTime},#{allCourseNum},#{totalPrice})
+               #{educationalTeacherId},#{paymentExpireDate},#{registrationStartTime},#{allCourseNum},#{totalPrice},#{activityUserMapperId})
     </insert>
 
     <select id="getUserFreePracticeGroup" resultMap="PracticeGroup">

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

@@ -47,6 +47,7 @@
         <result column="educational_teacher_id_" property="educationalTeacherId"/>
         <result column="vip_group_category_name_" property="vipGroupCategoryName"/>
         <result column="educational_teacher_name_" property="educationalTeacherName" />
+        <result column="activity_user_mapper_id_" property="activityUserMapperId" />
     </resultMap>
 
     <resultMap type="com.ym.mec.biz.dal.entity.School" id="School">
@@ -232,20 +233,27 @@
     <!-- 向数据库增加一条记录 -->
     <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.VipGroup" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
-        <!--
-        <selectKey resultClass="int" keyProperty="id" >
-        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
-        </selectKey>
-        -->
         INSERT INTO vip_group
-        (id_,user_id_,single_class_minutes_,payment_expire_date_,courses_expire_date_,create_time_,update_time_,teacher_school_id_,online_classes_num_,offline_classes_num_,registration_start_time_,name_,organ_id_list_,vip_group_activity_id_,group_status_,online_classes_unit_price_,offline_classes_unit_price_,total_price_,give_teach_mode_,vip_group_category_id_,organ_id_,stop_reason_,memo_,audit_status_,courses_start_date,course_schedules_json_,student_id_list_)
-        VALUES(#{id},#{userId},#{singleClassMinutes},#{paymentExpireDate},#{coursesExpireDate},now(),now(),#{teacherSchoolId},#{onlineClassesNum},#{offlineClassesNum},#{registrationStartTime},#{name},#{organIdList},#{vipGroupActivityId},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{onlineClassesUnitPrice},#{offlineClassesUnitPrice},#{totalPrice},#{giveTeachMode},#{vipGroupCategoryId},#{organId},#{stopReason},#{memo},#{auditStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{courseStartDate},#{courseSchedulesJson},#{studentIdList})
+        (id_,user_id_,single_class_minutes_,payment_expire_date_,courses_expire_date_,create_time_,
+         update_time_,teacher_school_id_,online_classes_num_,offline_classes_num_,registration_start_time_,
+         name_,organ_id_list_,vip_group_activity_id_,group_status_,online_classes_unit_price_,offline_classes_unit_price_,
+         total_price_,give_teach_mode_,vip_group_category_id_,organ_id_,stop_reason_,memo_,audit_status_,courses_start_date,
+         course_schedules_json_,student_id_list_,activity_user_mapper_id_)
+        VALUES(#{id},#{userId},#{singleClassMinutes},#{paymentExpireDate},#{coursesExpireDate},now(),now(),#{teacherSchoolId},
+               #{onlineClassesNum},#{offlineClassesNum},#{registrationStartTime},#{name},#{organIdList},#{vipGroupActivityId},
+               #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{onlineClassesUnitPrice},#{offlineClassesUnitPrice},
+               #{totalPrice},#{giveTeachMode},#{vipGroupCategoryId},#{organId},#{stopReason},#{memo},
+               #{auditStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{courseStartDate},#{courseSchedulesJson},#{studentIdList},#{activityUserMapperId})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
     <update id="update" parameterType="com.ym.mec.biz.dal.entity.VipGroup">
         UPDATE vip_group
         <set>
+            <if test="activityUserMapperId != null">
+                activity_user_mapper_id_
+                activity_user_mapper_id_ = #{activityUserMapperId},
+            </if>
             <if test="paymentExpireDate != null">
                 payment_expire_date_ = #{paymentExpireDate},
             </if>

+ 37 - 4
mec-student/src/main/java/com/ym/mec/student/controller/PracticeGroupController.java

@@ -5,12 +5,12 @@ import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.PracticeCourseDto;
 import com.ym.mec.biz.dal.dto.PracticeGroupBuyDto;
+import com.ym.mec.biz.dal.dto.PracticeGroupBuyParamsDto;
+import com.ym.mec.biz.dal.dto.VipGroupBuyParamsDto;
 import com.ym.mec.biz.dal.entity.*;
-import com.ym.mec.biz.dal.enums.GroupStatusEnum;
-import com.ym.mec.biz.dal.enums.GroupType;
-import com.ym.mec.biz.dal.enums.MessageTypeEnum;
-import com.ym.mec.biz.dal.enums.PracticeGroupType;
+import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.service.PracticeGroupService;
+import com.ym.mec.biz.service.StudentPaymentOrderService;
 import com.ym.mec.biz.service.SysConfigService;
 import com.ym.mec.biz.service.SysMessageService;
 import com.ym.mec.common.controller.BaseController;
@@ -58,6 +58,8 @@ public class PracticeGroupController extends BaseController {
     private CourseScheduleEvaluateDao courseScheduleEvaluateDao;
     @Autowired
     private StudentDao studentDao;
+    @Autowired
+    private StudentPaymentOrderService studentPaymentOrderService;
 
 //    private static final Set<Integer> ENABLE_APPLY_ORGANIDS = new HashSet<>(Arrays.asList(new Integer[]{28,34,37}));
 
@@ -264,6 +266,37 @@ public class PracticeGroupController extends BaseController {
         }
     }
 
+    @ApiOperation(value = "购买指导老师创建的网管课")
+    @PostMapping("/buyTeacherPracticeGroup")
+    @AuditLogAnnotation(operateName = "购买指导老师创建的网管课")
+    public Object buyTeacherPracticeGroup(PracticeGroupBuyParamsDto practiceGroupBuyParams) throws Exception {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (null == sysUser) {
+            return failed(HttpStatus.FORBIDDEN, "请登录");
+        }
+        if(!practiceGroupBuyParams.isRepeatPay()){
+            // 判断是否存在支付中的记录
+            List<StudentPaymentOrder> list = studentPaymentOrderService
+                    .queryByCondition(GroupType.PRACTICE,
+                            practiceGroupBuyParams.getPracticeGroupId().toString(),
+                            sysUser.getId(),
+                            DealStatusEnum.ING,
+                            OrderTypeEnum.PRACTICE_GROUP_BUY);
+            if (list.size() > 0) {
+                StudentPaymentOrder applyOrder = list.get(list.size() - 1);
+                // 查询订单状态
+                PayStatus payStatus = studentPaymentOrderService.queryPayStatus(applyOrder.getPaymentChannel(), applyOrder.getOrderNo(), applyOrder.getTransNo());
+                if(payStatus == PayStatus.SUCCESSED){
+                    throw new BizException("订单已支付成功,请勿重复支付");
+                }else if(payStatus == PayStatus.PAYING){
+                    throw new BizException("订单还在交易中,请稍后重试");
+                }
+                return failed(HttpStatus.CONTINUE, "您有待支付的订单");
+            }
+        }
+        return succeed(practiceGroupService.buyTeacherPracticeGroup(practiceGroupBuyParams));
+    }
+
     @ApiOperation("获取用户历史购买的陪练课")
     @GetMapping(value = "/findUserHistoryBuyPracticeGroups")
     public HttpResponseResult findUserHistoryBuyPracticeGroups(Long groupId, PracticeGroupType type){