| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 | 
							- 'use strict'
 
- /**
 
-  * 推送表模型
 
-  *
 
-  * @author LanJianRong
 
-  * @date 2017/11/16
 
-  * @version
 
-  */
 
- const auditConst = require('../const/audit');
 
- module.exports = app => {
 
-     class NoticePush extends app.BaseService {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx)
 
-             this.tableName = 'notice'
 
-         }
 
-         /**
 
-          * 将未读记录设置成已读
 
-          * @param {Number} id 推送记录id
 
-          */
 
-         async set(id) {
 
-             await this.update({ is_read: 1 }, { id })
 
-         }
 
-         /**
 
-          * 查询所有推送记录(取每个审批类型的前20条再拼接)
 
-          * @param {Integer} pid - 项目id
 
-          * @param {Integer} uid - 查询人id
 
-          */
 
-         async getNotice(pid, uid = 0) {
 
-             // const noticeList = [];
 
-             // for (const type in auditConst.pushType) {
 
-             //     const wheres = { pid, type: auditConst.pushType[type] };
 
-             //     if (uid !== 0) {
 
-             //         wheres.uid = uid;
 
-             //     }
 
-             //     let notice = await this.db.select(this.tableName, {
 
-             //         where: wheres,
 
-             //         orders: [['create_time', 'desc']],
 
-             //         limit: 20,
 
-             //         offset: 0
 
-             //     });
 
-             //     notice = notice.map(v => {
 
-             //         const extra = JSON.parse(v.content);
 
-             //         delete v.content;
 
-             //         return { ...v, ...extra };
 
-             //     });
 
-             //     noticeList.push(...notice);
 
-             // }
 
-             // return this._.orderBy(noticeList, ['create_time'], ['desc']);
 
-             const wheres = { pid };
 
-             if (uid !== 0) {
 
-                 wheres.uid = uid;
 
-             }
 
-             let notice = await this.db.select(this.tableName, {
 
-                 where: wheres,
 
-                 orders: [['create_time', 'desc']],
 
-                 limit: 30,
 
-                 offset: 0
 
-             });
 
-             notice = notice.map(v => {
 
-                 const extra = JSON.parse(v.content);
 
-                 delete v.content;
 
-                 return { ...v, ...extra };
 
-             });
 
-             return notice;
 
-         }
 
-         /**
 
-          * 查询所有推送记录,不重复数据
 
-          * @param {Integer} pid - 项目id
 
-          * @param {Integer} uid - 查询人id
 
-          */
 
-         async getNoticeByDataCollect(pid, tenderIds = []) {
 
-             const wheres = { pid };
 
-             let notice = await this.db.select(this.tableName, {
 
-                 where: wheres,
 
-                 orders: [['create_time', 'desc']],
 
-                 limit: 40,
 
-                 offset: 0
 
-             });
 
-             notice = this._.uniqBy(notice, 'content');
 
-             notice = notice.map(v => {
 
-                 const extra = JSON.parse(v.content);
 
-                 delete v.content;
 
-                 return { ...v, ...extra }
 
-             });
 
-             return notice
 
-         }
 
-     }
 
-     return NoticePush
 
- }
 
 
  |