|  | @@ -94,6 +94,40 @@ module.exports = app => {
 | 
												
													
														
															|  |              return result.filter(x => { return x.audit_order === result[0].audit_order });
 |  |              return result.filter(x => { return x.audit_order === result[0].audit_order });
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +        async getAuditorsByStatus(tenderId, status, times = 1) {
 | 
												
													
														
															|  | 
 |  | +            let auditor = [];
 | 
												
													
														
															|  | 
 |  | +            let sql = '';
 | 
												
													
														
															|  | 
 |  | +            let sqlParam = '';
 | 
												
													
														
															|  | 
 |  | +            let cur;
 | 
												
													
														
															|  | 
 |  | +            switch (status) {
 | 
												
													
														
															|  | 
 |  | +                case auditConst.status.checking:
 | 
												
													
														
															|  | 
 |  | +                case auditConst.status.checked:
 | 
												
													
														
															|  | 
 |  | +                    cur = await this.db.queryOne(`SELECT * From ${this.tableName} where tender_id = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`order` DESC', [tenderId, times, status]);
 | 
												
													
														
															|  | 
 |  | +                    if (!cur) return [];
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +                    sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.audit_order, la.audit_type, la.audit_ledger_id ' +
 | 
												
													
														
															|  | 
 |  | +                        '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
 | 
												
													
														
															|  | 
 |  | +                        '  WHERE la.`tender_id` = ? and la.`audit_order` = ? and la.`times` = ?';
 | 
												
													
														
															|  | 
 |  | +                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, cur.order, times];
 | 
												
													
														
															|  | 
 |  | +                    auditor = await this.db.query(sql, sqlParam);
 | 
												
													
														
															|  | 
 |  | +                    break;
 | 
												
													
														
															|  | 
 |  | +                case auditConst.status.checkNo:
 | 
												
													
														
															|  | 
 |  | +                    cur = await this.db.queryOne(`SELECT * From ${this.tableName} where tender_id = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`order` DESC', [tenderId, parseInt(times) - 1, status]);
 | 
												
													
														
															|  | 
 |  | +                    if (!cur) return [];
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +                    sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.audit_order, la.audit_type, la.audit_ledger_id ' +
 | 
												
													
														
															|  | 
 |  | +                        '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
 | 
												
													
														
															|  | 
 |  | +                        '  WHERE la.`sid` = ? and la.`audit_order` = ? and la.`times` = ?';
 | 
												
													
														
															|  | 
 |  | +                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, cur.order, parseInt(times) - 1];
 | 
												
													
														
															|  | 
 |  | +                    auditor = await this.db.query(sql, sqlParam);
 | 
												
													
														
															|  | 
 |  | +                    break;
 | 
												
													
														
															|  | 
 |  | +                case auditConst.status.uncheck:
 | 
												
													
														
															|  | 
 |  | +                default:
 | 
												
													
														
															|  | 
 |  | +                    break;
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            return auditor;
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  |          /**
 |  |          /**
 | 
												
													
														
															|  |           * 获取标段审核列表信息
 |  |           * 获取标段审核列表信息
 | 
												
													
														
															|  |           *
 |  |           *
 | 
												
											
												
													
														
															|  | @@ -198,13 +232,22 @@ module.exports = app => {
 | 
												
													
														
															|  |                      const auditors = await this.getAuditors(tenderId, i);
 |  |                      const auditors = await this.getAuditors(tenderId, i);
 | 
												
													
														
															|  |                      const group = this.ctx.helper.groupAuditors(auditors, 'audit_order');
 |  |                      const group = this.ctx.helper.groupAuditors(auditors, 'audit_order');
 | 
												
													
														
															|  |                      const historyGroup = [];
 |  |                      const historyGroup = [];
 | 
												
													
														
															|  | -                    const max_order = group.length > 0 && group[group.length - 1].length > 0 ? group[group.length - 1][0].audit_order : -1;
 |  | 
 | 
												
													
														
															|  | 
 |  | +                    let max_order = 0;
 | 
												
													
														
															|  |                      for (const g of group) {
 |  |                      for (const g of group) {
 | 
												
													
														
															|  |                          const his = {
 |  |                          const his = {
 | 
												
													
														
															|  |                              beginYear: '', beginDate: '', beginTime: '', endYear: '', endDate: '', endTime: '', begin_time: null, end_time: null,
 |  |                              beginYear: '', beginDate: '', beginTime: '', endYear: '', endDate: '', endTime: '', begin_time: null, end_time: null,
 | 
												
													
														
															|  | -                            audit_type: g[0].audit_type, audit_order: g[0].audit_order,
 |  | 
 | 
												
													
														
															|  | 
 |  | +                            audit_type: g[0].audit_type, order: g[0].audit_order,
 | 
												
													
														
															|  |                              auditors: g
 |  |                              auditors: g
 | 
												
													
														
															|  |                          };
 |  |                          };
 | 
												
													
														
															|  | 
 |  | +                        const curAuditId = g.map(x => { return x.audit_id; });
 | 
												
													
														
															|  | 
 |  | +                        const sameHis = historyGroup.find(x => {
 | 
												
													
														
															|  | 
 |  | +                            if (x.audit_type !== his.audit_type) return false;
 | 
												
													
														
															|  | 
 |  | +                            const auditId = x.auditors.map(xa => { return xa.audit_id; });
 | 
												
													
														
															|  | 
 |  | +                            this.ctx.helper._.remove(auditId, function(a) { return curAuditId.indexOf(a) >= 0; });
 | 
												
													
														
															|  | 
 |  | +                            return auditId.length === 0;
 | 
												
													
														
															|  | 
 |  | +                        });
 | 
												
													
														
															|  | 
 |  | +                        his.audit_order = sameHis ? sameHis.audit_order : his.order;
 | 
												
													
														
															|  | 
 |  | +                        if (!sameHis && his.audit_order > max_order) max_order = his.audit_order;
 | 
												
													
														
															|  |                          if (his.audit_type === auditType.key.common) {
 |  |                          if (his.audit_type === auditType.key.common) {
 | 
												
													
														
															|  |                              his.name = g[0].name;
 |  |                              his.name = g[0].name;
 | 
												
													
														
															|  |                          } else {
 |  |                          } else {
 | 
												
											
												
													
														
															|  | @@ -236,6 +279,9 @@ module.exports = app => {
 | 
												
													
														
															|  |                          }
 |  |                          }
 | 
												
													
														
															|  |                          historyGroup.push(his);
 |  |                          historyGroup.push(his);
 | 
												
													
														
															|  |                      }
 |  |                      }
 | 
												
													
														
															|  | 
 |  | +                    historyGroup.forEach(hg => {
 | 
												
													
														
															|  | 
 |  | +                        hg.is_final = hg.audit_order === max_order;
 | 
												
													
														
															|  | 
 |  | +                    });
 | 
												
													
														
															|  |                      if (reverse) {
 |  |                      if (reverse) {
 | 
												
													
														
															|  |                          history.push(historyGroup.reverse());
 |  |                          history.push(historyGroup.reverse());
 | 
												
													
														
															|  |                      } else {
 |  |                      } else {
 | 
												
											
												
													
														
															|  | @@ -442,7 +488,7 @@ module.exports = app => {
 | 
												
													
														
															|  |                  if (!auditor) {
 |  |                  if (!auditor) {
 | 
												
													
														
															|  |                      throw '该审核人不存在';
 |  |                      throw '该审核人不存在';
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  | -                await transaction.delete(this.tableName, { tid: tenderId, audit_order: auditor.audit_order, times});
 |  | 
 | 
												
													
														
															|  | 
 |  | +                await transaction.delete(this.tableName, { tender_id: tenderId, audit_order: auditor.audit_order, times});
 | 
												
													
														
															|  |                  await this._syncOrderByDelete(transaction, tenderId, auditor.audit_order, times);
 |  |                  await this._syncOrderByDelete(transaction, tenderId, auditor.audit_order, times);
 | 
												
													
														
															|  |                  await transaction.delete(this.tableName, condition);
 |  |                  await transaction.delete(this.tableName, condition);
 | 
												
													
														
															|  |                  await transaction.commit();
 |  |                  await transaction.commit();
 |