lrf 2 lat temu
rodzic
commit
23b415b533

+ 0 - 35
app/service/business/lessonPrivate.js

@@ -1,35 +0,0 @@
-'use strict';
-const { CrudService } = require('naf-framework-mongoose-free/lib/service');
-const { BusinessError, ErrorCode } = require('naf-core').Error;
-const _ = require('lodash');
-const assert = require('assert');
-
-//
-class LessonPrivateService extends CrudService {
-  constructor(ctx) {
-    super(ctx, 'lessonprivate');
-    this.model = this.ctx.model.Business.LessonPrivate;
-    this.cibService = this.ctx.service.business.coachInBill;
-  }
-  /**
-   * 处理下课的课程进行结算
-   * @param {Object} filter 修改条件
-   * @param {Object} body 修改内容
-   * @param {Object} data 修改后的结果
-   * @return {Object} 返回整理后的内容
-   */
-  async afterUpdate(filter, body, data) {
-    const { status, limit, money, student, _id: lesson_id, school_id, coach_id } = data;
-    if (status !== '4') return data;
-    // 4 是下课,下了课,就给老师结钱
-    // 目前按学生人数进行结款,限制的人数不一定是上课的学生人数,可能会临时加人
-    const num = student.length;
-    const total = num * money;
-    // 添加明细,通过明细那边,将工资处理了,这边就不处理了.因为公开课那边也是一样这么做
-    const obj = { lesson_id, type: '1', school_id, coach_id, money: total };
-    await this.cibService.create(obj);
-    return data;
-  }
-}
-
-module.exports = LessonPrivateService;

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

@@ -4,12 +4,33 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
 
-// 
+//
 class LessonStudentService extends CrudService {
   constructor(ctx) {
     super(ctx, 'lessonstudent');
     this.model = this.ctx.model.Business.LessonStudent;
   }
+
+  async beforeCreate(body) {
+    const { lesson_id, school_id, student_id } = body;
+    // 检查是否已经有数据
+    const data = await this.model.findOne({ lesson_id, school_id, student_id });
+    // 数据已存在,检查是否是申请试听
+    if (data) {
+      const { is_try, try_status } = 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;
+    // 检查是否使用试听名额
+    if (is_try === '1') {
+      const num = await this.model.count({ student_id, is_try: '1' });
+      if (num > 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, '您已使用过免费试听的机会');
+    }
+    return body;
+  }
 }
 
 module.exports = LessonStudentService;