| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 'use strict';
- module.exports = app => {
- class WeappAttentionController extends app.BaseController {
- // 关注标段
- async follow() {
- const { ctx } = this;
- try {
- const { tenderIds } = ctx.request.body;
- if (!tenderIds || !Array.isArray(tenderIds) || tenderIds.length === 0) {
- ctx.body = { code: 0, msg: '参数错误:请提供标段ID数组', data: null };
- return;
- }
- const result = await ctx.service.weappAttention.followSections(tenderIds, ctx.session.sessionUser.id);
- if (result) {
- ctx.body = { code: 0, msg: '关注成功', data: null };
- } else {
- ctx.body = { code: 0, msg: '关注失败', data: null };
- }
- } catch (error) {
- ctx.body = { code: -1, msg: error.toString(), data: null };
- }
- }
- // 取消关注标段
- async unfollow() {
- const { ctx } = this;
- try {
- const { attentionIds } = ctx.request.body;
- if (!attentionIds || !Array.isArray(attentionIds) || attentionIds.length === 0) {
- ctx.body = { code: 0, msg: '参数错误:请提供关注ID', data: null };
- return;
- }
- const result = await ctx.service.weappAttention.unfollowSections(attentionIds, ctx.session.sessionUser.id);
- if (result) {
- ctx.body = { code: 0, msg: '取消关注成功', data: null };
- } else {
- ctx.body = { code: -1, msg: '取消关注失败', data: null };
- }
- } catch (error) {
- ctx.body = { code: -1, msg: error.toString(), data: null };
- }
- }
- // 获取用户关注的标段列表
- async followedList() {
- const { ctx } = this;
- try {
- const result = await ctx.service.weappAttention.getFollowedSections(ctx.session.sessionUser.id);
- ctx.body = { code: 0, msg: '', data: result };
- } catch (error) {
- ctx.body = { code: -1, msg: error.toString(), data: null };
- }
- }
- // 检查用户是否关注了某个标段
- async checkFollowing() {
- const { ctx } = this;
- try {
- const { tenderId } = ctx.query;
- if (!tenderId) {
- ctx.body = { code: 0, msg: '参数错误:请提供标段ID', data: null };
- return;
- }
- const isFollowing = await ctx.service.weappAttention.isFollowingSection(ctx.session.sessionUser.id, tenderId);
- ctx.body = { code: 0, msg: '', data: { following: isFollowing } };
- } catch (error) {
- ctx.body = { code: -1, msg: error.toString(), data: null };
- }
- }
- }
- return WeappAttentionController;
- };
|