Commit ecae8929 authored by 任国军's avatar 任国军

add video & niutong & homeClassList

parent 3d7b8071
Pipeline #24230 passed with stage
in 14 seconds
......@@ -71,6 +71,14 @@ class InstitutionController extends Controller {
ctx.success(ret);
}
// 牛通社首页
async getNiutongshe() {
const { ctx, service } = this;
const ret = await service.course.v5.institution.getNiutongshe();
ctx.success(ret);
}
// 获取搜索联想
async getSearchRecommend() {
const { ctx, service } = this;
......@@ -96,6 +104,45 @@ class InstitutionController extends Controller {
ctx.success(ret);
}
// 获取视频列表
async getVideoList() {
const { ctx, service } = this;
const queryParams = ctx.request.query;
if (ctx.isEmpty(queryParams) || ctx.isEmpty(queryParams.class_id)) {
ctx.failed('class_id is empty');
}
const ret = await service.course.v5.institution.getVideoList(queryParams);
ctx.success(ret);
}
// 获取视频详情
async getVideoInfo() {
const { ctx, service } = this;
const params = ctx.params;
if (ctx.isEmpty(params) || ctx.isEmpty(params.id)) {
ctx.failed('id is empty');
}
const ret = await service.course.v5.institution.getVideoInfo(params.id);
ctx.success(ret);
}
// 获取课程首页
async getHomeClassList() {
const { ctx, service } = this;
const queryParams = ctx.request.query;
if (ctx.isEmpty(queryParams) || ctx.isEmpty(queryParams.cat_id)) {
ctx.failed('cat_id is empty');
}
const ret = await service.course.v5.institution.getHomeClassList(queryParams);
ctx.success(ret);
}
}
module.exports = InstitutionController;
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5Video = app.classModel.define('course_v5_video', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
class_id: INTEGER,
title: STRING,
time: STRING,
cover_image: STRING,
url: STRING,
is_free: INTEGER,
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_video',
});
return CourseV5Video;
};
......@@ -47,6 +47,13 @@ module.exports = app => {
router.get('third', '/recommend/class/all', auth({ is_force: 1 }), 'course.v5.report.getAllReportRecommendClassList');// 获取所有报告推荐课程
router.get('third', '/report/:report_id', auth({ is_force: 0 }), 'course.v5.report.getReportById');// 获取报告详情
router.get('third', '/niutongshe', auth({ is_force: 0 }), 'course.v5.institution.getNiutongshe');// 牛通社首页
router.get('third', '/search/recommend', auth({ is_force: 0 }), 'course.v5.institution.getSearchRecommend');// 搜索联想
router.get('third', '/search', auth({ is_force: 0 }), 'course.v5.institution.getSearch');// 搜索
router.get('third', '/video/all', auth({ is_force: 1 }), 'course.v5.institution.getVideoList');// 获取视频列表
router.get('third', '/video/:id', auth({ is_force: 1 }), 'course.v5.institution.getVideoInfo');// 获取视频详情
router.get('third', '/home/class/all', auth({ is_force: 0 }), 'course.v5.institution.getHomeClassList');// 获取课程首页
};
......@@ -288,8 +288,24 @@ class InstitutionSubService extends Service {
list: [
{
class_id: 1,
image: '',
title: '动力拼音',
sub_title: '轻松掌握声母韵母拼读108 个高频音节',
}, {
class_id: 2,
image: '',
title: '闪卡识字',
sub_title: '联想图像情景学习法入学即能识千字',
}, {
class_id: 3,
image: '',
title: '魔数思维',
sub_title: '3大模块100道题培养抽象 逻辑思维力',
}, {
class_id: 4,
image: '',
title: '家长课堂',
sub_title: '协助父母一站式解决孩子早期教育问题',
},
],
};
......@@ -369,9 +385,97 @@ class InstitutionSubService extends Service {
// 获取视频列表
async getVideoList(input) {
const { ctx } = this;
const classId = input.classId || 0;
const classId = input.class_id || 0;
const videoList = await ctx.classModel.V5.CourseV5Video.findAll({ where: { class_id: classId, status: 1, is_deleted: 0 }, attributes: [ 'id', 'class_id', 'title', 'time', 'cover_image', 'is_free' ], order: [[ 'sort', 'asc' ]] });
for (const i in videoList) {
videoList[i].is_latest = 0;
}
const ret = {
list: videoList,
};
return ret;
}
// 获取视频详情
async getVideoInfo(id) {
const { ctx } = this;
const userUuid = ctx.userUuid;
if (ctx.isEmpty(userUuid)) {
ctx.failed('用户异常');
}
const video = await ctx.classModel.V5.CourseV5Video.findOne({ where: { id, status: 1, is_deleted: 0 } });
if (ctx.isEmpty(video)) {
ctx.failed('视频不存在');
}
// 校验用户是否允许播放
const ret = {
id: video.id,
class_id: video.class_id,
title: video.title,
time: video.time,
cover_image: video.cover_image,
url: video.url,
is_free: video.is_free,
is_latest: 0,
};
return ret;
}
// 课程首页
async getHomeClassList(input) {
const { ctx } = this;
const cat_id = Number(input.cat_id) || 0;
const attributes = [ 'id', 'institution_id', 'name', 'logo', 'age', 'price', 'price_type', 'mode', 'time', 'class_amount', 'multi_classes', 'cycle', 'description', 'sort' ];
const results = [];
let classList = [];
// 体验课
classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { price_type: 1, status: 1, is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], offset: 0, limit: 3, raw: true });
classList = await this.formatClassList(classList);
for (const i in classList) {
classList[i].institution_icon = '';
}
results.push({
title: '体验课',
class: classList,
});
const videoList = await ctx.classModel.findAll({ where: {} });
// 低价课
classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { price_type: 2, status: 1, is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], offset: 0, limit: 3, raw: true });
classList = await this.formatClassList(classList);
for (const i in classList) {
classList[i].institution_icon = '';
}
results.push({
title: '低价课',
class: classList,
});
// 精品课
classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { price_type: 3, status: 1, is_deleted: 0 }, order: [[ 'sort', 'asc' ], [ 'id', 'desc' ]], offset: 0, limit: 3, raw: true });
classList = await this.formatClassList(classList);
for (const i in classList) {
classList[i].institution_icon = '';
}
results.push({
title: '精品课',
class: classList,
});
const ret = {
list: results,
};
return ret;
}
}
......
......@@ -23,6 +23,11 @@ class UserService extends Service {
ctx.failed('请勿频繁操作');
}
if (ctx.app.config.env === 'local') {
await ctx.app.memcache.set(`course_verify_code_${phone}`, '12345', 300);
return { result: true };
}
const code = await this.getRandomNumber(5);
const now = String(new Date().getTime() - 1000);
......
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