Commit 13bf2cbf authored by 任国军's avatar 任国军

add course v5

parent c017a99e
Pipeline #21576 passed with stage
in 12 seconds
'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.v4.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.v4.institution.getInstitution(inputParams);
ctx.success({ result });
}
// 课程列表
async getClasses() {
const { ctx } = this;
const inputParams = ctx.request.query;
const ret = await ctx.service.course.v4.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 inputParams = ctx.request.query;
inputParams.id = class_id;
const ret = await ctx.service.course.v4.institution.getClass(inputParams);
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.v4.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.v4.institution.getTeacher(teacher_id);
ctx.success(ret);
}
// 获取分类
async getCats() {
const { ctx } = this;
const ret = await ctx.service.course.v4.institution.getCats();
ctx.success(ret);
}
// 搜索
async search() {
const { ctx } = this;
const inputParams = ctx.request.query;
const ret = await ctx.service.course.v4.institution.search(inputParams);
ctx.success(ret);
}
// 用户搜索历史
async getUserSearch() {
const { ctx, service } = this;
const ret = await service.course.v4.institution.getUserSearch();
ctx.success(ret);
}
// 获取热搜
async getHotSearch() {
const { ctx, service } = this;
const ret = await service.course.v4.institution.getHotSearch();
ctx.success(ret);
}
// 删除用户搜索历史
async deleteUserSearch() {
const { ctx, service } = this;
await service.course.v4.institution.deleteUserSearch();
ctx.success();
}
// 评论列表
async getComments() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v4.institution.getComments(inputParams);
ctx.success(ret);
}
// 搜索联想
async getSuggestSearch() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v4.institution.getSuggestSearch(inputParams);
ctx.success(ret);
}
// 用户收藏机构列表
async getUserCollectedInstitutions() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v4.institution.getUserCollectedInstitutions(inputParams);
ctx.success(ret);
}
// 用户收藏课程列表
async getUserCollectedClasses() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v4.institution.getUserCollectedClasses(inputParams);
ctx.success(ret);
}
// 根据分类获取选课指南
async getArticlesByCat() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
if (ctx.isEmpty(inputParams) || ctx.isEmpty(inputParams.cat_id)) {
ctx.failed('cat_id is empty');
}
const ret = await service.course.v4.institution.getArticlesByCat(inputParams);
ctx.success(ret);
}
// 获取选课指南详情
async getArticle() {
const { ctx, service } = this;
const inputParams = ctx.params;
if (ctx.isEmpty(inputParams) || ctx.isEmpty(inputParams.id)) {
ctx.failed('article_id is empty');
}
const ret = await service.course.v4.institution.getArticle(Number(inputParams.id));
ctx.success(ret);
}
// 点赞
async like() {
const { ctx, service } = this;
const inputParams = ctx.request.body;
if (ctx.isEmpty(inputParams) || ctx.isEmpty(inputParams.type) || ctx.isEmpty(inputParams.type_id)) {
ctx.failed('参数错误');
}
const ret = await service.course.v4.institution.like(inputParams);
ctx.success(ret);
}
// 取消点赞
async unlike() {
const { ctx, service } = this;
const inputParams = ctx.request.body;
if (ctx.isEmpty(inputParams) || ctx.isEmpty(inputParams.type) || ctx.isEmpty(inputParams.type_id)) {
ctx.failed('参数错误');
}
const ret = await service.course.v4.institution.unlike(inputParams);
ctx.success(ret);
}
// 获取推荐选课指南
async getArticlesByRecommend() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v4.institution.getArticlesByRecommend(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.v4.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.v4.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 OnlineController extends Controller {
// 获取在线课程列表
async getClasses() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v4.online.getClasses(inputParams);
ctx.success(ret);
}
// 获取在线课程详情
async getClass() {
const { ctx, service } = this;
const params = ctx.params;
const inputParams = ctx.request.query;
if (ctx.isEmpty(params) || ctx.isEmpty(params.id)) {
ctx.failed('id error');
}
const input = {
id: params.id,
lng: inputParams.lng || 0,
lat: inputParams.lat || 0,
};
const ret = await service.course.v4.online.getClass(input);
ctx.success(ret);
}
// 获取在线课程选项
async getOption() {
const { ctx, service } = this;
const ret = await service.course.v4.online.getOption();
ctx.success(ret);
}
// 收藏在线课程
async collectClass() {
const { ctx, service } = this;
const inputParams = ctx.request.body;
if (ctx.isEmpty(inputParams) || ctx.isEmpty(inputParams.id)) {
ctx.failed('id is empty');
}
const ret = await service.course.v4.online.collectClass(inputParams.id);
ctx.success(ret);
}
// 获取在线课程收藏列表
async getCollectionClasses() {
const { ctx, service } = this;
const inputParams = ctx.request.query;
const ret = await service.course.v4.online.getCollectionClasses(inputParams);
ctx.success(ret);
}
// 收藏在线课程
async delCollectClass() {
const { ctx, service } = this;
const inputParams = ctx.request.body;
if (ctx.isEmpty(inputParams) || ctx.isEmpty(inputParams.id)) {
ctx.failed('id is empty');
}
const ret = await service.course.v4.online.delCollectClass(inputParams.id);
ctx.success(ret);
}
}
module.exports = OnlineController;
'use strict';
const Controller = require('egg').Controller;
class OptionController extends Controller {
/**
* 筛选项
*/
async getOptions() {
const { ctx } = this;
const results = await ctx.service.course.v4.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.v4.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 loginByPhone() {
const { ctx, service } = this;
const params = ctx.request.body;
if (ctx.isEmpty(params.phone) || isNaN(params.phone) || params.phone.length !== 11) {
ctx.failed('手机号错误');
}
if (ctx.isEmpty(params.code)) {
ctx.failed('验证码错误');
}
const ret = await service.course.v5.user.loginByPhone(params);
ctx.success(ret);
}
// 发送验证码
async sendVerificationCode() {
const { ctx, service } = this;
const queryParams = ctx.request.body;
if (ctx.isEmpty(queryParams.phone) || isNaN(queryParams.phone) || queryParams.phone.length !== 11) {
ctx.failed('手机号错误');
}
const ret = await service.course.v5.user.sendVerificationCode(queryParams);
ctx.success(ret);
}
// 微信登录
async loginByWX() {
const { ctx, service } = this;
const params = ctx.request.body;
if (ctx.isEmpty(params.code)) {
ctx.failed('code is empty');
}
const ret = await service.course.v5.user.loginByWX(params);
ctx.success(ret);
}
// 授权后注册用户信息
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.v5.user.registerUserInfo(params);
ctx.success(ret);
}
// 获取用户信息
async getUserInfo() {
const { ctx, service } = this;
const ret = await service.course.v5.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.v4.wechat.sendMsg(data);
ctx.success();
}
async callbackAction() {
const { ctx, service } = this;
await service.course.v4.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';
module.exports = (options, app) => {
return async function(ctx, next) {
const uuid = ctx.headers.uuid;
const key = 'course_v5_user_session_' + uuid;
let userInfo = await ctx.app.memcache.get(key);
if (!userInfo) {
userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { uuid, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
ctx.failed('用户不存在');
} else {
await ctx.app.memcache.set(key, { user_uuid: uuid, openid: userInfo.openid, session_key: '', phone: userInfo.phone }, 86400 * 7);
}
}
const openid = userInfo.openid;
const phone = userInfo.phone;
const authToken = ctx.headers.auth_token;
if (ctx.helper.md5(uuid + openid + phone + 'jbwl') !== authToken) {
ctx.failed('login auth error');
}
ctx.setUserUuid(uuid);
ctx.setOpenId(openid);
await next();
};
};
'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,
description: STRING,
content: TEXT,
image: STRING,
source: STRING,
like_count: INTEGER,
read_count: INTEGER,
is_recommend: INTEGER,
relations: 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_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 } = app.Sequelize;
const CourseLike = app.classModel.define('course_like', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_uuid: STRING,
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_like',
});
return CourseLike;
};
'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, DECIMAL, TEXT, ENUM, FLOAT } = app.Sequelize;
const CourseOnlineArea = app.classModel.define('course_online_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_online_area',
});
CourseOnlineArea.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineArea.findOne({
attributes,
where,
});
};
CourseOnlineArea.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineArea.findAll({
attributes,
where,
order,
});
};
CourseOnlineArea.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 CourseOnlineArea.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineArea.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineArea.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineArea.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineArea.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineArea;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseOnlineClassToCat = app.classModel.define('course_online_class_to_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_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_online_class_to_cat',
});
CourseOnlineClassToCat.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineClassToCat.findOne({
attributes,
where,
});
};
CourseOnlineClassToCat.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineClassToCat.findAll({
attributes,
where,
order,
});
};
CourseOnlineClassToCat.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 CourseOnlineClassToCat.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineClassToCat.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineClassToCat.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineClassToCat.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineClassToCat.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineClassToCat;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = app.Sequelize;
const CourseOnlineClassToType = app.classModel.define('course_online_class_to_type', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
type_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_online_class_to_type',
});
CourseOnlineClassToType.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineClassToType.findOne({
attributes,
where,
});
};
CourseOnlineClassToType.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineClassToType.findAll({
attributes,
where,
order,
});
};
CourseOnlineClassToType.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 CourseOnlineClassToType.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineClassToType.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineClassToType.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineClassToType.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineClassToType.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineClassToType;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, ENUM } = app.Sequelize;
const CourseOnlineType = app.classModel.define('course_online_type', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: 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_online_type',
});
CourseOnlineType.one = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
return await CourseOnlineType.findOne({
attributes,
where,
});
};
CourseOnlineType.all = async data => {
const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {};
const order = data.order ? data.order : [];
return await CourseOnlineType.findAll({
attributes,
where,
order,
});
};
CourseOnlineType.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 CourseOnlineType.findAndCountAll(condition);
return { page, count, rows };
};
CourseOnlineType.add = async data => {
try {
// 返回promise对象实力 instance
const res = await CourseOnlineType.create(data);
// 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id;
} catch (error) {
throw (error);
}
};
CourseOnlineType.edit = async data => {
const where = data.where;
const params = data.params;
try {
const res = await CourseOnlineType.update(params, { where });
return res;
} catch (error) {
throw (error);
}
};
return CourseOnlineType;
};
'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';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Age = app.classModel.define('course_v5_age', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
status: INTEGER,
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_v5_age',
});
return CourseV5Age;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Answer = app.classModel.define('course_v5_answer', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
question_id: INTEGER,
title: STRING,
sub_title: STRING,
selected_icon: STRING,
unselected_icon: STRING,
type: INTEGER,
type_value: STRING,
status: INTEGER,
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_v5_answer',
});
return CourseV5Answer;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Category = app.classModel.define('course_v5_category', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
type: INTEGER,
parent_id: INTEGER,
name: STRING,
selected_icon: STRING,
unselected_icon: STRING,
color: STRING,
status: INTEGER,
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_v5_category',
});
return CourseV5Category;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT } = app.Sequelize;
const CourseV5Class = app.classModel.define('course_v5_class', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
institution_id: INTEGER,
name: STRING,
logo: STRING,
age: STRING,
price: STRING,
filter_price: DECIMAL,
price_type: INTEGER,
mode: INTEGER,
time: INTEGER,
class_amount: INTEGER,
multi_classes: INTEGER,
cycle: STRING,
channel: TEXT,
description: TEXT,
status: 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;
},
},
}, {
timestamps: false,
tableName: 'course_v5_class',
});
return CourseV5Class;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, DATE } = app.Sequelize;
const CourseV5ClassToAge = app.classModel.define('course_v5_class_to_age', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
age_id: INTEGER,
status: 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_v5_class_to_age',
});
return CourseV5ClassToAge;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, DATE } = app.Sequelize;
const CourseV5ClassToCat = app.classModel.define('course_v5_class_to_cat', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
cat_id: INTEGER,
status: 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_v5_class_to_cat',
});
return CourseV5ClassToCat;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5ClassToColumn = app.classModel.define('course_v5_class_to_column', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
column_id: INTEGER,
value: STRING,
status: 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_v5_class_to_column',
});
return CourseV5ClassToColumn;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, DATE } = app.Sequelize;
const CourseV5ClassToFrequency = app.classModel.define('course_v5_class_to_frequency', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
frequency_id: INTEGER,
status: 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_v5_class_to_frequency',
});
return CourseV5ClassToFrequency;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, DATE } = app.Sequelize;
const CourseV5ClassToScore = app.classModel.define('course_v5_class_to_score', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
score_id: INTEGER,
status: 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_v5_class_to_score',
});
return CourseV5ClassToScore;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { INTEGER, DATE } = app.Sequelize;
const CourseV5ClassToType = app.classModel.define('course_v5_class_to_type', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
type_id: INTEGER,
status: 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_v5_class_to_type',
});
return CourseV5ClassToType;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Column = app.classModel.define('course_v5_column', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
status: 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_v5_column',
});
return CourseV5Column;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Frequency = app.classModel.define('course_v5_frequency', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
sort: INTEGER,
status: 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_v5_frequency',
});
return CourseV5Frequency;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;
const CourseV5Institution = app.classModel.define('course_v5_institution', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
relation_id: INTEGER,
name: STRING,
logo: STRING,
description: TEXT,
status: 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_v5_institution',
});
return CourseV5Institution;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Column = app.classModel.define('course_v5_column', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
cat_id: INTEGER,
title: STRING,
style: INTEGER,
score: INTEGER,
type: INTEGER,
sort: INTEGER,
status: 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_v5_column',
});
return CourseV5Column;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Column = app.classModel.define('course_v5_column', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
first: STRING,
second: STRING,
column: STRING,
score: INTEGER,
status: 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_v5_column',
});
return CourseV5Column;
};
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Type = app.classModel.define('course_v5_type', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: STRING,
status: INTEGER,
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_v5_type',
});
return CourseV5Type;
};
'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,
class_price: STRING,
class_frequency: STRING,
class_hours: 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,
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,
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,
order,
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 });
return res;
} catch (error) {
throw (error);
}
};
return CourseClass;
};
'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;
};
'use strict';
module.exports = app => {
const router = app.router.namespace(app.config.projectRootPath + '/course/v5');
const miniAuth = app.middleware.miniAuthV5();// 因为不跟现有的用户中心系统,所以使用单独的登录中间件
// 版本二
router.get('third', '/cats', 'course.v4.institution.getCats');// 分类
router.get('third', '/options', 'course.v4.option.getOptions');// 筛选项
router.get('third', '/banners', 'course.v4.option.getBanners');// banner
router.post('third', '/address', miniAuth, 'course.v4.location.getAddress');// 根据经纬度或ip获取地理位置信息
router.get('third', '/institutions', miniAuth, 'course.v4.institution.getInstitutions');// 机构列表
router.get('third', '/institution/:institution_id', miniAuth, 'course.v4.institution.getInstitution');// 机构详情
router.get('third', '/classes', miniAuth, 'course.v4.institution.getClasses');// 课程列表
router.get('third', '/class/:class_id', miniAuth, 'course.v4.institution.getClass');// 课程详情
router.get('third', '/teachers', miniAuth, 'course.v4.institution.getTeachers');// 老师列表
router.get('third', '/teacher/:teacher_id', miniAuth, 'course.v4.institution.getTeacher');// 老师详情
router.post('third', '/user/auth', 'course.v4.user.auth');// 微信授权登录
router.post('third', '/user/register_user', miniAuth, 'course.v4.user.registerUserInfo');// 授权后注册用户
router.get('third', '/user/info', miniAuth, 'course.v4.user.getUserInfo');// 获取用户信息
router.get('third', '/user/baby', miniAuth, 'course.v4.user.getBabyInfo');// 获取baby信息
router.post('third', '/user/baby', miniAuth, 'course.v4.user.saveBabyInfo');// 保存baby信息
router.delete('third', '/user/baby', miniAuth, 'course.v4.user.delBabyInfo');// 删除baby信息
router.get('third', '/user/collection/institution', miniAuth, 'course.v4.institution.getUserCollectedInstitutions');// 收藏的机构列表
router.get('third', '/user/collection/class', miniAuth, 'course.v4.institution.getUserCollectedClasses');// 收藏的课程列表
router.post('third', '/user/collection/institution', miniAuth, 'course.v4.user.collectInstitution');// 收藏机构
router.delete('third', '/user/collection/institution', miniAuth, 'course.v4.user.delCollectInstitution');// 取消收藏机构
router.post('third', '/user/collection/class', miniAuth, 'course.v4.user.collectClass');// 收藏课程
router.delete('third', '/user/collection/class', miniAuth, 'course.v4.user.delCollectClass');// 取消收藏课程
router.get('third', '/wechat/callbackAction', 'course.v4.wechat.check');
router.post('third', '/wechat/callbackAction', 'course.v4.wechat.callbackAction');
router.post('third', '/wechat/test', 'course.v4.wechat.test');
router.get('third', '/comments', miniAuth, 'course.v4.institution.getComments');// 评论列表
router.get('third', '/search/hot', miniAuth, 'course.v4.institution.getHotSearch');// 热搜
router.get('third', '/search/suggest', miniAuth, 'course.v4.institution.getSuggestSearch');// 搜索联想
router.get('third', '/search', miniAuth, 'course.v4.institution.search');// 搜索
router.get('third', '/user/search', miniAuth, 'course.v4.institution.getUserSearch');// 用户搜索历史
router.delete('third', '/user/search', miniAuth, 'course.v4.institution.deleteUserSearch');// 清空用户搜索记录
router.get('third', '/article/all', miniAuth, 'course.v4.institution.getArticlesByCat');// 根据分类获取选课指南
router.get('third', '/article/recommend', miniAuth, 'course.v4.institution.getArticlesByRecommend');// 获取推荐选课指南
router.get('third', '/article/:id', miniAuth, 'course.v4.institution.getArticle');// 获取选课指南详情
router.post('third', '/like', miniAuth, 'course.v4.institution.like');// 点赞
router.post('third', '/unlike', miniAuth, 'course.v4.institution.unlike');// 取消点赞
router.get('third', '/online/classes', 'course.v4.online.getClasses');// 在线课程列表
router.post('third', '/online/collection/class', miniAuth, 'course.v4.online.collectClass');// 收藏在线课程
router.get('third', '/online/collection/classes', miniAuth, 'course.v4.online.getCollectionClasses');// 在线课程收藏列表
router.get('third', '/online/class/:id', 'course.v4.online.getClass');// 在线课程详情
router.get('third', '/online/option', 'course.v4.online.getOption');// 在线课程选项
router.delete('third', '/online/collection/class', miniAuth, 'course.v4.online.delCollectClass');// 取消收藏课程
router.post('third', '/verification_code', 'course.v5.user.sendVerificationCode');// 发送验证码
router.post('third', '/login/phone', 'course.v5.user.loginByPhone');// 手机号登录
router.post('third', '/login/wechat', 'course.v5.user.loginByWX');// 微信登录
router.post('third', '/user/register_user', miniAuth, 'course.v5.user.registerUserInfo');// 授权后注册用户
router.get('third', '/user/info', miniAuth, 'course.v5.user.getUserInfo');// 获取用户信息
};
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;
This diff is collapsed.
'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.v4.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.V4.CourseBannerType.findOne({ where: { alias, status: 'online', is_deleted: 0 }, row: true });
if (ctx.isEmpty(bannerType)) {
ctx.failed('数据不存在');
}
const banners = await ctx.classModel.V4.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 uuidV4 = require('uuid/v4');
const moment = require('moment');
const R = require('ramda');
class UserService extends Service {
// 发送验证码
async sendVerificationCode(input) {
const { ctx } = this;
const phone = input.phone;
// to do
const ret = { result: true };
return ret;
}
// 手机号登录
async loginByPhone(input) {
const { ctx } = this;
const phone = input.phone;
const code = input.code;
// 判断用户是否存在
let userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { phone, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
const uuid = uuidV4();
userInfo = await ctx.classModel.V5.CourseUser.findOrCreate({ where: { phone, is_deleted: 0 }, defaults: { uuid, phone } });
}
// 校验验证码
if (code !== 'fuck') {
ctx.failed('验证码错误');
}
const key = 'course_v5_user_session_' + userInfo.uuid;
const value = {
user_uuid: userInfo.uuid,
openid: userInfo.openid,
session_key: '',
phone,
};
await ctx.app.memcache.set(key, value);
const authToken = ctx.helper.md5(userInfo.uuid + userInfo.openid + userInfo.phone + 'jbwl');
const ret = {
user_uuid: userInfo.uuid,
openid: userInfo.openid,
bind_phone: ctx.isEmpty(userInfo.phone) ? 0 : 1,
auth_token: authToken,
};
return ret;
}
// 微信登录
async loginByWX(input) {
const { ctx, app } = this;
const code = input.code;
if (ctx.isEmpty(code)) {
ctx.failed('error code');
}
// 请求微信授权 获取openid
const wxAuthInfo = await this.requestWxAuth(code);
const openid = wxAuthInfo.openid;// 获取openid
const session_key = wxAuthInfo.session_key;
// 判断用户是否存在
let userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { openid, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
const uuid = uuidV4();
userInfo = await ctx.classModel.V5.CourseUser.findOrCreate({ where: { openid, is_deleted: 0 }, defaults: { uuid, openid } });
}
// 存储缓存标识
const userUuid = userInfo.uuid;
const key = 'course_v5_user_session_' + userUuid;
const value = {
user_uuid: userInfo.uuid,
openid,
session_key,
phone: userInfo.phone,
};
await app.memcache.set(key, value);
const authToken = ctx.helper.md5(userInfo.uuid + openid + userInfo.phone + 'jbwl');
const ret = {
user_uuid: userInfo.uuid,
openid: userInfo.openid,
bind_phone: ctx.isEmpty(userInfo.phone) ? 0 : 1,
auth_token: authToken,
};
ctx.success(ret);
}
// 微信授权
async requestWxAuth(code) {
const { ctx } = this;
const APPID = ctx.app.config.COURSE_WX_APPID;
const SECRET = ctx.app.config.COURSE_WX_SECRET;
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 registerUserInfo(input) {
const { ctx, app } = this;
const userUuid = ctx.userUuid;
const { avatar, nickname, sex, encryptedData, iv } = input;
// 查找用户是否存在并更新
const user = await ctx.classModel.V5.CourseUser.findOne({ where: { uuid: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(user)) {
ctx.failed('用户不存在');
}
const data = {};
if (!ctx.isEmpty(avatar)) {
data.avatar = avatar;
}
if (!ctx.isEmpty(nickname)) {
data.nickname = nickname;
}
if (!ctx.isEmpty(sex)) {
data.sex = sex;
}
if (!ctx.isEmpty(encryptedData) && !ctx.isEmpty(iv)) {
const decoded = await ctx.service.course.v5.wechat.decodeData(encryptedData, iv);
if (!ctx.isEmpty(decoded) && !ctx.isEmpty(decoded.phoneNumber)) {
data.phone = decoded.phoneNumber;
}
}
// 校验手机号是否已经存在
const userInfo = await ctx.classModel.V5.findOne({ where: { phone: data.phone, is_deleted: 0 } });
if (!ctx.isEmpty(userInfo)) {
// 新微信覆盖旧微信
data.openid = user.openid;
await ctx.classModel.V5.update(data, { where: { id: userInfo.id } });
data.uuid = userInfo.uuid;
} else {
await ctx.classModel.V5.update(data, { where: { id: user.id } });
data.uuid = user.uuid;
}
// 更新登录信息
const key = 'course_v5_user_session_' + data.uuid;
const value = {
user_uuid: data.uuid,
openid: user.openid,
session_key: '',
phone: data.phone,
};
await app.memcache.set(key, value);
const authToken = ctx.helper.md5(data.uuid + user.openid + data.phone + 'jbwl');
const ret = {
user_uuid: data.uuid,
openid: user.openid,
bind_phone: 1,
auth_token: authToken,
};
return ret;
}
// 获取用户信息
async getUserInfo() {
const { ctx } = this;
const userUuid = ctx.userUuid;
const userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { uuid: userUuid, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
ctx.failed('用户不存在');
}
const ret = {
user_uuid: userInfo.uuid,
nickname: userInfo.nickname,
avatar: userInfo.avatar,
sex: userInfo.sex,
openid: userInfo.openid,
bind_phone: ctx.isEmpty(userInfo.phone) ? 0 : 1,
};
return ret;
}
}
module.exports = UserService;
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -179,6 +179,9 @@ module.exports = appInfo => { ...@@ -179,6 +179,9 @@ module.exports = appInfo => {
config.YYS_REPORT_APPSECRET = '233B8E10E31B4C899EE6FEB3AEC22F140B6528BF'; config.YYS_REPORT_APPSECRET = '233B8E10E31B4C899EE6FEB3AEC22F140B6528BF';
config.YYS_REPORT_URL = 'http://47.96.253.64:8049/mycredit/thxdReport'; config.YYS_REPORT_URL = 'http://47.96.253.64:8049/mycredit/thxdReport';
// 趣选课微信配置
config.COURSE_WX_APPID = 'wx07a5f0ed5bdf4751';
config.COURSE_WX_SECRET = 'a1b2d32b018988176181497bd74a0b7d';
return config; return config;
}; };
...@@ -14,7 +14,7 @@ module.exports = appInfo => { ...@@ -14,7 +14,7 @@ module.exports = appInfo => {
dir: '/jianbing/logs/51business', dir: '/jianbing/logs/51business',
}; };
// add your config here // add your config here
config.middleware = ['errorHandler', 'deviceLogin', 'deviceInit', 'responseSet']; config.middleware = [ 'errorHandler', 'deviceLogin', 'deviceInit', 'responseSet' ];
// 是否启用csrf安全 // 是否启用csrf安全
config.security = { config.security = {
...@@ -159,7 +159,7 @@ module.exports = appInfo => { ...@@ -159,7 +159,7 @@ module.exports = appInfo => {
config.YYS_REPORT_APPSECRET = process.env.YYS_REPORT_APPSECRET; config.YYS_REPORT_APPSECRET = process.env.YYS_REPORT_APPSECRET;
config.YYS_REPORT_URL = process.env.YYS_REPORT_URL; config.YYS_REPORT_URL = process.env.YYS_REPORT_URL;
//度小满金融查询 // 度小满金融查询
config.DXM_APP_ID = process.env.DXM_APP_ID; config.DXM_APP_ID = process.env.DXM_APP_ID;
config.DXM_SECRET = process.env.DXM_SECRET; config.DXM_SECRET = process.env.DXM_SECRET;
config.DXM_URL = process.env.DXM_URL; config.DXM_URL = process.env.DXM_URL;
...@@ -168,7 +168,9 @@ module.exports = appInfo => { ...@@ -168,7 +168,9 @@ module.exports = appInfo => {
config.CFG_ENV = process.env.CFG_ENV; config.CFG_ENV = process.env.CFG_ENV;
config.CASSANDRA_API = process.env.CASSANDRA_API; config.CASSANDRA_API = process.env.CASSANDRA_API;
// 趣选课微信配置
config.COURSE_WX_APPID = process.env.COURSE_WX_APPID;
config.COURSE_WX_SECRET = process.env.COURSE_WX_SECRET;
return config; return config;
}; };
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