Bläddra i källkod

fix: 修复台账审核数据异常bug

lanjianrong 5 år sedan
förälder
incheckning
dcfffd036b
3 ändrade filer med 80 tillägg och 384 borttagningar
  1. 11 72
      app/service/ledger_audit.js
  2. 34 95
      app/service/revise_audit.js
  3. 35 217
      app/service/stage_audit.js

+ 11 - 72
app/service/ledger_audit.js

@@ -54,17 +54,8 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async getStatusName(tenderId, times) {
-            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
-            ]
+            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)
         }
 
@@ -80,18 +71,9 @@ module.exports = app => {
                 '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 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 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) {
@@ -113,13 +95,7 @@ module.exports = app => {
                 '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
-            ]
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditConst.status.checking, times]
             return await this.db.queryOne(sql, sqlParam)
         }
 
@@ -248,12 +224,7 @@ module.exports = app => {
                 // 添加短信通知-需要审批提醒功能
                 // 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()
             } catch (err) {
@@ -291,7 +262,6 @@ module.exports = app => {
 
                 // 获取审核人列表
                 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 = [
@@ -330,12 +300,7 @@ module.exports = app => {
                         })
                         // 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, {
@@ -374,13 +339,7 @@ module.exports = app => {
                         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 {
                     // 同步标段信息
@@ -430,13 +389,7 @@ module.exports = app => {
                     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()
@@ -458,15 +411,7 @@ module.exports = app => {
                 '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
-            ]
+            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)
         }
 
@@ -516,13 +461,7 @@ module.exports = app => {
                 '  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 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]) : ''
         }

+ 34 - 95
app/service/revise_audit.js

@@ -78,18 +78,9 @@ module.exports = app => {
                 '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 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 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) {
@@ -111,13 +102,7 @@ module.exports = app => {
                 '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
-            ]
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditConst.status.checking, times]
             return await this.db.queryOne(sql, sqlParam)
         }
 
@@ -258,23 +243,13 @@ module.exports = app => {
                 // 下一人
                 // 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 auditList = await this.getAuditors(revise.id, 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()
             } catch (err) {
@@ -337,15 +312,15 @@ module.exports = app => {
             const pid = this.ctx.session.sessionProject.id
             const transaction = await this.db.beginTransaction()
             try {
-                const auditList = await this.getAuditors(revise.tid, times)
+                const auditList = await this.getAuditors(revise.id, times)
                 // 审核通过添加到推送表
-                const noticeContent = await this.getNoticeContent(pid, audit.tender_id, audit.rid)
+                const noticeContent = await this.getNoticeContent(pid, audit.tender_id, audit.rid, audit.audit_id)
                 const records = [
                     {
                         pid,
                         type: pushType.revise,
                         uid: revise.uid,
-                        status: auditConst.status.checked,
+                        status: checkType,
                         content: noticeContent
                     }
                 ]
@@ -354,7 +329,7 @@ module.exports = app => {
                         pid,
                         type: pushType.revise,
                         uid: audit.audit_id,
-                        status: auditConst.status.checked,
+                        status: checkType,
                         content: noticeContent
                     })
                 })
@@ -387,25 +362,17 @@ module.exports = app => {
                         // 下一人
                         // 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 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, {
@@ -437,24 +404,16 @@ module.exports = app => {
                         // 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 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 {
                     // 同步修订信息
@@ -479,13 +438,9 @@ module.exports = app => {
                     // 下一人
                     // 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(), '台账修订审批退回。');
@@ -494,7 +449,9 @@ module.exports = app => {
                         smsTypeConst.const.XD,
                         smsTypeConst.judge.result.toString(),
                         SmsAliConst.template.revise_result2,
-                        { status: SmsAliConst.status.back }
+                        {
+                            status: SmsAliConst.status.back
+                        }
                     )
                 }
 
@@ -531,13 +488,7 @@ module.exports = app => {
                 ' 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
-            ]
+            const sqlParam = [auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo]
             return await this.db.query(sql, sqlParam)
         }
 
@@ -581,23 +532,17 @@ module.exports = app => {
          * @param {Number} pid 项目id
          * @param {Number} tid 台账id
          * @param {Number} rid 修订id
+         * @param {Number} uid 审核人id
          */
-        async getNoticeContent(pid, tid, rid) {
+        async getNoticeContent(pid, tid, rid, uid) {
             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`' +
+                '  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,
-                tid,
-                this.ctx.service.ledgerRevise.tableName,
-                rid,
-                this.ctx.service.projectAccount.tableName,
-                pid
-            ]
+            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.ledgerRevise.tableName, rid, this.ctx.service.projectAccount.tableName, uid, pid]
             const content = await this.db.query(noticeSql, noticeSqlParam)
             return content.length ? JSON.stringify(content[0]) : ''
         }
@@ -630,13 +575,7 @@ module.exports = app => {
                         '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
-                    ]
+                    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:

+ 35 - 217
app/service/stage_audit.js

@@ -60,18 +60,9 @@ module.exports = app => {
                 'FROM ?? AS la, ?? AS pa, (SELECT `aid`,(@i:=@i+1) as `sort` FROM ??, (select @i:=0) as it WHERE `sid` = ? AND `times` = ? GROUP BY `aid`) as g ' +
                 'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order` ' +
                 order_sort
-            const sqlParam = [
-                this.tableName,
-                this.ctx.service.projectAccount.tableName,
-                this.tableName,
-                stageId,
-                times,
-                stageId,
-                times
-            ]
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, stageId, times, stageId, times]
             const result = await this.db.query(sql, sqlParam)
-            const sql2 =
-                'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `sid` = ? AND `times` = ? GROUP BY `aid`) as a'
+            const sql2 = 'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `sid` = ? AND `times` = ? GROUP BY `aid`) as a'
             const sqlParam2 = [this.tableName, stageId, times]
             const count = await this.db.queryOne(sql2, sqlParam2)
             for (const i in result) {
@@ -81,15 +72,7 @@ module.exports = app => {
         }
 
         async getAllAuditors(tenderId) {
-            const sql =
-                'SELECT sa.aid, sa.tid FROM ' +
-                this.tableName +
-                ' sa' +
-                '  LEFT JOIN ' +
-                this.ctx.service.tender.tableName +
-                ' t On sa.tid = t.id' +
-                '  WHERE t.id = ?' +
-                '  GROUP BY  sa.aid'
+            const sql = 'SELECT sa.aid, sa.tid FROM ' + this.tableName + ' sa' + '  LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On sa.tid = t.id' + '  WHERE t.id = ?' + '  GROUP BY  sa.aid'
             const sqlParam = [tenderId]
             return this.db.query(sql, sqlParam)
         }
@@ -103,17 +86,8 @@ module.exports = app => {
          * @return {Promise<*>}
          */
         async getStatusName(stageId) {
-            const sql =
-                'SELECT pa.`name` ' +
-                'FROM ?? AS sa, ?? AS pa ' +
-                'WHERE sa.`sid` = ?' +
-                '    and sa.`aid` = pa.`id` and sa.`status` != ? ORDER BY sa.`times` DESC, sa.`order` DESC'
-            const sqlParam = [
-                this.tableName,
-                this.ctx.service.projectAccount.tableName,
-                stageId,
-                auditConst.status.uncheck
-            ]
+            const sql = 'SELECT pa.`name` ' + 'FROM ?? AS sa, ?? AS pa ' + 'WHERE sa.`sid` = ?' + '    and sa.`aid` = pa.`id` and sa.`status` != ? ORDER BY sa.`times` DESC, sa.`order` DESC'
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.uncheck]
             return await this.db.queryOne(sql, sqlParam)
         }
 
@@ -130,13 +104,7 @@ module.exports = app => {
                 'FROM ?? AS la, ?? AS pa ' +
                 'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ?' +
                 '    and la.`aid` = pa.`id`'
-            const sqlParam = [
-                this.tableName,
-                this.ctx.service.projectAccount.tableName,
-                stageId,
-                auditConst.status.checking,
-                times
-            ]
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checking, times]
             return await this.db.queryOne(sql, sqlParam)
         }
 
@@ -300,21 +268,8 @@ module.exports = app => {
                 //     }
                 // }
                 const stageInfo = await this.ctx.service.stage.getDataById(audit.sid)
-                const shenpiUrl = await this.ctx.helper.urlToShort(
-                    'http://' +
-                        this.ctx.request.header.host +
-                        '/wap/tender/' +
-                        this.ctx.tender.id +
-                        '/stage/' +
-                        stageInfo.order
-                )
-                await this.ctx.helper.sendAliSms(
-                    audit.aid,
-                    smsTypeConst.const.JL,
-                    smsTypeConst.judge.approval.toString(),
-                    SmsAliConst.template.stage_check,
-                    { qi: stageInfo.order, code: shenpiUrl }
-                )
+                const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, { qi: stageInfo.order, code: shenpiUrl })
 
                 // todo 更新标段tender状态 ?
                 await transaction.commit()
@@ -345,7 +300,7 @@ module.exports = app => {
                         pid,
                         type: pushType.stage,
                         uid: this.ctx.stage.user_id,
-                        status: auditConst.status.checkNo,
+                        status: auditConst.status.checked,
                         content: noticeContent
                     }
                 ]
@@ -354,7 +309,7 @@ module.exports = app => {
                         pid,
                         type: pushType.stage,
                         uid: audit.aid,
-                        status: auditConst.status.checkNo,
+                        status: auditConst.status.checked,
                         content: noticeContent
                     })
                 })
@@ -379,12 +334,7 @@ module.exports = app => {
                 // 无下一审核人表示,审核结束
                 if (nextAudit) {
                     // 复制一份下一审核人数据
-                    await this.ctx.service.stagePay.copyAuditStagePays(
-                        this.ctx.stage,
-                        this.ctx.stage.times,
-                        nextAudit.order,
-                        transaction
-                    )
+                    await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction)
                     await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction)
                     await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction)
                     await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction)
@@ -424,32 +374,13 @@ module.exports = app => {
                     //     }
                     // }
                     const stageInfo = await this.ctx.service.stage.getDataById(nextAudit.sid)
-                    const shenpiUrl = await this.ctx.helper.urlToShort(
-                        'http://' +
-                            this.ctx.request.header.host +
-                            '/wap/tender/' +
-                            this.ctx.tender.id +
-                            '/stage/' +
-                            stageInfo.order
-                    )
-                    await this.ctx.helper.sendAliSms(
-                        nextAudit.aid,
-                        smsTypeConst.const.JL,
-                        smsTypeConst.judge.approval.toString(),
-                        SmsAliConst.template.stage_check,
-                        { qi: stageInfo.order, code: shenpiUrl }
-                    )
+                    const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                    await this.ctx.helper.sendAliSms(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, { qi: stageInfo.order, code: shenpiUrl })
                 } else {
                     // 本期结束
                     // 生成截止本期数据 final数据
-                    console.time('generatePre')
-                    await this.ctx.service.stageBillsFinal.generateFinalData(
-                        transaction,
-                        this.ctx.tender,
-                        this.ctx.stage
-                    )
+                    await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage)
                     await this.ctx.service.stagePosFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage)
-                    console.timeEnd('generatePre')
                     // 同步 期信息
                     await transaction.update(this.ctx.service.stage.tableName, {
                         id: stageId,
@@ -492,13 +423,7 @@ module.exports = app => {
                     //     sms.send(mobile_array, content);
                     // }
                     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 }
-                    )
+                    await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, { qi: stageInfo.order, status: SmsAliConst.status.success })
                 }
                 await transaction.commit()
             } catch (err) {
@@ -515,8 +440,7 @@ module.exports = app => {
                 throw '审核数据错误'
             }
             const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage)
-            const sql =
-                'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC'
+            const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC'
             const sqlParam = [this.tableName, stageId, times]
             const auditors = await this.db.query(sql, sqlParam)
             let order = 1
@@ -584,12 +508,7 @@ module.exports = app => {
                 // 计算该审批人最终数据
                 await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction)
                 // 复制一份最新数据给原报
-                await this.ctx.service.stagePay.copyAuditStagePays(
-                    this.ctx.stage,
-                    this.ctx.stage.times + 1,
-                    0,
-                    transaction
-                )
+                await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times + 1, 0, transaction)
                 await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction)
                 await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction)
 
@@ -623,13 +542,7 @@ module.exports = app => {
                 //     sms.send(mobile_array, content);
                 // }
                 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 }
-                )
+                await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, { qi: stageInfo.order, status: SmsAliConst.status.back })
                 await transaction.commit()
             } catch (err) {
                 await transaction.rollback()
@@ -735,12 +648,7 @@ module.exports = app => {
                 // 计算该审批人最终数据
                 await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction)
                 // 复制一份最新数据给下一人
-                await this.ctx.service.stagePay.copyAuditStagePays(
-                    this.ctx.stage,
-                    this.ctx.stage.times,
-                    audit.order + 1,
-                    transaction
-                )
+                await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction)
                 await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction)
                 await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction)
                 await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction)
@@ -769,21 +677,8 @@ module.exports = app => {
                 //     }
                 // }
                 const stageInfo = await this.ctx.service.stage.getDataById(audit.sid)
-                const shenpiUrl = await this.ctx.helper.urlToShort(
-                    'http://' +
-                        this.ctx.request.header.host +
-                        '/wap/tender/' +
-                        this.ctx.tender.id +
-                        '/stage/' +
-                        stageInfo.order
-                )
-                await this.ctx.helper.sendAliSms(
-                    preAuditor.aid,
-                    smsTypeConst.const.JL,
-                    smsTypeConst.judge.approval.toString(),
-                    SmsAliConst.template.stage_check,
-                    { qi: stageInfo.order, code: shenpiUrl }
-                )
+                const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                await this.ctx.helper.sendAliSms(preAuditor.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, { qi: stageInfo.order, code: shenpiUrl })
 
                 await transaction.commit()
             } catch (err) {
@@ -800,11 +695,7 @@ module.exports = app => {
          * @return {Promise<void>}
          */
         async check(stageId, checkData, times = 1) {
-            if (
-                checkData.checkType !== auditConst.status.checked &&
-                checkData.checkType !== auditConst.status.checkNo &&
-                checkData.checkType !== auditConst.status.checkNoPre
-            ) {
+            if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.checkNoPre) {
                 throw '提交数据错误'
             }
             // // 整理当前流程审核人状态更新
@@ -990,29 +881,15 @@ module.exports = app => {
                 await transaction.insert(this.tableName, newAuditors)
 
                 // 复制一份最新数据给下一人
-                await this.ctx.service.stagePay.copyAuditStagePays(
-                    this.ctx.stage,
-                    this.ctx.stage.times,
-                    audit.order + 1,
-                    transaction
-                )
-                await this.ctx.service.stagePay.copyAuditStagePays(
-                    this.ctx.stage,
-                    this.ctx.stage.times,
-                    audit.order + 2,
-                    transaction
-                )
+                await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction)
+                await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 2, transaction)
                 await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction)
                 await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction)
                 await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction)
 
                 // 本期结束
                 // 生成截止本期数据 final数据
-                await this.ctx.service.stageBillsFinal.delGenerateFinalData(
-                    transaction,
-                    this.ctx.tender,
-                    this.ctx.stage
-                )
+                await this.ctx.service.stageBillsFinal.delGenerateFinalData(transaction, this.ctx.tender, this.ctx.stage)
                 await this.ctx.service.stagePosFinal.delGenerateFinalData(transaction, this.ctx.tender, this.ctx.stage)
                 // 同步 期信息
                 await transaction.update(this.ctx.service.stage.tableName, {
@@ -1038,21 +915,8 @@ module.exports = app => {
                 //     }
                 // }
                 const stageInfo = await this.ctx.service.stage.getDataById(audit.sid)
-                const shenpiUrl = await this.ctx.helper.urlToShort(
-                    'http://' +
-                        this.ctx.request.header.host +
-                        '/wap/tender/' +
-                        this.ctx.tender.id +
-                        '/stage/' +
-                        stageInfo.order
-                )
-                await this.ctx.helper.sendAliSms(
-                    audit.aid,
-                    smsTypeConst.const.JL,
-                    smsTypeConst.judge.approval.toString(),
-                    SmsAliConst.template.stage_check,
-                    { qi: stageInfo.order, code: shenpiUrl }
-                )
+                const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order)
+                await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, { qi: stageInfo.order, code: shenpiUrl })
                 await transaction.commit()
             } catch (err) {
                 await transaction.rollback()
@@ -1074,16 +938,7 @@ module.exports = app => {
                 '  FROM ?? AS sa, ?? AS s, ?? As t ' +
                 '  WHERE ((sa.`aid` = ? and sa.`status` = ?) OR (s.`user_id` = ? and sa.`status` = ? and s.`status` = ? and sa.`times` = (s.`times`-1)))' +
                 '    and sa.`sid` = s.`id` and sa.`tid` = t.`id`'
-            const sqlParam = [
-                this.tableName,
-                this.ctx.service.stage.tableName,
-                this.ctx.service.tender.tableName,
-                auditorId,
-                auditConst.status.checking,
-                auditorId,
-                auditConst.status.checkNo,
-                auditConst.status.checkNo
-            ]
+            const sqlParam = [this.tableName, this.ctx.service.stage.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo]
             return await this.db.query(sql, sqlParam)
         }
 
@@ -1138,15 +993,7 @@ module.exports = app => {
                 '  LEFT JOIN ?? As s On s.`id` =  ?' +
                 '  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,
-                tid,
-                this.ctx.service.stage.tableName,
-                sid,
-                this.ctx.service.projectAccount.tableName,
-                uid,
-                pid
-            ]
+            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.stage.tableName, sid, this.ctx.service.projectAccount.tableName, uid, pid]
             const content = await this.db.query(noticeSql, noticeSqlParam)
             return content.length ? JSON.stringify(content[0]) : ''
         }
@@ -1247,13 +1094,7 @@ module.exports = app => {
                         'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
                         'FROM ?? AS la, ?? AS pa ' +
                         'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc'
-                    sqlParam = [
-                        this.tableName,
-                        this.ctx.service.projectAccount.tableName,
-                        stageId,
-                        auditConst.status.checkNo,
-                        parseInt(times) - 1
-                    ]
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checkNo, parseInt(times) - 1]
                     auditor = await this.db.queryOne(sql, sqlParam)
                     break
                 case auditConst.status.uncheck:
@@ -1271,11 +1112,7 @@ module.exports = app => {
          * @return {Promise<boolean>}
          */
         async getStageAudit(stageId, times = 1) {
-            const sql =
-                'SELECT a1.aid, a1.begin_time, a1.end_time, a1.status, a1.opinion ' +
-                'FROM ?? AS a1 ' +
-                'WHERE a1.`sid` = ? and a1.`times` = ? ' +
-                'ORDER BY a1.order'
+            const sql = 'SELECT a1.aid, a1.begin_time, a1.end_time, a1.status, a1.opinion ' + 'FROM ?? AS a1 ' + 'WHERE a1.`sid` = ? and a1.`times` = ? ' + 'ORDER BY a1.order'
             const sqlParam = [this.tableName, stageId, times]
             const rst = await this.db.query(sql, sqlParam)
             return rst
@@ -1297,14 +1134,7 @@ module.exports = app => {
                 '  FROM ?? AS sa, ?? AS s, ?? As t, ?? AS ti ' +
                 '  WHERE sa.`aid` = ? and sa.`status` = ?' +
                 '    and sa.`sid` = s.`id` and sa.`tid` = t.`id` and ti.`tid` = t.`id`'
-            const sqlParam = [
-                this.tableName,
-                this.ctx.service.stage.tableName,
-                this.ctx.service.tender.tableName,
-                this.ctx.service.tenderInfo.tableName,
-                auditorId,
-                auditConst.status.checking
-            ]
+            const sqlParam = [this.tableName, this.ctx.service.stage.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, auditorId, auditConst.status.checking]
             return await this.db.query(sql, sqlParam)
         }
 
@@ -1350,8 +1180,7 @@ module.exports = app => {
                     await this._timesDelete(this.ctx.stage.id, nowTimes, transaction)
                 }
                 // 添加上一次审批人
-                const sql =
-                    'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC'
+                const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC'
                 const sqlParam = [this.tableName, this.ctx.stage.id, nowTimes - 1]
                 const auditors = await this.db.query(sql, sqlParam)
                 let order = 1
@@ -1375,19 +1204,8 @@ module.exports = app => {
                 })
                 if (!lastAudit) throw '审批数据错误'
 
-                await this.ctx.service.stagePay.copyStagePays4DeleteTimes(
-                    this.ctx.stage,
-                    nowTimes,
-                    0,
-                    lastAudit.times,
-                    lastAudit.order,
-                    transaction
-                )
-                const stagePay = await this.ctx.service.stagePay.getAuditorStageData(
-                    this.ctx.stage.id,
-                    lastAudit.times,
-                    lastAudit.order
-                )
+                await this.ctx.service.stagePay.copyStagePays4DeleteTimes(this.ctx.stage, nowTimes, 0, lastAudit.times, lastAudit.order, transaction)
+                const stagePay = await this.ctx.service.stagePay.getAuditorStageData(this.ctx.stage.id, lastAudit.times, lastAudit.order)
                 const yfPay = stagePay.find(function (x) {
                     return x.ptype === payConst.payType.yf
                 })