Commit 98694127 authored by 任国军's avatar 任国军

classInfo add type & fix report calc class score

parent 0005145c
Pipeline #23025 passed with stage
in 3 seconds
......@@ -139,6 +139,10 @@ class InstitutionSubService extends Service {
const category = await ctx.classModel.V5.CourseV5Category.findAll({ where: { id: { $in: R.pluck('cat_id', categoryList) } }, attributes: [ 'id', 'name' ] });
// 班型
const typeList = await ctx.classModel.V5.CourseV5ClassToType.findAll({ where: { class_id: id, status: 1, is_deleted: 0 }, attributes: [ 'type_id' ] });
const type = await ctx.classModel.V5.CourseV5Type.findAll({ where: { id: { $in: R.pluck('type_id', typeList) } }, attributes: [ 'id', 'name' ] });
const columns = [];
for (const v of classColumns) {
if (!ctx.isEmpty(columnList[v.column_id])) {
......@@ -160,6 +164,7 @@ class InstitutionSubService extends Service {
classInfo.student_works = studentWorks;
classInfo.images = images;
classInfo.category = category;
classInfo.type = type;
classInfo.institution_name = ctx.isEmpty(institution) ? '' : institution.name;
classInfo.institution_logo = ctx.isEmpty(institution) ? '' : institution.logo;
classInfo.institution_description = ctx.isEmpty(institution) ? '' : institution.description;
......
......@@ -305,8 +305,8 @@ class ReportService extends Service {
// 判断是否是课程的额外字段
if (v.column_type === 1) { // 课程字段
switch (v.column) {
case 'price_filter':
where.price_filter = await this.getOptionValue(v);
case 'filter_price':
where.filter_price = await this.getOptionValue(v);
break;
case 'price_type':
where.price_type = await this.getOptionValue(v);
......@@ -346,8 +346,6 @@ class ReportService extends Service {
tmpClassList = await ctx.classModel.V5.CourseV5ClassToColumn.findAll(tmpFilter);
classIds = classFlag ? _.intersection(classIds, R.pluck('class_id', tmpClassList)) : R.pluck('class_id', tmpClassList);
classFlag = true;
console.log(v);
console.log(classIds);
}
}
}
......@@ -502,61 +500,116 @@ class ReportService extends Service {
// 计算所有公司评分
async calcClassScore(classList, answerFilterList) {
const { ctx } = this;
// 先获取所有评分筛选
let scoreFilterList = [];
const scoreFilterList = [];
for (const v of answerFilterList) {
if (v.type === 2) {
scoreFilterList.push({
column_type: v.column_value,
column: v.column,
column_value: v.column_value,
column_filter_key: `${v.column}---${v.column_value}`,
column_score: v.column_score,
});
scoreFilterList.push(v);
}
}
scoreFilterList = _.groupBy(scoreFilterList, 'column_filter_key');
const ret = [];
for (const v of classList) {
const tmpClass = v;
// 先计算所有的额外字段
for (const j of v.column_list) {
if (!ctx.isEmpty(scoreFilterList[j.filter_key])) {
tmpClass.score += scoreFilterList[j.filter_key][0].column_score;
}
}
tmpClass.score = await this.calcScore(v, scoreFilterList);
ret.push(tmpClass);
}
// 计算课程字段
// 年龄段
for (const j of v.age_list) {
if (!ctx.isEmpty(scoreFilterList[`age---${j.id}`])) {
tmpClass.score += scoreFilterList[`age---${j.id}`][0].column_score;
}
}
// 课程班型
for (const j of v.type_list) {
if (!ctx.isEmpty(scoreFilterList[`type---${j.id}`])) {
tmpClass.score += scoreFilterList[`type---${j.id}`][0].column_score;
}
}
// 授课频次
for (const j of v.frequency_list) {
if (!ctx.isEmpty(scoreFilterList[`frequency---${j.id}`])) {
tmpClass.score += scoreFilterList[`frequency---${j.id}`][0].column_score;
return ret;
}
// 计算公司分值
async calcScore(classInfo, scoreFilterList) {
let score = 0;
for (const v of scoreFilterList) {
if (v.type === 2) {
if (v.column_type === 1) {
switch (v.column) {
case 'filter_price':
score += await this.checkScore(classInfo.filter_price, v.option, v.column_value, v.column_score);
break;
case 'price_type':
score += await this.checkScore(classInfo.price_type, v.option, v.column_value, v.column_score);
break;
case 'mode':
score += await this.checkScore(classInfo.mode, v.option, v.column_value, v.column_score);
break;
case 'time':
score += await this.checkScore(classInfo.time, v.option, v.column_value, v.column_score);
break;
case 'class_amount':
score += await this.checkScore(classInfo.class_amount, v.option, v.column_value, v.column_score);
break;
case 'multi_classes':
score += await this.checkScore(classInfo.multi_classes, v.option, v.column_value, v.column_score);
break;
case 'cycle':
score += await this.checkScore(classInfo.cycle, v.option, v.column_value, v.column_score);
break;
case 'type':
for (const j of classInfo.type_list) {
score += await this.checkScore(String(j.id), v.option, v.column_value, v.column_score);
}
break;
case 'frequency':
for (const j of classInfo.frequency_list) {
score += await this.checkScore(String(j.id), v.option, v.column_value, v.column_score);
}
break;
case 'age':
for (const j of classInfo.age_list) {
score += await this.checkScore(String(j.id), v.option, v.column_value, v.column_score);
}
break;
default:
break;
}
} else {
for (const j of classInfo.column_list) {
if (v.column === j.id) {
score += await this.checkScore(j.value, v.option, v.column_value, v.column_score);
}
}
}
}
// 课程类型
if (!ctx.isEmpty(scoreFilterList[`price_type---${v.price_type}`])) {
tmpClass.score += scoreFilterList[`price_type---${v.price_type}`][0].column_score;
}
// 课程状态
if (!ctx.isEmpty(scoreFilterList[`mode---${v.mode}`])) {
tmpClass.score += scoreFilterList[`mode---${v.mode}`][0].column_score;
}
}
ret.push(tmpClass);
return score;
}
// 判断是否符合条件
async checkScore(value, option, filter, score) {
let ret = 0;
switch (option) {
case 1:
ret = value === filter ? Number(score) : 0;
break;
case 2:
ret = value > filter ? Number(score) : 0;
break;
case 3:
ret = value >= filter ? Number(score) : 0;
break;
case 4:
ret = value < filter ? Number(score) : 0;
break;
case 5:
ret = value <= filter ? Number(score) : 0;
break;
case 6:
filter = eval(filter);
for (const i in filter) {
if (filter[i] === value && score.length > i) {
ret += score[i];
}
}
break;
case 7:
ret = value !== filter ? Number(score) : 0;
break;
default:
break;
}
return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment