|
@@ -10,7 +10,54 @@ class StatisticsService extends CrudService {
|
|
constructor(ctx) {
|
|
constructor(ctx) {
|
|
super(ctx, 'statistics');
|
|
super(ctx, 'statistics');
|
|
this.billModel = this.ctx.model.Business.Bill;
|
|
this.billModel = this.ctx.model.Business.Bill;
|
|
|
|
+ this.rssModel = this.ctx.model.Relation.RelationStudentSchool;
|
|
|
|
+ this.rcsModel = this.ctx.model.Relation.RelationCoachSchool;
|
|
|
|
+ this.lessonCoachModel = this.ctx.model.Business.LessonCoach;
|
|
}
|
|
}
|
|
|
|
+ // 学校统计 教练出勤率
|
|
|
|
+ async schoolSignCoach({ school_id }) {
|
|
|
|
+ // 查出这个学校下面的教练
|
|
|
|
+ const rList = await this.rcsModel.find({ school_id }).populate('coach_id', 'name');
|
|
|
|
+ const coachList = rList.map(i => i.coach_id);
|
|
|
|
+ const lcList = await this.lessonCoachModel.find({ school_id }, { coach_id: 1, is_sign: 1 });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 学校统计:学员按岁数区间
|
|
|
|
+ async schoolStudentAge({ school_id }) {
|
|
|
|
+ // 年龄组
|
|
|
|
+ const ageList = [
|
|
|
|
+ [ null, 6 ],
|
|
|
|
+ [ 7, 9 ],
|
|
|
|
+ [ 10, 12 ],
|
|
|
|
+ [ 12, 18 ],
|
|
|
|
+ [ 19, 30 ],
|
|
|
|
+ [ 31, null ],
|
|
|
|
+ ];
|
|
|
|
+ const data = [];
|
|
|
|
+ let list = await this.rssModel.find({ school_id }).populate('student_id', 'age');
|
|
|
|
+ if (list.length > 0)list = JSON.parse(JSON.stringify(list));
|
|
|
|
+ for (const a of ageList) {
|
|
|
|
+ const start = _.head(a);
|
|
|
|
+ const end = _.last(a);
|
|
|
|
+ const obj = {};
|
|
|
|
+ if (start && end) obj.name = `${start}-${end}岁`;
|
|
|
|
+ else if (!start) obj.name = `${end}岁以下`;
|
|
|
|
+ else if (!end) obj.name = `${start}岁以上`;
|
|
|
|
+ const l = list.filter(f => {
|
|
|
|
+ const age = _.get(f, 'student_id.age');
|
|
|
|
+ if (start && end) return age >= start && age <= end;
|
|
|
|
+ else if (!start) return age <= end;
|
|
|
|
+ else if (!end) return age >= start;
|
|
|
|
+ return false;
|
|
|
|
+ });
|
|
|
|
+ obj.value = l.length;
|
|
|
|
+ data.push(obj);
|
|
|
|
+ }
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 羽校总收入
|
|
* 羽校总收入
|
|
* 统计账单的 收入(类型为-1/-2) - 退款(至余额,2) 且 is_pay 为 1
|
|
* 统计账单的 收入(类型为-1/-2) - 退款(至余额,2) 且 is_pay 为 1
|