notice_push.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 = 0) {
  34. const wheres = { pid };
  35. if (uid !== 0) {
  36. wheres.uid = uid;
  37. }
  38. let notice = await this.db.select(this.tableName, {
  39. where: wheres,
  40. orders: [['create_time', 'desc']],
  41. limit: 10,
  42. offset: 0
  43. })
  44. notice = notice.map(v => {
  45. const extra = JSON.parse(v.content)
  46. delete v.content
  47. return { ...v, ...extra }
  48. })
  49. return notice
  50. }
  51. /**
  52. * 查询所有推送记录,不重复数据
  53. * @param {Integer} pid - 项目id
  54. * @param {Integer} uid - 查询人id
  55. */
  56. async getNoticeByDataCollect(pid, tenderIds = []) {
  57. const wheres = { pid };
  58. let notice = await this.db.select(this.tableName, {
  59. where: wheres,
  60. orders: [['create_time', 'desc']],
  61. limit: 40,
  62. offset: 0
  63. });
  64. notice = this._.uniqBy(notice, 'content');
  65. notice = notice.map(v => {
  66. const extra = JSON.parse(v.content);
  67. delete v.content;
  68. return { ...v, ...extra }
  69. });
  70. return notice
  71. }
  72. }
  73. return NoticePush
  74. }