1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 'use strict'
- /**
- * 推送表模型
- *
- * @author LanJianRong
- * @date 2017/11/16
- * @version
- */
- 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 })
- }
- /**
- * 查询所有推送记录
- * @param {Integer} pid - 项目id
- * @param {Integer} uid - 查询人id
- */
- async getNotice(pid, uid) {
- let notice = await this.db.select(this.tableName, {
- where: { pid, uid },
- orders: [['create_time', 'desc']],
- limit: 10,
- offset: 0
- })
- notice = notice.map(v => {
- const extra = JSON.parse(v.content)
- delete v.content
- return { ...v, ...extra }
- })
- return notice
- }
- }
- return NoticePush
- }
|