notice_push.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. /**
  3. * 推送表模型
  4. *
  5. * @author LanJianRong
  6. * @date 2017/11/16
  7. * @version
  8. */
  9. module.exports = app => {
  10. class NoticePush extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'notice';
  20. }
  21. /**
  22. * 将未读记录设置成已读
  23. * @param {Number} id 推送记录id
  24. */
  25. async set(id) {
  26. await this.update({ is_read: 1 }, { id });
  27. }
  28. /**
  29. * 查询所有推送记录
  30. * @param {Integer} pid - 项目id
  31. * @param {Integer} uid - 查询人id
  32. */
  33. async getNotice(pid, uid) {
  34. let notice = await this.db.select(this.tableName, {
  35. where: { pid, uid },
  36. orders: [['create_time', 'desc']],
  37. limit: 10, offset: 0
  38. });
  39. notice = notice.map(v => {
  40. const extra = JSON.parse(v.content)
  41. delete v.content
  42. return { ...v, ...extra }
  43. }).sort((a, b) => a.name === b.name)
  44. return notice;
  45. }
  46. }
  47. return NoticePush;
  48. };