|
@@ -4,12 +4,33 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const _ = require('lodash');
|
|
const _ = require('lodash');
|
|
const assert = require('assert');
|
|
const assert = require('assert');
|
|
|
|
|
|
-//
|
|
|
|
|
|
+//
|
|
class LessonStudentService extends CrudService {
|
|
class LessonStudentService extends CrudService {
|
|
constructor(ctx) {
|
|
constructor(ctx) {
|
|
super(ctx, 'lessonstudent');
|
|
super(ctx, 'lessonstudent');
|
|
this.model = this.ctx.model.Business.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;
|
|
module.exports = LessonStudentService;
|