| 
					
				 | 
			
			
				@@ -117,8 +117,10 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         _checkSpecialTender(tender, special) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            for (const spec of special) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (tender[spec.key] === true) return spec.key; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (special) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for (const spec of special) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (tender[spec.key] === true) return spec.key; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -166,8 +168,8 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     const preStage = stage.order > 1 ? await this.ctx.service.stageBillsFinal.getFinalData(tender, stage.order - 1) : []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    this.ctx.helper.assignRelaData(posData, [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        {data: preStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'pid'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    this.ctx.helper.assignRelaData(billsData, [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        {data: preStage, fields: ['contract_qty', 'qc_qty'], prefix: 'pre_', relaId: 'lid'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -268,14 +270,14 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async _gatherFinalData(sTender, index, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const stages = await this.db.select(this.tableName, { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this.db.select(this.ctx.service.stage.tableName, { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 where: { tid: tender.id }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 orders: [['order', 'desc']], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (stages.length !== 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                const lastStage = stages[stages.length - 1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const lastStage = stages[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (lastStage.status === auditConst.stage.status.uncheck && lastStage.user_id !== this.ctx.session.sessionUser.accountId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    stages.splice(stages.length - 1, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    stages.splice(0, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             await this._gatherStageData(index, tender, stages[0], hasPre); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -283,14 +285,14 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async _gatherCheckedFinalData(sTender, index, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const stages = await this.db.select(this.tableName, { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this.db.select(this.ctx.service.stage.tableName, { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 where: { tid: tender.id }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 orders: [['order', 'desc']], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (stages.length !== 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                const lastStage = stages[stages.length - 1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const lastStage = stages[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (lastStage.status !== auditConst.stage.status.checked) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    stages.splice(stages.length - 1, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    stages.splice(0, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             await this._gatherStageData(index, tender, stages[0], hasPre); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -321,22 +323,23 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (!gsDefine || !gsDefine.enable) return []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (!gsCustom || !gsCustom.tenders || gsCustom.tenders.length === 0) return []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const gsSetting = JSON.parse(gsDefine.setting); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let commonIndex = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (const tender of gsCustom.tenders) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                const specialKey = this._checkSpecialTender(tender, gsDefine.setting.special); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const specialKey = this._checkSpecialTender(tender, gsSetting.special); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (specialKey === '') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    switch (gsDefine.setting.type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    switch (gsSetting.type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         case 'month': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            await this._gatherMonthData(tender, commonIndex, gsCustom.month, gsDefine.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherMonthData(tender, commonIndex, gsCustom.month, gsSetting.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         case 'zone': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             await this._gatherZoneData(tender, commonIndex, gsCustom.zone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         case 'final': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            await this._gatherFinalData(tender, commonIndex, gsDefine.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherFinalData(tender, commonIndex, gsSetting.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         case 'checked-final': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            await this._gatherCheckedFinalData(tender, commonIndex, gsDefine.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherCheckedFinalData(tender, commonIndex, gsSetting.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     commonIndex++; 
			 |