Commit 0c69d658 authored by 任国军's avatar 任国军

add tag & logo

parent e3708872
Pipeline #16461 passed with stage
in 8 seconds
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseInstitutionToTag = app.classModel.define('course_institution_to_tag', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
institution_id: INTEGER,
tag_id: INTEGER,
sort: 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_institution_to_tag',
});
return CourseInstitutionToTag;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseTag = app.classModel.define('course_tag', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
sort: 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_tag',
});
return CourseTag;
};
'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 CourseArea = app.classModel.define('course_area');
const CourseArea = app.classModel.define('course_area');
const CourseInstitution = app.classModel.define('course_institution', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
name: STRING,
type: STRING,
// image: STRING,
establishment_time: STRING,
class_type: STRING,
teacher_count: INTEGER,
teacher_experience: INTEGER,
corner: STRING,
min_age: INTEGER,
max_age: INTEGER,
price: STRING,
characteristic: STRING,
description: TEXT,
honor: STRING,
point: STRING,
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;
},
}
}, {
timestamps: false,
tableName: 'course_institution',
});
const CourseInstitution = app.classModel.define('course_institution', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
type: STRING,
// image: STRING,
establishment_time: STRING,
class_type: STRING,
teacher_count: INTEGER,
teacher_experience: INTEGER,
logo: STRING,
corner: STRING,
min_age: INTEGER,
max_age: INTEGER,
price: STRING,
characteristic: STRING,
description: TEXT,
honor: STRING,
point: STRING,
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;
},
},
}, {
timestamps: false,
tableName: 'course_institution',
});
CourseInstitution.hasMany(CourseArea, {
foreignKey: {
name: 'institution_id',
allowNull: false
}
});
CourseInstitution.hasMany(CourseArea, {
foreignKey: {
name: 'institution_id',
allowNull: false,
},
});
CourseInstitution.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseInstitution.findOne({
attributes: attributes,
where: where,
});
}
CourseInstitution.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseInstitution.findOne({
attributes,
where,
});
};
CourseInstitution.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseInstitution.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseInstitution.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseInstitution.findAll({
attributes,
where,
order,
});
};
CourseInstitution.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 CourseInstitution.findAndCountAll(condition);
return { page, count, rows };
}
CourseInstitution.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 CourseInstitution.findAndCountAll(condition);
return { page, count, rows };
};
CourseInstitution.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseInstitution.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
CourseInstitution.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseInstitution.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseInstitution.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseInstitution.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
CourseInstitution.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseInstitution.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseInstitution;
return CourseInstitution;
};
\ No newline at end of file
};
......@@ -127,8 +127,22 @@ class InstitutionSubService extends Service {
// 是否已收藏
const userCollect = await ctx.classModel.CourseUserCollection.findOne({ where: { institution_id, user_uuid: userUuid, is_deleted: 0 } });
// 获取所有标签
const allTags = await ctx.classModel.CourseTag.findAll({ where: { status: 'online', is_deleted: 0 } });
const tagList = [];
for (const v of allTags) {
tagList[v.id] = v;
}
let tags = await ctx.classModel.CourseInstitutionToTag.findAll({ where: { institution_id: institution.id, status: 'online', is_deleted: 0 } });
tags = _.orderBy(tags, [ 'sort' ], [ 'asc' ]);
institution.tags = [];
for (const v of tags) {
institution.tags.push(tagList[v.tag_id]);
}
institution.phone = areas.length > 0 ? areas[0].phone : '';
institution.distance = areas.length > 0 ? areas[0].distance : '';
institution.distance = areas.length > 0 ? String(areas[0].distance) + 'km' : '无法计算';
institution.travel_method = areas.length > 0 ? areas[0].travel_method : '';
institution.travel_tips = areas.length > 0 ? areas[0].travel_tips : '';
......@@ -284,6 +298,13 @@ class InstitutionSubService extends Service {
}
institutionCats = await ctx.classModel.CourseInstitutionToCat.findAll({ where: { status: 'online', is_deleted: 0, institution_id: { $in: institutionIds } } });
// 获取所有标签
const allTags = await ctx.classModel.CourseTag.findAll({ where: { status: 'online', is_deleted: 0 } });
const tagList = [];
for (const v of allTags) {
tagList[v.id] = v;
}
// 用户已收藏机构列表
const userInstitutions = await ctx.classModel.CourseUserCollection.findAll({ where: { is_deleted: 0, user_uuid: userUuid } });
const userInstitutionIds = R.pluck('id', userInstitutions);
......@@ -308,6 +329,14 @@ class InstitutionSubService extends Service {
institutionList[i].cats.push(catList[v]);
}
// 标签
let tags = await ctx.classModel.CourseInstitutionToTag.findAll({ where: { institution_id: institutionList[i].id, status: 'online', is_deleted: 0 } });
tags = _.orderBy(tags, [ 'sort' ], [ 'asc' ]);
institutionList[i].tags = [];
for (const v of tags) {
institutionList[i].tags.push(tagList[v.tag_id]);
}
// 优先获取机构详情图
let institutionImages = await ctx.classModel.CourseImages.findAll({ where: { type: 1, type_id: institutionList[i].id, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ]], limit: 3 });
if (institutionImages.length < 3) {
......@@ -316,7 +345,7 @@ class InstitutionSubService extends Service {
}
institutionList[i].images = institutionImages;
institutionList[i].distance = (institutionList[i].distance / 1000).toFixed(1);
institutionList[i].distance = String((institutionList[i].distance / 1000).toFixed(1)) + 'km';
institutionList[i].phone = institutionList[i].area.length > 0 ? institutionList[i].area[0].phone : '';
// 是否已收藏
......@@ -487,20 +516,20 @@ class InstitutionSubService extends Service {
}
//搜索关联
// 搜索关联
async getSuggestSearch(input) {
const {ctx} = this;
const {search} = input;
const { ctx } = this;
const { search } = input;
let results = [];
if (!ctx.isEmpty(search)) {
const institutions = await ctx.classModel.CourseInstitution.findAll({ where: { status: 'online', is_deleted: 0, name: { $like: '%' + search + '%' } }, limit: 10, attributes: [ 'id', 'name', 'status', 'is_deleted' ]})
const institutions = await ctx.classModel.CourseInstitution.findAll({ where: { status: 'online', is_deleted: 0, name: { $like: '%' + search + '%' } }, limit: 10, attributes: [ 'id', 'name', 'status', 'is_deleted' ] });
results = R.pluck('name', institutions);
}
const ret = {
results,
count: results.length,
}
};
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