lrf 2 лет назад
Родитель
Сommit
a4691604dd
2 измененных файлов с 13 добавлено и 3 удалено
  1. 12 0
      app/service/apply/tryLessonApply.js
  2. 1 3
      app/service/business/lessonStudent.js

+ 12 - 0
app/service/apply/tryLessonApply.js

@@ -9,6 +9,18 @@ class TryLessonApplyService extends CrudService {
   constructor(ctx) {
     super(ctx, 'trylessonapply');
     this.model = this.ctx.model.Apply.TryLessonApply;
+    this.lessonStudentService = this.ctx.service.business.lessonStudent;
+  }
+  // 处理审核成功的情况
+  async afterUpdate(filter, body, data) {
+    const { status } = data;
+    // 审核不通过, 不处理
+    if (status !== '1') return data;
+    // 通过,则需要在 lessonStudent中添加数据
+    const obj = _.pick(data, [ 'school_id', 'lesson_id', 'student_id' ]);
+    obj.is_try = '1';
+    await this.lessonStudentService.create(obj);
+    return data;
   }
 }
 

+ 1 - 3
app/service/business/lessonStudent.js

@@ -17,10 +17,8 @@ class LessonStudentService extends CrudService {
     const data = await this.model.findOne({ lesson_id, school_id, student_id });
     // 数据已存在,检查是否是申请试听
     if (data) {
-      const { is_try, try_status } = data;
+      const { is_try } = data;
       if (is_try === '0') throw new BusinessError(ErrorCode.DATA_EXISTED, '您已经报名');
-      else if (try_status === '0') throw new BusinessError(ErrorCode.DATA_EXISTED, '您的试听申请正在审核中');
-      else if (try_status === '1') throw new BusinessError(ErrorCode.DATA_EXISTED, '您的试听申请已通过,无需重复申请');
     }
     // 数据不存在
     const { is_try } = body;