lrf 2 年之前
父节点
当前提交
ca1be8dccb

+ 2 - 2
app/controller/business/config/.lesson.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['school_id', 'title', 'time_start', 'time_end', 'status', 'brief', 'type', 'limit'],
+    requestBody: ['school_id', 'title', 'time_start', 'time_end', 'status', 'brief', 'type', 'limit', 'refund_hour'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['school_id', 'title', 'time_start', 'time_end', 'status', 'brief', 'type', 'limit'],
+    requestBody: ['school_id', 'title', 'time_start', 'time_end', 'status', 'brief', 'type', 'limit', 'refund_hour'],
   },
   show: {
     parameters: {

+ 17 - 0
app/controller/view/student.js

@@ -0,0 +1,17 @@
+'use strict';
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 学生视图接口
+class StudentController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.view.student;
+  }
+
+  async lessonList() {
+    const data = await this.service.lessonList(this.ctx.query);
+    this.ctx.ok(data);
+  }
+}
+module.exports = CrudController(StudentController, {});

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

@@ -9,6 +9,7 @@ const lesson = {
   time_start: { type: String, required: false, zh: '开始上课时间' }, //
   time_end: { type: String, required: false, zh: '结束时间' }, //
   limit: { type: Number, zh: '人数上限' },
+  refund_hour: { type: String, 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: '简介' }, //

+ 2 - 0
app/router.js

@@ -40,4 +40,6 @@ module.exports = app => {
   require('./z_router/business/lessonStudent')(app); // 课程-学员
   require('./z_router/business/coachInBill')(app); // 教练费明细
   require('./z_router/business/billApply')(app); // 教练费申请
+
+  require('./z_router/view/student')(app); // 学生视图
 };

+ 24 - 0
app/service/view/student.js

@@ -0,0 +1,24 @@
+'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 StudentService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'lessonprivate');
+    this.lessonModel = this.ctx.model.Business.Lesson;
+    this.lessonStudentModel = this.ctx.model.Business.LessonStudent;
+  }
+  async lessonList({ student_id, school_id, skip = 0, limit = 0, ...otherQuery }) {
+    // 查出该学生的课表
+    const lsList = await this.lessonStudentModel.find({ student_id, school_id }, { lesson_id: 1 });
+    const lessonIds = lsList.map(i => i.lesson_id);
+    const data = await this.lessonModel.find({ _id: lessonIds, ...otherQuery }).skip(parseInt(skip)).limit(parseInt(limit));
+    const total = await this.lessonModel.count({ _id: lessonIds, ...otherQuery });
+    return { data, total };
+  }
+}
+
+module.exports = StudentService;

+ 13 - 0
app/z_router/view/student.js

@@ -0,0 +1,13 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'studentView';
+const ckey = 'view.student';
+const keyZh = '学生视图';
+const routes = [{ method: 'get', path: `${rkey}/lessonList`, controller: `${ckey}.lessonList`, name: `${ckey}LessonList`, zh: `${keyZh}-课程列表` }];
+
+module.exports = app => {
+  routerRegister(app, routes, keyZh, rkey, ckey);
+};