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

add userVideo && more buttonInfo

parent abe11f25
Pipeline #24625 passed with stage
in 4 seconds
...@@ -4,7 +4,7 @@ const xml2js = require('xml2js'); ...@@ -4,7 +4,7 @@ const xml2js = require('xml2js');
const Controller = require('egg').Controller; const Controller = require('egg').Controller;
class TestController extends Controller { class TestController extends Controller {
async test() { async test() {
const ret = await this.service.course.v5.wechat.pay({}); const ret = await this.service.course.v5.wechat.sendTest('这是一条测试');
this.ctx.success(ret); this.ctx.success(ret);
} }
} }
......
...@@ -29,6 +29,8 @@ module.exports = app => { ...@@ -29,6 +29,8 @@ module.exports = app => {
button_text: STRING, button_text: STRING,
button_type: INTEGER, button_type: INTEGER,
button_sub_text: STRING, button_sub_text: STRING,
button_url: STRING,
button_pay_text: STRING,
top_price: STRING, top_price: STRING,
pay_price: DECIMAL, pay_price: DECIMAL,
sort: INTEGER, sort: INTEGER,
......
'use strict';
const moment = require('moment');
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const CourseV5UserVideo = app.classModel.define('course_v5_user_video', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_uuid: STRING,
class_id: INTEGER,
video_id: 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_user_video',
});
return CourseV5UserVideo;
};
...@@ -99,7 +99,7 @@ class InstitutionSubService extends Service { ...@@ -99,7 +99,7 @@ class InstitutionSubService extends Service {
// 课程详情 // 课程详情
async getClassInfo(id) { async getClassInfo(id) {
const { ctx } = this; const { ctx } = this;
const attributes = [ 'id', 'institution_id', 'name', 'logo', 'age', 'price', 'price_type', 'mode', 'time', 'class_amount', 'multi_classes', 'cycle', 'description', 'button_style', 'button_text', 'button_type', 'button_sub_text', 'top_price', 'pay_price', 'sort' ]; const attributes = [ 'id', 'institution_id', 'name', 'logo', 'age', 'price', 'price_type', 'mode', 'time', 'class_amount', 'multi_classes', 'cycle', 'description', 'button_style', 'button_text', 'button_type', 'button_sub_text', 'button_url', 'button_pay_text', 'top_price', 'pay_price', 'sort' ];
const classInfo = await ctx.classModel.V5.CourseV5Class.findOne({ where: { id, status: 1, is_deleted: 0 }, attributes, raw: true }); const classInfo = await ctx.classModel.V5.CourseV5Class.findOne({ where: { id, status: 1, is_deleted: 0 }, attributes, raw: true });
if (ctx.isEmpty(classInfo)) { if (ctx.isEmpty(classInfo)) {
ctx.failed('数据不存在'); ctx.failed('数据不存在');
...@@ -159,6 +159,10 @@ class InstitutionSubService extends Service { ...@@ -159,6 +159,10 @@ class InstitutionSubService extends Service {
} }
classInfo.columns = columns; classInfo.columns = columns;
// 是否已购买
const userOrder = ctx.isEmpty(ctx.userUuid) ? {} : await ctx.classModel.V5.CourseUserOrder.findOne({ where: { user_uuid: ctx.userUuid, class_id: id, status: 1, is_deleted: 0 }, attributes: [ 'id' ] });
classInfo.is_bought = ctx.isEmpty(userOrder) ? 0 : 1;
classInfo.price_type = await this.getClassPriceType(classInfo.price_type); classInfo.price_type = await this.getClassPriceType(classInfo.price_type);
classInfo.mode = await this.getClassMode(classInfo.mode); classInfo.mode = await this.getClassMode(classInfo.mode);
classInfo.student_works = studentWorks; classInfo.student_works = studentWorks;
...@@ -386,10 +390,22 @@ class InstitutionSubService extends Service { ...@@ -386,10 +390,22 @@ class InstitutionSubService extends Service {
async getVideoList(input) { async getVideoList(input) {
const { ctx } = this; const { ctx } = this;
const classId = input.class_id || 0; const classId = input.class_id || 0;
const userUuid = ctx.userUuid;
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' ]] }); 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' ]] });
let latestVideoId = 0;
let valid = 0;
if (!ctx.isEmpty(userUuid)) {
const userVideo = await ctx.classModel.V5.CourseUserVideo.findOne({ where: { user_uuid: userUuid, class_id: classId } });
latestVideoId = ctx.isEmpty(userVideo) ? 0 : userVideo.video_id;
const userOrder = await ctx.classModel.V5.CourseUserOrder.findOne({ where: { user_uuid: userUuid, class_id: classId, status: 1, is_deleted: 0 }, attributes: [ 'id' ] });
valid = ctx.isEmpty(userOrder) ? 0 : 1;
}
for (const i in videoList) { for (const i in videoList) {
videoList[i].is_latest = 0; videoList[i].is_latest = videoList[i].id === latestVideoId ? 1 : 0;
videoList[i].valid = videoList[i].is_free === 1 ? 1 : valid;
} }
const ret = { const ret = {
list: videoList, list: videoList,
...@@ -419,6 +435,14 @@ class InstitutionSubService extends Service { ...@@ -419,6 +435,14 @@ class InstitutionSubService extends Service {
} }
} }
// 更新最新播放
const userVideo = await ctx.classModel.V5.CourseUserVideo.findOne({ where: { user_uuid: userUuid, class_id: video.class_id } });
if (ctx.isEmpty(userVideo)) {
await ctx.classModel.V5.CourseUserVideo.create({ user_uuid: userUuid, class_id: video.class_id, video_id: video.id });
} else {
await ctx.classModel.V5.CourseUserVideo.update({ video_id: video.id }, { where: { id: userVideo.id } });
}
const ret = { const ret = {
id: video.id, id: video.id,
class_id: video.class_id, class_id: video.class_id,
...@@ -427,7 +451,7 @@ class InstitutionSubService extends Service { ...@@ -427,7 +451,7 @@ class InstitutionSubService extends Service {
cover_image: video.cover_image, cover_image: video.cover_image,
url: video.url, url: video.url,
is_free: video.is_free, is_free: video.is_free,
is_latest: 0, is_latest: 1,
}; };
return ret; return ret;
......
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