Преглед на файлове

审批退回时,审批意见、审批时间取值

MaiXinRong преди 4 години
родител
ревизия
0582ac5ee7
променени са 2 файла, в които са добавени 20 реда и са изтрити 18 реда
  1. 4 16
      app/service/report_memory.js
  2. 16 2
      app/service/stage_audit.js

+ 4 - 16
app/service/report_memory.js

@@ -979,8 +979,9 @@ module.exports = app => {
         async getStageAuditors(tid, sid) {
             await this.ctx.service.tender.checkTender(tid);
             await this.ctx.service.stage.checkStage(sid);
+
+            const auditors = await this.ctx.service.stageAudit.getFinalAuditGroup(this.ctx.stage.id, this.ctx.stage.curTimes);
             const user = await this.ctx.service.projectAccount.getDataById(this.ctx.stage.user_id);
-            const auditors = this.ctx.stage.auditors;
             const result = [{
                 aid: user.id,
                 name: user.name,
@@ -992,21 +993,8 @@ module.exports = app => {
                 opinion: user.opinion,
                 end_time: auditors && auditors.length > 0 ? auditors[0].begin_time : null,
                 sort: 0,
-            }];
-            for (const a of auditors) {
-                const auditor = await this.ctx.service.stageAudit.getDataByCondition({tid: a.tid, sid: a.sid, order: a.max_order});
-                result.push({
-                    aid: a.aid,
-                    name: a.name,
-                    company: a.company,
-                    role: a.role,
-                    mobile: a.mobile,
-                    telephone: a.telephone,
-                    sign_path: a.sign_path,
-                    end_time: auditor.end_time,
-                    opinion: auditor.opinion,
-                })
-            }
+            }, ...auditors];
+            console.log(auditors);
             return result;
         }
 

+ 16 - 2
app/service/stage_audit.js

@@ -88,12 +88,11 @@ module.exports = app => {
                 order_sort;
             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, a.`max_order` FROM (SELECT `aid`, Max(`order`) as max_order 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) {
                 result[i].max_sort = count.num;
-                result[i].max_order = count.max_order;
             }
             return result;
         }
@@ -1307,6 +1306,21 @@ module.exports = app => {
                 throw err;
             }
         }
+
+        async getFinalAuditGroup(stageId, times) {
+            const sql =
+                'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, pa.`sign_path`, la.`times`, la.`sid`, la.`aid`, Max(la.`order`) as max_order ' +
+                'FROM ?? AS la, ?? AS pa ' +
+                'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` GROUP BY la.`aid` ORDER BY la.`order`';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, times];
+            const result = await this.db.query(sql, sqlParam);
+            for (const r of result) {
+                const auditor = await this.getDataByCondition({sid: stageId, times: r.times, order: r.max_order});
+                r.opinion = auditor.opinion;
+                r.en_time = auditor.end_time;
+            }
+            return result;
+        }
     }
 
     return StageAudit;