Browse Source

feat: 修复台账审核推送异常bug

lanjianrong 5 years ago
parent
commit
2782d41eff
1 changed files with 59 additions and 13 deletions
  1. 59 13
      app/service/stage_audit.js

+ 59 - 13
app/service/stage_audit.js

@@ -72,7 +72,15 @@ 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)
         }
@@ -86,7 +94,11 @@ 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 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)
         }
@@ -269,7 +281,10 @@ 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 })
+                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()
@@ -294,7 +309,7 @@ module.exports = app => {
 
             try {
                 // 添加推送
-                const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
+                const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid)
                 const records = [
                     {
                         pid,
@@ -375,7 +390,10 @@ 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 })
+                    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数据
@@ -423,7 +441,10 @@ 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) {
@@ -454,7 +475,7 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction()
             try {
                 // 添加推送
-                const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
+                const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid)
                 const records = [
                     {
                         pid,
@@ -542,7 +563,10 @@ 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()
@@ -569,7 +593,7 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction()
             try {
                 // 添加推送
-                const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
+                const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid)
                 const records = [
                     {
                         pid,
@@ -678,7 +702,10 @@ 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 })
+                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) {
@@ -916,7 +943,10 @@ 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 })
+                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()
@@ -938,7 +968,16 @@ 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)
         }
 
@@ -1134,7 +1173,14 @@ 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)
         }