notice_push.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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,
  38. offset: 0
  39. })
  40. notice = notice.map(v => {
  41. const extra = JSON.parse(v.content)
  42. delete v.content
  43. return { ...v, ...extra }
  44. })
  45. return notice
  46. }
  47. }
  48. return NoticePush
  49. }