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: {
......
This diff is collapsed.
...@@ -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