Explorar o código

fix: 待关注数据异常修复

lanjianrong %!s(int64=5) %!d(string=hai) anos
pai
achega
f3a58dd7f4
Modificáronse 5 ficheiros con 2025 adicións e 1205 borrados
  1. 780 495
      app/service/change.js
  2. 223 125
      app/service/ledger_audit.js
  3. 11 12
      app/service/notice_push.js
  4. 355 199
      app/service/revise_audit.js
  5. 656 374
      app/service/stage_audit.js

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 780 - 495
app/service/change.js


+ 223 - 125
app/service/ledger_audit.js

@@ -1,4 +1,4 @@
-'use strict';
+'use strict'
 
 /**
  * 台账审批流程表
@@ -8,11 +8,11 @@
  * @version
  */
 
-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;
+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 {
@@ -23,8 +23,8 @@ module.exports = app => {
          * @return {void}
          */
         constructor(ctx) {
-            super(ctx);
-            this.tableName = 'ledger_audit';
+            super(ctx)
+            this.tableName = 'ledger_audit'
         }
 
         /**
@@ -36,12 +36,13 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditor(tenderId, auditorId, times = 1) {
-            const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
+            const sql =
+                'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
                 'FROM ?? AS la, ?? AS pa ' +
                 'WHERE la.`tender_id` = ? and la.`audit_id` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditorId, times];
-            return await this.db.queryOne(sql, sqlParam);
+                '    and la.`audit_id` = pa.`id`'
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditorId, times]
+            return await this.db.queryOne(sql, sqlParam)
         }
 
         /**
@@ -53,12 +54,18 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getStatusName(tenderId, times) {
-            const sql = 'SELECT pa.`name` ' +
+            const sql =
+                'SELECT pa.`name` ' +
                 'FROM ?? AS la, ?? AS pa ' +
                 'WHERE la.`tender_id` = ?' +
-                '    and la.`audit_id` = pa.`id` and la.`status` != ? ORDER BY la.`times` DESC, la.`audit_order` DESC';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditConst.status.uncheck];
-            return await this.db.queryOne(sql, sqlParam);
+                '    and la.`audit_id` = pa.`id` and la.`status` != ? ORDER BY la.`times` DESC, la.`audit_order` DESC'
+            const sqlParam = [
+                this.tableName,
+                this.ctx.service.projectAccount.tableName,
+                tenderId,
+                auditConst.status.uncheck
+            ]
+            return await this.db.queryOne(sql, sqlParam)
         }
 
         /**
@@ -69,18 +76,28 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditors(tenderId, times = 1) {
-            const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
+            const sql =
+                'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
                 'FROM ?? AS la, ?? AS pa, (SELECT `audit_id`,(@i:=@i+1) as `sort` FROM ??, (select @i:=0) as it WHERE `tender_id` = ? AND `times` = ? GROUP BY `audit_id`) as g ' +
-                'WHERE la.`tender_id` = ? and la.`times` = ? and la.`audit_id` = pa.`id` and g.`audit_id` = la.`audit_id` order by la.`audit_order`';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, tenderId, times, tenderId, times];
-            const result = await this.db.query(sql, sqlParam);
-            const sql2 = 'SELECT COUNT(a.`audit_id`) as num FROM (SELECT `audit_id` FROM ?? WHERE `tender_id` = ? AND `times` = ? GROUP BY `audit_id`) as a';
-            const sqlParam2 = [this.tableName, tenderId, times];
-            const count = await this.db.queryOne(sql2, sqlParam2);
+                'WHERE la.`tender_id` = ? and la.`times` = ? and la.`audit_id` = pa.`id` and g.`audit_id` = la.`audit_id` order by la.`audit_order`'
+            const sqlParam = [
+                this.tableName,
+                this.ctx.service.projectAccount.tableName,
+                this.tableName,
+                tenderId,
+                times,
+                tenderId,
+                times
+            ]
+            const result = await this.db.query(sql, sqlParam)
+            const sql2 =
+                'SELECT COUNT(a.`audit_id`) as num FROM (SELECT `audit_id` FROM ?? WHERE `tender_id` = ? AND `times` = ? GROUP BY `audit_id`) as a'
+            const sqlParam2 = [this.tableName, tenderId, times]
+            const count = await this.db.queryOne(sql2, sqlParam2)
             for (const i in result) {
-                result[i].max_sort = count.num;
+                result[i].max_sort = count.num
             }
-            return result;
+            return result
         }
 
         /**
@@ -91,12 +108,19 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getCurAuditor(tenderId, times = 1) {
-            const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
+            const sql =
+                'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
                 'FROM ?? AS la, ?? AS pa ' +
                 'WHERE la.`tender_id` = ? and la.`status` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditConst.status.checking, times];
-            return await this.db.queryOne(sql, sqlParam);
+                '    and la.`audit_id` = pa.`id`'
+            const sqlParam = [
+                this.tableName,
+                this.ctx.service.projectAccount.tableName,
+                tenderId,
+                auditConst.status.checking,
+                times
+            ]
+            return await this.db.queryOne(sql, sqlParam)
         }
 
         /**
@@ -107,10 +131,10 @@ module.exports = app => {
          * @returns {Promise<number>}
          */
         async getNewOrder(tenderId, times = 1) {
-            const sql = 'SELECT Max(??) As max_order FROM ?? Where `tender_id` = ? and `times` = ?';
-            const sqlParam = ['audit_order', this.tableName, tenderId, times];
-            const result = await this.db.queryOne(sql, sqlParam);
-            return result && result.max_order ? result.max_order + 1 : 1;
+            const sql = 'SELECT Max(??) As max_order FROM ?? Where `tender_id` = ? and `times` = ?'
+            const sqlParam = ['audit_order', this.tableName, tenderId, times]
+            const result = await this.db.queryOne(sql, sqlParam)
+            return result && result.max_order ? result.max_order + 1 : 1
         }
 
         /**
@@ -122,16 +146,16 @@ module.exports = app => {
          * @returns {Promise<number>}
          */
         async addAuditor(tenderId, auditorId, times = 1) {
-            const newOrder = await this.getNewOrder(tenderId, times);
+            const newOrder = await this.getNewOrder(tenderId, times)
             const data = {
                 tender_id: tenderId,
                 audit_id: auditorId,
-                times: times,
+                times,
                 audit_order: newOrder,
-                status: auditConst.status.uncheck,
-            };
-            const result = await this.db.insert(this.tableName, data);
-            return result.effectRows = 1;
+                status: auditConst.status.uncheck
+            }
+            const result = await this.db.insert(this.tableName, data)
+            return (result.effectRows = 1)
         }
 
         /**
@@ -144,27 +168,27 @@ module.exports = app => {
          * @private
          */
         async _syncOrderByDelete(transaction, tenderId, order, times) {
-            this.initSqlBuilder();
+            this.initSqlBuilder()
             this.sqlBuilder.setAndWhere('tender_id', {
                 value: tenderId,
                 operate: '='
-            });
+            })
             this.sqlBuilder.setAndWhere('audit_order', {
                 value: order,
-                operate: '>=',
-            });
+                operate: '>='
+            })
             this.sqlBuilder.setAndWhere('times', {
                 value: times,
-                operate: '=',
-            });
+                operate: '='
+            })
             this.sqlBuilder.setUpdateData('audit_order', {
                 value: 1,
-                selfOperate: '-',
-            });
-            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
-            const data = await transaction.query(sql, sqlParam);
+                selfOperate: '-'
+            })
+            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update')
+            const data = await transaction.query(sql, sqlParam)
 
-            return data;
+            return data
         }
 
         /**
@@ -176,21 +200,21 @@ module.exports = app => {
          * @returns {Promise<boolean>}
          */
         async deleteAuditor(tenderId, auditorId, times = 1) {
-            const transaction = await this.db.beginTransaction();
+            const transaction = await this.db.beginTransaction()
             try {
-                const condition = {tender_id: tenderId, audit_id: auditorId, times: times};
-                const auditor = await this.getDataByCondition(condition);
+                const condition = { tender_id: tenderId, audit_id: auditorId, times }
+                const auditor = await this.getDataByCondition(condition)
                 if (!auditor) {
-                    throw '该审核人不存在';
+                    throw '该审核人不存在'
                 }
-                await this._syncOrderByDelete(transaction, tenderId, auditor.audit_order, times);
-                await transaction.delete(this.tableName, condition);
-                await transaction.commit();
+                await this._syncOrderByDelete(transaction, tenderId, auditor.audit_order, times)
+                await transaction.delete(this.tableName, condition)
+                await transaction.commit()
             } catch (err) {
-                await transaction.rollback();
-                throw err;
+                await transaction.rollback()
+                throw err
             }
-            return true;
+            return true
         }
 
         /**
@@ -201,78 +225,123 @@ module.exports = app => {
          * @returns {Promise<boolean>}
          */
         async start(tenderId, times = 1) {
-            const audit = await this.getDataByCondition({tender_id: tenderId, times: times, audit_order: 1});
+            const audit = await this.getDataByCondition({ tender_id: tenderId, times, audit_order: 1 })
             if (!audit) {
-                throw '审核人信息错误';
+                throw '审核人信息错误'
             }
-            const sum = await this.ctx.service.ledger.addUp({tender_id: tenderId/*, is_leaf: true*/});
+            const sum = await this.ctx.service.ledger.addUp({ tender_id: tenderId /* , is_leaf: true*/ })
 
-            const transaction = await this.db.beginTransaction();
+            const transaction = await this.db.beginTransaction()
             try {
-                await transaction.update(this.tableName, {id: audit.id, status: auditConst.status.checking, begin_time: new Date()});
+                await transaction.update(this.tableName, {
+                    id: audit.id,
+                    status: auditConst.status.checking,
+                    begin_time: new Date()
+                })
                 await transaction.update(this.ctx.service.tender.tableName, {
-                    id: tenderId, ledger_status: auditConst.status.checking,
-                    total_price: sum.total_price, deal_tp: sum.deal_tp,
-                });
+                    id: tenderId,
+                    ledger_status: auditConst.status.checking,
+                    total_price: sum.total_price,
+                    deal_tp: sum.deal_tp
+                })
 
                 // 添加短信通知-需要审批提醒功能
                 // await this.ctx.helper.sendUserSms(audit.audit_id, smsTypeConst.const.TZ,
                 //     smsTypeConst.judge.approval.toString(), '台帐需要您审批。');
-                await this.ctx.helper.sendAliSms(audit.audit_id, smsTypeConst.const.TZ,
-                    smsTypeConst.judge.approval.toString(), SmsAliConst.template.ledger_check);
+                await this.ctx.helper.sendAliSms(
+                    audit.audit_id,
+                    smsTypeConst.const.TZ,
+                    smsTypeConst.judge.approval.toString(),
+                    SmsAliConst.template.ledger_check
+                )
 
-                await transaction.commit();
+                await transaction.commit()
             } catch (err) {
-                await transaction.rollback();
-                throw err;
+                await transaction.rollback()
+                throw err
             }
-            return true;
+            return true
         }
 
         /**
          * 审批
          * @param {Number} tenderId - 标段id
          * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
+         * @param {String} opinion 审批意见
          * @param {Number} times - 第几次审批
          * @returns {Promise<void>}
          */
         async check(tenderId, checkType, opinion, times = 1) {
             if (checkType !== auditConst.status.checked && checkType !== auditConst.status.checkNo) {
-                throw '提交数据错误';
+                throw '提交数据错误'
             }
-            const pid = this.ctx.session.sessionProject.id;
-            const transaction = await this.db.beginTransaction();
+            const pid = this.ctx.session.sessionProject.id
+            const transaction = await this.db.beginTransaction()
             try {
                 // 整理当前流程审核人状态更新
-                const time = new Date();
-                const audit = await this.getDataByCondition({ tender_id: tenderId, times, status: auditConst.status.checking });
+                const time = new Date()
+                const audit = await this.getDataByCondition({
+                    tender_id: tenderId,
+                    times,
+                    status: auditConst.status.checking
+                })
                 if (!audit) {
-                    throw '审核数据错误';
+                    throw '审核数据错误'
                 }
 
                 // 获取审核人列表
-                const auditList = await this.getAuditors(tenderId, times);
+                const auditList = await this.getAuditors(tenderId, times)
+                console.log('auditList', auditList)
                 // 添加推送
                 const noticeContent = await this.getNoticeContent(audit.tender_id, pid, audit.audit_id)
-                const records = [{ pid, type: pushType.ledger, uid: this.ctx.tender.data.user_id, status: auditConst.status.checked, content: noticeContent }]
-                auditList.forEach( audit => {
-                    records.push({ pid, type: pushType.ledger, uid: audit.audit_id, status: auditConst.status.checked, content: noticeContent })
+                const records = [
+                    {
+                        pid,
+                        type: pushType.ledger,
+                        uid: this.ctx.tender.data.user_id,
+                        status: auditConst.status.checked,
+                        content: noticeContent
+                    }
+                ]
+                auditList.forEach(audit => {
+                    records.push({
+                        pid,
+                        type: pushType.ledger,
+                        uid: audit.audit_id,
+                        status: auditConst.status.checked,
+                        content: noticeContent
+                    })
                 })
-                await transaction.insert('zh_notice', records);
+                await transaction.insert('zh_notice', records)
                 // 更新当前审核流程
-                await transaction.update(this.tableName, { id: audit.id, status: checkType, opinion, end_time: time });
+                await transaction.update(this.tableName, { id: audit.id, status: checkType, opinion, end_time: time })
                 if (checkType === auditConst.status.checked) {
-                    const nextAudit = await this.getDataByCondition({ tender_id: tenderId, times, audit_order: audit.audit_order + 1 });
+                    const nextAudit = await this.getDataByCondition({
+                        tender_id: tenderId,
+                        times,
+                        audit_order: audit.audit_order + 1
+                    })
                     // 无下一审核人表示,审核结束
                     if (nextAudit) {
-                        await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
+                        await transaction.update(this.tableName, {
+                            id: nextAudit.id,
+                            status: auditConst.status.checking,
+                            begin_time: time
+                        })
                         // await this.ctx.helper.sendUserSms(nextAudit.audit_id, smsTypeConst.const.TZ,
                         //     smsTypeConst.judge.approval.toString(), '台帐需要您审批。');
-                        await this.ctx.helper.sendAliSms(nextAudit.audit_id, smsTypeConst.const.TZ,
-                            smsTypeConst.judge.approval.toString(), SmsAliConst.template.ledger_check);
+                        await this.ctx.helper.sendAliSms(
+                            nextAudit.audit_id,
+                            smsTypeConst.const.TZ,
+                            smsTypeConst.judge.approval.toString(),
+                            SmsAliConst.template.ledger_check
+                        )
                     } else {
                         // 同步标段信息
-                        await transaction.update(this.ctx.service.tender.tableName, { id: tenderId, ledger_status: checkType });
+                        await transaction.update(this.ctx.service.tender.tableName, {
+                            id: tenderId,
+                            ledger_status: checkType
+                        })
 
                         // 添加短信通知-审批通过提醒功能
                         // const mobile_array = [];
@@ -302,25 +371,34 @@ module.exports = app => {
                         //     const content = '【纵横计量支付】' + ptmsg + '台账审批通过,请登录系统处理。';
                         //     sms.send(mobile_array, content);
                         // }
-                        const users = this._.pull(this._.map(auditList, 'audit_id'), audit.id);
+                        const users = this._.pull(this._.map(auditList, 'audit_id'), audit.id)
                         // 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.success });
+                        await this.ctx.helper.sendAliSms(
+                            users,
+                            smsTypeConst.const.TZ,
+                            smsTypeConst.judge.result.toString(),
+                            SmsAliConst.template.ledger_result,
+                            { status: SmsAliConst.status.success }
+                        )
                     }
                 } else {
                     // 同步标段信息
-                    await transaction.update(this.ctx.service.tender.tableName, { id: tenderId, ledger_times: times + 1, ledger_status: checkType});
+                    await transaction.update(this.ctx.service.tender.tableName, {
+                        id: tenderId,
+                        ledger_times: times + 1,
+                        ledger_status: checkType
+                    })
                     // 拷贝新一次审核流程列表
                     const auditors = await this.getAllDataByCondition({
                         where: { tender_id: tenderId, times },
-                        columns: ['tender_id', 'audit_order', 'audit_id'],
-                    });
+                        columns: ['tender_id', 'audit_order', 'audit_id']
+                    })
                     for (const a of auditors) {
-                        a.times = times + 1;
-                        a.status = auditConst.status.uncheck;
+                        a.times = times + 1
+                        a.status = auditConst.status.uncheck
                     }
-                    await transaction.insert(this.tableName, auditors);
+                    await transaction.insert(this.tableName, auditors)
 
                     // 添加短信通知-审批退回提醒功能
                     // const mobile_array = [];
@@ -349,18 +427,22 @@ module.exports = app => {
                     //     const content = '【纵横计量支付】' + ptmsg + '台账审批退回,请登录系统处理。';
                     //     sms.send(mobile_array, content);
                     // }
-                    const users = this._.pull(this._.map(auditList, 'audit_id'), audit.id);
+                    const users = this._.pull(this._.map(auditList, 'audit_id'), audit.id)
                     // 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 });
-
+                    await this.ctx.helper.sendAliSms(
+                        users,
+                        smsTypeConst.const.TZ,
+                        smsTypeConst.judge.result.toString(),
+                        SmsAliConst.template.ledger_result,
+                        { status: SmsAliConst.status.back }
+                    )
                 }
 
-                await transaction.commit();
+                await transaction.commit()
             } catch (err) {
-                await transaction.rollback();
-                throw err;
+                await transaction.rollback()
+                throw err
             }
         }
 
@@ -371,18 +453,27 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditTender(auditorId) {
-            const sql = 'SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`begin_time`, la.`end_time`, t.`id`, t.`name`, t.`project_id`, t.`type`, t.`user_id`, t.`ledger_status` ' +
+            const sql =
+                'SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`begin_time`, la.`end_time`, t.`id`, t.`name`, t.`project_id`, t.`type`, t.`user_id`, t.`ledger_status` ' +
                 'FROM ?? AS la, ?? AS t ' +
                 'WHERE ((la.`audit_id` = ? and la.`status` = ?) OR (t.`user_id` = ? and t.`ledger_status` = ? and la.`status` = ? and la.`times` = (t.`ledger_times`-1)))' +
-                '    and la.`tender_id` = t.`id`';
-            const sqlParam = [this.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
-            return await this.db.query(sql, sqlParam);
+                '    and la.`tender_id` = t.`id`'
+            const sqlParam = [
+                this.tableName,
+                this.ctx.service.tender.tableName,
+                auditorId,
+                auditConst.status.checking,
+                auditorId,
+                auditConst.status.checkNo,
+                auditConst.status.checkNo
+            ]
+            return await this.db.query(sql, sqlParam)
         }
 
         /**
          * 获取 某时间后 审批进度 更新的台账
-         * @param {Integer} projectId - 项目id
-         * @param {Integer} auditorId - 查询人id
+         * @param {Integer} pid - 项目id
+         * @param {Integer} uid - 查询人id
          * @param {Date} noticeTime - 查询事件
          * @returns {Promise<*>}
          */
@@ -398,18 +489,18 @@ module.exports = app => {
             //     noticeTime, projectId];
             // return await this.db.query(sql, sqlParam);
 
-
-            let notice =  await this.db.select('zh_notice', {
+            let notice = await this.db.select('zh_notice', {
                 where: { pid, type: pushType.ledger, uid },
                 orders: [['create_time', 'desc']],
-                limit: 10, offset: 0
-            });
+                limit: 10,
+                offset: 0
+            })
             notice = notice.map(v => {
                 const extra = JSON.parse(v.content)
                 delete v.content
                 return { ...v, ...extra }
             })
-            return notice;
+            return notice
         }
 
         /**
@@ -419,16 +510,23 @@ module.exports = app => {
          * @param {Number} uid 审核人id
          */
         async getNoticeContent(id, pid, uid) {
-            const noticeSql = 'SELECT * FROM (SELECT ' +
+            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 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, uid, pid];
-            const content = await this.db.query(noticeSql, noticeSqlParam);
-            return content.length ? JSON.stringify(content[0]) : '';
+                '  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,
+                uid,
+                pid
+            ]
+            const content = await this.db.query(noticeSql, noticeSqlParam)
+            return content.length ? JSON.stringify(content[0]) : ''
         }
     }
 
-    return LedgerAudit;
-};
+    return LedgerAudit
+}

+ 11 - 12
app/service/notice_push.js

@@ -1,4 +1,4 @@
-'use strict';
+'use strict'
 
 /**
  * 推送表模型
@@ -9,9 +9,7 @@
  */
 
 module.exports = app => {
-
     class NoticePush extends app.BaseService {
-
         /**
          * 构造函数
          *
@@ -19,8 +17,8 @@ module.exports = app => {
          * @return {void}
          */
         constructor(ctx) {
-            super(ctx);
-            this.tableName = 'notice';
+            super(ctx)
+            this.tableName = 'notice'
         }
 
         /**
@@ -28,7 +26,7 @@ module.exports = app => {
          * @param {Number} id 推送记录id
          */
         async set(id) {
-            await this.update({ is_read: 1 }, { id });
+            await this.update({ is_read: 1 }, { id })
         }
 
         /**
@@ -37,18 +35,19 @@ module.exports = app => {
          * @param {Integer} uid - 查询人id
          */
         async getNotice(pid, uid) {
-            let notice =  await this.db.select(this.tableName, {
+            let notice = await this.db.select(this.tableName, {
                 where: { pid, uid },
                 orders: [['create_time', 'desc']],
-                limit: 10, offset: 0
-            });
+                limit: 10,
+                offset: 0
+            })
             notice = notice.map(v => {
                 const extra = JSON.parse(v.content)
                 delete v.content
                 return { ...v, ...extra }
             })
-            return notice;
+            return notice
         }
     }
-    return NoticePush;
-};
+    return NoticePush
+}

+ 355 - 199
app/service/revise_audit.js

@@ -1,4 +1,4 @@
-'use strict';
+'use strict'
 
 /**
  *
@@ -8,10 +8,10 @@
  * @version
  */
 
-const auditConst = require('../const/audit').revise;
-const smsTypeConst = require('../const/sms_type');
-const SmsAliConst = require('../const/sms_alitemplate');
-const pushType = require('../const/audit').pushType;
+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 {
@@ -22,8 +22,8 @@ module.exports = app => {
          * @return {void}
          */
         constructor(ctx) {
-            super(ctx);
-            this.tableName = 'revise_audit';
+            super(ctx)
+            this.tableName = 'revise_audit'
         }
 
         /**
@@ -35,12 +35,13 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditor(reviseId, auditorId, times = 1) {
-            const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
+            const sql =
+                'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
                 'FROM ?? AS la, ?? AS pa ' +
                 'WHERE la.`rid` = ? and la.`audit_id` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditorId, times];
-            return await this.db.queryOne(sql, sqlParam);
+                '    and la.`audit_id` = pa.`id`'
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditorId, times]
+            return await this.db.queryOne(sql, sqlParam)
         }
 
         /**
@@ -51,13 +52,18 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditors(reviseId, times = 1) {
-            const sql = 'SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`,' +
+            const sql =
+                'SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`,' +
                 '    pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`' +
-                '  FROM ' + this.tableName + ' AS la ' +
-                '  INNER JOIN ' + this.ctx.service.projectAccount.tableName + ' AS pa ON la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id`' +
-                '  ORDER BY la.`audit_order`';
-            const sqlParam = [reviseId, times];
-            return await this.db.query(sql, sqlParam);
+                '  FROM ' +
+                this.tableName +
+                ' AS la ' +
+                '  INNER JOIN ' +
+                this.ctx.service.projectAccount.tableName +
+                ' AS pa ON la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id`' +
+                '  ORDER BY la.`audit_order`'
+            const sqlParam = [reviseId, times]
+            return await this.db.query(sql, sqlParam)
         }
 
         /**
@@ -68,18 +74,28 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditors2ReviseList(rid, times = 1) {
-            const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
+            const sql =
+                'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
                 'FROM ?? AS la, ?? AS pa, (SELECT `audit_id`,(@i:=@i+1) as `sort` FROM ??, (select @i:=0) as it WHERE `rid` = ? AND `times` = ? GROUP BY `audit_id`) as g ' +
-                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` and g.`audit_id` = la.`audit_id` order by la.`audit_order`';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, rid, times, rid, times];
-            const result = await this.db.query(sql, sqlParam);
-            const sql2 = 'SELECT COUNT(a.`audit_id`) as num FROM (SELECT `audit_id` FROM ?? WHERE `rid` = ? AND `times` = ? GROUP BY `audit_id`) as a';
-            const sqlParam2 = [this.tableName, rid, times];
-            const count = await this.db.queryOne(sql2, sqlParam2);
+                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` and g.`audit_id` = la.`audit_id` order by la.`audit_order`'
+            const sqlParam = [
+                this.tableName,
+                this.ctx.service.projectAccount.tableName,
+                this.tableName,
+                rid,
+                times,
+                rid,
+                times
+            ]
+            const result = await this.db.query(sql, sqlParam)
+            const sql2 =
+                'SELECT COUNT(a.`audit_id`) as num FROM (SELECT `audit_id` FROM ?? WHERE `rid` = ? AND `times` = ? GROUP BY `audit_id`) as a'
+            const sqlParam2 = [this.tableName, rid, times]
+            const count = await this.db.queryOne(sql2, sqlParam2)
             for (const i in result) {
-                result[i].max_sort = count.num;
+                result[i].max_sort = count.num
             }
-            return result;
+            return result
         }
 
         /**
@@ -90,12 +106,19 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getCurAuditor(reviseId, times = 1) {
-            const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
+            const sql =
+                'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
                 'FROM ?? AS la, ?? AS pa ' +
                 'WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditConst.status.checking, times];
-            return await this.db.queryOne(sql, sqlParam);
+                '    and la.`audit_id` = pa.`id`'
+            const sqlParam = [
+                this.tableName,
+                this.ctx.service.projectAccount.tableName,
+                reviseId,
+                auditConst.status.checking,
+                times
+            ]
+            return await this.db.queryOne(sql, sqlParam)
         }
 
         /**
@@ -106,10 +129,10 @@ module.exports = app => {
          * @returns {Promise<number>}
          */
         async getNewOrder(reviseId, times = 1) {
-            const sql = 'SELECT Max(??) As max_order FROM ?? Where `rid` = ? and `times` = ?';
-            const sqlParam = ['audit_order', this.tableName, reviseId, times];
-            const result = await this.db.queryOne(sql, sqlParam);
-            return result && result.max_order ? result.max_order + 1 : 1;
+            const sql = 'SELECT Max(??) As max_order FROM ?? Where `rid` = ? and `times` = ?'
+            const sqlParam = ['audit_order', this.tableName, reviseId, times]
+            const result = await this.db.queryOne(sql, sqlParam)
+            return result && result.max_order ? result.max_order + 1 : 1
         }
 
         /**
@@ -121,19 +144,19 @@ module.exports = app => {
          * @returns {Promise<number>}
          */
         async addAuditor(revise, auditorId) {
-            const times = revise.times ? revise.times : 1;
-            const newOrder = await this.getNewOrder(revise.id, times);
+            const times = revise.times ? revise.times : 1
+            const newOrder = await this.getNewOrder(revise.id, times)
             const data = {
                 tender_id: revise.tid,
                 audit_id: auditorId,
-                times: times,
+                times,
                 audit_order: newOrder,
                 status: auditConst.status.uncheck,
                 rid: revise.id,
-                in_time: new Date(),
-            };
-            const result = await this.db.insert(this.tableName, data);
-            return result.effectRows = 1;
+                in_time: new Date()
+            }
+            const result = await this.db.insert(this.tableName, data)
+            return (result.effectRows = 1)
         }
 
         /**
@@ -146,27 +169,27 @@ module.exports = app => {
          * @private
          */
         async _syncOrderByDelete(transaction, reviseId, order, times) {
-            this.initSqlBuilder();
+            this.initSqlBuilder()
             this.sqlBuilder.setAndWhere('rid', {
                 value: this.db.escape(reviseId),
                 operate: '='
-            });
+            })
             this.sqlBuilder.setAndWhere('audit_order', {
                 value: order,
-                operate: '>=',
-            });
+                operate: '>='
+            })
             this.sqlBuilder.setAndWhere('times', {
                 value: times,
-                operate: '=',
-            });
+                operate: '='
+            })
             this.sqlBuilder.setUpdateData('audit_order', {
                 value: 1,
-                selfOperate: '-',
-            });
-            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
-            const data = await transaction.query(sql, sqlParam);
+                selfOperate: '-'
+            })
+            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update')
+            const data = await transaction.query(sql, sqlParam)
 
-            return data;
+            return data
         }
 
         /**
@@ -178,22 +201,22 @@ module.exports = app => {
          * @returns {Promise<boolean>}
          */
         async deleteAuditor(revise, auditorId) {
-            const times = revise.times ? revise.times : 1;
-            const transaction = await this.db.beginTransaction();
+            const times = revise.times ? revise.times : 1
+            const transaction = await this.db.beginTransaction()
             try {
-                const condition = {rid: revise.id, audit_id: auditorId, times: times};
-                const auditor = await this.getDataByCondition(condition);
+                const condition = { rid: revise.id, audit_id: auditorId, times }
+                const auditor = await this.getDataByCondition(condition)
                 if (!auditor) {
-                    throw '该审核人不存在';
+                    throw '该审核人不存在'
                 }
-                await this._syncOrderByDelete(transaction, revise.id, auditor.audit_order, times);
-                await transaction.delete(this.tableName, condition);
-                await transaction.commit();
-            } catch(err) {
-                await transaction.rollback();
-                throw err;
+                await this._syncOrderByDelete(transaction, revise.id, auditor.audit_order, times)
+                await transaction.delete(this.tableName, condition)
+                await transaction.commit()
+            } catch (err) {
+                await transaction.rollback()
+                throw err
             }
-            return true;
+            return true
         }
 
         /**
@@ -204,54 +227,69 @@ module.exports = app => {
          * @returns {Promise<boolean>}
          */
         async start(revise, times = 1) {
-            const audit = await this.getDataByCondition({rid: revise.id, times: times, audit_order: 1});
-            if (!audit) throw '审核人信息错误';
-            const time = new Date();
+            const audit = await this.getDataByCondition({ rid: revise.id, times, audit_order: 1 })
+            if (!audit) throw '审核人信息错误'
+            const time = new Date()
 
             // 拷贝备份台账数据
-            const [billsHis, posHis] = await this.ctx.service.ledgerRevise.backupReviseHistoryFile(revise);
+            const [billsHis, posHis] = await this.ctx.service.ledgerRevise.backupReviseHistoryFile(revise)
 
-            const transaction = await this.db.beginTransaction();
+            const transaction = await this.db.beginTransaction()
             try {
                 await transaction.update(this.tableName, {
-                    id: audit.id, status: auditConst.status.checking, begin_time: time,
-                    bills_file: revise.bills_file, pos_file: revise.pos_file,
-                });
+                    id: audit.id,
+                    status: auditConst.status.checking,
+                    begin_time: time,
+                    bills_file: revise.bills_file,
+                    pos_file: revise.pos_file
+                })
                 const reviseData = {
-                    id: revise.id, status: auditConst.status.checking,
-                    bills_file: billsHis, pos_file: posHis,
-                };
+                    id: revise.id,
+                    status: auditConst.status.checking,
+                    bills_file: billsHis,
+                    pos_file: posHis
+                }
                 if (revise.times === 1) {
-                    reviseData.begin_time = time;
+                    reviseData.begin_time = time
                 }
-                await transaction.update(this.ctx.service.ledgerRevise.tableName, reviseData);
+                await transaction.update(this.ctx.service.ledgerRevise.tableName, reviseData)
 
                 // 添加短信通知-需要审批提醒功能
                 // 下一人
                 // await this.ctx.helper.sendUserSms(audit.audit_id, smsTypeConst.const.XD,
                 //     smsTypeConst.judge.approval.toString(), '台帐修订需要您审批,请登录系统处理。');
-                await this.ctx.helper.sendAliSms(audit.audit_id, smsTypeConst.const.XD,
-                    smsTypeConst.judge.approval.toString(), SmsAliConst.template.revise_check);
+                await this.ctx.helper.sendAliSms(
+                    audit.audit_id,
+                    smsTypeConst.const.XD,
+                    smsTypeConst.judge.approval.toString(),
+                    SmsAliConst.template.revise_check
+                )
                 // 其他参与人
-                const auditList = await this.getAuditors(revise.tid, times);
-                const users = this._.pull(this._.map(auditList, 'user_id'), audit.id);
+                const auditList = await this.getAuditors(revise.tid, times)
+                const users = this._.pull(this._.map(auditList, 'user_id'), audit.id)
                 // await this.ctx.helper.sendUserSms(users, smsTypeConst.const.XD,
                 //     smsTypeConst.judge.result.toString(), '台账修订已上报。');
-                await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD,
-                    smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_report);
+                await this.ctx.helper.sendAliSms(
+                    users,
+                    smsTypeConst.const.XD,
+                    smsTypeConst.judge.result.toString(),
+                    SmsAliConst.template.revise_report
+                )
 
-                await transaction.commit();
+                await transaction.commit()
             } catch (err) {
-                await transaction.rollback();
-                throw err;
+                await transaction.rollback()
+                throw err
             }
-            return true;
+            return true
         }
 
         async _replaceLedgerByRevise(transaction, revise) {
-            const sqlParam = [revise.tid];
-            await transaction.delete(this.ctx.service.ledger.tableName, {tender_id: revise.tid});
-            const bSql = 'Insert Into ' + this.ctx.service.ledger.tableName +
+            const sqlParam = [revise.tid]
+            await transaction.delete(this.ctx.service.ledger.tableName, { tender_id: revise.tid })
+            const bSql =
+                'Insert Into ' +
+                this.ctx.service.ledger.tableName +
                 '  (id, code, b_code, name, unit, source, remark, ledger_id, ledger_pid, level, `order`, full_path, is_leaf,' +
                 '     quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '     sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp,' +
@@ -260,20 +298,24 @@ module.exports = app => {
                 '      quantity, total_price, unit_price, drawing_code, memo, dgn_qty1, dgn_qty2, deal_qty, deal_tp,' +
                 '      sgfh_qty, sgfh_tp, sjcl_qty, sjcl_tp, qtcl_qty, qtcl_tp, node_type, crid, tender_id, is_tp, ' +
                 '      sgfh_expr, sjcl_expr, qtcl_expr' +
-                '  From ' + this.ctx.service.reviseBills.tableName +
-                '  Where `tender_id` = ?';
-            await transaction.query(bSql, sqlParam);
-            await transaction.delete(this.ctx.service.pos.tableName, {tid: revise.tid});
-            const pSql = 'Insert Into ' + this.ctx.service.pos.tableName +
+                '  From ' +
+                this.ctx.service.reviseBills.tableName +
+                '  Where `tender_id` = ?'
+            await transaction.query(bSql, sqlParam)
+            await transaction.delete(this.ctx.service.pos.tableName, { tid: revise.tid })
+            const pSql =
+                'Insert Into ' +
+                this.ctx.service.pos.tableName +
                 '  (id, tid, lid, name, drawing_code, quantity, add_stage, add_times, add_user,' +
                 '     sgfh_qty, sjcl_qty, qtcl_qty, crid, porder, position, ' +
                 '     sgfh_expr, sjcl_expr, qtcl_expr)' +
                 '  Select id, tid, lid, name, drawing_code, quantity, add_stage, add_times, add_user,' +
                 '     sgfh_qty, sjcl_qty, qtcl_qty, crid, porder, position,' +
                 '     sgfh_expr, sjcl_expr, qtcl_expr' +
-                '  From ' + this.ctx.service.revisePos.tableName +
-                '  Where `tid` = ?';
-            await transaction.query(pSql, sqlParam);
+                '  From ' +
+                this.ctx.service.revisePos.tableName +
+                '  Where `tid` = ?'
+            await transaction.query(pSql, sqlParam)
         }
 
         /**
@@ -285,106 +327,181 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async check(revise, checkType, opinion, times = 1) {
-            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();
+            if (checkType !== auditConst.status.checked && checkType !== auditConst.status.checkNo) throw '提交数据错误'
+            const audit = await this.getDataByCondition({
+                rid: revise.id,
+                times,
+                status: auditConst.status.checking
+            })
+            if (!audit) throw '审核数据错误'
+            const pid = this.ctx.session.sessionProject.id
+            const transaction = await this.db.beginTransaction()
             try {
+                const auditList = await this.getAuditors(revise.tid, times)
+                // 审核通过添加到推送表
+                const noticeContent = await this.getNoticeContent(pid, audit.tender_id, audit.rid)
+                const records = [
+                    {
+                        pid,
+                        type: pushType.revise,
+                        uid: revise.uid,
+                        status: auditConst.status.checked,
+                        content: noticeContent
+                    }
+                ]
+                auditList.forEach(audit => {
+                    records.push({
+                        pid,
+                        type: pushType.revise,
+                        uid: audit.audit_id,
+                        status: auditConst.status.checked,
+                        content: noticeContent
+                    })
+                })
+                await transaction.insert('zh_notice', records)
+
                 // 整理当前流程审核人状态更新
-                const time = new Date();
+                const time = new Date()
                 // 更新当前审核流程
                 await transaction.update(this.tableName, {
-                    id: audit.id, status: checkType, opinion, end_time: time,
-                });
+                    id: audit.id,
+                    status: checkType,
+                    opinion,
+                    end_time: time
+                })
                 if (checkType === auditConst.status.checked) {
-                    const nextAudit = await this.getDataByCondition({ rid: revise.id, times, audit_order: audit.audit_order + 1 });
+                    const nextAudit = await this.getDataByCondition({
+                        rid: revise.id,
+                        times,
+                        audit_order: audit.audit_order + 1
+                    })
                     // 无下一审核人表示,审核结束
                     if (nextAudit) {
-                        await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
+                        await transaction.update(this.tableName, {
+                            id: nextAudit.id,
+                            status: auditConst.status.checking,
+                            begin_time: time
+                        })
 
                         // 短信通知-需要审批提醒功能
                         // 下一人
                         // await this.ctx.helper.sendUserSms(nextAudit.user_id, smsTypeConst.const.XD,
                         //     smsTypeConst.judge.approval.toString(), '台帐修订需要您审批,请登录系统处理。');
-                        await this.ctx.helper.sendAliSms(nextAudit.user_id, smsTypeConst.const.XD,
-                            smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result, { status: SmsAliConst.status.success });
+                        await this.ctx.helper.sendAliSms(
+                            nextAudit.user_id,
+                            smsTypeConst.const.XD,
+                            smsTypeConst.judge.result.toString(),
+                            SmsAliConst.template.revise_result,
+                            { status: SmsAliConst.status.success }
+                        )
                         // 其他参与人
-                        const auditList = await this.getAuditors(revise.tid, times);
-                        const users = this._.pull(this._.map(auditList, 'user_id'), audit.id);
-                        users.push(revise.uid);
+                        const users = this._.pull(this._.map(auditList, 'user_id'), audit.id)
+                        users.push(revise.uid)
                         // await this.ctx.helper.sendUserSms(users, smsTypeConst.const.XD,
                         //     smsTypeConst.judge.result.toString(), '台账修订审批通过。');
-                        await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD,
-                            smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, { status: SmsAliConst.status.success });
+                        await this.ctx.helper.sendAliSms(
+                            users,
+                            smsTypeConst.const.XD,
+                            smsTypeConst.judge.result.toString(),
+                            SmsAliConst.template.revise_result2,
+                            { status: SmsAliConst.status.success }
+                        )
                     } else {
                         // 同步修订信息
-                        await transaction.update(this.ctx.service.ledgerRevise.tableName, { id: revise.id, status: checkType, end_time: time });
+                        await transaction.update(this.ctx.service.ledgerRevise.tableName, {
+                            id: revise.id,
+                            status: checkType,
+                            end_time: time
+                        })
                         // 最新一期跟台账相关的缓存数据应过期
-                        const lastStage = await this.ctx.service.stage.getLastestStage(revise.tid, true);
-                        const cacheTime = new Date();
-                        if (lastStage) await transaction.update(this.ctx.service.stage.tableName,
-                            {id: lastStage.id, cache_time_l: cacheTime, cache_time_r: cacheTime});
+                        const lastStage = await this.ctx.service.stage.getLastestStage(revise.tid, true)
+                        const cacheTime = new Date()
+                        if (lastStage)
+                            await transaction.update(this.ctx.service.stage.tableName, {
+                                id: lastStage.id,
+                                cache_time_l: cacheTime,
+                                cache_time_r: cacheTime
+                            })
                         // 拷贝修订数据至台账
-                        await this._replaceLedgerByRevise(transaction, revise);
-                        const sum = await this.ctx.service.reviseBills.addUp({tender_id: revise.tid/*, is_leaf: true*/});
+                        await this._replaceLedgerByRevise(transaction, revise)
+                        const sum = await this.ctx.service.reviseBills.addUp({
+                            tender_id: revise.tid /* , is_leaf: true*/
+                        })
                         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 });
+                            id: revise.tid,
+                            total_price: sum.total_price,
+                            deal_tp: sum.deal_tp
+                        })
                         // 短信通知-审批通过提醒功能
                         // 下一人
                         // const msg = '台账修订审批通过,请登录系统处理。';
                         // await this.ctx.helper.sendUserSms(revise.uid, smsTypeConst.const.XD,
                         //     smsTypeConst.judge.result.toString(), msg);
-                        await this.ctx.helper.sendAliSms(revise.uid, smsTypeConst.const.XD,
-                            smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result, { status: SmsAliConst.status.success });
+                        await this.ctx.helper.sendAliSms(
+                            revise.uid,
+                            smsTypeConst.const.XD,
+                            smsTypeConst.judge.result.toString(),
+                            SmsAliConst.template.revise_result,
+                            { status: SmsAliConst.status.success }
+                        )
                         // 其他参与人
-                        const auditList = await this.getAuditors(revise.tid, times);
-                        const users = this._.pull(this._.map(auditList, 'user_id'), audit.id);
+                        const users = this._.pull(this._.map(auditList, 'user_id'), audit.id)
                         // await this.ctx.helper.sendUserSms(users, smsTypeConst.const.XD,
                         //     smsTypeConst.judge.result.toString(), '台账修订审批通过。');
-                        await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD,
-                            smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, { status: SmsAliConst.status.success });
+                        await this.ctx.helper.sendAliSms(
+                            users,
+                            smsTypeConst.const.XD,
+                            smsTypeConst.judge.result.toString(),
+                            SmsAliConst.template.revise_result2,
+                            { status: SmsAliConst.status.success }
+                        )
                     }
                 } else {
                     // 同步修订信息
-                    await transaction.update(this.ctx.service.ledgerRevise.tableName, { id: revise.id, times: times + 1, status: checkType });
+                    await transaction.update(this.ctx.service.ledgerRevise.tableName, {
+                        id: revise.id,
+                        times: times + 1,
+                        status: checkType
+                    })
                     // 拷贝新一次审核流程列表
                     const auditors = await this.getAllDataByCondition({
                         where: { rid: revise.id, times },
-                        columns: ['tender_id', 'rid', 'audit_order', 'audit_id'],
-                    });
+                        columns: ['tender_id', 'rid', 'audit_order', 'audit_id']
+                    })
                     for (const a of auditors) {
-                        a.times = times + 1;
-                        a.status = auditConst.status.uncheck;
-                        a.in_time = time;
+                        a.times = times + 1
+                        a.status = auditConst.status.uncheck
+                        a.in_time = time
                     }
-                    await transaction.insert(this.tableName, auditors);
+                    await transaction.insert(this.tableName, auditors)
 
                     // 短信通知-审批退回提醒功能
                     // 下一人
                     // await this.ctx.helper.sendUserSms(revise.uid, smsTypeConst.const.XD,
                     //     smsTypeConst.judge.result.toString(), '台账修订审批退回,请登录系统处理。');
-                    await this.ctx.helper.sendAliSms(revise.uid, smsTypeConst.const.XD,
-                        smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result, { status: SmsAliConst.status.back });
+                    await this.ctx.helper.sendAliSms(
+                        revise.uid,
+                        smsTypeConst.const.XD,
+                        smsTypeConst.judge.result.toString(),
+                        SmsAliConst.template.revise_result,
+                        { status: SmsAliConst.status.back }
+                    )
                     // 其他参与人
                     // await this.ctx.helper.sendUserSms(this._.map(auditors, 'user_id'),
                     //     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 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.commit();
+                await transaction.commit()
             } catch (err) {
-                await transaction.rollback();
-                throw err;
+                await transaction.rollback()
+                throw err
             }
         }
 
@@ -395,18 +512,33 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditRevise(auditorId) {
-            const sql = 'SELECT ra.`audit_id`, ra.`times`, ra.`audit_order`, ra.`begin_time`, ra.`end_time`,' +
+            const sql =
+                'SELECT ra.`audit_id`, ra.`times`, ra.`audit_order`, ra.`begin_time`, ra.`end_time`,' +
                 '    r.id, r.corder, r.uid, 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, t.`status` As t_status, ' +
                 '    p.name As audit_name, p.role As audit_role, p.company As audit_company' +
-                '  FROM ' + this.tableName + ' AS ra' +
-                '  Left Join ' + this.ctx.service.ledgerRevise.tableName + ' As r On ra.rid = r.id' +
-                '  Left Join ' + this.ctx.service.tender.tableName + ' AS t On r.tid = t.id' +
-                '  Left Join ' + this.ctx.service.projectAccount.tableName + ' As p On ra.audit_id = p.id' +
+                '  FROM ' +
+                this.tableName +
+                ' AS ra' +
+                '  Left Join ' +
+                this.ctx.service.ledgerRevise.tableName +
+                ' As r On ra.rid = r.id' +
+                '  Left Join ' +
+                this.ctx.service.tender.tableName +
+                ' AS t On r.tid = t.id' +
+                '  Left Join ' +
+                this.ctx.service.projectAccount.tableName +
+                ' As p On ra.audit_id = p.id' +
                 '  WHERE r.`valid` != 0 and ((ra.`audit_id` = ? and ra.`status` = ?) OR' +
-                '    (r.`uid` = ? and r.`status` = ? and ra.`status` = ? and ra.`times` = (r.`times`-1)))';
-            const sqlParam = [auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
-            return await this.db.query(sql, sqlParam);
+                '    (r.`uid` = ? and r.`status` = ? and ra.`status` = ? and ra.`times` = (r.`times`-1)))'
+            const sqlParam = [
+                auditorId,
+                auditConst.status.checking,
+                auditorId,
+                auditConst.status.checkNo,
+                auditConst.status.checkNo
+            ]
+            return await this.db.query(sql, sqlParam)
         }
 
         /**
@@ -430,17 +562,18 @@ module.exports = app => {
             //     '  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', {
+            let notice = await this.db.select('zh_notice', {
                 where: { pid, type: pushType.revise, uid },
                 orders: [['create_time', 'desc']],
-                limit: 10, offset: 0
-            });
+                limit: 10,
+                offset: 0
+            })
             notice = notice.map(v => {
                 const extra = JSON.parse(v.content)
                 delete v.content
                 return { ...v, ...extra }
             })
-            return notice;
+            return notice
         }
 
         /**
@@ -450,15 +583,23 @@ module.exports = app => {
          * @param {Number} rid 修订id
          */
         async getNoticeContent(pid, tid, rid) {
-            const noticeSql = 'SELECT * FROM (SELECT ' +
+            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]) : '';
+                '  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]) : ''
         }
 
         /**
@@ -470,30 +611,39 @@ module.exports = app => {
          * @return {Promise<boolean>}
          */
         async getAuditorByStatus(rid, status, times = 1) {
-            let auditor = null;
-            let sql = '';
-            let sqlParam = '';
+            let auditor = null
+            let sql = ''
+            let sqlParam = ''
             switch (status) {
-                case auditConst.status.checking :
-                case auditConst.status.checked :
-                case auditConst.status.checkNoPre :
-                    sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
+                case auditConst.status.checking:
+                case auditConst.status.checked:
+                case auditConst.status.checkNoPre:
+                    sql =
+                        'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
                         'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`rid` = ? and la.`status` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc';
-                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, status];
-                    auditor = await this.db.queryOne(sql, sqlParam);
-                    break;
-                case auditConst.status.checkNo :
-                    sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
+                        'WHERE la.`rid` = ? and la.`status` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc'
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, status]
+                    auditor = await this.db.queryOne(sql, sqlParam)
+                    break
+                case auditConst.status.checkNo:
+                    sql =
+                        'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
                         'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc';
-                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, auditConst.status.checkNo, parseInt(times) - 1];
-                    auditor = await this.db.queryOne(sql, sqlParam);
-                    break;
-                case auditConst.status.uncheck :
-                default:break;
+                        'WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc'
+                    sqlParam = [
+                        this.tableName,
+                        this.ctx.service.projectAccount.tableName,
+                        rid,
+                        auditConst.status.checkNo,
+                        parseInt(times) - 1
+                    ]
+                    auditor = await this.db.queryOne(sql, sqlParam)
+                    break
+                case auditConst.status.uncheck:
+                default:
+                    break
             }
-            return auditor;
+            return auditor
         }
 
         /**
@@ -503,25 +653,31 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getAuditGroupByList(rid, times) {
-            const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
+            const sql =
+                'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
                 'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` GROUP BY la.`audit_id` ORDER BY la.`audit_order`';
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, times];
-            return await this.db.query(sql, sqlParam);
+                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` GROUP BY la.`audit_id` ORDER BY la.`audit_order`'
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, times]
+            return await this.db.query(sql, sqlParam)
             // const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
             // const sqlParam = [this.tableName, stageId, times];
             // return await this.db.query(sql, sqlParam);
         }
 
         async getAllAuditors(tenderId) {
-            const sql = 'SELECT ra.audit_id, ra.tender_id FROM ' + this.tableName + ' ra' +
-                '  LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ra.tender_id = t.id' +
+            const sql =
+                'SELECT ra.audit_id, ra.tender_id FROM ' +
+                this.tableName +
+                ' ra' +
+                '  LEFT JOIN ' +
+                this.ctx.service.tender.tableName +
+                ' t On ra.tender_id = t.id' +
                 '  WHERE t.id = ?' +
-                '  GROUP BY ra.audit_id';
-            const sqlParam = [tenderId];
-            return this.db.query(sql, sqlParam);
+                '  GROUP BY ra.audit_id'
+            const sqlParam = [tenderId]
+            return this.db.query(sql, sqlParam)
         }
     }
 
-    return ReviseAudit;
-};
+    return ReviseAudit
+}

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 656 - 374
app/service/stage_audit.js