lrf há 2 anos atrás
pai
commit
8f49848015

+ 3 - 0
app/controller/business/config/.lessonStudent.js

@@ -45,4 +45,7 @@ module.exports = {
   toComputed: {
     requestBody: ['!lesson_id', '!student_id'],
   },
+  checkCanUse: {
+    requestBody: ['!lesson_id', '!school_id', '!student_id'],
+  },
 };

+ 6 - 0
app/service/business/lessonStudent.js

@@ -14,6 +14,12 @@ class LessonStudentService extends CrudService {
     this.lessonModel = this.ctx.model.Business.Lesson;
   }
 
+  async checkCanUse({ school_id, student_id, lesson_id }) {
+    const num = await this.model.count({ school_id, student_id, lesson_id, $or: [{ is_try: '0', is_pay: { $ne: '-3' } }, { is_try: '1' }] });
+    if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '已存在有效的报名信息');
+    return true;
+  }
+
   async beforeCreate(body) {
     const { lesson_id, school_id, student_id } = body;
     // 检查是否已经有数据