Commit 4d5a4da5 authored by 李尚科's avatar 李尚科
parents fa35e15a 391df626
Pipeline #16579 passed with stage
in 7 seconds
'use strict';
const Controller = require('egg').Controller;
class InstitutionSubController extends Controller {
//机构列表
async getInstitutions() {
const { ctx } = this;
const inputParams = ctx.request.query;
const ret = await ctx.service.course.institutionSub.getInstitutions(inputParams);
ctx.success(ret);
}
//机构详情
async getInstitution() {
const { ctx } = this;
let inputParams = ctx.params;
const query = ctx.query;
inputParams = Object.assign(inputParams, query);
const result = await ctx.service.course.institutionSub.getInstitution(inputParams);
ctx.success({ result });
}
//课程列表
async getClasses() {
const { ctx } = this;
const inputParams = ctx.request.query;
const ret = await ctx.service.course.institutionSub.getClasses(inputParams);
ctx.success(ret);
}
//课程详情
async getClass() {
const { ctx } = this;
const class_id = ctx.params.class_id;
if (!class_id) {
ctx.failed('error class_id');
}
const ret = await ctx.service.course.institutionSub.getClass(class_id);
ctx.success(ret);
}
// 老师列表
async getTeachers() {
const { ctx } = this;
const inputParams = ctx.request.query;
if (ctx.isEmpty(inputParams.institution_id)) {
ctx.failed('institution_id is empty');
}
const ret = await ctx.service.course.institutionSub.getTeachers(inputParams);
ctx.success(ret);
}
// 老师详情
async getTeacher() {
const { ctx } = this;
const teacher_id = ctx.params.teacher_id;
if (!teacher_id) {
ctx.failed('error teacher_id');
}
const ret = await ctx.service.course.institutionSub.getTeacher(teacher_id);
ctx.success(ret);
}
// 获取分类
async getCats() {
const { ctx } = this;
const ret = await ctx.service.course.institutionSub.getCats();
ctx.success(ret);
}
// 搜索
async search() {
const { ctx } = this;
const inputParams = ctx.request.query;
const ret = await ctx.service.course.institutionSub.search(inputParams);
ctx.success(ret);
}
// 用户搜索历史
async getUserSearch() {
const { ctx, service } = this;
const ret = await service.course.institutionSub.getUserSearch();
ctx.success(ret);
}
// 获取热搜
async getHotSearch() {
const { ctx, service } = this;
const ret = await service.course.institutionSub.getHotSearch();
ctx.success(ret);
}
// 删除用户搜索历史
async deleteUserSearch() {
const { ctx, service } = this;
await service.course.institutionSub.deleteUserSearch();
ctx.success();
}
// 评论列表
async getComments() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.institutionSub.getComments(inputParams);
ctx.success(ret);
}
// 搜索联想
async getSuggestSearch() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.institutionSub.getSuggestSearch(inputParams);
ctx.success(ret);
}
//用户收藏机构列表
async getUserCollectedInstitutions() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.institutionSub.getUserCollectedInstitutions(inputParams);
ctx.success(ret);
}
}
module.exports = InstitutionSubController;
'use strict';
const Controller = require('egg').Controller;
class OptionSubController extends Controller {
/**
* 筛选项
*/
async getOptions() {
const { ctx } = this;
const results = await ctx.service.course.optionSub.getOptions();
ctx.success({ results });
}
async getBanners() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
if (ctx.isEmpty(inputParams.alias)) {
ctx.failed('alias is empty');
}
const ret = await service.course.optionSub.getBanners(inputParams.alias);
ctx.success(ret);
}
}
module.exports = OptionSubController;
'use strict';
const Controller = require('egg').Controller;
class InstitutionController extends Controller {
/**
* 机构列表
*/
async institutionList() {
const { ctx } = this;
const input_params = ctx.request.body;
const results = await ctx.service.course.v1.institution.getInstitutions(input_params);
ctx.success({ results });
}
/**
* 机构详情
*/
async institutionInfo() {
const { ctx } = this;
let input_params = ctx.params;
const query = ctx.query;
input_params = Object.assign(input_params, query);
const result = await ctx.service.course.v1.institution.getInstitution(input_params);
ctx.success({ result });
}
/**
* 课程列表
*/
async classList() {
const { ctx } = this;
const input_params = ctx.request.body;
const results = await ctx.service.course.v1.institution.getClasses(input_params);
ctx.success({ results });
}
/**
* 课程详情
*/
async classInfo() {
const { ctx } = this;
const class_id = ctx.params.class_id;
if (!class_id) {
ctx.failed('error class_id');
}
let ret = await ctx.service.course.v1.institution.getClass(class_id);
ctx.success(ret);
}
/**
* 老师列表
*/
async teacherList() {
const { ctx } = this;
const input_params = ctx.request.body;
let ret = await ctx.service.course.v1.institution.getTeachers(input_params);
ctx.success(ret);
}
/**
* 老师详情
*/
async teacherInfo() {
const { ctx } = this;
const teacher_id = ctx.params.teacher_id;
if (!teacher_id) {
ctx.failed('error teacher_id');
}
let ret = await ctx.service.course.v1.institution.getTeacher(teacher_id);
ctx.success(ret);
}
}
module.exports = InstitutionController;
'use strict';
const Controller = require('egg').Controller;
class LocationController extends Controller {
/**
* 筛选项
*/
async getAddress() {
const { ctx } = this;
let { lat, lng } = ctx.request.body;
let address = '';
if (lat && lng) {
const location_ret = await ctx.service.course.v1.lbs.getLBSLocation({ lat, lng });
const loaction = location_ret.result;
if (loaction.formatted_addresses && loaction.formatted_addresses.recommend) {
address = loaction.formatted_addresses.recommend;
lat = loaction.location.lat;
lng = loaction.location.lng;
}
}
if (!address) {
const ip_ret = await ctx.service.course.v1.lbs.getLBSIp();
const ip = ip_ret.result;
if (ip.location && ip.ad_info) {
const city = ip.ad_info.city ? ip.ad_info.city : '';
const district = ip.ad_info.district ? ip.ad_info.district : '';
address = ip.ad_info.province + city + district;
lat = ip.location.lat;
lng = ip.location.lng;
}
}
if (!address) {
address = '获取地理位置信息失败';
}
ctx.success({ result: { address, lat, lng } });
}
}
module.exports = LocationController;
'use strict';
const Controller = require('egg').Controller;
class OptionController extends Controller {
/**
* 筛选项
*/
async getOptions() {
const { ctx } = this;
const results = await ctx.service.course.v1.option.getOptions();
ctx.success({ results });
}
}
module.exports = OptionController;
'use strict';
const Controller = require('egg').Controller;
const uuidv4 = require('uuid/v4');
class UserController extends Controller {
async auth() {
const { ctx, app } = this;
const code = ctx.request.body.code;
if (!code) {
ctx.failed('error code');
}
//请求微信授权 获取openid
const wx_auth_ret = await ctx.service.course.v1.user.requestWxAuth(code);
const openid = wx_auth_ret.openid;//获取openid
//检查是否已授权过 是否已入用户表
let user = await ctx.classModel.v1.CourseUser.one({ where: { openid, is_deleted: 0 } });
if (!user || !user.uuid) {
const uuid = uuidv4();
user = await ctx.classModel.v1.CourseUser.create({ uuid, openid });
// user.uuid = uuid;
}
console.info(user);
//存储缓存标识
const user_uuid = user.uuid;
const key = 'course_user_session_' + user_uuid;
await app.memcache.set(key, { user_uuid, openid }, 86400 * 180);
const auth_token = ctx.helper.md5(openid + user_uuid + 'jbwl');
ctx.set('uuid', key);
ctx.set('auth_token', auth_token);
const result = { uuid: user_uuid, auth_token };
ctx.success({ result });
}
async registerUserInfo() {
const { ctx } = this;
const uuid = ctx.userUuid;
const input_params = ctx.request.body;
const { avatar, nickname, province, country, sex, city } = input_params;
//查找用户是否存在并更新
const user = ctx.classModel.v1.CourseUser.one({ where: { uuid } });
await ctx.classModel.v1.CourseUser.edit({ params: { avatar, nickname, sex }, where: { uuid } });
let bindphone = 0;
if (user.phone) {
bindphone = 1;
}
const result = { bindphone };
ctx.success({ result });
}
/**
* 获取baby信息
*/
async getBabyInfo() {
const { ctx } = this;
const result = await ctx.service.course.v1.user.getBabyInfo();
ctx.success({ result });
}
/**
* 保存baby信息
*/
async saveBabyInfo() {
const { ctx } = this;
const input_params = ctx.request.body;
const result = await ctx.service.course.v1.user.saveBabyInfo(input_params);
ctx.success({ result });
}
/**
* 删除baby信息
*/
async delBabyInfo() {
const { ctx } = this;
const result = await ctx.service.course.v1.user.delBabyInfo();
ctx.success({ result });
}
/**
* 用户收藏机构列表
*/
async getCollectInstitutions() {
const { ctx } = this;
let input_params = ctx.request.body;
input_params = Object.assign(input_params, ctx.request.query);
const result = await ctx.service.course.v1.user.getCollectInstitutions(input_params);
ctx.success({ result });
}
/**
* 收藏机构
*/
async collectInstitution() {
const { ctx } = this;
const institution_id = ctx.request.body.institution_id;
if (!institution_id) {
ctx.failed('error institution_id');
}
const result = await ctx.service.course.v1.user.collectInstitution(institution_id);
ctx.success({ result });
}
/**
* 取消收藏机构
*/
async delCollectInstitution() {
const { ctx } = this;
const institution_id = ctx.request.body.institution_id;
if (!institution_id) {
ctx.failed('error institution_id');
}
const result = await ctx.service.course.v1.user.delCollectInstitution(institution_id);
ctx.success({ result });
}
}
module.exports = UserController;
'use strict';
const Controller = require('egg').Controller;
const crypto = require('crypto');
const fs = require('fs');
const request = require('request');
class WechatController extends Controller {
async test() {
const { ctx, service } = this;
const data = {MsgType: 'miniprogrampage'};
await service.course.v1.wechat.sendMsg(data);
ctx.success();
}
async callbackAction() {
const { ctx, service } = this;
await service.course.v1.wechat.callbackAction();
ctx.success('success');
}
async check() {
const { ctx } = this;
const params = ctx.request.query;
const {
signature,
timestamp,
nonce,
echostr,
} = params;
const array = [ '51gjj', timestamp, nonce ];
array.sort();
// 3.将三个参数字符串拼接成一个字符串进行sha1加密
const tempStr = array.join('');
const hashCode = crypto.createHash('sha1'); // 创建加密类型
const resultCode = hashCode.update(tempStr, 'utf8').digest('hex');
console.log(resultCode);
// 4.开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
if (resultCode === signature) {
ctx.success(echostr);
} else {
ctx.success();
}
}
}
module.exports = WechatController;
'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 CourseCat = app.classModel.define('course_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
first_id: INTEGER,
parent_id: INTEGER,
level: INTEGER,
name: STRING,
image: STRING,
color: STRING,
tips: STRING,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_cat',
});
const CourseCat = app.classModel.define('course_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
first_id: INTEGER,
parent_id: INTEGER,
level: INTEGER,
name: STRING,
image: STRING,
color: STRING,
tips: STRING,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_cat',
});
CourseCat.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseCat.findOne({
attributes: attributes,
where: where,
});
}
CourseCat.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseCat.findOne({
attributes,
where,
});
};
CourseCat.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseCat.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseCat.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseCat.findAll({
attributes,
where,
order,
});
};
CourseCat.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 CourseCat.findAndCountAll(condition);
return { page, count, rows };
}
CourseCat.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 CourseCat.findAndCountAll(condition);
return { page, count, rows };
};
CourseCat.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseCat.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
CourseCat.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseCat.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseCat.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseCat.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
CourseCat.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseCat.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseCat;
return CourseCat;
};
\ No newline at end of file
};
'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 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',
});
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.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseImages.findOne({
attributes,
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.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,
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.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 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.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);
}
CourseImages.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseImages.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseImages;
return CourseImages;
};
\ No newline at end of file
};
'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,
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',
});
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
};
......@@ -16,20 +16,11 @@ module.exports = app => {
address: STRING,
lat: DECIMAL,
lng: DECIMAL,
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
......
'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 CourseUser = app.classModel.define('course_user', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
uuid: STRING,
app_id: STRING,
app_user_id: STRING,
app_type_id: STRING,
user_id: STRING,
phone: STRING,
nickname: STRING,
avatar: STRING,
sex: STRING,
openid: STRING,
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_user',
});
const CourseUser = app.classModel.define('course_user', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
uuid: STRING,
app_id: STRING,
app_user_id: STRING,
app_type_id: STRING,
user_id: STRING,
phone: STRING,
nickname: STRING,
avatar: STRING,
sex: STRING,
openid: STRING,
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_user',
});
CourseUser.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUser.findOne({
attributes: attributes,
where: where,
});
}
CourseUser.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUser.findOne({
attributes,
where,
});
};
CourseUser.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUser.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseUser.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUser.findAll({
attributes,
where,
order,
});
};
CourseUser.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 CourseUser.findAndCountAll(condition);
return { page, count, rows };
}
CourseUser.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 CourseUser.findAndCountAll(condition);
return { page, count, rows };
};
CourseUser.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseUser.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
CourseUser.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseUser.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseUser.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUser.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
CourseUser.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUser.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseUser;
return CourseUser;
};
\ No newline at end of file
};
'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 CourseUserBaby = app.classModel.define('course_user_baby', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
user_uuid: STRING,
gender: ENUM('boy', 'girl'),
birth: STRING,
address: STRING,
lat: DECIMAL,
lng: DECIMAL,
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_user_baby',
});
const CourseUserBaby = app.classModel.define('course_user_baby', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_uuid: STRING,
gender: ENUM('boy', 'girl'),
birth: STRING,
address: STRING,
lat: DECIMAL,
lng: DECIMAL,
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_user_baby',
});
CourseUserBaby.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUserBaby.findOne({
attributes: attributes,
where: where,
});
}
CourseUserBaby.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUserBaby.findOne({
attributes,
where,
});
};
CourseUserBaby.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUserBaby.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseUserBaby.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUserBaby.findAll({
attributes,
where,
order,
});
};
CourseUserBaby.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 CourseUserBaby.findAndCountAll(condition);
return { page, count, rows };
}
CourseUserBaby.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 CourseUserBaby.findAndCountAll(condition);
return { page, count, rows };
};
CourseUserBaby.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseUserBaby.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
CourseUserBaby.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseUserBaby.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseUserBaby.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUserBaby.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
CourseUserBaby.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUserBaby.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseUserBaby;
return CourseUserBaby;
};
\ No newline at end of file
};
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM, FLOAT } = app.Sequelize;
const CourseArea = app.classModel.define('course_area_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_id: INTEGER,
name: STRING,
address: STRING,
phone: STRING,
lat: DECIMAL,
lng: DECIMAL,
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_area_v1',
});
CourseArea.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseArea.findOne({
attributes: attributes,
where: where,
});
}
CourseArea.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseArea.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseArea.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 CourseArea.findAndCountAll(condition);
return { page, count, rows };
}
CourseArea.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseArea.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseArea.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseArea.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseArea;
};
\ 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 CourseCat = app.classModel.define('course_cat_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
first_id: INTEGER,
parent_id: INTEGER,
level: INTEGER,
name: STRING,
image: STRING,
color: STRING,
tips: STRING,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_cat_v1',
});
CourseCat.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseCat.findOne({
attributes,
where,
});
};
CourseCat.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseCat.findAll({
attributes,
where,
order,
});
};
CourseCat.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 CourseCat.findAndCountAll(condition);
return { page, count, rows };
};
CourseCat.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseCat.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseCat.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseCat.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseCat;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseClass = app.classModel.define('course_class_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_id: INTEGER,
name: STRING,
// image: STRING,
price: DECIMAL,
min_age: INTEGER,
max_age: INTEGER,
suit_base: STRING,
type: STRING,
class_system: STRING,
class_period: STRING,
class_time: STRING,
student_count: STRING,
point: STRING,
description: 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_class_v1',
});
CourseClass.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseClass.findOne({
attributes: attributes,
where: where,
});
}
CourseClass.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseClass.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseClass.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 CourseClass.findAndCountAll(condition);
return { page, count, rows };
}
CourseClass.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseClass.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseClass.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseClass.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseClass;
};
\ 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 CourseImages = app.classModel.define('course_images_v1', {
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_v1',
});
CourseImages.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseImages.findOne({
attributes,
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,
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,
order,
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 });
return res;
} catch (error) {
throw (error);
}
};
return CourseImages;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseArea = app.classModel.define('course_area');
const CourseInstitution = app.classModel.define('course_institution_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
type: 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_v1',
});
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,
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,
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,
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.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;
};
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseInstitutionToCat = app.classModel.define('course_institution_to_cat_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_id: INTEGER,
cat_id: INTEGER,
status: ENUM('offline', 'online'),
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_institution_to_cat_v1',
});
CourseInstitutionToCat.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseInstitutionToCat.findOne({
attributes: attributes,
where: where,
});
}
CourseInstitutionToCat.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseInstitutionToCat.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseInstitutionToCat.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 CourseInstitutionToCat.findAndCountAll(condition);
return { page, count, rows };
}
CourseInstitutionToCat.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseInstitutionToCat.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseInstitutionToCat.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseInstitutionToCat.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseInstitutionToCat;
};
\ No newline at end of file
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseLogUserGps = app.classModel.define('course_log_user_gps_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
user_uuid: STRING,
address: STRING,
lat: DECIMAL,
lng: DECIMAL,
created_at: {
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_log_user_gps_v1',
});
CourseLogUserGps.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseLogUserGps.findOne({
attributes: attributes,
where: where,
});
}
CourseLogUserGps.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseLogUserGps.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseLogUserGps.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 CourseLogUserGps.findAndCountAll(condition);
return { page, count, rows };
}
CourseLogUserGps.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseLogUserGps.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseLogUserGps.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseLogUserGps.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseLogUserGps;
};
\ 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 CourseTeacher = app.classModel.define('course_teacher_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_id: INTEGER,
name: STRING,
avatar: STRING,
teacher_experience: INTEGER,
nationality: STRING,
educational_background: STRING,
certificate: STRING,
honor: STRING,
lesson: STRING,
work_experience: STRING,
point: STRING,
description: TEXT,
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_teacher_v1',
});
CourseTeacher.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseTeacher.findOne({
attributes: attributes,
where: where,
});
}
CourseTeacher.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseTeacher.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseTeacher.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? Number(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 CourseTeacher.findAndCountAll(condition);
return { page, count, rows };
}
CourseTeacher.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseTeacher.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseTeacher.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseTeacher.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseTeacher;
};
\ 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 CourseUser = app.classModel.define('course_user_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
uuid: STRING,
app_id: STRING,
app_user_id: STRING,
app_type_id: STRING,
user_id: STRING,
phone: STRING,
nickname: STRING,
avatar: STRING,
sex: STRING,
openid: STRING,
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_user_v1',
});
CourseUser.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUser.findOne({
attributes,
where,
});
};
CourseUser.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUser.findAll({
attributes,
where,
order,
});
};
CourseUser.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 CourseUser.findAndCountAll(condition);
return { page, count, rows };
};
CourseUser.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseUser.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseUser.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUser.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseUser;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseUserBaby = app.classModel.define('course_user_baby_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_uuid: STRING,
gender: ENUM('boy', 'girl'),
birth: STRING,
address: STRING,
lat: DECIMAL,
lng: DECIMAL,
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_user_baby_v1',
});
CourseUserBaby.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUserBaby.findOne({
attributes,
where,
});
};
CourseUserBaby.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUserBaby.findAll({
attributes,
where,
order,
});
};
CourseUserBaby.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 CourseUserBaby.findAndCountAll(condition);
return { page, count, rows };
};
CourseUserBaby.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseUserBaby.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseUserBaby.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUserBaby.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseUserBaby;
};
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseUserCollection = app.classModel.define('course_user_collection_v1', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
user_uuid: STRING,
institution_id: INTEGER,
is_deleted: INTEGER,
created_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('created_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
updated_at: {
type: DATE,
allowNull: true,
get() {
const date = this.getDataValue('updated_at');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
},
},
}, {
timestamps: false,
tableName: 'course_user_collection_v1',
});
CourseUserCollection.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUserCollection.findOne({
attributes: attributes,
where: where,
});
}
CourseUserCollection.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUserCollection.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseUserCollection.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 CourseUserCollection.findAndCountAll(condition);
return { page, count, rows };
}
CourseUserCollection.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseUserCollection.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseUserCollection.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUserCollection.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseUserCollection;
};
\ No newline at end of file
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseBanner = app.classModel.define('course_banner', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
type_id: INTEGER,
title: STRING,
url: 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_banner',
});
return CourseBanner;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseBannerType = app.classModel.define('course_banner_type', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
title: STRING,
alias: 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;
},
},
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_banner_type',
});
return CourseBannerType;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseComment = app.classModel.define('course_comment', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
institution_id: INTEGER,
user_uuid: STRING,
nickname: STRING,
avatar: STRING,
content: STRING,
has_image: 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_comment',
});
return CourseComment;
};
'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 CourseSearch = app.classModel.define('course_search', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
content: STRING,
count: INTEGER,
is_hot: 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_search',
});
return CourseSearch;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseStudentVideo = app.classModel.define('course_student_video', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
institution_id: INTEGER,
video_url: STRING,
title: STRING,
age: STRING,
time: 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_student_video',
});
return CourseStudentVideo;
};
'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';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseUserSearch = app.classModel.define('course_user_search', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_uuid: STRING,
content: STRING,
status: ENUM('offline', 'online'),
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_user_search',
});
return CourseUserSearch;
};
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM, FLOAT } = app.Sequelize;
const CourseArea = app.classModel.define('course_area', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_id: INTEGER,
name: STRING,
address: STRING,
phone: STRING,
lat: DECIMAL,
lng: DECIMAL,
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_area',
});
CourseArea.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseArea.findOne({
attributes: attributes,
where: where,
});
}
CourseArea.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseArea.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseArea.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 CourseArea.findAndCountAll(condition);
return { page, count, rows };
}
CourseArea.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseArea.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseArea.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseArea.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseArea;
};
\ 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 CourseCat = app.classModel.define('course_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
parent_id: INTEGER,
name: STRING,
image: STRING,
active_image: STRING,
color: STRING,
tips: 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_cat',
});
CourseCat.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseCat.findOne({
attributes,
where,
});
};
CourseCat.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseCat.findAll({
attributes,
where,
order,
});
};
CourseCat.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 CourseCat.findAndCountAll(condition);
return { page, count, rows };
};
CourseCat.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseCat.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseCat.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseCat.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseCat;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseClass = app.classModel.define('course_class', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_id: INTEGER,
name: STRING,
// image: STRING,
price: DECIMAL,
min_age: INTEGER,
max_age: INTEGER,
suit_base: STRING,
type: STRING,
class_system: STRING,
class_period: STRING,
class_time: STRING,
student_count: STRING,
point: STRING,
description: 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_class',
});
CourseClass.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseClass.findOne({
attributes: attributes,
where: where,
});
}
CourseClass.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseClass.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseClass.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 CourseClass.findAndCountAll(condition);
return { page, count, rows };
}
CourseClass.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseClass.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseClass.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseClass.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseClass;
};
\ 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 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,
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_images',
});
CourseImages.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseImages.findOne({
attributes,
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,
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,
order,
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 });
return res;
} catch (error) {
throw (error);
}
};
return CourseImages;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
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,
open_time: 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.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,
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,
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.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;
};
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseInstitutionToCat = app.classModel.define('course_institution_to_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_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_institution_to_cat',
});
CourseInstitutionToCat.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseInstitutionToCat.findOne({
attributes: attributes,
where: where,
});
}
CourseInstitutionToCat.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseInstitutionToCat.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseInstitutionToCat.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 CourseInstitutionToCat.findAndCountAll(condition);
return { page, count, rows };
}
CourseInstitutionToCat.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseInstitutionToCat.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseInstitutionToCat.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseInstitutionToCat.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseInstitutionToCat;
};
\ No newline at end of file
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseLogUserGps = app.classModel.define('course_log_user_gps', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
user_uuid: STRING,
address: STRING,
lat: DECIMAL,
lng: DECIMAL,
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_log_user_gps',
});
CourseLogUserGps.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseLogUserGps.findOne({
attributes: attributes,
where: where,
});
}
CourseLogUserGps.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseLogUserGps.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseLogUserGps.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 CourseLogUserGps.findAndCountAll(condition);
return { page, count, rows };
}
CourseLogUserGps.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseLogUserGps.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseLogUserGps.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseLogUserGps.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseLogUserGps;
};
\ 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 CourseTeacher = app.classModel.define('course_teacher', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
institution_id: INTEGER,
name: STRING,
avatar: STRING,
teacher_experience: INTEGER,
nationality: STRING,
educational_background: STRING,
certificate: STRING,
honor: STRING,
lesson: STRING,
work_experience: STRING,
point: STRING,
description: TEXT,
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_teacher',
});
CourseTeacher.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseTeacher.findOne({
attributes: attributes,
where: where,
});
}
CourseTeacher.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseTeacher.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseTeacher.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? Number(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 CourseTeacher.findAndCountAll(condition);
return { page, count, rows };
}
CourseTeacher.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseTeacher.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseTeacher.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseTeacher.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseTeacher;
};
\ 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 CourseUser = app.classModel.define('course_user', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
uuid: STRING,
app_id: STRING,
app_user_id: STRING,
app_type_id: STRING,
user_id: STRING,
phone: STRING,
nickname: STRING,
avatar: STRING,
sex: STRING,
openid: STRING,
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_user',
});
CourseUser.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUser.findOne({
attributes,
where,
});
};
CourseUser.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUser.findAll({
attributes,
where,
order,
});
};
CourseUser.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 CourseUser.findAndCountAll(condition);
return { page, count, rows };
};
CourseUser.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseUser.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseUser.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUser.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseUser;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseUserBaby = app.classModel.define('course_user_baby', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_uuid: STRING,
gender: ENUM('boy', 'girl'),
birth: STRING,
address: STRING,
lat: DECIMAL,
lng: DECIMAL,
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_user_baby',
});
CourseUserBaby.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUserBaby.findOne({
attributes,
where,
});
};
CourseUserBaby.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUserBaby.findAll({
attributes,
where,
order,
});
};
CourseUserBaby.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 CourseUserBaby.findAndCountAll(condition);
return { page, count, rows };
};
CourseUserBaby.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseUserBaby.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseUserBaby.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUserBaby.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseUserBaby;
};
'use strict';
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseUserCollection = app.classModel.define('course_user_collection', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true
},
user_uuid: STRING,
institution_id: INTEGER,
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_user_collection',
});
CourseUserCollection.one = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseUserCollection.findOne({
attributes: attributes,
where: where,
});
}
CourseUserCollection.all = async (data) => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseUserCollection.findAll({
attributes: attributes,
where: where,
order,
});
}
CourseUserCollection.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 CourseUserCollection.findAndCountAll(condition);
return { page, count, rows };
}
CourseUserCollection.add = async (data) => {
try {
//返回promise对象实力 instance
const res = await CourseUserCollection.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
}
CourseUserCollection.edit = async (data) => {
const where = data.where;
const params = data.params;
try {
const res = await CourseUserCollection.update(params, { where: where })
return res;
} catch (error) {
throw (error);
}
}
return CourseUserCollection;
};
\ No newline at end of file
......@@ -31,4 +31,40 @@ module.exports = app => {
router.get('third', '/wechat/callbackAction', 'course.wechat.check');
router.post('third', '/wechat/callbackAction', 'course.wechat.callbackAction');
router.post('third', '/wechat/test', 'course.wechat.test');
// 版本二
router.get('third', '/sub/cats', 'course.institutionSub.getCats');// 分类
router.get('third', '/sub/options', 'course.optionSub.getOptions');// 筛选项
router.get('third', '/sub/banners', 'course.optionSub.getBanners');// banner
router.post('third', '/sub/address', miniAuth, 'course.location.getAddress');// 根据经纬度或ip获取地理位置信息
router.get('third', '/sub/institutions', miniAuth, 'course.institutionSub.getInstitutions');// 机构列表
router.get('third', '/sub/institution/:institution_id', miniAuth, 'course.institutionSub.getInstitution');// 机构详情
router.get('third', '/sub/classes', miniAuth, 'course.institutionSub.getClasses');// 课程列表
router.get('third', '/sub/class/:class_id', miniAuth, 'course.institutionSub.getClass');// 课程详情
router.get('third', '/sub/teachers', miniAuth, 'course.institutionSub.getTeachers');// 老师列表
router.get('third', '/sub/teacher/:teacher_id', miniAuth, 'course.institutionSub.getTeacher');// 老师详情
router.post('third', '/sub/user/auth', 'course.user.auth');// 微信授权登录
router.post('third', '/sub/user/register_user', miniAuth, 'course.user.registerUserInfo');// 授权后注册用户
router.get('third', '/sub/user/baby', miniAuth, 'course.user.getBabyInfo');// 获取baby信息
router.post('third', '/sub/user/baby', miniAuth, 'course.user.saveBabyInfo');// 保存baby信息
router.delete('third', '/sub/user/baby', miniAuth, 'course.user.delBabyInfo');// 删除baby信息
router.get('third', '/sub/user/collection/institution', miniAuth, 'course.institutionSub.getUserCollectedInstitutions');// 收藏的机构列表
router.post('third', '/sub/user/collection/institution', miniAuth, 'course.user.collectInstitution');// 收藏机构
router.delete('third', '/sub/user/collection/institution', miniAuth, 'course.user.delCollectInstitution');// 取消收藏机构
router.get('third', '/sub/wechat/callbackAction', 'course.wechat.check');
router.post('third', '/sub/wechat/callbackAction', 'course.wechat.callbackAction');
router.post('third', '/sub/wechat/test', 'course.wechat.test');
router.get('third', '/sub/comments', miniAuth, 'course.institutionSub.getComments');// 评论列表
router.get('third', '/sub/search/hot', miniAuth, 'course.institutionSub.getHotSearch');// 热搜
router.get('third', '/sub/search/suggest', miniAuth, 'course.institutionSub.getSuggestSearch');//搜索联想
router.get('third', '/sub/search', miniAuth, 'course.institutionSub.search');// 搜索
router.get('third', '/sub/user/search', miniAuth, 'course.institutionSub.getUserSearch');// 用户搜索历史
router.delete('third', '/sub/user/search', miniAuth, 'course.institutionSub.deleteUserSearch');//清空用户搜索记录
};
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/course/v1');
const loginAuth = app.middleware.loginAuth({ type: 'new' });// 登录中间件
const miniAuth = app.middleware.miniAuth();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件
router.get('third', '/options', 'course.v1.option.getOptions');// 筛选项
router.post('third', '/address', miniAuth, 'course.v1.location.getAddress');// 根据经纬度或ip获取地理位置信息
router.post('third', '/institutions', miniAuth, 'course.v1.institution.institutionList');// 机构列表
router.get('third', '/institutions', miniAuth, 'course.v1.institution.institutionList');// 机构列表
router.get('third', '/institution/:institution_id/:area_id', miniAuth, 'course.v1.institution.institutionInfo');// 机构详情
router.post('third', '/classes', miniAuth, 'course.v1.institution.classList');// 课程列表
router.get('third', '/classes', miniAuth, 'course.v1.institution.classList');// 课程列表
router.get('third', '/class/:class_id', miniAuth, 'course.v1.institution.classInfo');// 课程详情
router.post('third', '/teachers', miniAuth, 'course.v1.institution.teacherList');// 老师列表
router.get('third', '/teachers', miniAuth, 'course.v1.institution.teacherList');// 老师详情
router.get('third', '/teacher/:teacher_id', miniAuth, 'course.v1.institution.teacherInfo');// 老师详情
router.post('third', '/user/auth', 'course.v1.user.auth');// 微信授权登录
router.post('third', '/user/register_user', miniAuth, 'course.v1.user.registerUserInfo');// 授权后注册用户
router.get('third', '/user/baby', miniAuth, 'course.v1.user.getBabyInfo');// 获取baby信息
router.post('third', '/user/baby', miniAuth, 'course.v1.user.saveBabyInfo');// 保存baby信息
router.delete('third', '/user/baby', miniAuth, 'course.v1.user.delBabyInfo');// 删除baby信息
router.get('third', '/user/collection/institution', miniAuth, 'course.v1.user.getCollectInstitutions');// 收藏的机构列表
router.post('third', '/user/collection/institution', miniAuth, 'course.v1.user.collectInstitution');// 收藏机构
router.delete('third', '/user/collection/institution', miniAuth, 'course.v1.user.delCollectInstitution');// 取消收藏机构
router.get('third', '/wechat/callbackAction', 'course.v1.wechat.check');
router.post('third', '/wechat/callbackAction', 'course.v1.wechat.callbackAction');
router.post('third', '/wechat/test', 'course.v1.wechat.test');
};
'use strict';
const Service = require('egg').Service;
const R = require('ramda');
const _ = require('lodash');
const moment = require('moment');
class InstitutionSubService extends Service {
// 获取分类
async getCats() {
const { ctx } = this;
const AllCats = await ctx.classModel.CourseCat.findAll({ where: { status: 1, is_deleted: 0 } });
const rootCats = [];
let ret = [];
// 先取出一级分类
for (const v of AllCats) {
if (v.parent_id === 0) {
rootCats[v.id] = v.dataValues;
rootCats[v.id].child = [{ id: 0, value: v.id, name: '全部', parent_id: 0, image: 'http://r.51gjj.com/webpublic/images/20191118/s6yRUsc5kclyu.png', active_image:'http://r.51gjj.com/webpublic/images/20191118/zYHkYp85vxk5m.png', color: '', tips: '', status: 'online', is_deleted: 0 }];
}
}
// 放入二级分类
for (const v of AllCats) {
if (v.parent_id > 0) {
v.value = v.id;
rootCats[v.parent_id].child.push(v);
}
}
const sort = function(a, b) {
return a.sort - b.sort;
};
// 整理
for (const v of rootCats) {
if (!ctx.isEmpty(v)) {
v.child = R.sort(sort)(v.child);
ret.push(v);
}
}
ret = R.sort(sort)(ret);
return { results: ret };
}
// 获取机构详情
async getInstitution(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const { institution_id } = input;
const lat = ctx.isEmpty(input.lat) ? 0 : input.lat;
const lng = ctx.isEmpty(input.lng) ? 0 : input.lng;
let institution = await ctx.classModel.CourseInstitution.findOne({ where: { id: institution_id, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(institution)) {
ctx.failed('机构不存在');
}
institution = institution.dataValues;
// 顶部相册
const images = await ctx.classModel.CourseImages.findAll({ where: { type: 1, type_id: institution_id, status: 'online', is_deleted: 0 } });
// 去重
const checkList = [];
let album = [];
for (const v of images) {
if ((v.is_video === 0 && checkList.includes(v.image_url)) || (v.is_video === 1 && checkList.includes(v.video_url))) {
continue;
}
album.push(v);
}
// 排序,视频在前
const albumSort = function(a, b) {
if (a.is_video === b.is_video) {
return a.sort - b.sort;
}
return b.is_video - a.is_video;
};
album = R.sort(albumSort)(album);
// 学习成果
const student_video = await ctx.classModel.CourseStudentVideo.findAll({ where: { institution_id, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ]] });
// 教师
const teachers = await ctx.classModel.CourseTeacher.findAll({ where: { institution_id, status: 'online', is_deleted: 0 } });
// 课程
let classes = await ctx.classModel.CourseClass.findAll({ where: { institution_id, status: 'online', is_deleted: 0 }, row: true });
classes = R.pluck('dataValues', classes);
// 处理课程封面图
const classHandle = [];
if (classes.length > 0) {
for (const v of classes) {
classHandle.push(ctx.classModel.CourseImages.findOne({ where: { type: 2, type_id: v.id, status: 'online', is_deleted: 0, is_cover: 1 } }));
}
const classImages = await Promise.all(classHandle).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
for (const i in classes) {
classes[i].image = classImages[i];
}
}
// 校区
let areas = await ctx.classModel.CourseArea.findAll({ where: { institution_id, status: 'online', is_deleted: 0 } });
const areaHandle = [];
if (areas.length > 0) {
for (const v of areas) {
areaHandle.push(this.formatArea(v, { lng, lat }));
}
areas = await Promise.all(areaHandle).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
}
areas = _.orderBy(areas, [ 'distance' ], [ 'asc' ]);
// 是否已收藏
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 ? 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 : '';
const ret = {
album,
detail: institution,
student_video,
teachers,
classes,
areas,
is_collected: ctx.isEmpty(userCollect) ? 0 : 1,
};
return ret;
}
// 处理校区
async formatArea(area, location) {
const { ctx, service } = this;
if (ctx.isEmpty(area)) {
return {};
}
const distance = await service.course.lbs.getDistance({ lng: location.lng, lat: location.lat }, { lng: area.lng, lat: area.lat });
// 暂定3公里以内步行
area.travel_method = distance < 3000 ? 'walking' : 'driving';
const lbsResult = await service.course.lbs.getLBSDistance(area.travel_method, { lng: location.lng, lat: location.lat }, [{ lng: area.lng, lat: area.lat }]);
if (lbsResult.results.length > 0) {
area.distance = (lbsResult.results[0].distance / 1000).toFixed(1);
area.duration = lbsResult.results[0].duration;
const minute = area.travel_method === 'walking' ? Math.ceil(area.distance / 80) : Math.ceil(area.duration / 60);
area.travel_tips = area.travel_method === 'walking' ? `距我${area.distance}km,步行${minute}分钟` : `距我${area.distance}km,开车${minute}分钟`;
} else {
area.distance = 999999;
area.duration = 0;
area.travel_tips = '';
}
return area;
}
// 机构列表
async getInstitutions(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const { cat_id, age, address } = input;
const lat = ctx.isEmpty(input.lat) ? 0 : input.lat;
const lng = ctx.isEmpty(input.lng) ? 0 : input.lng;
// 保存定位记录
if (address && lat && lng) {
ctx.classModel.CourseLogUserGps.create({ user_uuid: userUuid, address, lat, lng, created_time: moment().format('YYYY-MM-DD HH:mm:ss') });
}
let institutionList = [];
let institutionCats = [];
const filter = { where: { status: 'online', is_deleted: 0 } };
// 年龄筛选
if (Number(age) > 0) {
filter.where.min_age = { $lte: age };
filter.where.max_age = { $gte: age };
}
// 分类筛选
if (Number(cat_id) > 0) {
// 如果是一级分类,则需要加入该分类下所有子分类
const cats = await ctx.classModel.CourseCat.findAll({ where: { parent_id: cat_id, status: 'online', is_deleted: 0 } });
const catIds = R.pluck('id', cats);
catIds.push(Number(cat_id));
institutionCats = await ctx.classModel.CourseInstitutionToCat.findAll({ where: { status: 'online', is_deleted: 0, cat_id: { $in: catIds } } });
const institutionIds = R.pluck('institution_id', institutionCats);
filter.where.id = { $in: institutionIds };
}
institutionList = await ctx.classModel.CourseInstitution.findAll(filter);
institutionList = R.pluck('dataValues', institutionList);
const ret = await this.formatInstitutionList(institutionList, input);
return ret;
}
// 格式化机构列表
async formatInstitutionList(institutionList, input) {
const { ctx, service } = this;
const userUuid = ctx.userUuid;
const distance = Number(input.distance) || 0;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const { lng, lat } = input;
let institutionCats = [];
let institutionIds = R.pluck('id', institutionList);
// 获取机构对应的校区
const areaList = await ctx.classModel.CourseArea.findAll({ where: { status: 'online', is_deleted: 0, institution_id: { $in: institutionIds } } });
// 计算校区对应的距离
const areaHandle = [];
for (const v of areaList) {
areaHandle.push(service.course.lbs.getDistance({ lat, lng }, { lat: v.lat, lng: v.lng }));
}
const areaDistanceCalcResult = await Promise.all(areaHandle).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
for (const i in areaList) {
areaList[i].distance = areaDistanceCalcResult[i];
}
// 选出最短距离的校区
for (const v of areaList) {
for (const i in institutionList) {
if (institutionList[i].id === v.institution_id) {
if (ctx.isEmpty(institutionList[i].area) || (institutionList[i].area.distance > v.distance)) {
institutionList[i].area = v;
}
}
}
}
// 格式化机构距离
for (const i in institutionList) {
institutionList[i].distance = ctx.isEmpty(institutionList[i].area) ? 999999.0 : institutionList[i].area.distance;
}
institutionList = _.orderBy(institutionList, [ 'distance' ], [ 'asc' ]);
// 距离筛选
if (Number(distance) > 0) {
for (const i in institutionList) {
if (institutionList[i].distance > Number(distance)) {
institutionList = institutionList.slice(0, i);
break;
}
}
}
// 分页
const ret = {
results: [],
count: institutionList.length,
};
institutionList = institutionList.slice(Number(page - 1) * Number(limit), Number(page) * Number(limit));
institutionIds = R.pluck('id', institutionList);
// 获取所有分类
const allCats = await ctx.classModel.CourseCat.findAll({ where: { status: 'online', is_deleted: 0 } });
const catList = [];
for (const v of allCats) {
catList[v.id] = v;
}
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('institution_id', userInstitutions);
// 机构图片及格式化
for (const i in institutionList) {
// 格式化机构分类(展示一级分类)
let cats = [];
for (const v of institutionCats) {
if (v.institution_id === institutionList[i].id && catList[v.cat_id]) {
if (catList[v.cat_id].parent_id === 0) {
cats.push(v.cat_id);
} else {
cats.push(catList[v.cat_id].parent_id);
}
}
}
// 去重
cats = _.uniq(cats);
institutionList[i].cats = [];
for (const v of cats) {
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) {
const defaultImages = await ctx.classModel.CourseImages.findAll({ where: { type: 4, type_id: { $in: cats }, status: 'online', is_deleted: 0 }, limit: 3 - institutionImages.length });
institutionImages = institutionImages.concat(defaultImages);
}
institutionList[i].images = institutionImages;
institutionList[i].distance = String((institutionList[i].distance / 1000).toFixed(1)) + 'km';
institutionList[i].phone = institutionList[i].area.length > 0 ? institutionList[i].area[0].phone : '';
// 是否已收藏
institutionList[i].is_collected = userInstitutionIds.includes(institutionList[i].id) ? 1 : 0;
ret.results.push(institutionList[i]);
}
return ret;
}
// 搜索
async search(input) {
const { ctx } = this;
const { cat_id, age, search } = input;
const userUuid = ctx.userUuid;
// 保存搜索记录
if (search) {
const searchInfo = await ctx.classModel.CourseSearch.findOne({ where: { content: search, is_deleted: 0 } });
if (searchInfo) {
await ctx.classModel.CourseSearch.update({ count: searchInfo.count + 1 }, { where: { id: searchInfo.id } });
} else {
await ctx.classModel.CourseSearch.create({ content: search, sort: 0, count: 1, is_hot: 0, status: 'online', is_deleted: 0, created_time: moment().format('YYYY-MM-DD HH:mm:ss'), updated_time: moment().format('YYYY-MM-DD HH:mm:ss') });
}
await ctx.classModel.CourseUserSearch.create({ user_uuid: userUuid, content: search, status: 'online', created_time: moment().format('YYYY-MM-DD HH:mm:ss'), updated_time: moment().format('YYYY-MM-DD HH:mm:ss') });
}
let institutionList = [];
let institutionCats = [];
let institutionIds = [];
const filter = { where: { status: 'online', is_deleted: 0 }, row: true };
const classFilter = { where: { status: 'online', is_deleted: 0, name: { $like: '%' + search + '%' } }, attributes: [ 'id', 'institution_id', 'name', 'status', 'is_deleted' ], row: true };
// 年龄筛选
if (Number(age) > 0) {
filter.where.min_age = { $lte: age };
filter.where.max_age = { $gte: age };
}
// 分类筛选
if (Number(cat_id) > 0) {
// 如果是一级分类,则需要加入该分类下所有子分类
const cats = await ctx.classModel.CourseCat.findAll({ where: { parent_id: cat_id, status: 'online', is_deleted: 0 } });
const catIds = R.pluck('id', cats);
catIds.push(Number(cat_id));
institutionCats = await ctx.classModel.CourseInstitutionToCat.findAll({ where: { status: 'online', is_deleted: 0, cat_id: { $in: catIds } } });
institutionIds = R.pluck('institution_id', institutionCats);
}
if (institutionIds.length > 0) {
filter.where.id = { $in: institutionIds };
classFilter.where.institution_id = { $in: institutionIds };
}
const institutionFilter = filter;
institutionFilter.where.name = { $like: '%' + search + '%' };
institutionList = await ctx.classModel.CourseInstitution.findAll(institutionFilter);
const ids = R.pluck('id', institutionList);
// 课程搜索
const classList = await ctx.classModel.CourseClass.findAll(classFilter);
// 去除已经搜到的机构
const classInstitutionIds = _.difference(R.pluck('institution_id', classList), ids);
if (classInstitutionIds.length > 0) {
filter.where.id = { $in: classInstitutionIds };
const classInstitutionList = await ctx.classModel.CourseInstitution.findAll(filter);
institutionList = institutionList.concat(classInstitutionList);
}
institutionList = R.pluck('dataValues', institutionList);
const ret = await this.formatInstitutionList(institutionList, input);
return ret;
}
// 获取热搜
async getHotSearch() {
const { ctx } = this;
const search = await ctx.classModel.CourseSearch.findAll({ where: { status: 'online', is_deleted: 0, is_hot: 1 }, order: [[ 'sort', 'asc' ]] });
const ret = {
results: R.pluck('content', search),
count: search.length,
};
return ret;
}
// 获取用户搜索历史
async getUserSearch() {
const { ctx } = this;
const userUuid = ctx.userUuid;
const search = await ctx.classModel.CourseUserSearch.findAll({ where: { status: 'online', user_uuid: userUuid } });
const ret = {
results: R.pluck('content', search),
count: search.length,
};
return ret;
}
// 删除用户搜索历史
async deleteUserSearch() {
const { ctx } = this;
const userUuid = ctx.userUuid;
await ctx.classModel.CourseUserSearch.update({ status: 'offline' }, { where: { user_uuid: userUuid, status: 'online' } });
return;
}
// 评论列表
async getComments(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const institution_id = Number(input.institution_id) || 0;
const comments = await ctx.classModel.CourseComment.findAndCountAll({ where: { institution_id, status: 'online', is_deleted: 0 }, offset, limit, order: [[ 'id', 'desc' ]] });
comments.rows = R.pluck('dataValues', comments.rows);
const ret = {
results: await this.formatComments(comments.rows),
count: comments.count,
};
return ret;
}
// 格式化评论列表
async formatComments(comments) {
const { ctx } = this;
if (ctx.isEmpty(comments)) {
return [];
}
const ids = R.pluck('id', comments);
const images = await ctx.classModel.CourseImages.findAll({ where: { type: 3, type_id: { $in: ids }, status: 'online', is_deleted: 0 } });
const ret = [];
for (const v of comments) {
// 评论图片
let commentImages = [];
for (const j of images) {
if (j.type_id === v.id) {
commentImages.push(j);
}
}
commentImages = _.orderBy(commentImages, [ 'sort' ], [ 'asc' ]);
ret.push({
id: v.id,
institution_id: v.institution_id,
user_uuid: v.user_uuid,
nickname: v.nickname,
avatar: v.avatar,
content: v.content,
has_image: v.has_image,
images: commentImages,
created_time: v.created_time,
});
}
return ret;
}
// 搜索关联
async getSuggestSearch(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' ] });
results = R.pluck('name', institutions);
}
const ret = {
results,
count: results.length,
};
return ret;
}
// 教师详情
async getTeacher(id) {
const { ctx } = this;
let teacher = await ctx.classModel.CourseTeacher.findOne({ where: { id, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(teacher)) {
ctx.failed('数据不存在');
}
teacher = teacher.dataValues;
teacher.point_tags = teacher.point ? teacher.point.split(',') : [];
teacher.work_experience_tags = teacher.work_experience ? teacher.work_experience.split(';') : [];
const institution = await ctx.classModel.CourseInstitution.findOne({ where: { id: teacher.institution_id } });
teacher.institution_name = institution.name;
return teacher;
}
// 教师列表
async getTeachers(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const institutionId = Number(input.institution_id) || 0;
const teachers = await ctx.classModel.CourseTeacher.findAndCountAll({where: {institution_id: institutionId, status: 'online', is_deleted: 0}, raw:true, offset, limit});
const ret = {
results: teachers.rows,
count: teachers.count,
}
return ret;
}
//教师详情
async getTeacher(id) {
const {ctx} = this;
const teacher = await ctx.classModel.CourseTeacher.findOne({where: {id, status:'online', is_deleted: 0}, raw: true});
if (ctx.isEmpty(teacher)) {
ctx.failed('数据不存在');
}
teacher.point_tags = teacher.point ? teacher.point.split(',') : [];
teacher.work_experience_tags = teacher.work_experience ? teacher.work_experience.split(';') : [];
const institution = await ctx.classModel.CourseInstitution.findOne({ where: { id: teacher.institution_id } });
teacher.institution_name = institution.name;
return teacher;
}
//课程列表
async getClasses(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const institutionId = Number(input.institution_id) || 0;
const attributes = [ 'id', 'institution_id', 'name', 'type', 'price', 'status', 'is_deleted' ];
const classes = await ctx.classModel.CourseClass.findAndCountAll({where: {institution_id: institutionId, status: 'online', is_deleted: 0}, raw: true, offset, limit, attributes});
const classIds = R.pluck('id', classes.rows);
//课程图片
const classImages = await ctx.classModel.CourseImages.findAll({where: {type: 2, type_id: {$in:classIds}, status: 'online', is_deleted: 0}, raw:true});
for (const i in classes.rows) {
let images = [];
for (const v of classImages) {
if (v.type_id === classes.rows[i].id) {
images.push(v);
}
}
images = _.orderBy(images, ['is_cover', 'sort'], ['desc', 'asc']);
classes.rows[i].image = images.length > 0 ? images[0] : {};
}
const ret = {
results: classes.rows,
count: classes.count,
}
return ret;
}
//课程详情
async getClass(id) {
const {ctx} = this;
const classInfo = await ctx.classModel.CourseClass.findOne({where: {id, status: 'online', is_deleted: 0}, raw: true});
if (ctx.isEmpty(classInfo)) {
ctx.failed('数据不存在');
}
//课程图片
let images = await ctx.classModel.CourseImages.findAll({where: {type: 2, type_id: id, status: 'online', is_deleted: 0}, raw: true});
//去重
images = _.uniqBy(images, function(v){ return (v.is_image === 1 ? v.image_url : v.video_url)});
images = _.orderBy(images, ['sort'], ['asc']);
classInfo.images = images;
return classInfo;
}
//用户收藏机构列表
async getUserCollectedInstitutions(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const userCollection = await ctx.classModel.CourseUserCollection.findAll({where: {user_uuid: userUuid, is_deleted: 0}, raw: true});
const institutionIds = R.pluck('institution_id', userCollection);
const institutionList = await ctx.classModel.CourseInstitution.findAll({where: {id: {$in: institutionIds}, status: 'online', is_deleted:0}, raw: true});
const ret = await this.formatInstitutionList(institutionList, input);
return ret;
}
}
module.exports = InstitutionSubService;
......@@ -75,6 +75,21 @@ class OptionService extends Service {
return ret;
}
async getBanners(alias) {
const { ctx } = this;
const bannerType = await ctx.classModel.CourseBannerType.findOne({ where: { alias, status: 'online', is_deleted: 0 }, row: true });
if (ctx.isEmpty(bannerType)) {
ctx.failed('数据不存在');
}
const banners = await ctx.classModel.CourseBanner.findAll({ where: { type_id: bannerType.id, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ]], row: true });
const ret = {
results: banners,
count: banners.length,
};
return ret;
}
}
module.exports = OptionService;
'use strict';
const Service = require('egg').Service;
const AGE_CATS = [
{ id: -2, name: '全部', value: 0 },
{ id: -3, name: '3岁以下', value: 3 },
{ id: -4, name: '4岁', value: 4 },
{ id: -5, name: '5岁', value: 5 },
{ id: -6, name: '6岁', value: 6 },
{ id: -7, name: '7岁', value: 7 },
{ id: -8, name: '8岁', value: 8 },
{ id: -9, name: '9岁', value: 9 },
{ id: -10, name: '10岁', value: 10 },
{ id: -11, name: '11岁', value: 11 },
{ id: -12, name: '12岁', value: 12 },
{ id: -13, name: '12岁以上', value: 13 },
];
const INSTITUTION_TYPE = [
{ id: -14, name: '全部', value: '' },
{ id: -15, name: '品牌', value: '品牌' },
];
const DISTANCES = [
{ id: -16, name: '全部', value: 0 },
{ id: -17, name: '500米以内', value: 500 },
{ id: -18, name: '1公里以内', value: 1000 },
{ id: -19, name: '2公里以内', value: 2000 },
{ id: -20, name: '3公里以内', value: 3000 },
{ id: -21, name: '5公里以内', value: 5000 },
];
class OptionSubService extends Service {
async getOptions() {
const { service } = this;
const cats = await service.course.institutionSub.getCats();
const options = {
cats,
ages: AGE_CATS,
institutions: INSTITUTION_TYPE,
distances: DISTANCES,
};
return options;
}
async getBanners(alias) {
const { ctx } = this;
const bannerType = await ctx.classModel.CourseBannerType.findOne({ where: { alias, status: 'online', is_deleted: 0 }, row: true });
if (ctx.isEmpty(bannerType)) {
ctx.failed('数据不存在');
}
const banners = await ctx.classModel.CourseBanner.findAll({ where: { type_id: bannerType.id, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ]], row: true });
const ret = {
results: banners,
count: banners.length,
};
return ret;
}
}
module.exports = OptionSubService;
'use strict';
const Service = require('egg').Service;
const R = require('ramda');
const _ = require('lodash');
const moment = require('moment');
class InstitutionService extends Service {
// 机构列表页
async getInstitutions(input) {
const { ctx } = this;
const user_uuid = ctx.userUuid;
const { cats, ages, lat, lng, address, page } = input;
const distance = !ctx.isEmpty(input.distance) ? Number(input.distance) : 0;
const where_institutions = input.institutions;
// 保存定位记录
if (address && lat && lng) {
ctx.classModel.v1.CourseLogUserGps.add({ user_uuid, address, lat, lng });
}
// 处理条件过滤条件
const where = { status: 1, is_deleted: 0 };
if (Number(cats)) {
const cat_ret = await ctx.classModel.v1.CourseCat.one({ where: { id: cats } });
const cat_id = cat_ret.id;
const cat_level = cat_ret.level;
const next_level = cat_level + 1;
const next_next_level = cat_level + 2;
const next_cat = await ctx.classModel.v1.CourseCat.all({ where: { level: next_level, parent_id: cat_id } });
const next_next_cat = await ctx.classModel.v1.CourseCat.all({ where: { level: next_next_level, first_id: cat_id } });
let cat_ids = [ cat_id ];
cat_ids = cat_ids.concat(R.pluck('id', next_cat)).concat(R.pluck('id', next_next_cat));
const institutions = await ctx.classModel.v1.CourseInstitutionToCat.all({ where: { cat_id: { $in: cat_ids } } });
const institutions_ids = Array.from(new Set(R.pluck('institution_id', institutions)));
institutions_ids.length !== 0 ? where.id = { $in: institutions_ids } : [];
}
if (Number(ages)) {
where.max_age = { $gte: ages };
where.min_age = { $lte: ages };
}
if (where_institutions) {
where.corner = { $ne: '' };
}
// 关联校区表查找信息
const include = [{ model: ctx.classModel.v1.CourseArea, where: { status: 1, is_deleted: 0 }, attributes: [ 'id', 'institution_id', 'name', 'address', 'lat', 'lng' ] }];
const attributes = [ 'id', 'name', 'type', 'establishment_time', 'class_type', 'teacher_count', 'teacher_experience', 'corner', 'min_age', 'max_age', 'price', 'characteristic' ];
const institutions = await ctx.classModel.v1.CourseInstitution.findAll({ attributes, include, where });
const institution_area_list = await this.getInstitutionAreaList(institutions);// 将校区表处理成数组
// const from = { lat, lng };
// const area_lbs = await this.computeDistance(institution_area_list, { lat, lng });// 计算距离信息
const area_distance_list = await this.calcDistance(institution_area_list, { lat, lng }, page, distance);
const area_distance = area_distance_list.rows;
console.log(area_distance_list);
const institution_areas = await this.computeDistance(area_distance, { lat, lng });
for (const i in institution_areas) {
area_distance[i].distance = Number(institution_areas[i].distance) === 0 ? 999999999.0 : parseFloat(institution_areas[i].distance);
area_distance[i].duration = institution_areas[i].duration;
area_distance[i].travel_method = institution_areas[i].travel_method;
area_distance[i].travel_tips = `距我${area_distance[i].distance}km,开车${area_distance[i].duration}分钟`;
if (area_distance[i].travel_method === 'walking') {
area_distance[i].travel_tips = `距我${area_distance[i].distance}km,步行${area_distance[i].duration}分钟`;
}
if (Number(institution_areas[i].distance) === 0 && institution_areas[i].duration === 0) {
area_distance[i].travel_tips = '暂无法计算出距离';
}
}
// const institution_areas = await this.findShortestDistanceAreas(institution_area_list, area_lbs);// 查找最短距离并输出
// const ret = await this.formatInstitutions(institution_areas);
const ret = await this.formatInstitutions(area_distance, distance);
return { count: area_distance_list.count, rows: ret };
}
/**
* 机构详情页
*/
async getInstitution(input) {
const { ctx } = this;
const user_uuid = ctx.userUuid;
const { institution_id, area_id } = input;
const lat = ctx.isEmpty(input.lat) ? 0 : input.lat;
const lng = ctx.isEmpty(input.lng) ? 0 : input.lng;
const institution = await ctx.classModel.v1.CourseInstitution.one({ where: { id: institution_id } });
const teachers = await this.getTeachers({ institution_id, limit: 6 });
const classes = await this.getClasses({ institution_id, limit: 4 });
const institution_images = await ctx.classModel.v1.CourseImages.all({ where: { type: 1, type_id: institution_id } });// 图片
// 处理详情页信息
const current_area = await ctx.classModel.v1.CourseArea.one({ where: { id: area_id } });
let institution_detail = await this.formatInstitutions([ institution ]);
institution_detail = institution_detail[0];
institution_detail.address = current_area.address;
institution_detail.phone = current_area.phone;
institution_detail.description = institution.description;
institution_detail.point = institution.point;
institution_detail.honor = institution.honor;
institution_detail.is_collect = 0;
// 计算校区距离
const areas_ret = await this.getInstitutionAreas({ institution_id, limit: 1000 });// 校区
const area_rows = areas_ret.rows;
const area_lbs = (lat > 0 || lng > 0) ? await this.computeDistance(area_rows, { lat, lng }) : [];// 计算距离信息
let areas = [];
for (const i in area_rows) {
const area = area_rows[i];
const lbs = i < area_lbs.length ? area_lbs[i] : { distance: 0, duration: 0, travel_method: '' };
const area_name = area.name;
const distance = lbs.distance;
const duration = lbs.duration;
let travel_tips = `距我${distance}km,开车${duration}分钟`;
if (lbs.travel_method === 'walking') {
travel_tips = `距我${distance}km,步行${duration}分钟`;
}
if (Number(distance) === 0 && duration === 0) {
travel_tips = '暂无法计算出距离';
}
if (area.id == area_id && area.institution_id == institution_id) {
institution_detail.travel_tips = travel_tips;
institution_detail.lat = area.lat;
institution_detail.lng = area.lng;
}
areas.push({
id: area.id,
institution_id: area.institution_id,
name: area_name,
address: area.address,
phone: area.phone,
travel_tips,
lat: area.lat,
lng: area.lng,
distance: Number(distance) === 0 ? 999999999.0 : parseFloat(distance),
});
}
areas = _.orderBy(areas, [ 'distance' ], [ 'asc' ]);
// 是否收藏过
const collection_ret = await ctx.classModel.v1.CourseUserCollection.one({ where: { user_uuid, institution_id, is_deleted: 0 } });
if (collection_ret && collection_ret.id) {
institution_detail.is_collect = 1;
}
// 处理图片
const photo_album = [];
const photo_check = []; // 去重
for (const i in institution_images) {
const institution_image = institution_images[i];
if (institution_image.is_video > 0) {
if (photo_check.includes(institution_image.video_url)) {
continue;
} else {
photo_check.push(institution_image.video_url);
}
} else {
if (photo_check.includes(institution_image.image_url)) {
continue;
} else {
photo_check.push(institution_image.image_url);
}
}
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 };
}
async getTeacher(teacher_id) {
const { ctx } = this;
const where = { id: teacher_id };
const teacher = await ctx.classModel.v1.CourseTeacher.one({ where });
teacher.dataValues.point_tags = teacher.point ? teacher.point.split(',') : [];
teacher.dataValues.work_experience_tags = teacher.work_experience ? teacher.work_experience.split(';') : [];
const institution = await ctx.classModel.v1.CourseInstitution.find({ where: { id: teacher.institution_id } });
teacher.dataValues.institution_name = institution.name;
return teacher;
}
async getClass(class_id) {
const { ctx } = this;
const where = { id: class_id };
const classs = await ctx.classModel.v1.CourseClass.one({ where });
classs.dataValues.age_text = Number(classs.max_age) > 0 ? `${classs.min_age}-${classs.max_age}岁` : '';
classs.dataValues.point_tags = classs.point ? classs.point.split(',') : [];
const class_images = await ctx.classModel.v1.CourseImages.findAll({ where: { type: 2, type_id: classs.id } });
// 处理图片
const photo_album = [];
const photo_check = []; // 去重
for (const i in class_images) {
const class_image = class_images[i];
if (class_image.is_video > 0) {
if (photo_check.includes(class_image.video_url)) {
continue;
} else {
photo_check.push(class_image.video_url);
}
} else {
if (photo_check.includes(class_image.image_url)) {
continue;
} else {
photo_check.push(class_image.image_url);
}
}
photo_album.push({
image: class_image.image_url,
is_video: class_image.is_video,
video_url: class_image.video_url,
});
}
classs.dataValues.photo_album = photo_album;
classs.dataValues.class_period = classs.class_period > 0 ? classs.class_period : '';
return classs;
}
async getTeachers(input) {
const { ctx } = this;
const attributes = [ 'id', 'institution_id', 'name', 'avatar', 'teacher_experience', 'lesson', 'educational_background', 'certificate' ];
const { institution_id, page, limit } = input;
const where = { institution_id };
const teachers = await ctx.classModel.v1.CourseTeacher.list({ attributes, page, limit, where });
const ret = [];
for (const i in teachers.rows) {
const teacher = teachers.rows[i];
ret.push({
id: teacher.id,
institution_id: teacher.institution_id,
name: teacher.name ? teacher.name : '',
avatar: teacher.avatar ? teacher.avatar : '',
teacher_experience: teacher.teacher_experience ? teacher.teacher_experience : '',
lesson: teacher.lesson ? teacher.lesson : '',
educational_background: teacher.educational_background ? teacher.educational_background : '',
certificate: teacher.certificate ? teacher.certificate : '',
});
}
return { page, count: ret.length, rows: ret };
}
async getClasses(input) {
const { ctx } = this;
const attributes = [ 'id', 'institution_id', 'name', 'type', 'price' ];
const { institution_id, page, limit } = input;
const where = { institution_id };
const classes = await ctx.classModel.v1.CourseClass.list({ attributes, page, limit, where });
const p_class_images = [];
// 获取图片信息
for (const j in classes.rows) {
const classs = classes.rows[j];
p_class_images[j] = ctx.classModel.v1.CourseImages.one({ where: { type: 2, type_id: classs.id, is_video: 0 } });
}
const class_images = await Promise.all(p_class_images).then(result => { // 等待所有异步内容获取完成
return result;
}).catch(error => {
ctx.failed(error);
});
// 格式化课程信息
const ret = [];
for (const i in classes.rows) {
const classs = classes.rows[i];
classs.dataValues.image = class_images[i] ? class_images[i].image_url : '';
classs.dataValues.price_text = classs.price ? classs.price : '现场咨询';
classs.dataValues.class_period = classs.class_period > 0 ? classs.class_period : '';
ret.push(classs);
}
return { page: classes.page, count: classes.count, rows: ret };
}
async getInstitutionAreas(input) {
const { ctx } = this;
const attributes = [ 'id', 'institution_id', 'name', 'address', 'phone', 'lat', 'lng' ];
const { institution_id, page, limit } = input;
const where = { institution_id };
const areas = await ctx.classModel.v1.CourseArea.list({ attributes, page, limit, where });
return areas;
}
// 机构列表 并有多校区 {id:1,..., course_areas:[{},{}]
async getInstitutionAreaList(institutions) {
const { ctx } = this;
if (!Array.isArray(institutions) || institutions.length === 0) {
return [];
}
const ret = [];
for (const i in institutions) {
const institution = institutions[i];
if (!institution.course_areas || institution.course_areas.length === 0) continue;
const course_areas = institution.course_areas;
for (const j in course_areas) {
const course_area = course_areas[j];
ret.push({
id: institution.id,
name: institution.name,
type: institution.type,
image: institution.image,
establishment_time: institution.establishment_time,
class_type: institution.class_type,
teacher_count: institution.teacher_count,
teacher_experience: institution.teacher_experience,
corner: institution.corner,
min_age: institution.min_age,
max_age: institution.max_age,
price: institution.price,
characteristic: institution.characteristic,
area_id: course_area.id,
area_name: course_area.name,
area_address: course_area.address,
lat: course_area.lat,
lng: course_area.lng,
});
}
}
return ret;
}
/**
* 起点()到多个终点([{ lng: 120.212997, lat: 30.29133 }];) 计算距离 distance=3km
* @param {*} lbs_array [{ lng: 120.212997, lat: 30.29133 }]
* @param {*} from_gps { lng: 120.069206, lat: 30.291121 }
* @param {*} distance 3
*/
async computeDistance(lbs_array, from_gps, distance = 3) {
const { ctx } = this;
if (!Array.isArray(lbs_array) || lbs_array.length === 0) {
return [];
}
const from = from_gps;
const lat = from.lat;
const lng = from.lng;
// console.info({ lat, lng });
// 计算距离
const driving_results = await ctx.service.course.lbs.getLBSDistance('driving', { lat, lng }, lbs_array);
const walking_results = await ctx.service.course.lbs.getLBSDistance('walking', { lat, lng }, lbs_array);
if (!walking_results.results && !driving_results.results) {
return [];
}
// 处理距离结果
const drivings = driving_results.results.map(item => {
const distance = (item.distance / 1000).toFixed(1);
const duration = Math.ceil(item.duration / 60);
return { distance, duration };
});
const walkings = walking_results.results.map(item => {
const distance = (item.distance / 1000).toFixed(2);
const duration = Math.ceil(item.distance / 80);
return { distance, duration };
});
// 格式化 判断步行或驾车
const results = [];
for (const i in lbs_array) {
const lbs = lbs_array[i];
const driving = (drivings[i] && drivings[i].distance !== -1) ? drivings[i] : { distance: 0, duration: 0 };
const walking = (walkings[i] && walkings[i].distance !== -1) ? walkings[i] : { distance: 0, duration: 0 };
const lbs_distance = driving.distance > distance ? driving : walking;
const travel_method = driving.distance > distance ? 'driving' : 'walking';
results.push({
lat: lbs.lat,
lng: lbs.lng,
distance: lbs_distance.distance,
duration: lbs_distance.duration,
travel_method,
});
}
return results;
}
// 先本地用公式计算距离,然后分页,取对应的再去调腾讯接口
async calcDistance(lbs_array, from_gps, page = 1, distance = 0) {
const { ctx } = this;
if (!Array.isArray(lbs_array) || lbs_array.length === 0) {
return { count: 0, rows: [] };
}
const calcHandle = [];
for (const v of lbs_array) {
calcHandle.push(ctx.service.course.lbs.getDistance(v, from_gps));
}
const result = await Promise.all(calcHandle).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
let ret = [];
for (const i in result) {
const tmp = lbs_array[i];
tmp.distance = result[i];
if (distance === 0 || (distance > 0 && tmp.distance <= distance)) {
ret.push(tmp);
}
}
const sort = function(a, b) {
return a.distance - b.distance;
};
ret = R.sort(sort)(ret);
const institutions = [];
for (const v of ret) {
if (!institutions[v.id] && !ctx.isEmpty(v)) {
institutions[v.id] = v;
}
}
let results = [];
for (const v of institutions) {
if (!ctx.isEmpty(v)) {
results.push(v);
}
}
results = R.sort(sort)(results);
if (results.length <= (page - 1) * 10) {
return { count: 0, rows: [] };
}
const end = page * 10 > results.length ? results.length : page * 10;
return {
count: results.length,
rows: R.slice((page - 1) * 10, end)(results),
};
}
/**
*
* @param {*} institution_areas 校区列表
* @param {*} areas_list 校区距离列表
*/
async findShortestDistanceAreas(institution_areas, areas_list) {
const { ctx } = this;
let ret = [];
// const institution_lbs = await this.computeDistance(areas_list);
const institution_lbs = areas_list;
for (const i in institution_areas) {
const institution_area = institution_areas[i];
// TODO 校验经纬度
const lbs = i < institution_lbs.length ? institution_lbs[i] : { distance: 0, duration: 0, travel_method: '' };
const area_name = institution_area.area_name;
const distance = lbs.distance;
const duration = lbs.duration;
let travel_tips = `${area_name},距我${distance}km,开车${duration}分钟`;
if (lbs.travel_method === 'walking') {
travel_tips = `${area_name},距我${distance}km,步行${duration}分钟`;
}
if (Number(distance) === 0 && Number(duration) === 0) {
travel_tips = '暂无法计算出距离';
}
// area.distance = distance;
// area.duration = duration;
// area.travel_tips = travel_tips;
institution_area.distance = Number(distance) === 0 ? 999999999.0 : parseFloat(distance);
institution_area.duration = duration;
institution_area.travel_tips = travel_tips;
ret[i] = institution_area;
}
const results = [];
ret = _.orderBy(ret, [ 'distance' ], [ 'asc' ]);
for (const j in ret) {
const val = ret[j];
if (!results[val.id]) {
results[val.id] = val;
}
}
return results;
}
async formatInstitutions(institutions, distance = 0) {
const { ctx } = this;
if (!Array.isArray(institutions) || institutions.length === 0) {
return [];
}
// 处理机构图片
const p_institution_images = [];
for (const j in institutions) {
const institution = institutions[j];
p_institution_images[j] = ctx.classModel.v1.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 userCollect = await ctx.classModel.v1.CourseUserCollection.findAll({ where: { user_uuid: ctx.userUuid, is_deleted: 0 } });
const ids = R.pluck('institution_id', userCollect);
let ret = [];
for (const i in institutions) {
const institution = institutions[i];
if (distance > 0 && distance < institution.distance * 1000) {
continue;
}
// const course_areas = institution.course_areas;
// if (!course_areas || course_areas.length === 0) continue;
const age_tag = institution.min_age + '-' + institution.max_age + '岁';
const build_time = moment().format('YYYY') - institution.establishment_time;
const tags = [];
if (institution.max_age) {
tags.push(age_tag);
}
if (institution.class_type) {
tags.push(institution.class_type);
}
if (Number(institution.establishment_time)) {
tags.push('成立' + build_time + '年');
}
let image = institution_images[i] ? institution_images[i].image_url : '';
// 取不到封面图就从详情图列表里选一张
if (ctx.isEmpty(image)) {
const tmpImage = await ctx.classModel.v1.CourseImages.one({ where: { type: 1, type_id: institution.id, is_cover: 0, is_video: 0 } });
image = ctx.isEmpty(tmpImage) ? '' : tmpImage.image_url;
}
ret.push({
id: institution.id,
name: institution.name,
image,
establishment_time: institution.establishment_time,
class_type: institution.class_type,
teacher_count: institution.teacher_count ? institution.teacher_count : 0,
teacher_experience: institution.teacher_experience ? institution.teacher_experience : 0,
corner: institution.corner ? institution.corner : '',
min_age: institution.min_age,
max_age: institution.max_age,
price: institution.price ? institution.price : 0,
tags,
area_id: institution.area_id, // 校区id TODO
travel_tips: institution.travel_tips, // TODO
characteristic: institution.characteristic ? institution.characteristic : '',
distance: institution.distance,
is_collected: ids.includes(institution.id) ? 1 : 0,
});
}
ret = _.orderBy(ret, [ 'distance' ], [ 'asc' ]);
return ret;
}
}
module.exports = InstitutionService;
'use strict';
const Service = require('egg').Service;
class LbsService extends Service {
// 计算两个经纬度之间的距离,用Haversine公式,单位:m
async getDistance(from, to) {
const rad_from = from.lat * Math.PI / 180.0;
const rad_to = to.lat * Math.PI / 180.0;
const sub_lat = rad_from - rad_to;
const sub_lng = from.lng * Math.PI / 180.0 - to.lng * Math.PI / 180.0;
const r = 6378137; // 地球半径
const distance = r * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(sub_lat / 2), 2) + Math.cos(rad_from) * Math.cos(rad_to) * Math.pow(Math.sin(sub_lng / 2), 2)));
return distance;
}
// 腾讯位置服务WebService API,距离计算(一对多)
// 返回示例:
// {
// "results": [
// {
// "from": {
// "lat": 39.983171,
// "lng": 116.308479
// },
// "to": {
// "lat": 39.996059,
// "lng": 116.353454
// },
// "distance": 5354.7,
// "duration": 1678
// },
// {
// "from": {
// "lat": 39.983171,
// "lng": 116.308479
// },
// "to": {
// "lat": 39.949226,
// "lng": 116.394309
// },
// "distance": 10495.8, // 起点到终点的距离,单位:米。如果radius半径过小或者无法搜索到,则返回-1
// "duration": 2635 // 表示从起点到终点的结合路况的时间,秒为单位。 注:步行方式不计算耗时,该值始终为0
// }
// ]
// }
async getLBSDistance(mode = 'driving', from, toArr) {
const { ctx } = this;
const to = [];
let result = [];
for (const v of toArr) {
to.push(String(v.lat) + ',' + String(v.lng));
}
console.info(from);
const params = {
mode, // driving, walking;默认driving
from: String(from.lat) + ',' + String(from.lng),
to: to.join(';'),
key: ctx.app.config.TX_LBS_KEY,
};
const resp = await ctx.helper.send_request(ctx.app.config.TX_LBS_DISTANCE_URL, params, { method: 'GET' });
// resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权
ctx.logger.info('tx_lbs_distance_params: ' + JSON.stringify(params));
ctx.logger.info('tx_lbs_distance_resp: ' + JSON.stringify(resp));
if (resp.status === 200) {
// 判断响应是否正确
if (resp.data.status === 0) {
result = resp.data.result.elements;
}
}
return { results: result };
}
// 地址解析
async getLBSAddress(address) {
const { ctx } = this;
let result = {};
const params = {
address,
key: ctx.app.config.TX_LBS_KEY,
};
const resp = await ctx.helper.send_request(ctx.app.config.TX_LBS_ADDRESS_URL, params, { method: 'GET' });
// resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权
ctx.logger.info('tx_lbs_address_resp: ' + JSON.stringify(resp));
if (resp.status === 200) {
// 判断响应是否正确
if (resp.data.status === 0) {
result = resp.data.result;
}
}
return { result };
}
// 逆地址解析
async getLBSLocation(location) {
const { ctx } = this;
let result = {};
const params = {
location: location.lat + ',' + location.lng,
key: ctx.app.config.TX_LBS_KEY,
};
const resp = await ctx.helper.send_request(ctx.app.config.TX_LBS_ADDRESS_URL, params, { method: 'GET' });
// resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权
ctx.logger.info('tx_lbs_address_resp: ' + JSON.stringify(resp));
if (resp.status === 200) {
// 判断响应是否正确
if (resp.data.status === 0) {
result = resp.data.result;
}
}
return { result };
}
// 地址解析
async getLBSAddress(address) {
const { ctx } = this;
let result = {};
const params = {
address,
key: ctx.app.config.TX_LBS_KEY,
};
const resp = await ctx.helper.send_request(ctx.app.config.TX_LBS_ADDRESS_URL, params, { method: 'GET' });
// resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权
ctx.logger.info('tx_lbs_location_resp: ' + JSON.stringify(resp));
if (resp.status === 200) {
// 判断响应是否正确
if (resp.data.status === 0) {
result = resp.data.result;
}
}
return { result };
}
// 逆地址解析
async getLBSIp() {
const { ctx } = this;
let result = {};
const ip = ctx.helper.getClientIP();
if (!ip) {
return result;
}
const params = {
ip: ip,
key: ctx.app.config.TX_LBS_KEY,
};
const resp = await ctx.helper.send_request(ctx.app.config.TX_LBS_URL + '/location/v1/ip ', params, { method: 'GET' });
// resp.data.status 状态码,0:正常,310:请求参数信息有误,311:Key格式错误,306:请求有护持信息请检查字符串,110:请求来源未被授权
ctx.logger.info('tx_lbs_ip_resp: ' + JSON.stringify(resp));
if (resp.status === 200) {
// 判断响应是否正确
if (resp.data.status === 0) {
result = resp.data.result;
}
}
return { result };
}
}
module.exports = LbsService;
'use strict';
const Service = require('egg').Service;
const AGE_CATS = [
{ id: -2, name: '全部', value: 0 },
{ id: -3, name: '3岁以下', value: 3 },
{ id: -4, name: '4岁', value: 4 },
{ id: -5, name: '5岁', value: 5 },
{ id: -6, name: '6岁', value: 6 },
{ id: -7, name: '7岁', value: 7 },
{ id: -8, name: '8岁', value: 8 },
{ id: -9, name: '9岁', value: 9 },
{ id: -10, name: '10岁', value: 10 },
{ id: -11, name: '11岁', value: 11 },
{ id: -12, name: '12岁', value: 12 },
{ id: -13, name: '12岁以上', value: 13 },
];
const INSTITUTION_TYPE = [
{ id: -14, name: '全部', value: '' },
{ id: -15, name: '品牌', value: '品牌' },
];
const DISTANCES = [
{ id: -16, name: '全部', value: 0 },
{ id: -17, name: '500米以内', value: 500 },
{ id: -18, name: '1公里以内', value: 1000 },
{ id: -19, name: '2公里以内', value: 2000 },
{ id: -20, name: '3公里以内', value: 3000 },
{ id: -21, name: '5公里以内', value: 5000 },
];
class OptionService extends Service {
/**
* 我的信用首页
*/
async getOptions() {
const { ctx } = this;
const cats = await ctx.classModel.v1.CourseCat.all({ where: { status: 1, is_deleted: 0 } });
const tree_cats = this.getTrees(cats, 0);
const options = {
cats: tree_cats,
ages: AGE_CATS,
institutions: INSTITUTION_TYPE,
distances: DISTANCES,
};
return options;
}
getTrees(data, rootId) {
const ret = [];
for (let i = 0; i < data.length; i++) {
const node = data[i];
if (node.parent_id == rootId) {
const newNode = {};
// if (node.parent_id == 0) newNode._child.push({ id: 0, name: '全部', value: '' });
newNode.id = node.id;
newNode.name = node.name;
newNode.tips = node.tips;
newNode.image = node.image;
newNode.color = node.color;
newNode.level = node.level;
newNode.value = node.id;
newNode._child = this.getTrees(data, node.id);
if (newNode._child.length !== 0) newNode._child.unshift({ id: 0, name: '全部', value: node.id });
ret.push(newNode);
}
}
return ret;
}
async getBanners(alias) {
const { ctx } = this;
const bannerType = await ctx.classModel.v1.CourseBannerType.findOne({ where: { alias, status: 'online', is_deleted: 0 }, row: true });
if (ctx.isEmpty(bannerType)) {
ctx.failed('数据不存在');
}
const banners = await ctx.classModel.v1.CourseBanner.findAll({ where: { type_id: bannerType.id, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ]], row: true });
const ret = {
results: banners,
count: banners.length,
};
return ret;
}
}
module.exports = OptionService;
'use strict';
const Service = require('egg').Service;
const moment = require('moment');
const R = require('ramda');
const GENDER = {
boy: '小王子',
girl: '小公主',
};
class UserService extends Service {
async getBabyInfo() {
const { ctx } = this;
const user_uuid = ctx.userUuid;
const where = { user_uuid, is_deleted: 0 };
const babys_info = await ctx.classModel.v1.CourseUserBaby.all({ where, order: [[ 'id', 'desc' ]] });
const babys = [];
for (const i in babys_info) {
const baby_info = babys_info[i];
babys.push({
id: baby_info.id,
gender: baby_info.gender,
birth: baby_info.birth,
address: baby_info.address,
lat: baby_info.lat,
lng: baby_info.lng,
gender_text: GENDER[baby_info.gender],
age: moment().format('YYYY') - baby_info.birth.substr(0, 4),
});
}
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) {
const { ctx } = this;
const user_uuid = ctx.userUuid;
const { id, gender, birth, address, lat, lng } = input;
const where = { id, user_uuid, is_deleted: 0 };
if (id) {
await ctx.classModel.v1.CourseUserBaby.edit({ params: { gender, birth, address, lat, lng }, where });
} else {
await ctx.classModel.v1.CourseUserBaby.add({ user_uuid, gender, birth, address, lat, lng });
}
return true;
}
async delBabyInfo() {
const { ctx } = this;
const user_uuid = ctx.userUuid;
await ctx.classModel.v1.CourseUserBaby.edit({ params: { is_deleted: 1 }, where: { user_uuid } });
return true;
}
async collectInstitution(institution_id) {
const { ctx } = this;
const user_uuid = ctx.userUuid;
const where = { user_uuid, is_deleted: 0, institution_id };
let ret = await ctx.classModel.v1.CourseUserCollection.one({ where });
if (ret && ret.id) {
return ret.id;
}
ret = await await ctx.classModel.v1.CourseUserCollection.add({ user_uuid, institution_id });
return ret;
}
async delCollectInstitution(institution_id) {
const { ctx } = this;
const user_uuid = ctx.userUuid;
const where = { user_uuid, is_deleted: 0, institution_id };
let ret = await ctx.classModel.v1.CourseUserCollection.one({ where });
if (!ret || !ret.id) {
return true;
}
ret = await await ctx.classModel.v1.CourseUserCollection.edit({ params: { is_deleted: 1 }, where });
return true;
}
async getCollectInstitutions(input) {
const { ctx } = this;
const user_uuid = ctx.userUuid;
const { page, limit } = input;
const lat = ctx.isEmpty(input.lat) ? 0 : input.lat;
const lng = ctx.isEmpty(input.lng) ? 0 : input.lng;
const where = { user_uuid, is_deleted: 0 };
const collect_institution_rows = await ctx.classModel.v1.CourseUserCollection.list({ page, limit, where });
const institution_ids = R.pluck('institution_id', collect_institution_rows.rows);
if (institution_ids.length === 0) {
return { page: collect_institution_rows.page, count: collect_institution_rows.count, rows: [] };
}
const include = [{ model: ctx.classModel.v1.CourseArea, where: { status: 1, is_deleted: 0 }, attributes: [ 'id', 'institution_id', 'name', 'address', 'lat', 'lng' ] }];
const attributes = [ 'id', 'name', 'type', 'establishment_time', 'class_type', 'teacher_count', 'teacher_experience', 'corner', 'min_age', 'max_age', 'price', 'characteristic' ];
const institutions = await ctx.classModel.v1.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 = (lat > 0 || lng > 0) ? await ctx.service.course.institution.computeDistance(institution_area_list, { lat, lng }) : [];// 计算距离
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 };
}
async requestWxAuth(code) {
const { ctx } = this;
const APPID = 'wx4769ebba9b91f8ec';
const SECRET = '680440637b4e38c9b66529cfd5dc590e';
const url = `https://api.weixin.qq.com/sns/jscode2session?appid=${APPID}&secret=${SECRET}&js_code=${code}&grant_type=authorization_code`;
const result = await ctx.helper.send_request(url, {}, { method: 'GET' });
// const result = {"data":{"session_key":"Ce7HE1+MXfyZpWLYmkP0Iw==","openid":"oSjKI5LlG6AF7_vdV5Qb_DsbHcf4"},"status":200,"headers":{"connection":"keep-alive","content-type":"text/plain","date":"Tue, 24 Sep 2019 06:18:58 GMT","content-length":"82"},"res":{"status":200,"statusCode":200,"statusMessage":"OK","headers":{"connection":"keep-alive","content-type":"text/plain","date":"Tue, 24 Sep 2019 06:18:58 GMT","content-length":"82"},"size":82,"aborted":false,"rt":113,"keepAliveSocket":false,"data":{"session_key":"Ce7HE1+MXfyZpWLYmkP0Iw==","openid":"oSjKI5LlG6AF7_vdV5Qb_DsbHcf4"},"requestUrls":["https://api.weixin.qq.com/sns/jscode2session?appid=wx4769ebba9b91f8ec&secret=680440637b4e38c9b66529cfd5dc590e&js_code=021678ss18NNAk0Fohps1oA6ss1678sT&grant_type=authorization_code"],"timing":{"queuing":15,"dnslookup":15,"connected":27,"requestSent":57,"waiting":111,"contentDownload":113},"remoteAddress":"101.227.162.120","remotePort":443,"socketHandledRequests":1,"socketHandledResponses":1}};
ctx.logger.info(JSON.stringify({ course_mini_auth_ret: result }));
if (result.status !== 200) {
ctx.failed('授权失败');
}
const ret = result.data;
if (!ret.session_key && !ret.openid && ret.errcode !== 0) {
ctx.failed(ret.errmsg);
}
const openid = ret.openid;
const session_key = ret.session_key;
return { openid, session_key };
}
}
module.exports = UserService;
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -17,8 +17,8 @@ module.exports = appInfo => {
domainWhiteList: [],
};
config.middleware = ['errorHandler', 'deviceLogin', 'deviceInit', 'responseSet'];
config.middleware = [];
config.middleware = [ 'errorHandler', 'deviceLogin', 'deviceInit', 'responseSet' ];
// config.middleware = [];
exports.multipart = {
// 不用steam用file
......@@ -90,7 +90,7 @@ module.exports = appInfo => {
// other sequelize configurations
dialect: 'mysql',
host: 'rm-bp1mnwmta5778y0d3jo.mysql.rds.aliyuncs.com',
database: 'prometheus_uat',
database: 'prometheus_dev',
username: 'prometheus',
password: 'q9t8Ay4qIUW4sw3s25K28',
port: 3306,
......@@ -170,11 +170,11 @@ module.exports = appInfo => {
config.TX_LBS_URL = 'https://apis.map.qq.com/ws'; // 地址解析;逆地址解析
//我的信用-通化检测
// 我的信用-通化检测
config.YYS_APP_KEY = 'A86BB96F55B64DCE87A46E919A347993';
config.YYS_APPLY_APPSECRET = 'a695e9b3c0f1e3f15fb0b958fd3a4b67';
//运营商报告
// 运营商报告
config.YYS_REPORT_KEY = 'F4E0CA710F484CFFB1756741696E29A3';
config.YYS_REPORT_APPSECRET = '233B8E10E31B4C899EE6FEB3AEC22F140B6528BF';
config.YYS_REPORT_URL = 'http://47.96.253.64:8049/mycredit/thxdReport';
......
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