weapp_attention_controller.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. module.exports = app => {
  3. class WeappAttentionController extends app.BaseController {
  4. // 关注标段
  5. async follow() {
  6. const { ctx } = this;
  7. try {
  8. const { tenderIds } = ctx.request.body;
  9. if (!tenderIds || !Array.isArray(tenderIds) || tenderIds.length === 0) {
  10. ctx.body = { code: 0, msg: '参数错误:请提供标段ID数组', data: null };
  11. return;
  12. }
  13. const result = await ctx.service.weappAttention.followSections(tenderIds, ctx.session.sessionUser.id);
  14. if (result) {
  15. ctx.body = { code: 0, msg: '关注成功', data: null };
  16. } else {
  17. ctx.body = { code: 0, msg: '关注失败', data: null };
  18. }
  19. } catch (error) {
  20. ctx.body = { code: -1, msg: error.toString(), data: null };
  21. }
  22. }
  23. // 取消关注标段
  24. async unfollow() {
  25. const { ctx } = this;
  26. try {
  27. const { attentionIds } = ctx.request.body;
  28. if (!attentionIds || !Array.isArray(attentionIds) || attentionIds.length === 0) {
  29. ctx.body = { code: 0, msg: '参数错误:请提供关注ID', data: null };
  30. return;
  31. }
  32. const result = await ctx.service.weappAttention.unfollowSections(attentionIds, ctx.session.sessionUser.id);
  33. if (result) {
  34. ctx.body = { code: 0, msg: '取消关注成功', data: null };
  35. } else {
  36. ctx.body = { code: -1, msg: '取消关注失败', data: null };
  37. }
  38. } catch (error) {
  39. ctx.body = { code: -1, msg: error.toString(), data: null };
  40. }
  41. }
  42. // 获取用户关注的标段列表
  43. async followedList() {
  44. const { ctx } = this;
  45. try {
  46. const result = await ctx.service.weappAttention.getFollowedSections(ctx.session.sessionUser.id);
  47. ctx.body = { code: 0, msg: '', data: result };
  48. } catch (error) {
  49. ctx.body = { code: -1, msg: error.toString(), data: null };
  50. }
  51. }
  52. // 检查用户是否关注了某个标段
  53. async checkFollowing() {
  54. const { ctx } = this;
  55. try {
  56. const { tenderId } = ctx.query;
  57. if (!tenderId) {
  58. ctx.body = { code: 0, msg: '参数错误:请提供标段ID', data: null };
  59. return;
  60. }
  61. const isFollowing = await ctx.service.weappAttention.isFollowingSection(ctx.session.sessionUser.id, tenderId);
  62. ctx.body = { code: 0, msg: '', data: { following: isFollowing } };
  63. } catch (error) {
  64. ctx.body = { code: -1, msg: error.toString(), data: null };
  65. }
  66. }
  67. }
  68. return WeappAttentionController;
  69. };