Przeglądaj źródła

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

TonyKang 4 lat temu
rodzic
commit
38a16bfc83

+ 3 - 3
app/const/audit.js

@@ -216,9 +216,9 @@ statusButtonClass[status.backnew] = 'btn-success';
 const statusString = [];
 statusString[status.uncheck] = '';
 statusString[status.checking] = '审批中';
-statusString[status.checked] = '完成';
+statusString[status.checked] = '审批完成';
 // statusString[status.checkNo] = '终止';
-statusString[status.back] = '退回';
+statusString[status.back] = '审批退回';
 statusString[status.backnew] = '退回';
 
 const statusClass = [];
@@ -340,7 +340,7 @@ const pushType = {
     material: 1,
     stage: 2,
     change: 3,
-    revize: 4,
+    revise: 4,
     ledger: 5,
 };
 

+ 3 - 2
app/controller/change_controller.js

@@ -548,15 +548,16 @@ module.exports = app => {
                 }
                 const status = parseInt(ctx.request.body.status);
                 let result = false;
+                const pid = this.ctx.session.sessionProject.id;
                 switch (status) {
                     case 3:// 审批通过
-                        result = await ctx.service.change.approvalSuccess(ctx.request.body, changeData);
+                        result = await ctx.service.change.approvalSuccess(pid, ctx.request.body, changeData);
                         break;
                     case 4:// 审批终止
                         result = await ctx.service.change.approvalStop(ctx.request.body);
                         break;
                     case 5:// 审批退回到原报人
-                        result = await ctx.service.change.approvalBack(ctx.request.body, changeData);
+                        result = await ctx.service.change.approvalBack(pid, ctx.request.body, changeData);
                         break;
                     case 6:// 审批退回到上一个审批人
                         result = await ctx.service.change.approvalBackNew(ctx.request.body, changeData);

+ 0 - 4
app/controller/dashboard_controller.js

@@ -127,7 +127,6 @@ module.exports = app => {
                 userMsgPermission,
                 msgList: JSON.parse(JSON.stringify(msgList).replace(/\\r\\n/g, '<br>').replace(/\\"/g, '&#34;').replace(/'/g, '&#39;').replace(/\\t/g, '&#9;')),
             };
-            console.log(renderData.msgList);
             await this.layout('dashboard/msg.ejs', renderData);
         }
 
@@ -153,7 +152,6 @@ module.exports = app => {
                 };
                 await this.layout('dashboard/msg_add.ejs', renderData, 'dashboard/msg_modal.ejs');
             } catch (error) {
-                console.log(error);
                 // this.setMessage(error.toString(), this.messageType.ERROR);
                 ctx.redirect(ctx.request.header.referer);
             }
@@ -179,7 +177,6 @@ module.exports = app => {
                     ctx.redirect('/dashboard/msg/list');
                 }
             } catch (error) {
-                console.log(error);
                 ctx.redirect(ctx.request.header.referer);
             }
         }
@@ -206,7 +203,6 @@ module.exports = app => {
                     ctx.redirect('/dashboard/msg/list');
                 }
             } catch (error) {
-                console.log(error);
                 ctx.redirect(ctx.request.header.referer);
             }
         }

+ 18 - 13
app/public/js/change_set.js

@@ -49,6 +49,9 @@ $(document).ready(() => {
 
         gclGatherData = gclGatherModel.gatherGclData();
         for (const ggd in gclGatherData) {
+            if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
+                gclGatherData.splice(ggd, 1);
+            }
             gclGatherData[ggd].code = gclGatherData[ggd].b_code;
         }
         // 数组去重
@@ -73,16 +76,18 @@ $(document).ready(() => {
             const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
             let gclhtml = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? ' data-gcl="' + gcl_index + '"': '';
             gcl_index = gclhtml !== '' ? ++gcl_index : gcl_index;
-            const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? gcl.leafXmjs[0].gcl_id : gcl.id;
-            listHtml += '<tr data-lid="' + lid + '"'+ gclhtml +' data-index="' + list_index + '" data-bwmx="">' +
-                '<td class="text-center">' + list_index + '</td>' +
-                '<td>' + gcl.code + '</td>' +
-                '<td class="text-left">' + gcl.name + '</td>' +
-                '<td class="text-center">' + unit + '</td>' +
-                '<td class="text-right">' + roundnum(unit_price, unitPriceUnit) + '</td>' +
-                '<td class="text-right">' + quantity + '</td>' +
-                '</tr>';
-            list_index++;
+            const lid = gcl.leafXmjs !== undefined && gcl.leafXmjs !== null ? (gcl.leafXmjs.length !== 0 ? gcl.leafXmjs[0].gcl_id : false) : gcl.id;
+            if (lid) {
+                listHtml += '<tr data-lid="' + lid + '"'+ gclhtml +' data-index="' + list_index + '" data-bwmx="">' +
+                    '<td class="text-center">' + list_index + '</td>' +
+                    '<td>' + gcl.code + '</td>' +
+                    '<td class="text-left">' + gcl.name + '</td>' +
+                    '<td class="text-center">' + unit + '</td>' +
+                    '<td class="text-right">' + roundnum(unit_price, unitPriceUnit) + '</td>' +
+                    '<td class="text-right">' + quantity + '</td>' +
+                    '</tr>';
+                list_index++;
+            }
         }
         $('#table-list-select').html(listHtml);
         tableDataRemake(changeListData);
@@ -242,7 +247,7 @@ $(document).ready(() => {
     });
 
     $('#hideSp').click(function () {
-       $('#sub-sp2').modal('hide');
+        $('#sub-sp2').modal('hide');
     });
 
     // 添加到审批流程中
@@ -546,8 +551,8 @@ $(document).ready(() => {
 
     // 自动编号
     $('.reduction-code').click(function () {
-       const code = $(this).attr('data-code');
-       $('input[name="code"]').val(code);
+        const code = $(this).attr('data-code');
+        $('input[name="code"]').val(code);
     });
 
     // 记录变更信息操作

+ 40 - 10
app/service/change.js

@@ -14,6 +14,7 @@ const path = require('path');
 const smsTypeConst = require('../const/sms_type');
 const SMS = require('../lib/sms');
 const SmsAliConst = require('../const/sms_alitemplate');
+const pushType = require('../const/audit').pushType;
 
 module.exports = app => {
     class Change extends app.BaseService {
@@ -470,11 +471,12 @@ module.exports = app => {
 
         /**
          * 审批通过
+         * @param {Number} pid 项目id
          * @param {int} postData - 表单提交的数据
          * @param {int} changeData - 变更令的数据
          * @return {void}
          */
-        async approvalSuccess(postData, changeData) {
+        async approvalSuccess(pid, postData, changeData) {
             let tenderInfo;
             // 初始化事务
             this.transaction = await this.db.beginTransaction();
@@ -526,6 +528,9 @@ module.exports = app => {
                     change_update.p_code = postData.p_code;
                     change_update.sin_time = Date.parse(new Date()) / 1000;
 
+                    // 添加到消息推送表
+                    const noticeContent = await this.getNoticeContent(pid, changeData.tid, changeData.cid);
+                    await this.transaction.insert('zh_notice', { pid, type: pushType.change, uid: changeData.uid, status: audit.flow.status.checked, is_read: 0, content: noticeContent });
                     // 添加短信通知-审批通过提醒功能
                     // const mobile_array = [];
                     const auditList = await this.ctx.service.changeAudit.getListGroupByTimes(changeData.cid, changeData.times);
@@ -633,15 +638,19 @@ module.exports = app => {
 
         /**
          * 审批退回到原报人
+         * @param {Number} pid 项目id
          * @param {int} postData - 表单提交的数据
          * @param {int} changeData - 变更令的数据
          * @return {void}
          */
-        async approvalBack(postData, changeData) {
+        async approvalBack(pid, postData, changeData) {
             // 初始化事务
+            const noticeContent = await this.getNoticeContent(pid, changeData.tid, changeData.cid);
             this.transaction = await this.db.beginTransaction();
             let result = false;
             try {
+                // 添加到消息推送表
+                await this.transaction.insert('zh_notice', { pid, type: pushType.change, uid: changeData.uid, status: audit.flow.status.back, is_read: 0, content: noticeContent });
                 const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
                 const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeInfo.tid);
                 // 设置审批人退回
@@ -697,6 +706,7 @@ module.exports = app => {
                     },
                 };
                 await this.transaction.update(this.tableName, change_update, options);
+
                 await this.transaction.commit();
                 result = true;
 
@@ -722,6 +732,7 @@ module.exports = app => {
                 const code = await sms.contentChange(changeData.code);
                 await this.ctx.helper.sendAliSms(users, smsTypeConst.const.BG,
                     smsTypeConst.judge.result.toString(), SmsAliConst.template.change_result, { biangeng: code, status: SmsAliConst.status.back });
+
             } catch (error) {
                 await this.transaction.rollback();
                 result = false;
@@ -861,7 +872,7 @@ module.exports = app => {
          * 查询可用的变更令
          * @param bills - 查询的清单
          * @param pos - 查询的部位
-         * @returns {Promise<*>} - 可用的变更令列表
+         * @return {Promise<*>} - 可用的变更令列表
          */
         async getValidChanges(tid, bills, pos) {
             const timesLen = 100;
@@ -875,7 +886,7 @@ module.exports = app => {
                         '    cb.id As cbid, cb.code As b_code, cb.name As b_name, cb.unit As b_unit, cb.samount As b_amount, cb.detail As b_detail, cb.bwmx As b_bwmx, ' +
                         '    scb.used_amount' +
                         '  FROM ' + this.tableName + ' As c ' +
-                        '  Left Join ' + this.ctx.service.changeAuditList.tableName +' As cb On c.cid = cb.cid ' +
+                        '  Left Join ' + this.ctx.service.changeAuditList.tableName + ' As cb On c.cid = cb.cid ' +
                         '  Left Join (' +
                         '    SELECT SUM(sc.qty) As used_amount, sc.cbid' +
                         '      FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
@@ -906,7 +917,7 @@ module.exports = app => {
         /**
          * 查询变更令 + 变更令执行
          * @param tid
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async getChangeAndUsedInfo(tid) {
             const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
@@ -921,7 +932,7 @@ module.exports = app => {
                     filter = '';
                 } else if (lastStage.status === audit.stage.status.checkNo) {
                     filter = this.db.format(' And (s.`order` < ? OR (s.`order` = ? And sChange.`stimes` <= ?))',
-                        [lastStage.order, lastStage.order, lastStage.times])
+                        [lastStage.order, lastStage.order, lastStage.times]);
                 } else {
                     const curAuditor = await this.ctx.service.stageAudit.getCurAuditor(lastStage.id, lastStage.times);
                     filter = this.db.format(' And (s.`order` < ? OR (s.`order` = ? And (sChange.`stimes` < ? OR (sChange.`stimes` = ? And sChange.`sorder` <= ?))))',
@@ -1094,7 +1105,7 @@ module.exports = app => {
          * @param cid
          * @param code
          * @param tid
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async isRepeat(cid, code, tid) {
             const sql = 'SELECT COUNT(*) as count FROM ?? WHERE ((`code` = ? AND `status` != ?) OR (`p_code` = ? AND `status` = ?)) AND `cid` != ? AND `tid` = ?';
@@ -1105,10 +1116,29 @@ module.exports = app => {
 
         async getAllCheckedChanges(tid) {
             return await this.getAllDataByCondition({
-                where: {tid: tid, status: audit.flow.status.checked},
-                orders: [['in_time', 'desc']]
-            })
+                where: { tid, status: audit.flow.status.checked },
+                orders: [['in_time', 'desc']],
+            });
+        }
+
+        /**
+         * 用于添加推送所需的content内容
+         * @param {Number} pid 项目id
+         * @param {Number} tid 台账id
+         * @param {Number} cid 变更id
+         */
+        async getNoticeContent(pid, tid, cid) {
+            const noticeSql = 'SELECT * FROM (SELECT ' +
+                '  t.`id` As `tid`, t.`name`, c.`cid`, c.`code` As `c_code`, pa.`name` As `su_name`, pa.role As `su_role`' +
+                '  FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
+                '  LEFT JOIN ?? As c ON c.`cid` = ?' +
+                '  LEFT JOIN ?? As pa ON c.`uid` = pa.`id`' +
+                '  WHERE  t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
+            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.change.tableName, cid, this.ctx.service.projectAccount.tableName, pid];
+            const content = await this.db.query(noticeSql, noticeSqlParam);
+            return content.length ? JSON.stringify(content[0]) : '';
         }
     }
+
     return Change;
 };

+ 26 - 14
app/service/change_audit.js

@@ -9,6 +9,7 @@
  */
 
 const audit = require('../const/audit');
+const pushType = require('../const/audit').pushType;
 
 module.exports = app => {
     class ChangeAudit extends app.BaseService {
@@ -261,7 +262,7 @@ module.exports = app => {
         /**
          * 获取 审核人 待审批的() 变更令列表
          * @param uid
-         * @returns {Promise<void>}
+         * @return {Promise<void>}
          */
         async getAuditChange(uid) {
             const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`sin_time`, ca.`name` As `caname`, ' +
@@ -293,22 +294,33 @@ module.exports = app => {
          * @param {Number} pid - 查询标段
          * @param {Number} uid - 查询人
          * @param {Date} time - 查询时间
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getNoticeChange(pid, uid, time) {
-            const sql = 'SELECT * FROM (SELECT t.`id`, t.`name`, t.`type`, t.`user_id`, ' +
-                        '    ca.`cid`, c.`code` As `c_code`, c.name As `c_name`, ' +
-                        '    ca.`uid`, ca.`sin_time` As `cu_time`, ca.`status` As `cu_status`, ca.`name` As `cu_name`, ca.`jobs` As `cu_jobs`, ca.company As `cu_company`' +
-                        '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `uid` = ? GROUP BY `tid`)) As t' +
-                        '  LEFT JOIN ?? As c ON c.`tid` = t.`id`' +
-                        '  LEFT JOIN ?? As ca ON ca.`cid` = c.`cid`' +
-                        '  WHERE t.`project_id` = ? and `ca`.`sin_time` > ? and `ca`.`usite` != 0 and `ca`.`status` != ?' +
-                        '  ORDER By ca.`sin_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`id`' +
-                        '  ORDER BY new_t.`cu_time`';
-            const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.change.tableName, this.tableName, pid, time, audit.flow.status.checking];
-            return await this.db.query(sql, sqlParam);
+            // const sql = 'SELECT * FROM (SELECT t.`id`, t.`name`, t.`type`, t.`user_id`, ' +
+            //             '    ca.`cid`, c.`code` As `c_code`, c.name As `c_name`, ' +
+            //             '    ca.`uid`, ca.`sin_time` As `cu_time`, ca.`status` As `cu_status`, ca.`name` As `cu_name`, ca.`jobs` As `cu_jobs`, ca.company As `cu_company`' +
+            //             '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `uid` = ? GROUP BY `tid`)) As t' +
+            //             '  LEFT JOIN ?? As c ON c.`tid` = t.`id`' +
+            //             '  LEFT JOIN ?? As ca ON ca.`cid` = c.`cid`' +
+            //             '  WHERE t.`project_id` = ? and `ca`.`sin_time` > ? and `ca`.`usite` != 0 and `ca`.`status` != ?' +
+            //             '  ORDER By ca.`sin_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`id`' +
+            //             '  ORDER BY new_t.`cu_time`';
+            // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.change.tableName, this.tableName, pid, time, audit.flow.status.checking];
+            // return await this.db.query(sql, sqlParam);
+            let notice =  await this.db.select('zh_notice', {
+                where: { pid, type: pushType.change, uid, is_read: 0 },
+            });
+            notice = notice.map(v => {
+                const extra = JSON.parse(v.content)
+                delete v.content
+                return { ...v, ...extra }
+            })
+            return notice;
         }
 
+
+
         async getAllAuditors(tenderId) {
             const sql = 'SELECT ca.uid, ca.tid FROM ' + this.tableName + ' ca' +
                 '  LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ca.tid = t.id' +
@@ -322,7 +334,7 @@ module.exports = app => {
          * 取待审批变更列表(wap用)
          *
          * @param auditorId
-         * @returns {Promise<*>}
+         * @return {Promise<*>}
          */
         async getAuditChangeByWap(uid) {
             const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`sin_time`, ca.`name` As `caname`, ' +

+ 46 - 14
app/service/ledger_audit.js

@@ -12,6 +12,7 @@ const auditConst = require('../const/audit').ledger;
 const smsTypeConst = require('../const/sms_type');
 const SMS = require('../lib/sms');
 const SmsAliConst = require('../const/sms_alitemplate');
+const pushType = require('../const/audit').pushType;
 
 module.exports = app => {
     class LedgerAudit extends app.BaseService {
@@ -239,7 +240,7 @@ module.exports = app => {
             if (checkType !== auditConst.status.checked && checkType !== auditConst.status.checkNo) {
                 throw '提交数据错误';
             }
-
+            const pid = this.ctx.session.sessionProject.id;
             const transaction = await this.db.beginTransaction();
             try {
                 // 整理当前流程审核人状态更新
@@ -297,6 +298,9 @@ module.exports = app => {
                         //     smsTypeConst.judge.result.toString(), '台账审批通过,请登录系统处理。');
                         await this.ctx.helper.sendAliSms(users, smsTypeConst.const.TZ,
                             smsTypeConst.judge.result.toString(), SmsAliConst.template.ledger_result, { status: SmsAliConst.status.success });
+                        // 添加到消息推送表
+                        const noticeContent = await this.getNoticeContent(audit.tender_id, pid)
+                        await transaction.insert('zh_notice', { pid, type: pushType.ledger, uid: this.ctx.tender.data.user_id, status: auditConst.status.checked, is_read: 0, content: noticeContent });
                     }
                 } else {
                     // 同步标段信息
@@ -340,13 +344,14 @@ module.exports = app => {
                     //     sms.send(mobile_array, content);
                     // }
                     const auditList = await this.getAuditors(tenderId, times);
-                    console.log(auditList);
                     const users = this._.pull(this._.map(auditList, 'audit_id'), audit.id);
-                    console.log(users);
                     // await this.ctx.helper.sendUserSms(users, smsTypeConst.const.TZ,
                     //     smsTypeConst.judge.result.toString(), '台账审批退回,请登录系统处理。');
                     await this.ctx.helper.sendAliSms(users, smsTypeConst.const.TZ,
                         smsTypeConst.judge.result.toString(), SmsAliConst.template.ledger_result, { status: SmsAliConst.status.back });
+                    // 添加到消息推送表
+                    const noticeContent = await this.getNoticeContent(audit.tender_id, pid)
+                    await transaction.insert('zh_notice', { pid, type: pushType.ledger, uid: this.ctx.tender.data.user_id, status: auditConst.status.checkNo, is_read: 0, content: noticeContent });
                 }
 
                 await transaction.commit();
@@ -378,17 +383,44 @@ module.exports = app => {
          * @param {Date} noticeTime - 查询事件
          * @returns {Promise<*>}
          */
-        async getNoticeTender(projectId, auditorId, noticeTime) {
-            const sql = 'SELECT * FROM (SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`end_time`, la.`status`, t.`id`, t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
-                        '    pa.name As `lu_name`, pa.role As `lu_role`, pa.company As `lu_company`' +
-                        '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tender_id` FROM ?? WHERE `audit_id` = ? GROUP BY `tender_id`)) As t ' +
-                        '  LEFT JOIN ?? As la ON la.`tender_id` = t.`id`' +
-                        '  LEFT JOIN ?? As pa ON la.`audit_id` = pa.`id`' +
-                        '  WHERE la.`end_time` > ? and t.`project_id` = ?' +
-                        '  ORDER By la.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`id` ORDER BY new_t.`end_time`';
-            const sqlParam = [this.ctx.service.tender.tableName, auditorId, this.tableName, auditorId, this.tableName, this.ctx.service.projectAccount.tableName,
-                noticeTime, projectId];
-            return await this.db.query(sql, sqlParam);
+        async getNoticeTender(pid, uid, noticeTime) {
+            // const sql = 'SELECT * FROM (SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`end_time`, la.`status`, t.`id`, t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
+            //             '    pa.name As `lu_name`, pa.role As `lu_role`, pa.company As `lu_company`' +
+            //             '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tender_id` FROM ?? WHERE `audit_id` = ? GROUP BY `tender_id`)) As t ' +
+            //             '  LEFT JOIN ?? As la ON la.`tender_id` = t.`id`' +
+            //             '  LEFT JOIN ?? As pa ON la.`audit_id` = pa.`id`' +
+            //             '  WHERE la.`end_time` > ? and t.`project_id` = ?' +
+            //             '  ORDER By la.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`id` ORDER BY new_t.`end_time`';
+            // const sqlParam = [this.ctx.service.tender.tableName, auditorId, this.tableName, auditorId, this.tableName, this.ctx.service.projectAccount.tableName,
+            //     noticeTime, projectId];
+            // return await this.db.query(sql, sqlParam);
+
+
+            let notice =  await this.db.select('zh_notice', {
+                where: { pid, type: pushType.ledger, uid, is_read: 0 },
+            });
+            notice = notice.map(v => {
+                const extra = JSON.parse(v.content)
+                delete v.content
+                return { ...v, ...extra }
+            })
+            return notice;
+        }
+
+        /**
+         * 用于添加推送所需的content内容
+         * @param {Number} id 台账id
+         * @param {Number} pid 项目id
+         */
+        async getNoticeContent(id, pid) {
+            const noticeSql = 'SELECT * FROM (SELECT ' +
+                '  t.`id` As `tid`, t.`name`,  pa.`name` As `su_name`, pa.role As `su_role`' +
+                '  FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
+                '  LEFT JOIN ?? As pa ON t.`user_id` = pa.`id`' +
+                '  WHERE  t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
+            const noticeSqlParam = [this.ctx.service.tender.tableName, id, this.ctx.service.projectAccount.tableName, pid];
+            const content = await this.db.query(noticeSql, noticeSqlParam);
+            return content.length ? JSON.stringify(content[0]) : '';
         }
     }
 

+ 2 - 2
app/service/material_audit.js

@@ -10,6 +10,7 @@
 
 const auditConst = require('../const/audit').material;
 const pushType = require('../const/audit').pushType;
+
 module.exports = app => {
     class MaterialAudit extends app.BaseService {
         /**
@@ -349,11 +350,11 @@ module.exports = app => {
                 a.status = auditConst.status.uncheck;
                 order++;
             }
-            const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId)
             const transaction = await this.db.beginTransaction();
             try {
                 await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
                 // 添加到消息推送表
+                const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId)
                 await transaction.insert('zh_notice', { pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNo, is_read: 0, content: noticeContent });
                 // 同步期信息
                 await transaction.update(this.ctx.service.material.tableName, {
@@ -494,7 +495,6 @@ module.exports = app => {
             const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.material.tableName, mid, this.tableName, this.ctx.service.projectAccount.tableName, pid];
             const content = await this.db.query(noticeSql, noticeSqlParam);
             return content.length ? JSON.stringify(content[0]) : '';
-
         }
 
         /**

+ 52 - 18
app/service/revise_audit.js

@@ -11,6 +11,7 @@
 const auditConst = require('../const/audit').revise;
 const smsTypeConst = require('../const/sms_type');
 const SmsAliConst = require('../const/sms_alitemplate');
+const pushType = require('../const/audit').pushType;
 
 module.exports = app => {
     class ReviseAudit extends app.BaseService {
@@ -287,7 +288,8 @@ module.exports = app => {
             if (checkType !== auditConst.status.checked && checkType !== auditConst.status.checkNo) throw '提交数据错误';
             const audit = await this.getDataByCondition({rid: revise.id, times: times, status: auditConst.status.checking});
             if (!audit) throw '审核数据错误';
-
+            const pid = this.ctx.session.sessionProject.id;
+            const noticeContent = await this.getNoticeContent(pid, audit.tender_id, audit.rid)
             const transaction = await this.db.beginTransaction();
             try {
                 // 整理当前流程审核人状态更新
@@ -330,7 +332,9 @@ module.exports = app => {
                         await transaction.update(this.ctx.service.tender.tableName, {
                             id: revise.tid, total_price: sum.total_price, deal_tp: sum.deal_tp
                         });
-
+                        // 审核结束,将原报添加到推送表
+                        // const noticeContent = await this.getNoticeContent(pid, audit.tender_id, audit.rid)
+                        await transaction.insert('zh_notice', { pid, type: pushType.revise, uid: revise.uid, status: auditConst.status.checked, is_read: 0, content: noticeContent });
                         // 短信通知-审批通过提醒功能
                         // 下一人
                         // const msg = '台账修订审批通过,请登录系统处理。';
@@ -372,6 +376,9 @@ module.exports = app => {
                     //     smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), '台账修订审批退回。');
                     await this.ctx.helper.sendAliSms(this._.map(auditors, 'user_id'), smsTypeConst.const.XD,
                         smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, { status: SmsAliConst.status.back });
+
+                    // 审核结束,将原报添加到推送表
+                    await transaction.insert('zh_notice', { pid, type: pushType.revise, uid: revise.uid, status: auditConst.status.checkNo, is_read: 0, content: noticeContent });
                 }
 
                 await transaction.commit();
@@ -404,25 +411,52 @@ module.exports = app => {
 
         /**
          * 获取 某时间后 审批进度 更新的台账
-         * @param {Integer} projectId - 项目id
-         * @param {Integer} auditorId - 查询人id
+         * @param {Integer} pid - 项目id
+         * @param {Integer} uid - 查询人id
          * @param {Date} noticeTime - 查询事件
          * @returns {Promise<*>}
          */
-        async getNoticeRevise(projectId, auditorId, noticeTime) {
-            const sql = 'SELECT * FROM (SELECT ra.`audit_id`, ra.`times`, ra.`audit_order`, ra.`end_time`, ra.`status`,' +
-                '    r.id, r.corder, r.uid, r.status As `r_status`, r.content, ' +
-                '    t.`id` As t_id, t.`name` As t_name, t.`project_id` As t_pid, t.`type` As t_type, t.`user_id` As t_uid, ' +
-                '    pa.name As `ru_name`, pa.role As `ru_role`, pa.company As `ru_company`' +
-                '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tender_id` FROM ?? WHERE `audit_id` = ? GROUP BY `tender_id`)) As t' +
-                '  LEFT JOIN ' + this.ctx.service.ledgerRevise.tableName + ' As r ON r.`tid` = t.`id`' +
-                '  LEFT JOIN ' + this.tableName + ' As ra  ON ra.rid = r.id' +
-                '  LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa ON ra.`audit_id` = pa.`id`' +
-                '  WHERE ra.end_time > ? and t.project_id = ?' +
-                '  ORDER By ra.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`id`' +
-                '  ORDER By new_t.`end_time`';
-            const sqlParam = [this.ctx.service.tender.tableName, auditorId, this.tableName, auditorId, noticeTime, projectId];
-            return await this.db.query(sql, sqlParam);
+        async getNoticeRevise(pid, uid, noticeTime) {
+            // const sql = 'SELECT * FROM (SELECT ra.`audit_id`, ra.`times`, ra.`audit_order`, ra.`end_time`, ra.`status`,' +
+            //     '    r.id, r.corder, r.uid, r.status As `r_status`, r.content, ' +
+            //     '    t.`id` As t_id, t.`name` As t_name, t.`project_id` As t_pid, t.`type` As t_type, t.`user_id` As t_uid, ' +
+            //     '    pa.name As `ru_name`, pa.role As `ru_role`, pa.company As `ru_company`' +
+            //     '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tender_id` FROM ?? WHERE `audit_id` = ? GROUP BY `tender_id`)) As t' +
+            //     '  LEFT JOIN ' + this.ctx.service.ledgerRevise.tableName + ' As r ON r.`tid` = t.`id`' +
+            //     '  LEFT JOIN ' + this.tableName + ' As ra  ON ra.rid = r.id' +
+            //     '  LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa ON ra.`audit_id` = pa.`id`' +
+            //     '  WHERE ra.end_time > ? and t.project_id = ?' +
+            //     '  ORDER By ra.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`id`' +
+            //     '  ORDER By new_t.`end_time`';
+            // const sqlParam = [this.ctx.service.tender.tableName, auditorId, this.tableName, auditorId, noticeTime, projectId];
+            // return await this.db.query(sql, sqlParam);
+            let notice =  await this.db.select('zh_notice', {
+                where: { pid, type: pushType.revise, uid, is_read: 0 },
+            });
+            notice = notice.map(v => {
+                const extra = JSON.parse(v.content)
+                delete v.content
+                return { ...v, ...extra }
+            })
+            return notice;
+        }
+
+        /**
+         * 用于添加推送所需的content内容
+         * @param {Number} pid 项目id
+         * @param {Number} tid 台账id
+         * @param {Number} rid 修订id
+         */
+        async getNoticeContent(pid, tid, rid) {
+            const noticeSql = 'SELECT * FROM (SELECT ' +
+                '  t.`id` As `tid`, t.`name`, r.`corder`, pa.`name` As `su_name`, pa.role As `su_role`' +
+                '  FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
+                '  LEFT JOIN ?? As r On r.`id` = ? ' +
+                '  LEFT JOIN ?? As pa ON t.`user_id` = pa.`id`' +
+                '  WHERE  t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
+            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.ledgerRevise.tableName, rid, this.ctx.service.projectAccount.tableName, pid];
+            const content = await this.db.query(noticeSql, noticeSqlParam);
+            return content.length ? JSON.stringify(content[0]) : '';
         }
 
         /**

+ 53 - 20
app/service/stage_audit.js

@@ -13,6 +13,7 @@ const smsTypeConst = require('../const/sms_type');
 const SMS = require('../lib/sms');
 const SmsAliConst = require('../const/sms_alitemplate');
 const payConst = require('../const/deal_pay');
+const pushType = require('../const/audit').pushType;
 
 module.exports = app => {
     class StageAudit extends app.BaseService {
@@ -276,7 +277,7 @@ module.exports = app => {
             return true;
         }
 
-        async _checked(stageId, checkData, times) {
+        async _checked(pid, stageId, checkData, times) {
             const time = new Date();
             // 整理当前流程审核人状态更新
             const audit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
@@ -389,6 +390,9 @@ module.exports = app => {
                     const users = this._.pull(this._.map(auditList, 'aid'), stageInfo.user_id);
                     await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL,
                         smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, { qi: stageInfo.order, status: SmsAliConst.status.success });
+                    // 添加到消息推送表
+                    const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
+                    await transaction.insert('zh_notice', { pid, type: pushType.stage, uid: this.ctx.stage.user_id, status: auditConst.status.checked, is_read: 0, content: noticeContent });
                 }
                 await transaction.commit();
             } catch (err) {
@@ -397,7 +401,7 @@ module.exports = app => {
             }
         }
 
-        async _checkNo(stageId, checkData, times) {
+        async _checkNo(pid, stageId, checkData, times) {
             const time = new Date();
             // 整理当前流程审核人状态更新
             const audit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
@@ -480,7 +484,9 @@ module.exports = app => {
                 const users = this._.pull(this._.map(auditList, 'aid'), stageInfo.user_id);
                 await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL,
                     smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, { qi: stageInfo.order, status: SmsAliConst.status.back });
-
+                // 添加到消息推送表
+                const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
+                await transaction.insert('zh_notice', { pid, type: pushType.stage, uid: this.ctx.stage.user_id, status: auditConst.status.checkNo, is_read: 0, content: noticeContent });
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();
@@ -606,13 +612,13 @@ module.exports = app => {
             //     throw '审核数据错误';
             // }
             // const time = new Date();
-
+            const pid = this.ctx.session.sessionProject.id;
             switch (checkData.checkType) {
                 case auditConst.status.checked:
-                    await this._checked(stageId, checkData, times);
+                    await this._checked(pid, stageId, checkData, times);
                     break;
                 case auditConst.status.checkNo:
-                    await this._checkNo(stageId, checkData, times);
+                    await this._checkNo(pid, stageId, checkData, times);
                     break;
                 case auditConst.status.checkNoPre:
                     await this._checkNoPre(stageId, checkData, times);
@@ -834,20 +840,47 @@ module.exports = app => {
          * @return {Promise<*>}
          */
         async getNoticeStage(pid, uid, time) {
-            const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
-                        '    s.`order` As `s_order`, s.`status` As `s_status`, ' +
-                        '    sa.`aid`, sa.`times`, sa.`order`, sa.`end_time`, sa.`tid`, sa.`sid`, sa.`status`, ' +
-                        '    pa.`name` As `su_name`, pa.role As `su_role`, pa.company As `su_company`' +
-                        '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `aid` = ? GROUP BY `tid`)) As t' +
-                        '  LEFT JOIN ?? As s On t.`id` = s.`tid`' +
-                        '  LEFT JOIN ?? As sa ON s.`id` = sa.`sid`' +
-                        '  LEFT JOIN ?? As pa ON sa.`aid` = pa.`id`' +
-                        '  WHERE sa.`end_time` > ? and t.`project_id` = ?' +
-                        '  ORDER By sa.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`tid`' +
-                        '  ORDER By new_t.`end_time`';
-            const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.stage.tableName, this.tableName,
-                this.ctx.service.projectAccount.tableName, time, pid];
-            return await this.db.query(sql, sqlParam);
+            // const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
+            //             '    s.`order` As `s_order`, s.`status` As `s_status`, ' +
+            //             '    sa.`aid`, sa.`times`, sa.`order`, sa.`end_time`, sa.`tid`, sa.`sid`, sa.`status`, ' +
+            //             '    pa.`name` As `su_name`, pa.role As `su_role`, pa.company As `su_company`' +
+            //             '  FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `aid` = ? GROUP BY `tid`)) As t' +
+            //             '  LEFT JOIN ?? As s On t.`id` = s.`tid`' +
+            //             '  LEFT JOIN ?? As sa ON s.`id` = sa.`sid`' +
+            //             '  LEFT JOIN ?? As pa ON sa.`aid` = pa.`id`' +
+            //             '  WHERE sa.`end_time` > ? and t.`project_id` = ?' +
+            //             '  ORDER By sa.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`tid`' +
+            //             '  ORDER By new_t.`end_time`';
+            // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.stage.tableName, this.tableName,
+            //     this.ctx.service.projectAccount.tableName, time, pid];
+            // return await this.db.query(sql, sqlParam);
+            let notice =  await this.db.select('zh_notice', {
+                where: { pid, type: pushType.stage, uid, is_read: 0 },
+            });
+            notice = notice.map(v => {
+                const extra = JSON.parse(v.content)
+                delete v.content
+                return { ...v, ...extra }
+            })
+            return notice;
+        }
+
+        /**
+         * 用于添加推送所需的content内容
+         * @param {Number} pid 项目id
+         * @param {Number} tid 台账id
+         * @param {Number} sid 期id
+         */
+        async getNoticeContent(pid, tid, sid) {
+            const noticeSql = 'SELECT * FROM (SELECT ' +
+                '  t.`id` As `tid`, t.`name`, s.`order`, pa.`name` As `su_name`, pa.role As `su_role`' +
+                '  FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
+                '  LEFT JOIN ?? As s On s.`id` =  ?' +
+                '  LEFT JOIN ?? As pa ON t.`user_id` = pa.`id`' +
+                '  WHERE  t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
+            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.stage.tableName, sid,  this.ctx.service.projectAccount.tableName, pid];
+            const content = await this.db.query(noticeSql, noticeSqlParam);
+            return content.length ? JSON.stringify(content[0]) : '';
         }
 
         /**

+ 14 - 14
app/view/dashboard/index.ejs

@@ -165,11 +165,11 @@
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-info">台帐审批</span></div>
                                                     <div class="col-6">
-                                                        <a data-id="<%- nl.id %>"href="/tender/<%- nl.id %>"><%- nl.name %></a> 台帐<%- acLedger.statusString[nl.status]%>
+                                                        <a data-id="<%- nl.id %>"href="/tender/<%- nl.tid %>/ledger"><%- nl.name %></a> 台帐<%- acLedger.statusString[nl.status]%>
                                                     </div>
                                                 </div>
-                                                <p class="mt-1 mb-0"><%- nl.lu_name %><small class="ml-1 text-muted"><%- (nl.lu_role ? '- ' + nl.lu_role : '') %></small>
-                                                    <span class="pull-right text-muted"><%- nl.end_time.toLocaleString() %></span>
+                                                <p class="mt-1 mb-0"><%- nl.su_name %><small class="ml-1 text-muted"><%- (nl.su_role ? '- ' + nl.su_role : '') %></small>
+                                                    <span class="pull-right text-muted"><%- ctx.helper.formatFullDate(nl.create_time) %></span>
                                                 </p>
                                             </div>
                                         </li>
@@ -180,13 +180,13 @@
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-info">台账修订</span></div>
                                                     <div class="col-6">
-                                                        <a data-id="<%- nr.id %>" href="/tender/<%- nr.t_id %>"><%- nr.t_name %></a>
-                                                        <a data-id="<%- nr.id %>" href="/tender/<%- nr.t_id %>/revise/info">台账修订(第<%- nr.corder %>次)</a>
+                                                        <a data-id="<%- nr.id %>" href="/tender/<%- nr.tid %>"><%- nr.name %></a>
+                                                        <a data-id="<%- nr.id %>" href="/tender/<%- nr.tid %>/revise/info">台账修订(第<%- nr.corder %>次)</a>
                                                         <%- acRevise.statusString[nr.status]%>
                                                     </div>
                                                 </div>
-                                                <p class="mt-1 mb-0"><%- nr.ru_name %><small class="ml-1 text-muted"><%- (nr.ru_role ? '- ' + nr.ru_role : '') %></small>
-                                                    <span class="pull-right text-muted"><%- (nr.end_time ? nr.end_time.toLocaleString() : '') %></span>
+                                                <p class="mt-1 mb-0"><%- nr.su_name %><small class="ml-1 text-muted"><%- (nr.su_role ? '- ' + nr.su_role : '') %></small>
+                                                    <span class="pull-right text-muted"><%- ctx.helper.formatFullDate(nr.create_time) %></span>
                                                 </p>
                                             </div>
                                         </li>
@@ -198,12 +198,12 @@
                                                     <div class="col-auto"><span class="badge badge-success">计量审批</span></div>
                                                     <div class="col-6">
                                                         <a data-id="<%- ns.id %>" href="/tender/<%- ns.tid %>"><%- ns.name %></a>
-                                                        <a data-id="<%- ns.id %>" href="/tender/<%- ns.tid %>/measure/stage/<%- ns.s_order %>">第<%- ns.s_order %>期 </a>
+                                                        <a data-id="<%- ns.id %>" href="/tender/<%- ns.tid %>/measure/stage/<%- ns.order %>">第<%- ns.order %>期 </a>
                                                         <%- acStage.statusString[ns.status]%>
                                                     </div>
                                                 </div>
                                                 <p class="mt-1 mb-0"><%- ns.su_name %><small class="ml-1 text-muted"><%- (ns.su_role ? '- ' + ns.su_role : '') %></small>
-                                                    <span class="pull-right text-muted"><%- ns.end_time.toLocaleString() %></span>
+                                                    <span class="pull-right text-muted"><%- ctx.helper.formatFullDate(ns.create_time) %></span>
                                                 </p>
                                             </div>
                                         </li>
@@ -214,13 +214,13 @@
                                                 <div class="row">
                                                     <div class="col-auto"><span class="badge badge-danger">变更审批</span></div>
                                                     <div class="col-6">
-                                                        <a data-id="<%- nc.id %>" href="/tender/<%- nc.id %>"><%- nc.name %></a>
-                                                        <a data-id="<%- nc.id %>" href="/tender/<%- nc.id %>/change/<%- nc.cid %>/info"><%- nc.c_code %> </a>
-                                                        <%- acChange.statusString[nc.cu_status]%>
+                                                        <a data-id="<%- nc.id %>" href="/tender/<%- nc.tid %>"><%- nc.name %></a>
+                                                        <a data-id="<%- nc.id %>" href="/tender/<%- nc.tid %>/change/<%- nc.cid %>/info"><%- nc.c_code %> </a>
+                                                        <%- acChange.statusString[nc.status]%>
                                                     </div>
                                                 </div>
-                                                <p class="mt-1 mb-0"><%- nc.cu_name %><small class="ml-1 text-muted"><%- (nc.cu_jobs ? '- ' + nc.cu_jobs : '') %></small>
-                                                    <span class="pull-right text-muted"><%- nc.cu_time.toLocaleString() %></span>
+                                                <p class="mt-1 mb-0"><%- nc.su_name %><small class="ml-1 text-muted"><%- (nc.su_role ? '- ' + nc.su_role : '') %></small>
+                                                    <span class="pull-right text-muted"><%- ctx.helper.formatFullDate(nc.create_time) %></span>
                                                 </p>
                                             </div>
                                         </li>

+ 1 - 1
app/view/stage/index.ejs

@@ -572,7 +572,7 @@
         colWidth: true,
     }
     const posSpreadSetting = JSON.parse('<%- JSON.stringify(posSpread) %>');
-    ledgerSpreadSetting.localCache = {
+    posSpreadSetting.localCache = {
         key: 'stage-pos',
         colWidth: true,
     }

+ 1 - 1
app/view/tender/detail.ejs

@@ -29,7 +29,7 @@
                             <div class="card text-center">
                                 <div class="card-body">
                                     <h5 class="card-title"><%- ctx.helper.formatMoney(tender.total_price) %></h5>
-                                    <p class="card-text text-muted">0号台帐合同</p>
+                                    <p class="card-text text-muted">0号台帐</p>
                                 </div>
                             </div>
                         </div>