|
@@ -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, '缺少学校信息');
|