|
@@ -17,6 +17,43 @@ class StatisticsService extends CrudService {
|
|
|
this.lessonStudentModel = this.ctx.model.Business.LessonStudent;
|
|
|
this.lessonModel = this.ctx.model.Business.Lesson;
|
|
|
}
|
|
|
+
|
|
|
+ async studentLearning({ school_id, student_id }) {
|
|
|
+ assert(student_id, '缺少学生信息');
|
|
|
+ const query = { school_id, student_id, is_pay: '1' };
|
|
|
+ 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 lsList = await this.lessonStudentModel.find(query).populate('lesson_id');
|
|
|
+ const lessonList = lsList.map(i => i.lesson_id).map(i => _.pick(i, [ '_id', 'type', 'title', 'meta', 'status', 'time_start', 'time_end' ]));
|
|
|
+ const minutes = [];
|
|
|
+ const signs = [];
|
|
|
+ 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, '[]') && f.status === '4');
|
|
|
+ let minute = 0;
|
|
|
+ let sign = 0;
|
|
|
+ for (const lesson of list) {
|
|
|
+ const { time_start, time_end, _id: lesson_id } = lesson;
|
|
|
+ minute += moment(time_end).diff(time_start, 'minutes');
|
|
|
+ const r = lsList.find(f => ObjectId(f.lesson_id._id).equals(lesson_id));
|
|
|
+ if (r && _.get(r, 'is_sign') === '1') sign++;
|
|
|
+ }
|
|
|
+ minutes.push(minute);
|
|
|
+ signs.push(sign);
|
|
|
+ }
|
|
|
+ return { minutes, signs };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 学校统计,教练收入
|
|
|
async schoolCoachIn({ school_id, coach_id }) {
|
|
|
assert(school_id, '缺少学校信息');
|