Browse Source

待办页数量控制

laiguoran 3 năm trước cách đây
mục cha
commit
f89e0b8cbc
2 tập tin đã thay đổi với 22 bổ sung18 xóa
  1. 1 1
      app/controller/dashboard_controller.js
  2. 21 17
      app/service/notice_push.js

+ 1 - 1
app/controller/dashboard_controller.js

@@ -75,7 +75,7 @@ module.exports = app => {
                 await ctx.service.materialAudit.getLastEndTimeByChecked(ctx.session.sessionUser.accountId),
             ];
             const last_time = ctx.app._.max(shenpi_lastime);
-            console.log(ctx.app._.max(shenpi_lastime), ctx.helper.calcDayNum(last_time));
+            // console.log(ctx.app._.max(shenpi_lastime), ctx.helper.calcDayNum(last_time));
             const renderData = {
                 auditTenders,
                 auditStages,

+ 21 - 17
app/service/notice_push.js

@@ -7,7 +7,7 @@
  * @date 2017/11/16
  * @version
  */
-
+const auditConst = require('../const/audit');
 module.exports = app => {
     class NoticePush extends app.BaseService {
         /**
@@ -30,27 +30,31 @@ module.exports = app => {
         }
 
         /**
-         * 查询所有推送记录
+         * 查询所有推送记录(取每个审批类型的前20条再拼接)
          * @param {Integer} pid - 项目id
          * @param {Integer} uid - 查询人id
          */
         async getNotice(pid, uid = 0) {
-            const wheres = { pid };
-            if (uid !== 0) {
-                wheres.uid = uid;
+            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);
             }
-            let notice = await this.db.select(this.tableName, {
-                where: wheres,
-                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 this._.orderBy(noticeList, ['create_time'], ['desc']);
         }
 
         /**