lrf пре 2 година
родитељ
комит
94b7cfdca3

+ 3 - 5
app/controller/business/config/.lessonPrivate.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['school_id', 'title', 'coach_id', 'money', 'limit', 'student', 'time_start', 'time_end', 'status', 'brief'],
+    requestBody: ['school_id', 'title', 'time_start', 'time_end', 'status', 'brief', 'type', 'limit'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['school_id', 'title', 'coach_id', 'money', 'limit', 'student', 'time_start', 'time_end', 'status', 'brief'],
+    requestBody: ['school_id', 'title', 'time_start', 'time_end', 'status', 'brief', 'type', 'limit'],
   },
   show: {
     parameters: {
@@ -22,13 +22,11 @@ module.exports = {
         'meta.createdAt@start': 'meta.createdAt@start',
         'meta.createdAt@end': 'meta.createdAt@end',
         school_id: 'school_id',
-        coach_id: 'coach_id',
-        student: 'student',
         'time_start@start': 'time_start@start',
         'time_start@end': 'time_start@end',
         'time_end@start': 'time_end@start',
         'time_end@end': 'time_end@end',
-        status: 'status',
+        type: 'type',
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 3 - 9
app/controller/business/config/.lessonPublic.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['school_id', 'title', 'coach_id', 'limit', 'student', 'time_start', 'time_end', 'status', 'brief'],
+    requestBody: ['lesson_id', 'school_id', 'coach_id', 'money'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['school_id', 'title', 'coach_id', 'limit', 'student', 'time_start', 'time_end', 'status', 'brief'],
+    requestBody: ['lesson_id', 'school_id', 'coach_id', 'money'],
   },
   show: {
     parameters: {
@@ -21,15 +21,9 @@ module.exports = {
       query: {
         'meta.createdAt@start': 'meta.createdAt@start',
         'meta.createdAt@end': 'meta.createdAt@end',
+        lesson_id: 'lesson_id',
         school_id: 'school_id',
-        title: 'title',
         coach_id: 'coach_id',
-        student: 'student',
-        'time_start@start': 'time_start@start',
-        'time_start@end': 'time_start@end',
-        'time_end@start': 'time_end@start',
-        'time_end@end': 'time_end@end',
-        status: 'status',
       },
       // options: {
       //   "meta.state": 0 // 默认条件

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

@@ -0,0 +1,42 @@
+module.exports = {
+  create: {
+    requestBody: ['lesson_id', 'school_id', 'student_id', 'money', 'is_try'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['lesson_id', 'school_id', 'student_id', 'money', 'is_try'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        'meta.createdAt@start': 'meta.createdAt@start',
+        'meta.createdAt@end': 'meta.createdAt@end',
+        lesson_id: 'lesson_id',
+        school_id: 'school_id',
+        student_id: 'student_id',
+        money: 'money',
+        is_try: 'is_try',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/business/lesson.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.lesson.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+//
+class LessonController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.business.lesson;
+  }
+}
+module.exports = CrudController(LessonController, meta);

+ 13 - 0
app/controller/business/lessonCoach.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.lessonCoach.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+//
+class LessonCoachController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.business.lessonCoach;
+  }
+}
+module.exports = CrudController(LessonCoachController, meta);

+ 0 - 13
app/controller/business/lessonPrivate.js

@@ -1,13 +0,0 @@
-'use strict';
-const meta = require('./config/.lessonPrivate.js');
-const Controller = require('egg').Controller;
-const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
-
-//
-class LessonPrivateController extends Controller {
-  constructor(ctx) {
-    super(ctx);
-    this.service = this.ctx.service.business.lessonPrivate;
-  }
-}
-module.exports = CrudController(LessonPrivateController, meta);

+ 0 - 13
app/controller/business/lessonPublic.js

@@ -1,13 +0,0 @@
-'use strict';
-const meta = require('./config/.lessonPublic.js');
-const Controller = require('egg').Controller;
-const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
-
-// 
-class LessonPublicController extends Controller {
-  constructor(ctx) {
-    super(ctx);
-    this.service = this.ctx.service.business.lessonPublic;
-  }
-}
-module.exports = CrudController(LessonPublicController, meta);

+ 13 - 0
app/controller/business/lessonStudent.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.lessonStudent.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+//
+class LessonStudentController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.business.lessonStudent;
+  }
+}
+module.exports = CrudController(LessonStudentController, meta);

+ 7 - 12
app/model/business/lessonPublic.js

@@ -2,31 +2,26 @@
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
-// 课程表-公开课
-const lessonPublic = {
+// 课程表
+const lesson = {
   school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
   title: { type: String, required: false, zh: '课程标题' }, //
-  coach_id: { type: Array, required: false, zh: '教练id' }, //
-  limit: { type: Number, required: false, zh: '人数上限' }, //
-  student: { type: Array, required: false, zh: '上课学员', ref: 'Student', getProp: [ 'name' ] }, //
   time_start: { type: String, required: false, zh: '开始上课时间' }, //
   time_end: { type: String, required: false, zh: '结束时间' }, //
-  status: { type: String, required: false, zh: '状态' }, // 0-准备中;1-报名中;2-报名结束;3-已开课;4-已结课;-1-停课
+  limit: { type: Number, zh: '人数上限' },
+  type: { type: String, required: false, zh: '课程类型', default: '0' }, // 0:公开课;1私教课
+  status: { type: String, required: false, zh: '状态', default: '0' }, // 0-准备中;1-报名中;2-报名结束;3-已开课;4-已结课;-1-停课
   brief: { type: String, required: false, zh: '简介' }, //
 };
-const schema = new Schema(lessonPublic, { toJSON: { virtuals: true } });
+const schema = new Schema(lesson, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.index({ school_id: 1 });
-schema.index({ title: 1 });
-schema.index({ coach_id: 1 });
-schema.index({ student: 1 });
 schema.index({ time_start: 1 });
 schema.index({ time_end: 1 });
-schema.index({ status: 1 });
 
 schema.plugin(metaPlugin);
 module.exports = app => {
   const { mongoose } = app;
-  return mongoose.model('LessonPublic', schema, 'lessonPublic');
+  return mongoose.model('Lesson', schema, 'lesson');
 };

+ 23 - 0
app/model/business/lessonCoach.js

@@ -0,0 +1,23 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 课程表-教练
+const lessonCoach = {
+  lesson_id: { type: String, required: false, zh: '课程id', ref: 'Lesson', getProp: [ 'title' ] }, //
+  school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
+  coach_id: { type: String, required: false, zh: '教练id', ref: 'Coach', getProp: [ 'name' ] }, //
+  money: { type: Number, required: false, zh: '课时费' }, //
+};
+const schema = new Schema(lessonCoach, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ lesson_id: 1 });
+schema.index({ school_id: 1 });
+schema.index({ coach_id: 1 });
+
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('LessonCoach', schema, 'lessonCoach');
+};

+ 0 - 32
app/model/business/lessonPrivate.js

@@ -1,32 +0,0 @@
-'use strict';
-const Schema = require('mongoose').Schema;
-const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
-
-// 课程表-私教课
-const lessonPrivate = {
-  school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
-  title: { type: String, required: false, zh: '课程标题' }, //
-  coach_id: { type: String, required: false, zh: '教练id', ref: 'Coach', getProp: [ 'name' ] }, //
-  money: { type: Number, required: false, zh: '金额' }, //
-  limit: { type: Number, required: false, zh: '人数上限' }, //
-  student: { type: Array, required: false, zh: '上课学员' }, // 存学员id
-  time_start: { type: String, required: false, zh: '开始上课时间' }, //
-  time_end: { type: String, required: false, zh: '结束时间' }, //
-  status: { type: String, required: false, default: '0', zh: '状态' }, // 0-准备中;1-报名中;2-报名结束;3-已开课;4-已结课;-1-停课
-  brief: { type: String, required: false, zh: '简介' }, //
-};
-const schema = new Schema(lessonPrivate, { toJSON: { virtuals: true } });
-schema.index({ id: 1 });
-schema.index({ 'meta.createdAt': 1 });
-schema.index({ school_id: 1 });
-schema.index({ coach_id: 1 });
-schema.index({ student: 1 });
-schema.index({ time_start: 1 });
-schema.index({ time_end: 1 });
-schema.index({ status: 1 });
-
-schema.plugin(metaPlugin);
-module.exports = app => {
-  const { mongoose } = app;
-  return mongoose.model('LessonPrivate', schema, 'lessonPrivate');
-};

+ 27 - 0
app/model/business/lessonStudent.js

@@ -0,0 +1,27 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 课程表-学员
+const lessonStudent = {
+  lesson_id: { type: String, required: false, zh: '课程id', ref: 'Lesson', getProp: [ 'name' ] }, //
+  school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
+  student_id: { type: String, required: false, zh: '学生id', ref: 'Student', getProp: [ 'name' ] }, //
+  money: { type: String, required: false, zh: '缴费金额' }, //
+  is_try: { type: String, required: false, default: '0', zh: '是否试课' }, // 0:非试课;1:试课
+  try_status: { type: String, default: '0', zh: '试课审核状态' }, // 0:未审核;1:审核通过;2审核拒绝
+};
+const schema = new Schema(lessonStudent, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ lesson_id: 1 });
+schema.index({ school_id: 1 });
+schema.index({ student_id: 1 });
+schema.index({ money: 1 });
+schema.index({ is_try: 1 });
+
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('LessonStudent', schema, 'lessonStudent');
+};

+ 5 - 2
app/router.js

@@ -33,8 +33,11 @@ module.exports = app => {
   require('./z_router/relation/relationCoachSchool')(app); // 教练与学校关系
   require('./z_router/relation/relationStudentSchool')(app); // 学员与学校关系
   require('./z_router/relation/studentApplyForSchool')(app); // 学员入学申请
-  require('./z_router/business/lessonPrivate')(app); // 私教课
-  require('./z_router/business/lessonPublic')(app); // 公开课
+  // require('./z_router/business/lessonPrivate')(app); // 私教课
+  // require('./z_router/business/lessonPublic')(app); // 公开课
+  require('./z_router/business/lesson')(app); // 课程
+  require('./z_router/business/lessonCoach')(app); // 课程-教练
+  require('./z_router/business/lessonStudent')(app); // 课程-学员
   require('./z_router/business/coachInBill')(app); // 教练费明细
   require('./z_router/business/billApply')(app); // 教练费申请
 };

+ 15 - 0
app/service/business/coachInBill.js

@@ -9,6 +9,7 @@ class CoachInBillService extends CrudService {
   constructor(ctx) {
     super(ctx, 'coachinbill');
     this.model = this.ctx.model.Business.CoachInBill;
+    this.rcsModel = this.ctx.model.Relation.RelationCoachSchool;
   }
   // 查重,重了不加
   async beforeCreate(body) {
@@ -17,6 +18,20 @@ class CoachInBillService extends CrudService {
     if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '已经存在 该节课已经存在明细,请核对数据');
     return body;
   }
+  // 改工资
+  async afterCreate(body, data) {
+    const { money } = data;
+    const query = _.pick(data, [ 'school_id', 'coach_id' ]);
+    // 查学校与教练的关联数据
+    const rcsData = await this.rcsModel.findOne(query);
+    if (!rcsData) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到教练在该学校下任教的信息');
+    // 累加工资
+    let salary = _.get(rcsData, 'salary', 0);
+    salary += money;
+    rcsData.salary = salary;
+    await rcsData.save();
+    return data;
+  }
 }
 
 module.exports = CoachInBillService;

+ 34 - 0
app/service/business/lesson.js

@@ -0,0 +1,34 @@
+'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 LessonService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'lesson');
+    this.model = this.ctx.model.Business.Lesson;
+  }
+
+  // TODO:缺少:使用coach_id/student_id查询课程:教练/学生看自己的课程
+
+  // TODO:缺少:修改课程为下课状态,给教师结工资的问题
+
+  /**
+   * 处理下课的课程进行结算
+   * @param {Object} filter 修改条件
+   * @param {Object} body 修改内容
+   * @param {Object} data 修改后的结果
+   * @return {Object} 返回整理后的内容
+   */
+  async afterUpdate(filter, body, data) {
+    const { _id: lesson_id, type, status } = data;
+    if (status !== '4') return data;
+    // 公开课,每个教师都带着
+
+    return data;
+  }
+}
+
+module.exports = LessonService;

+ 15 - 0
app/service/business/lessonCoach.js

@@ -0,0 +1,15 @@
+'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 LessonCoachService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'lessoncoach');
+    this.model = this.ctx.model.Business.LessonCoach;
+  }
+}
+
+module.exports = LessonCoachService;

+ 4 - 4
app/service/business/lessonPublic.js

@@ -5,11 +5,11 @@ const _ = require('lodash');
 const assert = require('assert');
 
 // 
-class LessonPublicService extends CrudService {
+class LessonStudentService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'lessonpublic');
-    this.model = this.ctx.model.Business.LessonPublic;
+    super(ctx, 'lessonstudent');
+    this.model = this.ctx.model.Business.LessonStudent;
   }
 }
 
-module.exports = LessonPublicService;
+module.exports = LessonStudentService;

+ 3 - 3
app/z_router/business/lessonPublic.js

@@ -3,9 +3,9 @@
 const path = require('path');
 const regPath = path.resolve('app', 'public', 'routerRegister');
 const routerRegister = require(regPath);
-const rkey = 'lessonPublic';
-const ckey = 'business.lessonPublic';
-const keyZh = '公开课';
+const rkey = 'lesson';
+const ckey = 'business.lesson';
+const keyZh = '课';
 const routes = [
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },

+ 3 - 3
app/z_router/business/lessonPrivate.js

@@ -3,9 +3,9 @@
 const path = require('path');
 const regPath = path.resolve('app', 'public', 'routerRegister');
 const routerRegister = require(regPath);
-const rkey = 'lessonPrivate';
-const ckey = 'business.lessonPrivate';
-const keyZh = '私教课';
+const rkey = 'lessonCoach';
+const ckey = 'business.lessonCoach';
+const keyZh = '课程-教练';
 const routes = [
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },

+ 19 - 0
app/z_router/business/lessonStudent.js

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'lessonStudent';
+const ckey = 'business.lessonStudent';
+const keyZh = '课程-学员';
+const routes = [
+  { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
+  { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
+  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
+  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
+  { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
+];
+
+module.exports = app => {
+  routerRegister(app, routes, keyZh, rkey, ckey);
+};