Commit 3ffae893 authored by 任国军's avatar 任国军

add course v3

parent c211713e
Pipeline #18027 passed with stage
in 56 seconds
......@@ -16,7 +16,6 @@ class UserController extends Controller {
// 请求微信授权 获取openid
const wx_auth_ret = await ctx.service.course.v2.user.requestWxAuth(code);
const openid = wx_auth_ret.openid;// 获取openid
const session_key = wx_auth_ret.session_key;
// 检查是否已授权过 是否已入用户表
let user = await ctx.classModel.V2.CourseUser.one({ where: { openid, is_deleted: 0 } });
......@@ -29,7 +28,7 @@ class UserController extends Controller {
// 存储缓存标识
const user_uuid = user.uuid;
const key = 'course_v2_user_session_' + user_uuid;
await app.memcache.set(key, { user_uuid, openid, session_key }, 86400 * 7);
await app.memcache.set(key, { user_uuid, openid }, 86400 * 7);
const auth_token = ctx.helper.md5(openid + user_uuid + 'jbwl');
ctx.set('uuid', key);
ctx.set('auth_token', auth_token);
......@@ -41,15 +40,22 @@ class UserController extends Controller {
}
async registerUserInfo() {
const { ctx, service } = this;
const { ctx } = this;
const uuid = ctx.userUuid;
const input_params = ctx.request.body;
const { avatar, nickname, province, country, sex, city } = input_params;
const encryptedData = input_params.encryptedData || '';
const iv = input_params.iv || '';
const params = { avatar, nickname, province, country, sex, city, encryptedData, iv };
const ret = await service.course.v2.user.registerUserInfo(params);
ctx.success(ret);
// 查找用户是否存在并更新
const user = ctx.classModel.V2.CourseUser.one({ where: { uuid } });
await ctx.classModel.V2.CourseUser.edit({ params: { avatar, nickname, sex }, where: { uuid } });
let bindphone = 0;
if (user.phone) {
bindphone = 1;
}
const result = { bindphone };
ctx.success({ result });
}
/**
......@@ -129,13 +135,7 @@ class UserController extends Controller {
ctx.success({ result });
}
// 获取用户信息
async getUserInfo() {
const { ctx, service } = this;
const ret = await service.course.v2.user.getUserInfo();
ctx.success(ret);
}
}
module.exports = UserController;
......@@ -8,7 +8,7 @@ const request = require('request');
class WechatController extends Controller {
async test() {
const { ctx, service } = this;
const data = {MsgType: 'miniprogrampage'};
const data = { MsgType: 'miniprogrampage' };
await service.course.v2.wechat.sendMsg(data);
ctx.success();
}
......
'use strict';
const Controller = require('egg').Controller;
class InstitutionController extends Controller {
// 机构列表
async getInstitutions() {
const { ctx } = this;
const inputParams = ctx.request.query;
const ret = await ctx.service.course.v3.institution.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.v3.institution.getInstitution(inputParams);
ctx.success({ result });
}
// 课程列表
async getClasses() {
const { ctx } = this;
const inputParams = ctx.request.query;
const ret = await ctx.service.course.v3.institution.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.v3.institution.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.v3.institution.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.v3.institution.getTeacher(teacher_id);
ctx.success(ret);
}
// 获取分类
async getCats() {
const { ctx } = this;
const ret = await ctx.service.course.v3.institution.getCats();
ctx.success(ret);
}
// 搜索
async search() {
const { ctx } = this;
const inputParams = ctx.request.query;
const ret = await ctx.service.course.v3.institution.search(inputParams);
ctx.success(ret);
}
// 用户搜索历史
async getUserSearch() {
const { ctx, service } = this;
const ret = await service.course.v3.institution.getUserSearch();
ctx.success(ret);
}
// 获取热搜
async getHotSearch() {
const { ctx, service } = this;
const ret = await service.course.v3.institution.getHotSearch();
ctx.success(ret);
}
// 删除用户搜索历史
async deleteUserSearch() {
const { ctx, service } = this;
await service.course.v3.institution.deleteUserSearch();
ctx.success();
}
// 评论列表
async getComments() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v3.institution.getComments(inputParams);
ctx.success(ret);
}
// 搜索联想
async getSuggestSearch() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v3.institution.getSuggestSearch(inputParams);
ctx.success(ret);
}
// 用户收藏机构列表
async getUserCollectedInstitutions() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v3.institution.getUserCollectedInstitutions(inputParams);
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.v3.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.v3.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.v3.option.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.v3.option.getBanners(inputParams.alias);
ctx.success(ret);
}
}
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.v3.user.requestWxAuth(code);
const openid = wx_auth_ret.openid;// 获取openid
const session_key = wx_auth_ret.session_key;
// 检查是否已授权过 是否已入用户表
let user = await ctx.classModel.V3.CourseUser.one({ where: { openid, is_deleted: 0 } });
if (!user || !user.uuid) {
const uuid = uuidv4();
user = await ctx.classModel.V3.CourseUser.create({ uuid, openid });
// user.uuid = uuid;
}
console.info(user);
// 存储缓存标识
const user_uuid = user.uuid;
const key = 'course_v2_user_session_' + user_uuid;
await app.memcache.set(key, { user_uuid, openid, session_key }, 86400 * 7);
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, service } = this;
const input_params = ctx.request.body;
const { avatar, nickname, province, country, sex, city } = input_params;
const encryptedData = input_params.encryptedData || '';
const iv = input_params.iv || '';
const params = { avatar, nickname, province, country, sex, city, encryptedData, iv };
const ret = await service.course.v3.user.registerUserInfo(params);
ctx.success(ret);
}
/**
* 获取baby信息
*/
async getBabyInfo() {
const { ctx } = this;
const result = await ctx.service.course.v3.user.getBabyInfo();
ctx.success({ result });
}
/**
* 保存baby信息
*/
async saveBabyInfo() {
const { ctx } = this;
const input_params = ctx.request.body;
const result = await ctx.service.course.v3.user.saveBabyInfo(input_params);
ctx.success({ result });
}
/**
* 删除baby信息
*/
async delBabyInfo() {
const { ctx } = this;
const result = await ctx.service.course.v3.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.v3.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.v3.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.v3.user.delCollectInstitution(institution_id);
ctx.success({ result });
}
// 获取用户信息
async getUserInfo() {
const { ctx, service } = this;
const ret = await service.course.v3.user.getUserInfo();
ctx.success(ret);
}
}
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.v3.wechat.sendMsg(data);
ctx.success();
}
async callbackAction() {
const { ctx, service } = this;
await service.course.v3.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';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
const CourseArticle = app.classModel.define('course_article', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
type: INTEGER,
cat_id: INTEGER,
title: STRING,
content: TEXT,
image: STRING,
source: STRING,
like_count: 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_article',
});
return CourseArticle;
};
'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,
link: 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 CourseLogUser = app.classModel.define('course_log_user', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_uuid: STRING,
type: 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_log_user',
});
return CourseLogUser;
};
'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,
content: STRING,
age: STRING,
time: STRING,
sort: INTEGER,
cover_image: 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_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';
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,
type: INTEGER,
type_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,
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,
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,
order,
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 });
return res;
} catch (error) {
throw (error);
}
};
return CourseUserCollection;
};
......@@ -19,7 +19,6 @@ module.exports = app => {
router.post('third', '/user/auth', 'course.v2.user.auth');// 微信授权登录
router.post('third', '/user/register_user', miniAuth, 'course.v2.user.registerUserInfo');// 授权后注册用户
router.get('third', '/user/info', miniAuth, 'course.v2.user.getUserInfo');// 获取用户信息
router.get('third', '/user/baby', miniAuth, 'course.v2.user.getBabyInfo');// 获取baby信息
router.post('third', '/user/baby', miniAuth, 'course.v2.user.saveBabyInfo');// 保存baby信息
......
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/course/v3');
const loginAuth = app.middleware.loginAuth({ type: 'new' });// 登录中间件
const miniAuth = app.middleware.miniAuthV2();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件
// 版本二
router.get('third', '/cats', 'course.v3.institution.getCats');// 分类
router.get('third', '/options', 'course.v3.option.getOptions');// 筛选项
router.get('third', '/banners', 'course.v3.option.getBanners');// banner
router.post('third', '/address', miniAuth, 'course.v3.location.getAddress');// 根据经纬度或ip获取地理位置信息
router.get('third', '/institutions', miniAuth, 'course.v3.institution.getInstitutions');// 机构列表
router.get('third', '/institution/:institution_id', miniAuth, 'course.v3.institution.getInstitution');// 机构详情
router.get('third', '/classes', miniAuth, 'course.v3.institution.getClasses');// 课程列表
router.get('third', '/class/:class_id', miniAuth, 'course.v3.institution.getClass');// 课程详情
router.get('third', '/teachers', miniAuth, 'course.v3.institution.getTeachers');// 老师列表
router.get('third', '/teacher/:teacher_id', miniAuth, 'course.v3.institution.getTeacher');// 老师详情
router.post('third', '/user/auth', 'course.v3.user.auth');// 微信授权登录
router.post('third', '/user/register_user', miniAuth, 'course.v3.user.registerUserInfo');// 授权后注册用户
router.get('third', '/user/info', miniAuth, 'course.v3.user.getUserInfo');// 获取用户信息
router.get('third', '/user/baby', miniAuth, 'course.v3.user.getBabyInfo');// 获取baby信息
router.post('third', '/user/baby', miniAuth, 'course.v3.user.saveBabyInfo');// 保存baby信息
router.delete('third', '/user/baby', miniAuth, 'course.v3.user.delBabyInfo');// 删除baby信息
router.get('third', '/user/collection/institution', miniAuth, 'course.v3.institution.getUserCollectedInstitutions');// 收藏的机构列表
router.post('third', '/user/collection/institution', miniAuth, 'course.v3.user.collectInstitution');// 收藏机构
router.delete('third', '/user/collection/institution', miniAuth, 'course.v3.user.delCollectInstitution');// 取消收藏机构
router.get('third', '/wechat/callbackAction', 'course.v3.wechat.check');
router.post('third', '/wechat/callbackAction', 'course.v3.wechat.callbackAction');
router.post('third', '/wechat/test', 'course.v3.wechat.test');
router.get('third', '/comments', miniAuth, 'course.v3.institution.getComments');// 评论列表
router.get('third', '/search/hot', miniAuth, 'course.v3.institution.getHotSearch');// 热搜
router.get('third', '/search/suggest', miniAuth, 'course.v3.institution.getSuggestSearch');// 搜索联想
router.get('third', '/search', miniAuth, 'course.v3.institution.search');// 搜索
router.get('third', '/user/search', miniAuth, 'course.v3.institution.getUserSearch');// 用户搜索历史
router.delete('third', '/user/search', miniAuth, 'course.v3.institution.deleteUserSearch');// 清空用户搜索记录
};
......@@ -118,59 +118,7 @@ class UserService extends Service {
}
// 获取用户信息
async getUserInfo() {
const { ctx } = this;
const userUuid = ctx.userUuid;
const userInfo = await ctx.classModel.V2.CourseUser.findOne({ where: { uuid: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
ctx.failed('用户不存在');
}
const ret = {
bind_phone: ctx.isEmpty(userInfo.phone) ? 0 : 1,
};
return ret;
}
// 保存用户信息
async registerUserInfo(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const { avatar, nickname, province, country, sex, city, encryptedData, iv } = input;
// 查找用户是否存在并更新
const user = await ctx.classModel.V2.CourseUser.findOne({ where: { uuid: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(user)) {
ctx.failed('用户不存在');
}
const data = {};
let bind_phone = ctx.isEmpty(user.phone) ? 0 : 1;
if (!ctx.isEmpty(avatar)) {
data.avatar = avatar;
}
if (!ctx.isEmpty(nickname)) {
data.nickname = nickname;
}
if (!ctx.isEmpty(encryptedData) && !ctx.isEmpty(iv)) {
const decoded = await ctx.service.course.v2.wechat.decodeData(encryptedData, iv);
if (!ctx.isEmpty(decoded) && !ctx.isEmpty(decoded.phoneNumber)) {
data.phone = decoded.phoneNumber;
bind_phone = 1;
}
}
await ctx.classModel.V2.CourseUser.update(data, { where: { id: user.id } });
const ret = {
result: {
bind_phone,
},
};
return ret;
}
}
module.exports = UserService;
......@@ -4,7 +4,6 @@ const APPID = 'wx07a5f0ed5bdf4751';
const SECRET = 'a1b2d32b018988176181497bd74a0b7d';
const fs = require('fs');
const request = require('request');
const crypto = require('crypto');
class WechatService extends Service {
async getAccessToken() {
......@@ -137,38 +136,6 @@ class WechatService extends Service {
return ret;
}
// 解密
async decodeData(encryptedData, iv) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const userInfo = await ctx.app.memcache.get('course_v2_user_session_' + userUuid);
if (ctx.isEmpty(userInfo) || ctx.isEmpty(userInfo.session_key)) {
ctx.failed('sessionKey不存在');
}
const sessionKey = new Buffer(userInfo.session_key, 'base64');
// base64 decode
encryptedData = new Buffer(encryptedData, 'base64');
iv = new Buffer(iv, 'base64');
try {
// 解密
const decipher = crypto.createDecipheriv('aes-128-cbc', sessionKey, iv);
// 设置自动 padding 为 true,删除填充补位
decipher.setAutoPadding(true);
var decoded = decipher.update(encryptedData, 'binary', 'utf8');
decoded += decipher.final('utf8');
decoded = JSON.parse(decoded);
} catch (err) {
ctx.failed('Illegal Buffer');
}
return decoded;
}
}
module.exports = WechatService;
This diff is collapsed.
'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_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,
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 { service } = this;
const cats = await service.course.v3.institution.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.V3.CourseBannerType.findOne({ where: { alias, status: 'online', is_deleted: 0 }, row: true });
if (ctx.isEmpty(bannerType)) {
ctx.failed('数据不存在');
}
const banners = await ctx.classModel.V3.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.V3.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.V3.CourseUserBaby.edit({ params: { gender, birth, address, lat, lng }, where });
} else {
await ctx.classModel.V3.CourseUserBaby.add({ user_uuid, gender, birth, address, lat, lng });
}
return true;
}
async delBabyInfo() {
const { ctx } = this;
const user_uuid = ctx.userUuid;
await ctx.classModel.V3.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.V3.CourseUserCollection.one({ where });
if (ret && ret.id) {
return ret.id;
}
ret = await await ctx.classModel.V3.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.V3.CourseUserCollection.one({ where });
if (!ret || !ret.id) {
return true;
}
ret = await await ctx.classModel.V3.CourseUserCollection.edit({ params: { is_deleted: 1 }, where });
return true;
}
async requestWxAuth(code) {
const { ctx } = this;
const APPID = 'wx07a5f0ed5bdf4751';
const SECRET = 'a1b2d32b018988176181497bd74a0b7d';
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 };
}
// 获取用户信息
async getUserInfo() {
const { ctx } = this;
const userUuid = ctx.userUuid;
const userInfo = await ctx.classModel.V3.CourseUser.findOne({ where: { uuid: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
ctx.failed('用户不存在');
}
let need_bind_phone = 0;
if (ctx.isEmpty(userInfo.phone)) {
const userLog = await ctx.classModel.V3.CourseLogUser.findOne({ where: { user_uuid: userUuid, type: 1 }, order: [[ 'id', 'desc' ]], limit: 1 });
if ((!ctx.isEmpty(userLog) && moment(userLog.created_time, 'YYYY-MM-DD HH:mm:ss').format('YYYY-MM-DD') !== moment().format('YYYY-MM-DD')) || ctx.isEmpty(userLog)) {
need_bind_phone = 1;
await ctx.classModel.V3.CourseLogUser.create({ user_uuid: userUuid, type: 1, created_time: moment().format('YYYY-MM-DD HH:mm:ss') });
}
}
const ret = {
bind_phone: ctx.isEmpty(userInfo.phone) ? 0 : 1,
need_bind_phone,
};
return ret;
}
// 保存用户信息
async registerUserInfo(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const { avatar, nickname, province, country, sex, city, encryptedData, iv } = input;
// 查找用户是否存在并更新
const user = await ctx.classModel.V3.CourseUser.findOne({ where: { uuid: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(user)) {
ctx.failed('用户不存在');
}
const data = {};
let bind_phone = ctx.isEmpty(user.phone) ? 0 : 1;
if (!ctx.isEmpty(avatar)) {
data.avatar = avatar;
}
if (!ctx.isEmpty(nickname)) {
data.nickname = nickname;
}
if (!ctx.isEmpty(encryptedData) && !ctx.isEmpty(iv)) {
const decoded = await ctx.service.course.v3.wechat.decodeData(encryptedData, iv);
if (!ctx.isEmpty(decoded) && !ctx.isEmpty(decoded.phoneNumber)) {
data.phone = decoded.phoneNumber;
bind_phone = 1;
}
}
await ctx.classModel.V3.CourseUser.update(data, { where: { id: user.id } });
const ret = {
result: {
bind_phone,
},
};
return ret;
}
}
module.exports = UserService;
This diff is collapsed.
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