Commit 44fea3d0 authored by 李尚科's avatar 李尚科

add class

parent 64bb2879
Pipeline #14004 passed with stage
in 28 seconds
...@@ -6,7 +6,7 @@ const moment = require('moment'); ...@@ -6,7 +6,7 @@ const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM, FLOAT } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM, FLOAT } = app.Sequelize;
const CourseArea = app.prometheusModel.define('course_area', { const CourseArea = app.classModel.define('course_area', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
......
...@@ -6,7 +6,7 @@ const moment = require('moment'); ...@@ -6,7 +6,7 @@ const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseCat = app.prometheusModel.define('course_cat', { const CourseCat = app.classModel.define('course_cat', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
...@@ -16,6 +16,7 @@ module.exports = app => { ...@@ -16,6 +16,7 @@ module.exports = app => {
parent_id: INTEGER, parent_id: INTEGER,
level: INTEGER, level: INTEGER,
name: STRING, name: STRING,
image: STRING,
tips: STRING, tips: STRING,
status: ENUM('offline', 'online'), status: ENUM('offline', 'online'),
is_deleted: INTEGER, is_deleted: INTEGER,
......
...@@ -5,7 +5,7 @@ const moment = require('moment'); ...@@ -5,7 +5,7 @@ const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseClass = app.prometheusModel.define('course_class', { const CourseClass = app.classModel.define('course_class', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
...@@ -13,7 +13,7 @@ module.exports = app => { ...@@ -13,7 +13,7 @@ module.exports = app => {
}, },
institution_id: INTEGER, institution_id: INTEGER,
name: STRING, name: STRING,
image: STRING, // image: STRING,
price: DECIMAL, price: DECIMAL,
min_age: INTEGER, min_age: INTEGER,
max_age: INTEGER, max_age: INTEGER,
......
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseImages = app.classModel.define('course_images', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
type: INTEGER,
type_id: INTEGER,
image_url: STRING,
video_url: STRING,
is_cover: INTEGER,
is_video: 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;
},
},
}, {
timestamps: false,
tableName: 'course_images',
});
CourseImages.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseImages.findOne({
attributes: attributes,
where: where,
});
}
CourseImages.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseImages.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseImages.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 CourseImages.findAndCountAll(condition);
return { page, count, rows };
}
CourseImages.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseImages.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseImages.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseImages.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseImages;
};
\ No newline at end of file
...@@ -7,9 +7,9 @@ module.exports = app => { ...@@ -7,9 +7,9 @@ module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseArea = app.prometheusModel.define('course_area'); const CourseArea = app.classModel.define('course_area');
const CourseInstitution = app.prometheusModel.define('course_institution', { const CourseInstitution = app.classModel.define('course_institution', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
...@@ -17,7 +17,7 @@ module.exports = app => { ...@@ -17,7 +17,7 @@ module.exports = app => {
}, },
name: STRING, name: STRING,
type: STRING, type: STRING,
image: STRING, // image: STRING,
establishment_time: STRING, establishment_time: STRING,
class_type: STRING, class_type: STRING,
teacher_count: INTEGER, teacher_count: INTEGER,
......
...@@ -6,7 +6,7 @@ const moment = require('moment'); ...@@ -6,7 +6,7 @@ const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseInstitutionToCat = app.prometheusModel.define('course_institution_to_cat', { const CourseInstitutionToCat = app.classModel.define('course_institution_to_cat', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
......
...@@ -5,7 +5,7 @@ const moment = require('moment'); ...@@ -5,7 +5,7 @@ const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseTeacher = app.prometheusModel.define('course_teacher', { const CourseTeacher = app.classModel.define('course_teacher', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
......
...@@ -6,19 +6,18 @@ const moment = require('moment'); ...@@ -6,19 +6,18 @@ const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseUserBaby = app.prometheusModel.define('course_user_baby', { const CourseUserBaby = app.classModel.define('course_user_baby', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
autoIncrement: true autoIncrement: true
}, },
user_id: STRING, user_uuid: STRING,
app_user_id: STRING,
app_id: STRING,
app_type_id: STRING,
gender: ENUM('boy', 'girl'), gender: ENUM('boy', 'girl'),
birth: STRING, birth: STRING,
address: STRING, address: STRING,
lat: DECIMAL,
lng: DECIMAL,
is_deleted: INTEGER, is_deleted: INTEGER,
created_at: { created_at: {
type: DATE, type: DATE,
......
...@@ -6,16 +6,13 @@ const moment = require('moment'); ...@@ -6,16 +6,13 @@ const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseUserCollection = app.prometheusModel.define('course_user_collection', { const CourseUserCollection = app.classModel.define('course_user_collection', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
autoIncrement: true autoIncrement: true
}, },
user_id: STRING, user_uuid: STRING,
app_user_id: STRING,
app_id: STRING,
app_type_id: STRING,
institution_id: INTEGER, institution_id: INTEGER,
is_deleted: INTEGER, is_deleted: INTEGER,
created_at: { created_at: {
......
...@@ -14,16 +14,16 @@ class InstitutionService extends Service { ...@@ -14,16 +14,16 @@ class InstitutionService extends Service {
const { cat, age, institution } = input; const { cat, age, institution } = input;
let where = { status: 1, is_deleted: 0 }; let where = { status: 1, is_deleted: 0 };
if (cat) { if (cat) {
const cat_ret = await ctx.prometheusModel.CourseCat.one({ where: { id: cat } }); const cat_ret = await ctx.classModel.CourseCat.one({ where: { id: cat } });
const cat_id = cat_ret.id; const cat_id = cat_ret.id;
const cat_level = cat_ret.level; const cat_level = cat_ret.level;
const next_level = cat_level + 1; const next_level = cat_level + 1;
const next_next_level = cat_level + 2; const next_next_level = cat_level + 2;
const next_cat = await ctx.prometheusModel.CourseCat.all({ where: { level: next_level, parent_id: cat_id } }); const next_cat = await ctx.classModel.CourseCat.all({ where: { level: next_level, parent_id: cat_id } });
const next_next_cat = await ctx.prometheusModel.CourseCat.all({ where: { level: next_next_level, first_id: cat_id } }); const next_next_cat = await ctx.classModel.CourseCat.all({ where: { level: next_next_level, first_id: cat_id } });
let cat_ids = [cat_id,]; let cat_ids = [cat_id,];
cat_ids = cat_ids.concat(R.pluck('id', next_cat)).concat(R.pluck('id', next_next_cat)); cat_ids = cat_ids.concat(R.pluck('id', next_cat)).concat(R.pluck('id', next_next_cat));
const institutions = await ctx.prometheusModel.CourseInstitutionToCat.all({ where: { cat_id: { $in: cat_ids } } }); const institutions = await ctx.classModel.CourseInstitutionToCat.all({ where: { cat_id: { $in: cat_ids } } });
where.id = { $in: R.pluck('institution_id', institutions) }; where.id = { $in: R.pluck('institution_id', institutions) };
} }
if (age) { if (age) {
...@@ -33,14 +33,15 @@ class InstitutionService extends Service { ...@@ -33,14 +33,15 @@ class InstitutionService extends Service {
if (institution) { if (institution) {
where.corner = { $ne: '' }; where.corner = { $ne: '' };
} }
const include = [{ model: ctx.prometheusModel.CourseArea, where: { status: 1, is_deleted: 0 }, attributes: ['id', 'institution_id', 'name', 'address', 'lat', 'lng'] }]; const include = [{ model: ctx.classModel.CourseArea, where: { status: 1, is_deleted: 0 }, attributes: ['id', 'institution_id', 'name', 'address', 'lat', 'lng'] }];
const attributes = ['id', 'name', 'type', 'image', 'establishment_time', 'class_type', 'teacher_count', 'teacher_experience', 'corner', 'min_age', 'max_age', 'price', 'characteristic',]; const attributes = ['id', 'name', 'type', 'establishment_time', 'class_type', 'teacher_count', 'teacher_experience', 'corner', 'min_age', 'max_age', 'price', 'characteristic',];
const institutions = await ctx.prometheusModel.CourseInstitution.findAll({ attributes, include, where }); const institutions = await ctx.classModel.CourseInstitution.findAll({ attributes, include, where });
const institution_area_list = await this.getInstitutionAreaList(institutions); const institution_area_list = await this.getInstitutionAreaList(institutions);
const area_lbs = await this.computeDistance(institution_area_list); const area_lbs = await this.computeDistance(institution_area_list);
const institution_areas = await this.findShortestDistanceAreas(institution_area_list, area_lbs); const institution_areas = await this.findShortestDistanceAreas(institution_area_list, area_lbs);
const ret = await this.formatInstitutions(institution_areas); const ret = await this.formatInstitutions(institution_areas);
return ret; return ret;
} }
...@@ -50,16 +51,27 @@ class InstitutionService extends Service { ...@@ -50,16 +51,27 @@ class InstitutionService extends Service {
async getInstitution({ institution_id, area_id }) { async getInstitution({ institution_id, area_id }) {
const { ctx } = this; const { ctx } = this;
const institution = await ctx.prometheusModel.CourseInstitution.one({ where: { id: institution_id } }); const institution = await ctx.classModel.CourseInstitution.one({ where: { id: institution_id } });
const teachers = await this.getTeachers({ institution_id, limit: 6 }); const teachers = await this.getTeachers({ institution_id, limit: 6 });
const classes = await this.getClasses({ institution_id, limit: 4 }); const classes = await this.getClasses({ institution_id, limit: 4 });
const areas = await this.getInstitutionAreas({ institution_id, limit: 1000 }); const areas = await this.getInstitutionAreas({ institution_id, limit: 1000 });
const current_area = await ctx.prometheusModel.CourseArea.one({ id: area_id }); const institution_images = await ctx.classModel.CourseImages.all({ where: { type: 1, type_id: institution_id } });
const current_area = await ctx.classModel.CourseArea.one({ id: area_id });
let institution_detail = await this.formatInstitutions([institution]); let institution_detail = await this.formatInstitutions([institution]);
institution_detail = institution_detail[0]; institution_detail = institution_detail[0];
institution_detail.address = current_area.address; institution_detail.address = current_area.address;
institution_detail.phone = current_area.phone; institution_detail.phone = current_area.phone;
institution_detail.photo_album = institution.image.split(';'); //处理图片
const photo_album = [];
for (let i in institution_images) {
const institution_image = institution_images[i];
photo_album.push({
image: institution_image.image_url,
is_video: institution_image.is_video,
video_url: institution_image.video_url,
});
}
institution_detail.photo_album = photo_album;
return { institution_detail, teachers: teachers.rows, classes: classes.rows, areas: areas.rows }; return { institution_detail, teachers: teachers.rows, classes: classes.rows, areas: areas.rows };
} }
...@@ -68,7 +80,7 @@ class InstitutionService extends Service { ...@@ -68,7 +80,7 @@ class InstitutionService extends Service {
const { ctx } = this; const { ctx } = this;
const where = { id: teacher_id }; const where = { id: teacher_id };
let teacher = await ctx.prometheusModel.CourseTeacher.one({ where }); let teacher = await ctx.classModel.CourseTeacher.one({ where });
teacher.dataValues.point_tags = teacher.point.split(';'); teacher.dataValues.point_tags = teacher.point.split(';');
teacher.dataValues.work_experience_tags = teacher.work_experience.split(';'); teacher.dataValues.work_experience_tags = teacher.work_experience.split(';');
...@@ -79,7 +91,7 @@ class InstitutionService extends Service { ...@@ -79,7 +91,7 @@ class InstitutionService extends Service {
const { ctx } = this; const { ctx } = this;
const where = { id: class_id }; const where = { id: class_id };
let classs = await ctx.prometheusModel.CourseClass.one({ where }); let classs = await ctx.classModel.CourseClass.one({ where });
classs.dataValues.age_text = `${classs.min_age}-${classs.max_age}岁`; classs.dataValues.age_text = `${classs.min_age}-${classs.max_age}岁`;
classs.dataValues.point_tags = classs.point.split(';'); classs.dataValues.point_tags = classs.point.split(';');
classs.dataValues.photo_album = classs.image.split(';'); classs.dataValues.photo_album = classs.image.split(';');
...@@ -92,7 +104,7 @@ class InstitutionService extends Service { ...@@ -92,7 +104,7 @@ class InstitutionService extends Service {
const attributes = ['id', 'institution_id', 'name', 'avatar', 'teacher_experience', 'lesson', 'educational_background', 'certificate']; const attributes = ['id', 'institution_id', 'name', 'avatar', 'teacher_experience', 'lesson', 'educational_background', 'certificate'];
const { institution_id, page, limit } = input; const { institution_id, page, limit } = input;
const where = { institution_id }; const where = { institution_id };
const teachers = await ctx.prometheusModel.CourseTeacher.list({ attributes, page, limit, where }); const teachers = await ctx.classModel.CourseTeacher.list({ attributes, page, limit, where });
return teachers; return teachers;
...@@ -101,15 +113,25 @@ class InstitutionService extends Service { ...@@ -101,15 +113,25 @@ class InstitutionService extends Service {
async getClasses(input) { async getClasses(input) {
const { ctx } = this; const { ctx } = this;
const attributes = ['id', 'institution_id', 'name', 'image', 'type', 'price']; const attributes = ['id', 'institution_id', 'name', 'type', 'price'];
const { institution_id, page, limit } = input; const { institution_id, page, limit } = input;
const where = { institution_id }; const where = { institution_id };
const classes = await ctx.prometheusModel.CourseClass.list({ attributes, page, limit, where }); const classes = await ctx.classModel.CourseClass.list({ attributes, page, limit, where });
const p_class_images = [];
for (let j in classes.rows) {
const classs = classes.rows[j];
p_class_images[j] = ctx.classModel.CourseImages.one({ where: { type: 2, type_id: classs.id, is_cover: 1, is_video: 0 } });
}
const class_images = await Promise.all(p_class_images).then(result => {//等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
let ret = []; let ret = [];
for (let i in classes.rows) { for (let i in classes.rows) {
let classs = classes.rows[i]; let classs = classes.rows[i];
const photo_album = institution.image.split(';'); classs.dataValues.image = class_images[i] ? class_images[i].image_url : '';;
classs.dataValues.image = photo_album[0];
classs.dataValues.price_text = classs.price ? classs.price : '现场咨询'; classs.dataValues.price_text = classs.price ? classs.price : '现场咨询';
ret.push(classs); ret.push(classs);
} }
...@@ -124,7 +146,7 @@ class InstitutionService extends Service { ...@@ -124,7 +146,7 @@ class InstitutionService extends Service {
const attributes = ['id', 'institution_id', 'name', 'address', 'phone']; const attributes = ['id', 'institution_id', 'name', 'address', 'phone'];
const { institution_id, page, limit } = input; const { institution_id, page, limit } = input;
const where = { institution_id }; const where = { institution_id };
const areas = await ctx.prometheusModel.CourseArea.list({ attributes, page, limit, where }); const areas = await ctx.classModel.CourseArea.list({ attributes, page, limit, where });
return areas; return areas;
...@@ -213,8 +235,7 @@ class InstitutionService extends Service { ...@@ -213,8 +235,7 @@ class InstitutionService extends Service {
const ret = []; const ret = [];
const institution_lbs = await this.computeDistance(areas_list); const institution_lbs = await this.computeDistance(areas_list);
for (let i in areas_list) { for (let i in institution_areas) {
let area = areas_list[i];
let institution_area = institution_areas[i]; let institution_area = institution_areas[i];
const lbs = institution_lbs[i]; const lbs = institution_lbs[i];
const area_name = institution_area.area_name; const area_name = institution_area.area_name;
...@@ -240,9 +261,20 @@ class InstitutionService extends Service { ...@@ -240,9 +261,20 @@ class InstitutionService extends Service {
async formatInstitutions(institutions) { async formatInstitutions(institutions) {
const { ctx } = this;
if (!Array.isArray(institutions) || institutions.length === 0) { if (!Array.isArray(institutions) || institutions.length === 0) {
return []; return [];
} }
const p_institution_images = [];
for (let j in institutions) {
const institution = institutions[j];
p_institution_images[j] = ctx.classModel.CourseImages.one({ where: { type: 1, type_id: institution.id, is_cover: 1, is_video: 0 } });
}
const institution_images = await Promise.all(p_institution_images).then(result => {//等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
const ret = []; const ret = [];
for (let i in institutions) { for (let i in institutions) {
const institution = institutions[i]; const institution = institutions[i];
...@@ -251,12 +283,12 @@ class InstitutionService extends Service { ...@@ -251,12 +283,12 @@ class InstitutionService extends Service {
const age_tag = institution.min_age + '-' + institution.max_age + '岁'; const age_tag = institution.min_age + '-' + institution.max_age + '岁';
const build_time = moment().format('YYYY') - institution.establishment_time; const build_time = moment().format('YYYY') - institution.establishment_time;
const tags = [age_tag, institution.class_type, '成立' + build_time + '年']; const tags = [age_tag, institution.class_type, '成立' + build_time + '年'];
const photo_album = institution.image.split(';'); const image = institution_images[i] ? institution_images[i].image_url : '';
ret.push({ ret.push({
id: institution.id, id: institution.id,
name: institution.name, name: institution.name,
image: photo_album[0], image,
establishment_time: institution.establishment_time, establishment_time: institution.establishment_time,
class_type: institution.class_type, class_type: institution.class_type,
teacher_count: institution.teacher_count, teacher_count: institution.teacher_count,
......
...@@ -32,7 +32,7 @@ class OptionService extends Service { ...@@ -32,7 +32,7 @@ class OptionService extends Service {
async getOptions() { async getOptions() {
const { ctx } = this; const { ctx } = this;
const cats = await ctx.prometheusModel.CourseCat.all({ where: { status: 1, is_deleted: 0 } }); const cats = await ctx.classModel.CourseCat.all({ where: { status: 1, is_deleted: 0 } });
const tree_cats = this.getTrees(cats, 0); const tree_cats = this.getTrees(cats, 0);
const options = { const options = {
cats: tree_cats, cats: tree_cats,
...@@ -52,6 +52,7 @@ class OptionService extends Service { ...@@ -52,6 +52,7 @@ class OptionService extends Service {
newNode.id = node.id; newNode.id = node.id;
newNode.name = node.name; newNode.name = node.name;
newNode.tips = node.tips; newNode.tips = node.tips;
newNode.image = node.image;
newNode.level = node.level; newNode.level = node.level;
newNode.value = node.id; newNode.value = node.id;
newNode._child = this.getTrees(data, node.id); newNode._child = this.getTrees(data, node.id);
...@@ -60,13 +61,7 @@ class OptionService extends Service { ...@@ -60,13 +61,7 @@ class OptionService extends Service {
} }
return ret; return ret;
} }
} }
module.exports = OptionService; module.exports = OptionService;
...@@ -15,39 +15,41 @@ class UserService extends Service { ...@@ -15,39 +15,41 @@ class UserService extends Service {
async getBabyInfo() { async getBabyInfo() {
const { ctx } = this; const { ctx } = this;
const user_id = 1; const user_uuid = 1;
const app_type_id = 1; const where = { user_uuid, is_deleted: 0 };
const app_user_id = 1; const babys_info = await ctx.classModel.CourseUserBaby.all({ where, order: [['id', 'desc']] });
const app_id = 1; let babys = [];
const where = { user_id, is_deleted: 0 }; for (let i in babys_info) {
const baby_info = await ctx.prometheusModel.CourseUserBaby.one({ where, }); const baby_info = babys_info[i];
let ret = {}; babys.push({
if (baby_info && baby_info.id) { id: baby_info.id,
ret.id = baby_info.id; gender: baby_info.gender,
ret.gender = baby_info.gender; birth: baby_info.birth,
ret.birth = baby_info.birth; address: baby_info.address,
ret.address = baby_info.address; lat: baby_info.lat,
ret.gender_text = GENDER[ret.gender]; lng: baby_info.lng,
ret.age = moment().format('YYYY') - baby_info.birth.substr(0, 4); gender_text: GENDER[baby_info.gender],
} age: moment().format('YYYY') - baby_info.birth.substr(0, 4),
});
return ret; }
if (babys.length === 0) {
return {};
}
const user_info = { address: babys[0].address, lat: babys[0].lat, lng: babys[0].lng };
return { user_info, babys };
} }
async saveBabyInfo(input) { async saveBabyInfo(input) {
const { ctx } = this; const { ctx } = this;
const user_id = 1; const user_uuid = 1;
const app_type_id = 1; const { id, gender, birth, address, lat, lng } = input;
const app_user_id = 1; const where = { id, user_uuid, is_deleted: 0 };
const app_id = 1; if (id) {
const { gender, birth, address } = input; await ctx.classModel.CourseUserBaby.edit({ params: { gender, birth, address, lat, lng }, where });
const baby_info = await this.getBabyInfo();
const where = { user_id, is_deleted: 0 };
if (baby_info && baby_info.id) {
await ctx.prometheusModel.CourseUserBaby.edit({ params: { gender, birth, address }, where });
} else { } else {
await ctx.prometheusModel.CourseUserBaby.add({ user_id, app_type_id, app_user_id, app_id, gender, birth, address }); await ctx.classModel.CourseUserBaby.add({ user_uuid, gender, birth, address, lat, lng });
} }
return true; return true;
...@@ -56,12 +58,8 @@ class UserService extends Service { ...@@ -56,12 +58,8 @@ class UserService extends Service {
async delBabyInfo() { async delBabyInfo() {
const { ctx } = this; const { ctx } = this;
const user_id = 1; const user_uuid = 1;
const app_type_id = 1; await ctx.classModel.CourseUserBaby.edit({ params: { is_deleted: 1, }, where: { user_uuid } });
const app_user_id = 1;
const app_id = 1;
await ctx.prometheusModel.CourseUserBaby.edit({ params: { is_deleted: 1, }, where: { user_id } });
return true; return true;
} }
...@@ -69,16 +67,13 @@ class UserService extends Service { ...@@ -69,16 +67,13 @@ class UserService extends Service {
async collectInstitution(institution_id) { async collectInstitution(institution_id) {
const { ctx } = this; const { ctx } = this;
const user_id = 1; const user_uuid = 1;
const app_type_id = 1; const where = { user_uuid, is_deleted: 0 };
const app_user_id = 1; let ret = await ctx.classModel.CourseUserCollection.one({ where, });
const app_id = 1;
const where = { user_id, is_deleted: 0 };
let ret = await ctx.prometheusModel.CourseUserCollection.one({ where, });
if (ret && ret.id) { if (ret && ret.id) {
return ret.id; return ret.id;
} }
ret = await await ctx.prometheusModel.CourseUserCollection.add({ user_id, app_type_id, app_user_id, app_id, institution_id }); ret = await await ctx.classModel.CourseUserCollection.add({ user_uuid, institution_id });
return ret; return ret;
} }
...@@ -86,21 +81,23 @@ class UserService extends Service { ...@@ -86,21 +81,23 @@ class UserService extends Service {
async getCollectInstitutions(input) { async getCollectInstitutions(input) {
const { ctx } = this; const { ctx } = this;
const user_id = 1; const user_uuid = 1;
const app_type_id = 1;
const app_user_id = 1;
const app_id = 1;
const { page, limit } = input; const { page, limit } = input;
const where = { user_id, is_deleted: 0 }; const where = { user_uuid, is_deleted: 0 };
const collect_institution_rows = await ctx.prometheusModel.CourseUserCollection.list({ page, limit, where }); const collect_institution_rows = await ctx.classModel.CourseUserCollection.list({ page, limit, where });
const institution_ids = R.pluck('institution_id', collect_institution_rows.rows); const institution_ids = R.pluck('institution_id', collect_institution_rows.rows);
if (institution_ids.length === 0) { if (institution_ids.length === 0) {
return { page: collect_institution_rows.page, count: collect_institution_rows.count, rows: [] }; return { page: collect_institution_rows.page, count: collect_institution_rows.count, rows: [] };
} }
const institutions = await ctx.prometheusModel.CourseInstitution.all({ where: { id: { $in: institution_ids }, status: 1, is_deleted: 0 } }); const include = [{ model: ctx.classModel.CourseArea, where: { status: 1, is_deleted: 0 }, attributes: ['id', 'institution_id', 'name', 'address', 'lat', 'lng'] }];
const ret = await ctx.service.course.institution.formatInstitutions(institutions); const attributes = ['id', 'name', 'type', 'establishment_time', 'class_type', 'teacher_count', 'teacher_experience', 'corner', 'min_age', 'max_age', 'price', 'characteristic',];
return { page: collect_institution_rows.page, count: collect_institution_rows.count, rows: ret }; const institutions = await ctx.classModel.CourseInstitution.findAll({ attributes, include, where: { id: { $in: institution_ids }, status: 1, is_deleted: 0 } });
const institution_area_list = await ctx.service.course.institution.getInstitutionAreaList(institutions);
const area_lbs = await ctx.service.course.institution.computeDistance(institution_area_list);
const institution_areas = await ctx.service.course.institution.findShortestDistanceAreas(institution_area_list, area_lbs);
const ret = await ctx.service.course.institution.formatInstitutions(institution_areas);
return { page: collect_institution_rows.page, count: collect_institution_rows.count, rows: 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