lrf 2 years ago
parent
commit
d27393b5c3

+ 45 - 0
app/controller/business/config/.lessonPrivate.js

@@ -0,0 +1,45 @@
+module.exports = {
+  create: {
+    requestBody: ['school_id', 'title', 'coach_id', 'money', 'limit', 'student', 'time_start', 'time_end', 'status', 'brief'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['school_id', 'title', 'coach_id', 'money', 'limit', 'student', 'time_start', 'time_end', 'status', 'brief'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        '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',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 8 - 4
app/controller/business/config/.lesson.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['title', 'school_id', 'coach_id', 'class_hour', 'money', 'type'],
+    requestBody: ['school_id', 'title', 'coach_id', 'limit', 'student', 'time_start', 'time_end', 'status', 'brief'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['title', 'school_id', 'coach_id', 'class_hour', 'money', 'type'],
+    requestBody: ['school_id', 'title', 'coach_id', 'limit', 'student', 'time_start', 'time_end', 'status', 'brief'],
   },
   show: {
     parameters: {
@@ -22,10 +22,14 @@ module.exports = {
         'meta.createdAt@start': 'meta.createdAt@start',
         'meta.createdAt@end': 'meta.createdAt@end',
         school_id: 'school_id',
+        title: 'title',
         coach_id: 'coach_id',
-        type: 'type',
         student: 'student',
-        title: 'title',
+        '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 // 默认条件

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

@@ -1,13 +0,0 @@
-'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/lessonPrivate.js

@@ -0,0 +1,13 @@
+'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);

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

@@ -0,0 +1,13 @@
+'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);

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

@@ -1,27 +0,0 @@
-'use strict';
-const Schema = require('mongoose').Schema;
-const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
-
-// 课程表
-const lesson = {
-  school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
-  coach_id: { type: String, required: false, zh: '教练id', ref: 'Coach', getProp: [ 'name' ] }, //
-  title: { type: String, zh: '标题' },
-  class_hour: { type: Number, required: false, zh: '课时' }, //
-  money: { type: Number, required: false, zh: '金额' }, //
-  student: { type: Array, ref: 'Student', getProp: [ 'name' ], zh: '学员' },
-  type: { type: String, required: false, zh: '类型' }, // 0-公开课;1-私教课
-};
-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({ type: 1 });
-
-schema.plugin(metaPlugin);
-module.exports = app => {
-  const { mongoose } = app;
-  return mongoose.model('Lesson', schema, 'lesson');
-};

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

@@ -0,0 +1,32 @@
+'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: '上课学员', ref: 'Student', getProp: [ 'name' ] }, // 存学员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');
+};

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

@@ -0,0 +1,32 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 课程表-公开课
+const lessonPublic = {
+  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', ref: 'Coach', getProp: [ 'name' ] }, //
+  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-停课
+  brief: { type: String, required: false, zh: '简介' }, //
+};
+const schema = new Schema(lessonPublic, { 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');
+};

+ 5 - 0
app/model/relation/relationStudentSchool.js

@@ -1,6 +1,11 @@
 'use strict';
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+// 学生档案
+const doc = {
+  is_past: { type: String, default: '0' }, // 往期学员: 0-当期;1-往期
+  term: { type: String }, // 学期
+};
 
 // 学员与学校关系表
 const relationStudentSchool = {

+ 1 - 1
app/model/relation/studentApplyForSchool.js

@@ -4,7 +4,7 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 
 // 学员入学申请
 const studentApplyForSchool = {
-  student_id: { type: String, required: true, zh: '学生id', ref: 'Student', getProp: [ 'name' ] }, //
+  student_id: { type: String, required: true, zh: '学生id', ref: 'Student', getProp: [ 'name', 'icon', 'level', 'phone' ] }, //
   school_id: { type: String, required: true, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
   result: { type: String, required: false, default: '0', zh: '审核结果' }, // 0-未审核;1-审核通过;-1-审核拒绝
   time: { type: String, required: false, zh: '申请时间' }, //

+ 2 - 1
app/router.js

@@ -33,5 +33,6 @@ 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/lesson')(app); // 课程
+  require('./z_router/business/lessonPrivate')(app); // 私教课
+  require('./z_router/business/lessonPublic')(app); // 公开课
 };

+ 15 - 0
app/service/business/lessonPrivate.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 LessonPrivateService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'lessonprivate');
+    this.model = this.ctx.model.Business.LessonPrivate;
+  }
+}
+
+module.exports = LessonPrivateService;

+ 5 - 5
app/service/business/lesson.js

@@ -4,12 +4,12 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
 
-//
-class LessonService extends CrudService {
+// 
+class LessonPublicService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'lesson');
-    this.model = this.ctx.model.Business.Lesson;
+    super(ctx, 'lessonpublic');
+    this.model = this.ctx.model.Business.LessonPublic;
   }
 }
 
-module.exports = LessonService;
+module.exports = LessonPublicService;

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

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+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 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);
+};

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

@@ -3,9 +3,9 @@
 const path = require('path');
 const regPath = path.resolve('app', 'public', 'routerRegister');
 const routerRegister = require(regPath);
-const rkey = 'lesson';
-const ckey = 'business.lesson';
-const keyZh = '课程表';
+const rkey = 'lessonPublic';
+const ckey = 'business.lessonPublic';
+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}查询` },

+ 1 - 1
config/config.default.js

@@ -109,7 +109,7 @@ module.exports = appInfo => {
   // 数据库设置
   config.dbName = 'court_v2';
   config.mongoose = {
-    url: `mongodb://127.0.0.1:27017/${config.dbName}`,
+    url: `mongodb://127.0.0.1:27017/${config.dbName}`, // 120.48.146.1
     options: {
       user: 'admin',
       pass: 'admin',