Browse Source

概况页台账审批人员显示

ellisran 11 months ago
parent
commit
82a0a120f3
2 changed files with 45 additions and 2 deletions
  1. 11 2
      app/controller/tender_controller.js
  2. 34 0
      app/service/ledger_audit.js

+ 11 - 2
app/controller/tender_controller.js

@@ -436,8 +436,17 @@ module.exports = app => {
                     }
                     tender.sum = ctx.helper.add(tender.total_price, tender.change_tp);
                     if (tender.ledger_status !== auditConst.ledger.status.uncheck) {
-                        const status_name = await this.ctx.service.ledgerAudit.getStatusName(tender.id, tender.ledger_times);
-                        tender.status_users = status_name ? status_name.name : '';
+                        let cur;
+                        if (tender.ledger_status === auditConst.ledger.status.checked) {
+                            cur = await this.ctx.service.ledgerAudit.getLastestAuditors(tender.id, tender.ledger_times, auditConst.ledger.status.checked);
+                        } else if (tender.ledger_status === auditConst.ledger.status.checking) {
+                            cur = await this.ctx.service.ledgerAudit.getCurAuditors(tender.id, tender.ledger_times);
+                        } else {
+                            cur = await this.ctx.service.ledgerAudit.getAuditorsByStatus(tender.id, tender.ledger_status, tender.ledger_times);
+                        }
+                        // const status_name = await this.ctx.service.ledgerAudit.getStatusName(tender.id, tender.ledger_times);
+                        // tender.status_users = status_name ? status_name.name : '';
+                        tender.status_users = cur.length > 0 ? (cur[0].audit_type === auditConst.auditType.key.common ? cur[0].name : ctx.helper.transFormToChinese(cur[0].audit_order) + '审') : '';
                         const times = tender.ledger_status === auditConst.ledger.status.checkNo ? tender.ledger_times - 1 : tender.ledger_times;
                         const history = await ctx.service.ledgerAudit.getAuditorHistory(tender.id, times);
                         tender.auditors = history[history.length - 1];

+ 34 - 0
app/service/ledger_audit.js

@@ -94,6 +94,40 @@ module.exports = app => {
             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;
+        }
+
         /**
          * 获取标段审核列表信息
          *