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

add unlike

parent 8bab5c76
Pipeline #18120 passed with stage
in 10 seconds
...@@ -180,6 +180,18 @@ class InstitutionController extends Controller { ...@@ -180,6 +180,18 @@ class InstitutionController extends Controller {
const ret = await service.course.v3.institution.like(inputParams); const ret = await service.course.v3.institution.like(inputParams);
ctx.success(ret); 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.v3.institution.unlike(inputParams);
ctx.success(ret);
}
} }
module.exports = InstitutionController; module.exports = InstitutionController;
...@@ -44,5 +44,6 @@ module.exports = app => { ...@@ -44,5 +44,6 @@ module.exports = app => {
router.get('third', '/article/:id', miniAuth, 'course.v3.institution.getArticle');// 获取选课指南详情 router.get('third', '/article/:id', miniAuth, 'course.v3.institution.getArticle');// 获取选课指南详情
router.post('third', '/like', miniAuth, 'course.v3.institution.like');// 点赞 router.post('third', '/like', miniAuth, 'course.v3.institution.like');// 点赞
router.post('third', '/unlike', miniAuth, 'course.v3.institution.unlike');// 取消点赞
}; };
...@@ -744,6 +744,40 @@ class InstitutionSubService extends Service { ...@@ -744,6 +744,40 @@ class InstitutionSubService extends Service {
return; 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.V3.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.V3.CourseArticle.findOne({ where: { id: typeId, status: 'online', is_deleted: 0 } });
if (ctx.isEmpty(tmp)) {
ctx.failed('数据不存在');
}
// 更新点赞数
await ctx.classModel.V3.CourseArticle.update({ read_count: sequelize.literal('`read_count` - 1') }, { where: { id: typeId } });
break;
default:
break;
}
await ctx.classModel.V3.CourseLike.update({ is_deleted: 1 }, {where:{id: userLike.id}});
return;
}
} }
module.exports = InstitutionSubService; module.exports = InstitutionSubService;
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