Commit 582a80d2 authored by Aria's avatar Aria

onlineClass add age, type filter

parent fbe61bee
Pipeline #19503 passed with stage
in 57 seconds
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseOnlineAge = app.classModel.define('course_online_age', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
sort: INTEGER,
created_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_online_age',
});
CourseOnlineAge.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineAge.findOne({
attributes,
where,
});
};
CourseOnlineAge.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineAge.findAll({
attributes,
where,
order,
});
};
CourseOnlineAge.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await CourseOnlineAge.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineAge.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineAge.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineAge.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineAge.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineAge;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseOnlineClassToAge = app.classModel.define('course_online_class_to_age', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
age_id: INTEGER,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_online_class_to_age',
});
CourseOnlineClassToAge.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineClassToAge.findOne({
attributes,
where,
});
};
CourseOnlineClassToAge.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineClassToAge.findAll({
attributes,
where,
order,
});
};
CourseOnlineClassToAge.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await CourseOnlineClassToAge.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineClassToAge.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineClassToAge.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineClassToAge.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineClassToAge.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineClassToAge;
};
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseOnlineClassToCat = app.classModel.define('course_online_class_to_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
class_id: INTEGER,
cat_id: INTEGER,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_online_class_to_cat',
});
const CourseOnlineClassToCat = app.classModel.define('course_online_class_to_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
cat_id: INTEGER,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_online_class_to_cat',
});
CourseOnlineClassToCat.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineClassToCat.findOne({
attributes: attributes,
where: where,
});
}
CourseOnlineClassToCat.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineClassToCat.findOne({
attributes,
where,
});
};
CourseOnlineClassToCat.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineClassToCat.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseOnlineClassToCat.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineClassToCat.findAll({
attributes,
where,
order,
});
};
CourseOnlineClassToCat.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where: where,
order: order,
attributes: attributes,
};
const { count, rows } = await CourseOnlineClassToCat.findAndCountAll(condition);
return { page, count, rows };
}
CourseOnlineClassToCat.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await CourseOnlineClassToCat.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineClassToCat.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseOnlineClassToCat.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
CourseOnlineClassToCat.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineClassToCat.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineClassToCat.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineClassToCat.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
CourseOnlineClassToCat.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineClassToCat.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineClassToCat;
return CourseOnlineClassToCat;
};
\ No newline at end of file
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseOnlineClassToType = app.classModel.define('course_online_class_to_type', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
type_id: INTEGER,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_online_class_to_type',
});
CourseOnlineClassToType.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineClassToType.findOne({
attributes,
where,
});
};
CourseOnlineClassToType.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineClassToType.findAll({
attributes,
where,
order,
});
};
CourseOnlineClassToType.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await CourseOnlineClassToType.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineClassToType.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineClassToType.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineClassToType.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineClassToType.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineClassToType;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseOnlineType = app.classModel.define('course_online_type', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
sort: INTEGER,
created_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_time: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_online_type',
});
CourseOnlineType.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineType.findOne({
attributes,
where,
});
};
CourseOnlineType.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineType.findAll({
attributes,
where,
order,
});
};
CourseOnlineType.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1;
const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const condition = {
offset: (page - 1) * limit,
limit,
where,
order,
attributes,
};
const { count, rows } = await CourseOnlineType.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineType.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineType.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineType.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineType.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineType;
};
......@@ -14,11 +14,13 @@ class OnlineService extends Service {
let cats = await ctx.classModel.V4.CourseOnlineCat.findAll({ where: { status: 'online', is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true });
cats = [{ id: 0, name: '全部' }].concat(cats);
// 年龄段
const ages = [ '全部', '学龄前', '幼儿园', '小学', '初中', '高中' ];
let ages = await ctx.classModel.V4.CourseOnlineAge.findAll({ where: { status: 'online', is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true });
ages = [{ id: 0, name: '全部' }].concat(cats);
// 课程状态
const mode = [{ id: 0, name: '全部' }, { id: 1, name: '直播' }, { id: 2, name: '录播' }];
// 课程班型
const type = [ '全部', '1对1', '1对多', '讲座' ];
let type = await ctx.classModel.V4.CourseOnlineType.findAll({ where: { status: 'online', is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true });
type = [{ id: 0, name: '全部' }].concat(cats);
const options = {
cats,
......@@ -57,6 +59,16 @@ class OnlineService extends Service {
const catIds = R.pluck('cat_id', classCats);
const cats = await ctx.classModel.V4.CourseOnlineCat.findAll({ where: { id: { $in: catIds } }, attributes: [ 'id', 'name' ] });
// 年龄段
const classAges = await ctx.classModel.V4.CourseOnlineClassToAge.findAll({ where: { class_id: id, status: 'online', is_deleted: 0 }, attributes: [ 'age_id' ] });
const ageIds = R.pluck('age_id', classAges);
const ages = await ctx.classModel.V4.CourseOnlineAge.findAll({ where: { id: { $in: ageIds } }, attributes: [ 'id', 'name' ] });
// 班型
const classTypes = await ctx.classModel.V4.CourseOnlineClassToType.findAll({ where: { class_id: id, status: 'online', is_deleted: 0 }, attributes: [ 'type_id' ] });
const typeIds = R.pluck('type_id', classTypes);
const type = await ctx.classModel.V4.CourseOnlineType.findAll({ where: { id: { $in: typeIds } }, attributes: [ 'id', 'name' ] });
// 收藏信息
const uuid = ctx.headers.uuid || '';
const userCollect = await ctx.classModel.V4.CourseUserCollection.findOne({ where: { user_uuid: uuid, type: 3, type_id: id, is_deleted: 0 } });
......@@ -73,7 +85,8 @@ class OnlineService extends Service {
phone: ctx.isEmpty(area) ? '' : area.phone,
travel_tips: ctx.isEmpty(area) ? '' : area.travel_tips,
price: classInfo.price,
type: classInfo.type,
type,
ages,
mode: await this.getClassModelInfo(classInfo.mode),
time: classInfo.time,
channel: classInfo.channel,
......@@ -95,13 +108,26 @@ class OnlineService extends Service {
const { type, mode, age, cat } = input;
const filter = { where: { status: 'online', is_deleted: 0 }, order: [[ 'institution_id', 'desc' ]], limit, offset, attributes: [ 'id', 'institution_id', 'name', 'price', 'type', 'age', 'mode', 'time', 'created_time' ] };
// 年龄段筛选
let ids = [];
let flag = false;
if (!ctx.isEmpty(age)) {
filter.where.age = age;
const classes = await ctx.classModel.V4.CourseOnlineClassToAge.findAll({ where: { age_id: age, status: 'online', is_deleted: 0 }, attributes: [ 'class_id' ] });
if (flag) {
ids = _.intersection(ids, R.pluck('class_id', classes));
} else {
flag = true;
ids = R.pluck('class_id', classes);
}
}
// 课程类型筛选
if (!ctx.isEmpty(cat) && Number(cat) > 0) {
const classes = await ctx.classModel.V4.CourseOnlineClassToCat.findAll({ where: { cat_id: cat, status: 'online', is_deleted: 0 }, attributes: [ 'class_id' ] });
filter.where.id = { $in: R.pluck('class_id', classes) };
if (flag) {
ids = _.intersection(ids, R.pluck('class_id', classes));
} else {
flag = true;
ids = R.pluck('class_id', classes);
}
}
// 课程状态筛选
if (!ctx.isEmpty(mode)) {
......@@ -109,7 +135,13 @@ class OnlineService extends Service {
}
// 课程班型筛选
if (!ctx.isEmpty(type)) {
filter.where.type = type;
const classes = await ctx.classModel.V4.CourseOnlineClassToType.findAll({ where: { type_id: type, status: 'online', is_deleted: 0 }, attributes: [ 'class_id' ] });
if (flag) {
ids = _.intersection(ids, R.pluck('class_id', classes));
} else {
flag = true;
ids = R.pluck('class_id', classes);
}
}
const classes = await ctx.classModel.V4.CourseOnlineClass.findAndCountAll(filter);
......@@ -131,6 +163,22 @@ class OnlineService extends Service {
}
classCats = _.groupBy(classCats, 'class_id');
// 班型
const classToTypes = await ctx.classModel.V4.CourseOnlineClassTotype.findAll({ where: { class_id: { $in: classIds }, status: 'online', is_deleted: 0 }, attributes: [ 'class_id', 'type_id' ] });
const typeIds = R.pluck('type_id', classToTypes);
let types = await ctx.classModel.V4.CourseOnlineType.findAll({ where: { id: { $in: typeIds } } });
types = _.groupBy(types, 'id');
let classTypes = [];
for (const v of classToTypes) {
const tmp = {
id: v.type_id,
class_id: v.class_id,
name: ctx.isEmpty(types[v.type_id]) ? '' : types[v.type_id][0].name,
};
classTypes.push(tmp);
}
classTypes = _.groupBy(classTypes, 'class_id');
// 机构
const institutionIds = R.pluck('institution_id', classes.rows);
let institutions = await ctx.classModel.V4.CourseOnlineInstitution.findAll({ where: { id: { $in: institutionIds } }, attributes: [ 'id', 'name', 'logo' ] });
......@@ -144,7 +192,7 @@ class OnlineService extends Service {
institution_id: v.institution_id,
institution_name: ctx.isEmpty(institutions[v.institution_id]) ? '' : institutions[v.institution_id][0].name,
logo: ctx.isEmpty(institutions[v.institution_id]) ? '' : institutions[v.institution_id][0].logo,
type: v.type,
type: ctx.isEmpty(classTypes[v.id]) ? [] : classTypes[v.id],
mode: await this.getClassModelInfo(v.mode),
price: v.price,
time: v.time,
......
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