Commit 9b008b64 authored by 任国军's avatar 任国军

fix userVideo table bug

parent ef341823
Pipeline #24718 passed with stage
in 4 seconds
......@@ -82,9 +82,21 @@ class BackService extends Service {
}
const filter = { where: { status: 1, is_deleted: 0 }, limit, offset, attributes: [ 'id', 'order_no', 'class_id', 'pay', 'pay_time', 'type', 'redeem', 'address' ], order: [[ 'pay_time', 'desc' ]] };
let filterClassIds = [];
if (!ctx.isEmpty(input.class_name)) {
const classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { name: { $like: `%${input.class_name}%` } }, attributes: [ 'id' ] });
filterClassIds = R.pluck('id', classList);
filter.where.class_id = { $in: filterClassIds };
}
if (!ctx.isEmpty(input.user_name)) {
const orderList = await ctx.classModel.V5.CourseUserOrder.findAll({ where: { address: { $like: `%${input.user_name}%` } }, attributes: [ 'id' ] });
filter.where.id = { $in: R.pluck('id', orderList) };
}
if (userInfo.is_admin === 0) {
const classList = await ctx.classModel.V5.CourseV5Class.findAll({ where: { institution_id: { $in: userInfo.institution_id } }, attributes: [ 'id' ] });
const classIds = R.pluck('id', classList);
const classIds = ctx.isEmpty(input.class_name) ? R.pluck('id', classList) : _.intersection(filterClassIds, R.pluck('id', classList));
filter.where.class_id = { $in: classIds };
}
......
......@@ -397,7 +397,7 @@ class InstitutionSubService extends Service {
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 } });
const userVideo = await ctx.classModel.V5.CourseV5UserVideo.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;
......@@ -436,11 +436,11 @@ class InstitutionSubService extends Service {
}
// 更新最新播放
const userVideo = await ctx.classModel.V5.CourseUserVideo.findOne({ where: { user_uuid: userUuid, class_id: video.class_id } });
const userVideo = await ctx.classModel.V5.CourseV5UserVideo.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 });
await ctx.classModel.V5.CourseV5UserVideo.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 } });
await ctx.classModel.V5.CourseV5UserVideo.update({ video_id: video.id }, { where: { id: userVideo.id } });
}
const 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