Просмотр исходного кода

新建变更添加上一个变更令的审批人列表

laiguoran 5 лет назад
Родитель
Сommit
da205f1b20
1 измененных файлов с 33 добавлено и 3 удалено
  1. 33 3
      app/service/change.js

+ 33 - 3
app/service/change.js

@@ -109,7 +109,7 @@ module.exports = app => {
 
                 // 把提交人信息添加到zh_change_audit
                 const userInfo = await this.ctx.service.projectAccount.getDataById(userId);
-                const changeaudit = {
+                const changeaudit = [{
                     tid: tenderId,
                     cid,
                     uid: userId,
@@ -120,8 +120,32 @@ module.exports = app => {
                     usite: 0,
                     usort: 0,
                     status: 2,
-                };
-
+                }];
+                // 并把之前存在的变更令审批人添加到zh_change_audit
+                // 先找出标段最近存在的变更令审批人的变更令info
+                const changeInfo = await this.ctx.service.change.getHaveAuditLastInfo(tenderId);
+                if (changeInfo) {
+                    // 再获取非原报审批人
+                    const auditList = await this.ctx.service.changeAudit.getListGroupByTimes(changeInfo.cid, changeInfo.times);
+                    let sort = 1;
+                    for (const audit of auditList) {
+                        if (audit.usite !== 0) {
+                            const oneaudit = {
+                                tid: tenderId,
+                                cid,
+                                uid: audit.uid,
+                                name: userInfo.name,
+                                jobs: userInfo.role,
+                                company: userInfo.company,
+                                times: 1,
+                                usite: audit.usite,
+                                usort: sort++,
+                                status: 1,
+                            };
+                            changeaudit.push(oneaudit);
+                        }
+                    }
+                }
                 await this.transaction.insert(this.ctx.service.changeAudit.tableName, changeaudit);
 
                 result = change;
@@ -135,6 +159,12 @@ module.exports = app => {
             return result;
         }
 
+        async getHaveAuditLastInfo(tenderId) {
+            const sql = 'SELECT * FROM ?? as a LEFT JOIN ?? as b ON a.`cid` = b.`cid` WHERE a.`tid` = ? AND b.`usite` > 0 ORDER BY a.`in_time` DESC';
+            const sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName, tenderId];
+            return await this.db.queryOne(sql, sqlParam);
+        }
+
         async pendingDatas(tenderId, userId) {
             return await this.getAllDataByCondition({
                 tid: tenderId,