lrf 2 jaren geleden
bovenliggende
commit
3f8fea3877
3 gewijzigde bestanden met toevoegingen van 37 en 0 verwijderingen
  1. 8 0
      app/controller/config/.statistics.js.js
  2. 28 0
      app/service/statistics.js
  3. 1 0
      app/z_router/statistics.js

+ 8 - 0
app/controller/config/.statistics.js.js

@@ -46,4 +46,12 @@ module.exports = {
       },
     },
   },
+  coachLesson: {
+    parameters: {
+      query: {
+        school_id: 'school_id',
+        coach_id: 'coach_id',
+      },
+    },
+  },
 };

+ 28 - 0
app/service/statistics.js

@@ -17,6 +17,34 @@ class StatisticsService extends CrudService {
     this.lessonStudentModel = this.ctx.model.Business.LessonStudent;
     this.lessonModel = this.ctx.model.Business.Lesson;
   }
+  // 教练统计, 授课情况
+  async coachLesson({ coach_id, school_id }) {
+    assert(school_id, '缺少学校信息');
+    assert(coach_id, '缺少教练信息');
+    const query = { school_id, coach_id };
+    const { year } = this.getPartsOfNow();
+    const yearEnd = `${year}-12-01`;
+    let monthList = this.getMonthList(12, yearEnd);
+    monthList = monthList.map(i => {
+      const start = moment(i).startOf('month').format('YYYY-MM-DD HH:mm:ss');
+      const end = moment(i).endOf('month').format('YYYY-MM-DD HH:mm:ss');
+      return [ start, end ];
+    });
+    query.$and = [{ 'meta.createdAt': { $gte: `${year}-01-01 00:00:00` } }, { 'meta.createdAt': { $lte: `${year}-12-31 23:59:59` } }];
+    const lcList = await this.lessonCoachModel.find(query).populate('lesson_id');
+    const lessonList = lcList.filter(f => f.lesson_id && f.lesson_id.status === '4');
+    const arr = [];
+    for (const months of monthList) {
+      const s = _.head(months);
+      const l = _.last(months);
+      const m = moment(s).month() + 1;
+      const list = lessonList.filter(f => moment(_.get(f, 'meta.createdAt')).isBetween(s, l, null, '[]'));
+      arr.push(list.length);
+    }
+    return arr;
+  }
+
+
   // 学员统计,付费情况
   async studentPay({ school_id, student_id }) {
     assert(school_id, '缺少学校信息');

+ 1 - 0
app/z_router/statistics.js

@@ -7,6 +7,7 @@ const rkey = 'statistics';
 const ckey = 'statistics';
 const keyZh = '统计';
 const routes = [
+  { method: 'get', path: `${rkey}/coachLesson`, controller: `${ckey}.coachLesson`, name: `${ckey}coachLesson`, zh: `${keyZh}-教练,授课情况` },
   { method: 'get', path: `${rkey}/studentPay`, controller: `${ckey}.studentPay`, name: `${ckey}studentPay`, zh: `${keyZh}-学员,付费情况` },
   { method: 'get', path: `${rkey}/studentLearning`, controller: `${ckey}.studentLearning`, name: `${ckey}studentLearning`, zh: `${keyZh}-学员,学习情况` },
   { method: 'get', path: `${rkey}/schoolCoachIn`, controller: `${ckey}.schoolCoachIn`, name: `${ckey}schoolCoachIn`, zh: `${keyZh}-羽校,教练收入` },