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');// 获取用户信息
};
'use strict';
const Service = require('egg').Service;
const R = require('ramda');
const _ = require('lodash');
const moment = require('moment');
const sequelize = require('sequelize');
class InstitutionSubService extends Service {
// 获取分类
async getCats() {
const { ctx } = this;
const AllCats = await ctx.classModel.V4.CourseCat.findAll({ where: { status: 1, is_deleted: 0 } });
const rootCats = [];
let ret = [];
// 先取出一级分类
for (const v of AllCats) {
if (v.parent_id === 0) {
rootCats[v.id] = v.dataValues;
rootCats[v.id].child = [{ id: 0, value: v.id, name: '全部', parent_id: 0, image: 'http://r.51gjj.com/webpublic/images/20191118/s6yRUsc5kclyu.png', active_image: 'http://r.51gjj.com/webpublic/images/20191118/zYHkYp85vxk5m.png', color: '', tips: '', status: 'online', is_deleted: 0 }];
}
}
// 放入二级分类
for (const v of AllCats) {
if (v.parent_id > 0) {
v.value = v.id;
rootCats[v.parent_id].child.push(v);
}
}
const sort = function(a, b) {
return a.sort - b.sort;
};
// 整理
for (const v of rootCats) {
if (!ctx.isEmpty(v)) {
v.child = R.sort(sort)(v.child);
ret.push(v);
}
}
ret = R.sort(sort)(ret);
return { results: ret };
}
// 获取机构详情
async getInstitution(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const { institution_id } = input;
const lat = ctx.isEmpty(input.lat) ? 0 : input.lat;
const lng = ctx.isEmpty(input.lng) ? 0 : input.lng;
let institution = await ctx.classModel.V4.CourseInstitution.findOne({ where: { id: institution_id, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(institution)) {
ctx.failed('机构不存在');
}
institution = institution.dataValues;
// 顶部相册
const images = await ctx.classModel.V4.CourseImages.findAll({ where: { type: 1, type_id: institution_id, status: 'online', is_deleted: 0 } });
// 去重
const checkList = [];
let album = [];
for (const v of images) {
if ((v.is_video === 0 && checkList.includes(v.image_url)) || (v.is_video === 1 && checkList.includes(v.video_url))) {
continue;
}
album.push(v);
}
// 排序,视频在前
const albumSort = function(a, b) {
if (a.is_video === b.is_video) {
return a.sort - b.sort;
}
return b.is_video - a.is_video;
};
album = R.sort(albumSort)(album);
// 学习成果
const student_video = await ctx.classModel.V4.CourseStudentVideo.findAll({ where: { institution_id, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ]] });
// 教师
const teachers = await ctx.classModel.V4.CourseTeacher.findAll({ where: { institution_id, status: 'online', is_deleted: 0 }, raw: true });
// 课程
const classes = await ctx.classModel.V4.CourseClass.findAll({ where: { institution_id, status: 'online', is_deleted: 0 }, raw: true });
// 处理课程封面图
const classHandle = [];
if (classes.length > 0) {
for (const v of classes) {
classHandle.push(ctx.classModel.V4.CourseImages.findOne({ where: { type: 2, type_id: v.id, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ]] }));
}
const classImages = await Promise.all(classHandle).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
for (const i in classes) {
classes[i].image = classImages[i];
}
}
// 校区
let areas = await ctx.classModel.V4.CourseArea.findAll({ where: { institution_id, status: 'online', is_deleted: 0 }, raw: true });
const areaHandle = [];
if (areas.length > 0) {
for (const v of areas) {
areaHandle.push(this.formatArea(v, { lng, lat }));
}
areas = await Promise.all(areaHandle).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
}
areas = _.orderBy(areas, [ 'distance' ], [ 'asc' ]);
// 是否已收藏
const userCollect = await ctx.classModel.V4.CourseUserCollection.findOne({ where: { type: 1, type_id: institution_id, user_uuid: userUuid, is_deleted: 0 } });
// 获取所有标签
const allTags = await ctx.classModel.V4.CourseTag.findAll({ where: { status: 'online', is_deleted: 0 } });
const tagList = [];
for (const v of allTags) {
tagList[v.id] = v;
}
let tags = await ctx.classModel.V4.CourseInstitutionToTag.findAll({ where: { institution_id: institution.id, status: 'online', is_deleted: 0 } });
tags = _.orderBy(tags, [ 'sort' ], [ 'asc' ]);
institution.tags = [];
for (const v of tags) {
institution.tags.push(tagList[v.tag_id]);
}
institution.phone = areas.length > 0 ? areas[0].phone : '';
institution.distance = areas.length > 0 ? String(areas[0].distance) + 'km' : '无法计算';
institution.travel_method = areas.length > 0 ? areas[0].travel_method : '';
institution.travel_tips = areas.length > 0 ? areas[0].travel_tips : '';
const ret = {
album,
detail: institution,
student_video,
teachers,
classes,
areas,
is_collected: ctx.isEmpty(userCollect) ? 0 : 1,
};
return ret;
}
// 处理校区
async formatArea(area, location) {
const { ctx, service } = this;
if (ctx.isEmpty(area)) {
return {};
}
const distance = await service.course.v4.lbs.getDistance({ lng: location.lng, lat: location.lat }, { lng: area.lng, lat: area.lat });
// 暂定3公里以内步行
area.travel_method = distance < 3000 ? 'walking' : 'driving';
const lbsResult = await service.course.v4.lbs.getLBSDistance(area.travel_method, { lng: location.lng, lat: location.lat }, [{ lng: area.lng, lat: area.lat }]);
if (lbsResult.results.length > 0) {
area.distance = parseFloat((lbsResult.results[0].distance / 1000).toFixed(1));
area.duration = lbsResult.results[0].duration;
const minute = area.travel_method === 'walking' ? Math.ceil(area.distance / 0.08) : Math.ceil(area.duration / 60);
area.travel_tips = area.travel_method === 'walking' ? `距我${area.distance}km,步行${minute}分钟` : `距我${area.distance}km,开车${minute}分钟`;
} else {
area.distance = 999999;
area.duration = 0;
area.travel_tips = '';
}
return area;
}
// 机构列表
async getInstitutions(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const { cat_id, age, address } = input;
const lat = ctx.isEmpty(input.lat) ? 0 : input.lat;
const lng = ctx.isEmpty(input.lng) ? 0 : input.lng;
// 保存定位记录
if (address && lat && lng) {
ctx.classModel.V4.CourseLogUserGps.create({ user_uuid: userUuid, address, lat, lng, created_time: moment().format('YYYY-MM-DD HH:mm:ss') });
}
let institutionList = [];
let institutionCats = [];
const filter = { where: { status: 'online', is_deleted: 0 } };
// 年龄筛选
if (Number(age) > 0) {
filter.where.min_age = { $lte: age };
filter.where.max_age = { $gte: age };
}
// 分类筛选
if (Number(cat_id) > 0) {
// 如果是一级分类,则需要加入该分类下所有子分类
const cats = await ctx.classModel.V4.CourseCat.findAll({ where: { parent_id: cat_id, status: 'online', is_deleted: 0 } });
const catIds = R.pluck('id', cats);
catIds.push(Number(cat_id));
institutionCats = await ctx.classModel.V4.CourseInstitutionToCat.findAll({ where: { status: 'online', is_deleted: 0, cat_id: { $in: catIds } } });
const institutionIds = R.pluck('institution_id', institutionCats);
filter.where.id = { $in: institutionIds };
}
institutionList = await ctx.classModel.V4.CourseInstitution.findAll(filter);
institutionList = R.pluck('dataValues', institutionList);
const ret = await this.formatInstitutionList(institutionList, input);
return ret;
}
// 格式化机构列表
async formatInstitutionList(institutionList, input) {
const { ctx, service } = this;
const userUuid = ctx.userUuid;
const distance = Number(input.distance) || 0;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const { lng, lat } = input;
let institutionCats = [];
let institutionIds = R.pluck('id', institutionList);
// 获取机构对应的校区
const areaList = await ctx.classModel.V4.CourseArea.findAll({ where: { status: 'online', is_deleted: 0, institution_id: { $in: institutionIds } } });
// 计算校区对应的距离
const areaHandle = [];
for (const v of areaList) {
areaHandle.push(service.course.v4.lbs.getDistance({ lat, lng }, { lat: v.lat, lng: v.lng }));
}
const areaDistanceCalcResult = await Promise.all(areaHandle).then(result => {
return result;
}).catch(error => {
ctx.failed(error);
});
for (const i in areaList) {
areaList[i].distance = areaDistanceCalcResult[i];
}
// 选出最短距离的校区
for (const v of areaList) {
for (const i in institutionList) {
if (institutionList[i].id === v.institution_id) {
if (ctx.isEmpty(institutionList[i].area) || (institutionList[i].area.distance > v.distance)) {
institutionList[i].area = v;
}
}
}
}
// 格式化机构距离
for (const i in institutionList) {
institutionList[i].distance = ctx.isEmpty(institutionList[i].area) ? 999999.0 : institutionList[i].area.distance;
}
institutionList = _.orderBy(institutionList, [ 'distance' ], [ 'asc' ]);
// 距离筛选
if (Number(distance) > 0) {
for (const i in institutionList) {
if (institutionList[i].distance > Number(distance)) {
institutionList = institutionList.slice(0, i);
break;
}
}
}
// 分页
const ret = {
results: [],
count: institutionList.length,
};
institutionList = institutionList.slice(Number(page - 1) * Number(limit), Number(page) * Number(limit));
institutionIds = R.pluck('id', institutionList);
// 获取所有分类
const allCats = await ctx.classModel.V4.CourseCat.findAll({ where: { status: 'online', is_deleted: 0 } });
const catList = [];
for (const v of allCats) {
catList[v.id] = v;
}
institutionCats = await ctx.classModel.V4.CourseInstitutionToCat.findAll({ where: { status: 'online', is_deleted: 0, institution_id: { $in: institutionIds } } });
// 获取所有标签
const allTags = await ctx.classModel.V4.CourseTag.findAll({ where: { status: 'online', is_deleted: 0 } });
const tagList = [];
for (const v of allTags) {
tagList[v.id] = v;
}
// 用户已收藏机构列表
const userInstitutions = await ctx.classModel.V4.CourseUserCollection.findAll({ where: { type: 1, is_deleted: 0, user_uuid: userUuid } });
const userInstitutionIds = R.pluck('type_id', userInstitutions);
// 机构图片及格式化
for (const i in institutionList) {
// 格式化机构分类(展示一级分类)
let cats = [];
for (const v of institutionCats) {
if (v.institution_id === institutionList[i].id && catList[v.cat_id]) {
if (catList[v.cat_id].parent_id === 0) {
cats.push(v.cat_id);
} else {
cats.push(catList[v.cat_id].parent_id);
}
}
}
// 去重
cats = _.uniq(cats);
institutionList[i].cats = [];
for (const v of cats) {
institutionList[i].cats.push(catList[v]);
}
// 标签
let tags = await ctx.classModel.V4.CourseInstitutionToTag.findAll({ where: { institution_id: institutionList[i].id, status: 'online', is_deleted: 0 } });
tags = _.orderBy(tags, [ 'sort' ], [ 'asc' ]);
institutionList[i].tags = [];
for (const v of tags) {
institutionList[i].tags.push(tagList[v.tag_id]);
}
// 优先获取机构详情图
let institutionImages = await ctx.classModel.V4.CourseImages.findAll({ where: { type: 1, type_id: institutionList[i].id, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ]], limit: 3 });
if (institutionImages.length < 3) {
const defaultImages = await ctx.classModel.V4.CourseImages.findAll({ where: { type: 4, type_id: { $in: cats }, status: 'online', is_deleted: 0 }, limit: 3 - institutionImages.length });
institutionImages = institutionImages.concat(defaultImages);
}
institutionList[i].images = institutionImages;
institutionList[i].distance = String((institutionList[i].distance / 1000).toFixed(1)) + 'km';
institutionList[i].phone = institutionList[i].area.length > 0 ? institutionList[i].area[0].phone : '';
// 是否已收藏
institutionList[i].is_collected = userInstitutionIds.includes(institutionList[i].id) ? 1 : 0;
ret.results.push(institutionList[i]);
}
return ret;
}
// 搜索
async search(input) {
const { ctx } = this;
const { cat_id, age, search } = input;
const userUuid = ctx.userUuid;
// 保存搜索记录
if (search) {
const searchInfo = await ctx.classModel.V4.CourseSearch.findOne({ where: { content: search, is_deleted: 0 } });
if (searchInfo) {
await ctx.classModel.V4.CourseSearch.update({ count: searchInfo.count + 1 }, { where: { id: searchInfo.id } });
} else {
await ctx.classModel.V4.CourseSearch.create({ content: search, sort: 0, count: 1, is_hot: 0, status: 'online', is_deleted: 0, created_time: moment().format('YYYY-MM-DD HH:mm:ss'), updated_time: moment().format('YYYY-MM-DD HH:mm:ss') });
}
await ctx.classModel.V4.CourseUserSearch.create({ user_uuid: userUuid, content: search, status: 'online', created_time: moment().format('YYYY-MM-DD HH:mm:ss'), updated_time: moment().format('YYYY-MM-DD HH:mm:ss') });
}
let institutionList = [];
let institutionCats = [];
let institutionIds = [];
const filter = { where: { status: 'online', is_deleted: 0 }, row: true };
const classFilter = { where: { status: 'online', is_deleted: 0, name: { $like: '%' + search + '%' } }, attributes: [ 'id', 'institution_id', 'name', 'status', 'is_deleted' ], row: true };
// 年龄筛选
if (Number(age) > 0) {
filter.where.min_age = { $lte: age };
filter.where.max_age = { $gte: age };
}
// 分类筛选
if (Number(cat_id) > 0) {
// 如果是一级分类,则需要加入该分类下所有子分类
const cats = await ctx.classModel.V4.CourseCat.findAll({ where: { parent_id: cat_id, status: 'online', is_deleted: 0 } });
const catIds = R.pluck('id', cats);
catIds.push(Number(cat_id));
institutionCats = await ctx.classModel.V4.CourseInstitutionToCat.findAll({ where: { status: 'online', is_deleted: 0, cat_id: { $in: catIds } } });
institutionIds = R.pluck('institution_id', institutionCats);
}
if (institutionIds.length > 0) {
filter.where.id = { $in: institutionIds };
classFilter.where.institution_id = { $in: institutionIds };
}
const institutionFilter = filter;
institutionFilter.where.name = { $like: '%' + search + '%' };
institutionList = await ctx.classModel.V4.CourseInstitution.findAll(institutionFilter);
const ids = R.pluck('id', institutionList);
// 课程搜索
const classList = await ctx.classModel.V4.CourseClass.findAll(classFilter);
// 去除已经搜到的机构
const classInstitutionIds = _.difference(R.pluck('institution_id', classList), ids);
if (classInstitutionIds.length > 0) {
filter.where.id = { $in: classInstitutionIds };
const classInstitutionList = await ctx.classModel.V4.CourseInstitution.findAll(filter);
institutionList = institutionList.concat(classInstitutionList);
}
institutionList = R.pluck('dataValues', institutionList);
const ret = await this.formatInstitutionList(institutionList, input);
return ret;
}
// 获取热搜
async getHotSearch() {
const { ctx } = this;
const search = await ctx.classModel.V4.CourseSearch.findAll({ where: { status: 'online', is_deleted: 0, is_hot: 1 }, order: [[ 'sort', 'asc' ]] });
const ret = {
results: R.pluck('content', search),
count: search.length,
};
return ret;
}
// 获取用户搜索历史
async getUserSearch() {
const { ctx } = this;
const userUuid = ctx.userUuid;
const search = await ctx.classModel.V4.CourseUserSearch.findAll({ where: { status: 'online', user_uuid: userUuid }, limit: 10, order: [[ 'id', 'desc' ]] });
const result = _.uniq(R.pluck('content', search));
const ret = {
results: result,
count: result.length,
};
return ret;
}
// 删除用户搜索历史
async deleteUserSearch() {
const { ctx } = this;
const userUuid = ctx.userUuid;
await ctx.classModel.V4.CourseUserSearch.update({ status: 'offline' }, { where: { user_uuid: userUuid, status: 'online' } });
return;
}
// 评论列表
async getComments(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const institution_id = Number(input.institution_id) || 0;
const comments = await ctx.classModel.V4.CourseComment.findAndCountAll({ where: { institution_id, status: 'online', is_deleted: 0 }, offset, limit, order: [[ 'id', 'desc' ]] });
comments.rows = R.pluck('dataValues', comments.rows);
const ret = {
results: await this.formatComments(comments.rows),
count: comments.count,
};
return ret;
}
// 格式化评论列表
async formatComments(comments) {
const { ctx } = this;
if (ctx.isEmpty(comments)) {
return [];
}
const ids = R.pluck('id', comments);
const images = await ctx.classModel.V4.CourseImages.findAll({ where: { type: 3, type_id: { $in: ids }, status: 'online', is_deleted: 0 } });
const ret = [];
for (const v of comments) {
// 评论图片
let commentImages = [];
for (const j of images) {
if (j.type_id === v.id) {
commentImages.push(j);
}
}
commentImages = _.orderBy(commentImages, [ 'sort' ], [ 'asc' ]);
ret.push({
id: v.id,
institution_id: v.institution_id,
user_uuid: v.user_uuid,
nickname: v.nickname,
avatar: v.avatar,
content: v.content,
has_image: v.has_image,
images: commentImages,
created_time: v.created_time,
});
}
return ret;
}
// 搜索关联
async getSuggestSearch(input) {
const { ctx } = this;
const { search } = input;
let results = [];
if (!ctx.isEmpty(search)) {
const institutions = await ctx.classModel.V4.CourseInstitution.findAll({ where: { status: 'online', is_deleted: 0, name: { $like: '%' + search + '%' } }, limit: 10, attributes: [ 'id', 'name', 'status', 'is_deleted' ] });
results = R.pluck('name', institutions);
}
const ret = {
results,
count: results.length,
};
return ret;
}
// 教师详情
async getTeacher(id) {
const { ctx } = this;
let teacher = await ctx.classModel.V4.CourseTeacher.findOne({ where: { id, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(teacher)) {
ctx.failed('数据不存在');
}
teacher = teacher.dataValues;
teacher.point_tags = teacher.point ? teacher.point.split(',') : [];
teacher.work_experience_tags = teacher.work_experience ? teacher.work_experience.split(';') : [];
const institution = await ctx.classModel.V4.CourseInstitution.findOne({ where: { id: teacher.institution_id } });
teacher.institution_name = institution.name;
return teacher;
}
// 教师列表
async getTeachers(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const institutionId = Number(input.institution_id) || 0;
const teachers = await ctx.classModel.V4.CourseTeacher.findAndCountAll({ where: { institution_id: institutionId, status: 'online', is_deleted: 0 }, raw: true, offset, limit });
const ret = {
results: teachers.rows,
count: teachers.count,
};
return ret;
}
// 课程列表
async getClasses(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const institutionId = Number(input.institution_id) || 0;
const inputClassIds = input.classIds || [];
const attributes = [ 'id', 'institution_id', 'name', 'type', 'class_price', 'min_age', 'max_age', 'status', 'is_deleted' ];
let classes = { rows: [], count: 0 };
if (institutionId > 0) {
classes = await ctx.classModel.V4.CourseClass.findAndCountAll({ where: { institution_id: institutionId, status: 'online', is_deleted: 0 }, raw: true, offset, limit, attributes });
} else if (inputClassIds.length > 0) {
classes = await ctx.classModel.V4.CourseClass.findAndCountAll({ where: { id: { $in: inputClassIds }, status: 'online', is_deleted: 0 }, raw: true, offset, limit, attributes });
}
const classIds = R.pluck('id', classes.rows);
// 课程图片
const classImages = await ctx.classModel.V4.CourseImages.findAll({ where: { type: 2, type_id: { $in: classIds }, status: 'online', is_deleted: 0 }, raw: true });
// 用户收藏的课程
const userCollection = await ctx.classModel.V4.CourseUserCollection.findAll({ where: { user_uuid: ctx.userUuid, is_deleted: 0, type: 2 }, raw: true });
const collectedIds = R.pluck('type_id', userCollection);
for (const i in classes.rows) {
let images = [];
for (const v of classImages) {
if (v.type_id === classes.rows[i].id) {
images.push(v);
}
}
images = _.orderBy(images, [ 'sort' ], [ 'asc' ]);
classes.rows[i].image = images.length > 0 ? images[0] : {};
classes.rows[i].is_collected = collectedIds.includes(classes.rows[i].id) ? 1 : 0;
classes.rows[i].age = classes.rows[i].min_age === 0 && classes.rows[i].max_age === 0 ? '' : `${classes.rows[i].min_age}-${classes.rows[i].max_age}岁`;
classes.rows[i].class_price = classes.rows[i].class_price || '到店咨询';
}
const ret = {
results: classes.rows,
count: classes.count,
};
return ret;
}
// 课程详情
async getClass(input) {
const { ctx } = this;
const classInfo = await ctx.classModel.V4.CourseClass.findOne({ where: { id: input.id, status: 'online', is_deleted: 0 }, raw: true });
if (ctx.isEmpty(classInfo)) {
ctx.failed('数据不存在');
}
// 课程图片
let images = await ctx.classModel.V4.CourseImages.findAll({ where: { type: 2, type_id: input.id, status: 'online', is_deleted: 0 }, raw: true });
// 去重
images = _.uniqBy(images, function(v) { return (v.is_image === 1 ? v.image_url : v.video_url); });
images = _.orderBy(images, [ 'sort' ], [ 'asc' ]);
classInfo.images = images;
classInfo.class_price = ctx.isEmpty(classInfo.class_price) ? '' : classInfo.class_price + '元/课时';
input.institution_id = classInfo.institution_id;
const institution = await this.getInstitution(input);
classInfo.institution = ctx.isEmpty(institution) ? {} : institution.detail;
classInfo.area = ctx.isEmpty(institution) || ctx.isEmpty(institution.areas) ? {} : institution.areas[0];
const isCollected = await ctx.classModel.V4.CourseUserCollection.findOne({ where: { user_uuid: ctx.userUuid, type: 2, type_id: input.id, is_deleted: 0 } });
classInfo.is_collected = ctx.isEmpty(isCollected) ? 0 : 1;
return classInfo;
}
// 用户收藏机构列表
async getUserCollectedInstitutions(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const userCollection = await ctx.classModel.V4.CourseUserCollection.findAll({ where: { user_uuid: userUuid, is_deleted: 0, type: 1 }, raw: true });
const institutionIds = R.pluck('type_id', userCollection);
const institutionList = await ctx.classModel.V4.CourseInstitution.findAll({ where: { id: { $in: institutionIds }, status: 'online', is_deleted: 0 }, raw: true });
const ret = await this.formatInstitutionList(institutionList, input);
return ret;
}
// 用户收藏课程列表
async getUserCollectedClasses(input) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const userCollection = await ctx.classModel.V4.CourseUserCollection.findAll({ where: { user_uuid: userUuid, is_deleted: 0, type: 2 }, raw: true });
const classIds = R.pluck('type_id', userCollection);
input.classIds = classIds;
const ret = await this.getClasses(input);
return ret;
}
// 获取指定分类及子分类的选课指南
async getArticlesByCat(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 2;
const offset = (page - 1) * limit;
const catId = Number(input.cat_id) || 0;
let catIds = [];
const filter = { where: { status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], limit, offset };
// 获取子分类
if (catId > 0) {
const cats = await ctx.classModel.V4.CourseCat.findAll({ where: { parent_id: catId, status: 'online', is_deleted: 0 } });
catIds = R.pluck('id', cats);
catIds.push(catId);
filter.where.cat_id = { $in: catIds };
}
// 获取分类
const cats = await ctx.classModel.V4.CourseCat.findAll({ where: { status: 'online', is_deleted: 0 } });
const catMap = new Map();
for (const v of cats) {
catMap.set(v.id, v);
}
const articles = await ctx.classModel.V4.CourseArticle.findAndCountAll(filter);
const ret = [];
// 用户点赞列表
const userLikes = await ctx.classModel.V4.CourseLike.findAll({ where: { user_uuid: ctx.userUuid, type: 1, is_deleted: 0 } });
const userLikeIds = R.pluck('type_id', userLikes);
for (const v of articles.rows) {
ret.push({
id: v.id,
type: v.type,
cat_id: v.cat_id,
cat_title: catMap.has(v.cat_id) ? catMap.get(v.cat_id).name : '',
title: v.title,
description: v.description,
content: v.content,
image: v.image,
source: v.source,
like_count: v.like_count,
read_count: v.read_count,
sort: v.sort,
is_like: userLikeIds.includes(v.id) ? 1 : 0,
created_time: v.created_time,
});
}
return { results: ret, count: articles.count, page };
}
// 获取选课指南
async getArticle(id) {
const { ctx } = this;
const article = await ctx.classModel.V4.CourseArticle.findOne({ where: { id, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(article)) {
ctx.failed('数据不存在');
}
await ctx.classModel.V4.CourseArticle.update({ read_count: sequelize.literal('`read_count` + 1') }, { where: { id } });
// 用户是否点赞
const userLike = await ctx.classModel.V4.CourseLike.findOne({ where: { user_uuid: ctx.userUuid, type: 1, type_id: id, is_deleted: 0 } });
// 获取分类
const cats = await ctx.classModel.V4.CourseCat.findAll({ where: { status: 'online', is_deleted: 0 } });
const catMap = new Map();
for (const v of cats) {
catMap.set(v.id, v);
}
// 获取关联列表
let relations = [];
if (!ctx.isEmpty(article.relations)) {
const ids = article.relations.split(',');
relations = await ctx.classModel.V4.CourseArticle.findAll({ where: { id: { $in: ids }, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], attributes: [ 'id', 'title', 'type', 'image', 'read_count' ] });
}
const ret = {
id: article.id,
type: article.type,
cat_id: article.cat_id,
cat_title: catMap.has(article.cat_id) ? catMap.get(article.cat_id).name : '',
title: article.title,
description: article.description,
content: article.content,
image: article.image,
source: article.source,
like_count: article.like_count,
read_count: article.read_count,
sort: article.sort,
relations,
is_like: ctx.isEmpty(userLike) ? 0 : 1,
created_time: article.created_time,
};
return ret;
}
// 点赞 1:选课指南;
async like(input) {
const { ctx } = this;
const type = Number(input.type) || 0;
const typeId = Number(input.type_id) || 0;
let tmp = {};
if (type === 0 || typeId === 0) {
ctx.failed('参数异常');
}
// 是否重复点赞
tmp = await ctx.classModel.V4.CourseLike.findOne({ where: { user_uuid: ctx.userUuid, type, type_id: typeId, is_deleted: 0 } });
if (!ctx.isEmpty(tmp)) {
ctx.failed('请勿重复点赞');
}
// 校验点赞对象是否存在
switch (type) {
case 1:
tmp = await ctx.classModel.V4.CourseArticle.findOne({ where: { id: typeId, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(tmp)) {
ctx.failed('数据不存在');
}
// 更新点赞数
await ctx.classModel.V4.CourseArticle.update({ like_count: sequelize.literal('`like_count` + 1') }, { where: { id: typeId } });
break;
default:
break;
}
await ctx.classModel.V4.CourseLike.create({ user_uuid: ctx.userUuid, type, type_id: typeId, is_deleted: 0, created_time: moment().format('YYYY-MM-DD HH:mm:ss') });
return;
}
// 取消点赞
async unlike(input) {
const { ctx } = this;
const type = Number(input.type) || 0;
const typeId = Number(input.type_id) || 0;
let tmp = {};
if (type === 0 || typeId === 0) {
ctx.failed('参数异常');
}
// 是否重复点赞
const userLike = await ctx.classModel.V4.CourseLike.findOne({ where: { user_uuid: ctx.userUuid, type, type_id: typeId, is_deleted: 0 } });
if (ctx.isEmpty(userLike)) {
ctx.failed('尚未点赞');
}
// 校验点赞对象是否存在
switch (type) {
case 1:
tmp = await ctx.classModel.V4.CourseArticle.findOne({ where: { id: typeId, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(tmp)) {
ctx.failed('数据不存在');
}
// 更新点赞数
await ctx.classModel.V4.CourseArticle.update({ like_count: sequelize.literal('`like_count` - 1') }, { where: { id: typeId } });
break;
default:
break;
}
await ctx.classModel.V4.CourseLike.update({ is_deleted: 1 }, { where: { id: userLike.id } });
return;
}
// 获取选课指南推荐列表
async getArticlesByRecommend(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 2;
const offset = (page - 1) * limit;
const articles = await ctx.classModel.V4.CourseArticle.findAndCountAll({ where: { is_recommend: 1, status: 'online', is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], limit, offset });
// 获取分类
const cats = await ctx.classModel.V4.CourseCat.findAll({ where: { status: 'online', is_deleted: 0 } });
const catMap = new Map();
for (const v of cats) {
catMap.set(v.id, v);
}
const ret = [];
// 用户点赞列表
const userLikes = await ctx.classModel.V4.CourseLike.findAll({ where: { user_uuid: ctx.userUuid, type: 1, is_deleted: 0 } });
const userLikeIds = R.pluck('type_id', userLikes);
for (const v of articles.rows) {
ret.push({
id: v.id,
type: v.type,
cat_id: v.cat_id,
cat_title: catMap.has(v.cat_id) ? catMap.get(v.cat_id).name : '',
title: v.title,
description: v.description,
content: v.content,
image: v.image,
source: v.source,
like_count: v.like_count,
read_count: v.read_count,
sort: v.sort,
is_like: userLikeIds.includes(v.id) ? 1 : 0,
created_time: v.created_time,
});
}
return { results: ret, count: articles.count, page };
}
}
module.exports = InstitutionSubService;
'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 R = require('ramda');
const moment = require('moment');
const _ = require('lodash');
class OnlineService extends Service {
// 获取在线课程选项
async getOption() {
const { ctx } = this;
// 分类
let cats = await ctx.classModel.V4.CourseOnlineCat.findAll({ where: { status: 'online', is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true });
cats = [{ id: 0, name: '全部' }].concat(cats);
// 年龄段
let ages = await ctx.classModel.V4.CourseOnlineAge.findAll({ where: { status: 'online', is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true });
ages = [{ id: 0, name: '全部' }].concat(ages);
// 课程状态
const mode = [{ id: 0, name: '全部' }, { id: 1, name: '直播' }, { id: 2, name: '录播' }, { id: 3, name: '直播+录播' }];
// 课程班型
// let type = await ctx.classModel.V4.CourseOnlineType.findAll({ where: { status: 'online', is_deleted: 0 }, attributes: [ 'id', 'name' ], raw: true });
// type = [{ id: 0, name: '全部' }].concat(type);
// 课程类型
const price_type = [{ id: 0, name: '全部' }, { id: 2, name: '免费公益课' }, { id: 1, name: '低价体验课' }, { id: 3, name: '正价课' }];
const options = {
cats,
ages,
mode,
// type,
price_type,
};
return options;
}
// 获取课程详情
async getClass(input) {
const { ctx } = this;
const { id, lng, lat } = input;
const classInfo = await ctx.classModel.V4.CourseOnlineClass.findOne({ where: { id, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(classInfo)) {
ctx.failed('课程不存在');
}
// 缩略图
const imageInfo = await ctx.classModel.V4.CourseImages.findAll({ where: { type: 5, type_id: id, status: 'online', is_deleted: 0 } });
const images = [];
for (const v of imageInfo) {
const image = v.is_video > 0 ? { url: v.video_url, type: 1 } : { url: v.image_url, type: 0 };
images.push(image);
}
// 机构信息
const institution = await ctx.classModel.V4.CourseOnlineInstitution.findOne({ where: { id: classInfo.institution_id } });
// 校区信息
let area = await ctx.classModel.V4.CourseOnlineArea.findOne({ where: { institution_id: classInfo.institution_id, status: 'online', is_deleted: 0 }, raw: true });
area = ctx.isEmpty(area) ? area : await this.service.course.v4.institution.formatArea(area, { lng, lat });
// 分类
const classCats = await ctx.classModel.V4.CourseOnlineClassToCat.findAll({ where: { class_id: id, status: 'online', is_deleted: 0 }, attributes: [ 'cat_id' ] });
const catIds = R.pluck('cat_id', classCats);
const cats = await ctx.classModel.V4.CourseOnlineCat.findAll({ where: { id: { $in: catIds } }, attributes: [ 'id', 'name' ] });
// 年龄段
const classAges = await ctx.classModel.V4.CourseOnlineClassToAge.findAll({ where: { class_id: id, status: 'online', is_deleted: 0 }, attributes: [ 'age_id' ] });
const ageIds = R.pluck('age_id', classAges);
const ages = await ctx.classModel.V4.CourseOnlineAge.findAll({ where: { id: { $in: ageIds } }, attributes: [ 'id', 'name' ] });
// 班型
const classTypes = await ctx.classModel.V4.CourseOnlineClassToType.findAll({ where: { class_id: id, status: 'online', is_deleted: 0 }, attributes: [ 'type_id' ] });
const typeIds = R.pluck('type_id', classTypes);
const type = await ctx.classModel.V4.CourseOnlineType.findAll({ where: { id: { $in: typeIds } }, attributes: [ 'id', 'name' ] });
// 收藏信息
const uuid = ctx.headers.uuid || '';
const userCollect = await ctx.classModel.V4.CourseUserCollection.findOne({ where: { user_uuid: uuid, type: 3, type_id: id, is_deleted: 0 } });
const ret = {
id,
images,
name: classInfo.name,
institution_name: ctx.isEmpty(institution) ? '' : institution.name,
institution_id: classInfo.institution_id,
institution_logo: ctx.isEmpty(institution) ? '' : institution.logo,
relation_institution_id: ctx.isEmpty(institution) ? 0 : institution.relation_id,
address: ctx.isEmpty(area) ? '' : area.address,
phone: ctx.isEmpty(area) ? '' : area.phone,
travel_tips: ctx.isEmpty(area) ? '' : area.travel_tips,
price: classInfo.price,
price_type: this.getClassModelPriceType(classInfo.price_type),
type,
ages,
mode: await this.getClassModelInfo(classInfo.mode),
time: classInfo.time,
channel: classInfo.channel,
description: classInfo.description,
cats: ctx.isEmpty(cats) ? [] : cats,
is_collected: ctx.isEmpty(userCollect) ? 0 : 1,
};
return ret;
}
// 获取在线课程列表
async getClasses(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const { type, mode, age, cat, price_type } = input;
const filter = { where: { status: 'online', is_deleted: 0 }, order: [[ 'institution_id', 'desc' ]], limit, offset, attributes: [ 'id', 'institution_id', 'name', 'price_type', 'price', 'mode', 'time', 'created_time' ] };
// 年龄段筛选
let ids = [];
let flag = false;
if (!ctx.isEmpty(age) && Number(age) > 0) {
const classes = await ctx.classModel.V4.CourseOnlineClassToAge.findAll({ where: { age_id: age, status: 'online', is_deleted: 0 }, attributes: [ 'class_id' ] });
if (flag) {
ids = _.intersection(ids, R.pluck('class_id', classes));
} else {
flag = true;
ids = R.pluck('class_id', classes);
}
}
// 课程类型筛选
if (!ctx.isEmpty(cat) && Number(cat) > 0) {
const classes = await ctx.classModel.V4.CourseOnlineClassToCat.findAll({ where: { cat_id: cat, status: 'online', is_deleted: 0 }, attributes: [ 'class_id' ] });
if (flag) {
ids = _.intersection(ids, R.pluck('class_id', classes));
} else {
flag = true;
ids = R.pluck('class_id', classes);
}
}
// 课程状态筛选
if (!ctx.isEmpty(mode) && Number(mode) > 0) {
filter.where.mode = mode;
}
// 课程类型筛选
if (!ctx.isEmpty(price_type) && Number(price_type) > 0) {
filter.where.price_type = price_type;
}
// 课程班型筛选
if (!ctx.isEmpty(type) && Number(type) > 0) {
const classes = await ctx.classModel.V4.CourseOnlineClassToType.findAll({ where: { type_id: type, status: 'online', is_deleted: 0 }, attributes: [ 'class_id' ] });
if (flag) {
ids = _.intersection(ids, R.pluck('class_id', classes));
} else {
flag = true;
ids = R.pluck('class_id', classes);
}
}
if (flag) {
filter.where.id = { $in: ids };
}
const classes = await ctx.classModel.V4.CourseOnlineClass.findAndCountAll(filter);
const classIds = R.pluck('id', classes.rows);
// 分类
const classToCats = await ctx.classModel.V4.CourseOnlineClassToCat.findAll({ where: { class_id: { $in: classIds }, status: 'online', is_deleted: 0 }, attributes: [ 'class_id', 'cat_id' ] });
const catIds = R.pluck('cat_id', classToCats);
let cats = await ctx.classModel.V4.CourseOnlineCat.findAll({ where: { id: { $in: catIds } } });
cats = _.groupBy(cats, 'id');
let classCats = [];
for (const v of classToCats) {
const tmp = {
id: v.cat_id,
class_id: v.class_id,
name: ctx.isEmpty(cats[v.cat_id]) ? '' : cats[v.cat_id][0].name,
};
classCats.push(tmp);
}
classCats = _.groupBy(classCats, 'class_id');
// 年龄段
const classToAge = await ctx.classModel.V4.CourseOnlineClassToAge.findAll({ where: { class_id: { $in: classIds }, status: 'online', is_deleted: 0 }, attributes: [ 'class_id', 'age_id' ] });
const ageIds = R.pluck('age_id', classToAge);
let ages = await ctx.classModel.V4.CourseOnlineAge.findAll({ where: { id: { $in: ageIds } } });
ages = _.groupBy(ages, 'id');
let classAge = [];
for (const v of classToAge) {
const tmp = {
id: v.age_id,
class_id: v.class_id,
name: ctx.isEmpty(ages[v.age_id]) ? '' : ages[v.age_id][0].name,
};
classAge.push(tmp);
}
classAge = _.groupBy(classAge, 'class_id');
// 班型
const classToTypes = await ctx.classModel.V4.CourseOnlineClassToType.findAll({ where: { class_id: { $in: classIds }, status: 'online', is_deleted: 0 }, attributes: [ 'class_id', 'type_id' ] });
const typeIds = R.pluck('type_id', classToTypes);
let types = await ctx.classModel.V4.CourseOnlineType.findAll({ where: { id: { $in: typeIds } } });
types = _.groupBy(types, 'id');
let classTypes = [];
for (const v of classToTypes) {
const tmp = {
id: v.type_id,
class_id: v.class_id,
name: ctx.isEmpty(types[v.type_id]) ? '' : types[v.type_id][0].name,
};
classTypes.push(tmp);
}
classTypes = _.groupBy(classTypes, 'class_id');
// 机构
const institutionIds = R.pluck('institution_id', classes.rows);
let institutions = await ctx.classModel.V4.CourseOnlineInstitution.findAll({ where: { id: { $in: institutionIds } }, attributes: [ 'id', 'name', 'logo' ] });
institutions = _.groupBy(institutions, 'id');
const result = [];
for (const v of classes.rows) {
const tmp = {
id: v.id,
name: v.name,
institution_id: v.institution_id,
institution_name: ctx.isEmpty(institutions[v.institution_id]) ? '' : institutions[v.institution_id][0].name,
logo: ctx.isEmpty(institutions[v.institution_id]) ? '' : institutions[v.institution_id][0].logo,
type: ctx.isEmpty(classTypes[v.id]) ? [] : classTypes[v.id],
mode: await this.getClassModelInfo(v.mode),
price_type: this.getClassModelPriceType(v.price_type),
price: v.price,
time: v.time,
created_time: v.created_time,
cats: ctx.isEmpty(classCats[v.id]) ? [] : classCats[v.id],
age: ctx.isEmpty(classAge[v.id]) ? [] : classAge[v.id],
};
result.push(tmp);
}
const ret = {
results: result,
count: classes.count,
page,
};
return ret;
}
// 判断课程状态(直播录播)
async getClassModelInfo(mode) {
let ret = '';
switch (mode) {
case 1:
ret = '直播';
break;
case 2:
ret = '录播';
break;
case 3:
ret = '直播+录播';
break;
default:
break;
}
return ret;
}
// 判断课程类型
getClassModelPriceType(price_type) {
let ret = '';
switch (price_type) {
case 1:
ret = '低价体验课';
break;
case 2:
ret = '免费公益课';
break;
case 3:
ret = '正价课';
break;
default:
break;
}
return ret;
}
// 收藏在线课程
async collectClass(id) {
const { ctx } = this;
const userUuid = ctx.userUuid;
const data = {
user_uuid: userUuid,
type: 3,
type_id: id,
is_deleted: 0,
created_time: moment().format('YYYY-MM-DD HH:mm:ss'),
};
const check = await ctx.classModel.V4.CourseUserCollection.findOne({ where: { user_uuid: userUuid, type: 3, type_id: id, is_deleted: 0 } });
if (!ctx.isEmpty(check)) {
ctx.failed('请勿重复收藏');
}
const ret = await ctx.classModel.V4.CourseUserCollection.create(data);
return { result: ret.id };
}
// 获取收藏课程列表
async getCollectionClasses(input) {
const { ctx } = this;
const page = Number(input.page) || 1;
const limit = Number(input.limit) || 10;
const offset = (page - 1) * limit;
const userUuid = ctx.userUuid;
const userCollection = await ctx.classModel.V4.CourseUserCollection.findAndCountAll({ where: { user_uuid: userUuid, is_deleted: 0, type: 3 }, raw: true, limit, offset });
let classIds = R.pluck('type_id', userCollection.rows);
const filter = { where: { id: { $in: classIds }, status: 'online', is_deleted: 0 }, order: [[ 'institution_id', 'desc' ]], limit, offset, attributes: [ 'id', 'institution_id', 'name', 'price', 'mode', 'time', 'created_time' ] };
const classes = await ctx.classModel.V4.CourseOnlineClass.findAll(filter);
classIds = R.pluck('id', classes);
// 分类
const classToCats = await ctx.classModel.V4.CourseOnlineClassToCat.findAll({ where: { class_id: { $in: classIds }, status: 'online', is_deleted: 0 }, attributes: [ 'class_id', 'cat_id' ] });
const catIds = R.pluck('cat_id', classToCats);
let cats = await ctx.classModel.V4.CourseOnlineCat.findAll({ where: { id: { $in: catIds } } });
cats = _.groupBy(cats, 'id');
let classCats = [];
for (const v of classToCats) {
const tmp = {
id: v.cat_id,
class_id: v.class_id,
name: ctx.isEmpty(cats[v.cat_id]) ? '' : cats[v.cat_id][0].name,
};
classCats.push(tmp);
}
classCats = _.groupBy(classCats, 'class_id');
// 年龄段
const classToAge = await ctx.classModel.V4.CourseOnlineClassToAge.findAll({ where: { class_id: { $in: classIds }, status: 'online', is_deleted: 0 }, attributes: [ 'class_id', 'age_id' ] });
const ageIds = R.pluck('age_id', classToAge);
let ages = await ctx.classModel.V4.CourseOnlineAge.findAll({ where: { id: { $in: ageIds } } });
ages = _.groupBy(ages, 'id');
let classAge = [];
for (const v of classToAge) {
const tmp = {
id: v.age_id,
class_id: v.class_id,
name: ctx.isEmpty(ages[v.age_id]) ? '' : ages[v.age_id][0].name,
};
classAge.push(tmp);
}
classAge = _.groupBy(classAge, 'class_id');
// 班型
const classToTypes = await ctx.classModel.V4.CourseOnlineClassToType.findAll({ where: { class_id: { $in: classIds }, status: 'online', is_deleted: 0 }, attributes: [ 'class_id', 'type_id' ] });
const typeIds = R.pluck('type_id', classToTypes);
let types = await ctx.classModel.V4.CourseOnlineType.findAll({ where: { id: { $in: typeIds } } });
types = _.groupBy(types, 'id');
let classTypes = [];
for (const v of classToTypes) {
const tmp = {
id: v.type_id,
class_id: v.class_id,
name: ctx.isEmpty(types[v.type_id]) ? '' : types[v.type_id][0].name,
};
classTypes.push(tmp);
}
classTypes = _.groupBy(classTypes, 'class_id');
// 机构
const institutionIds = R.pluck('institution_id', classes);
let institutions = await ctx.classModel.V4.CourseOnlineInstitution.findAll({ where: { id: { $in: institutionIds } }, attributes: [ 'id', 'name', 'logo' ] });
institutions = _.groupBy(institutions, 'id');
// 缩略图
const imageInfo = await ctx.classModel.V4.CourseImages.findAll({ where: { type: 5, type_id: { $in: classIds }, status: 'online', is_deleted: 0 } });
let images = [];
for (const v of imageInfo) {
const image = v.is_video > 0 ? { url: v.video_url, type: 1 } : { url: v.image_url, type: 0 };
image.type_id = v.type_id;
images.push(image);
}
images = _.groupBy(images, 'type_id');
const result = [];
for (const v of classes) {
const tmp = {
id: v.id,
name: v.name,
images: ctx.isEmpty(images[v.id]) ? [] : images[v.id],
institution_id: v.institution_id,
institution_name: ctx.isEmpty(institutions[v.institution_id]) ? '' : institutions[v.institution_id][0].name,
logo: ctx.isEmpty(institutions[v.institution_id]) ? '' : institutions[v.institution_id][0].logo,
type: ctx.isEmpty(classTypes[v.id]) ? [] : classTypes[v.id],
mode: await this.getClassModelInfo(v.mode),
price: v.price,
time: v.time,
created_time: v.created_time,
cats: ctx.isEmpty(classCats[v.id]) ? [] : classCats[v.id],
age: ctx.isEmpty(classAge[v.id]) ? [] : classAge[v.id],
};
result.push(tmp);
}
const ret = {
results: result,
count: userCollection.count,
page,
};
return ret;
}
// 取消在线课程收藏
async delCollectClass(id) {
const { ctx } = this;
const userUuid = ctx.userUuid;
// 是否已收藏
const check = await ctx.classModel.V4.CourseUserCollection.findOne({ where: { user_uuid: userUuid, type: 3, type_id: id, is_deleted: 0 } });
if (ctx.isEmpty(check)) {
ctx.failed('尚未收藏');
}
await ctx.classModel.V4.CourseUserCollection.update({ is_deleted: 1 }, { where: { id: check.id } });
return;
}
}
module.exports = OnlineService;
'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