| 
					
				 | 
			
			
				@@ -210,6 +210,35 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _getTimeZoneStages(tender, zone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const times = zone.split(' - '); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (times.length !== 2) throw '选择的汇总周期无效'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const beginTime = moment(times[0], 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const endTime = moment(times[1], 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getValidStages(tender.id), validStages = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const stage of stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const sTime = moment(stage.s_time, 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (sTime.isBetween(beginTime, endTime, null, '[]')) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    validStages.push(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return validStages; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _getOrderZoneStages (tender, zone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let [iBegin, iEnd] = zone.split(':'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            iBegin = this.ctx.helper._.toInteger(iBegin) || 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            iEnd = this.ctx.helper._.toInteger(iEnd) || 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getValidStages(tender.id), validStages = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const stage of stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (stage.order < iBegin || stage.order > iEnd) continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                validStages.push(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return validStages; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * 台账数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -278,15 +307,10 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        async _gatherMonthData(sTender, completeData, month, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const stages = await this._getValidStages(tender.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const stage = this.ctx.helper._.find(stages, {s_time: month}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            await this._gatherStageData(completeData, tender, stage, hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        async _gatherZoneData(sTender, completeData, zone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherStagesData(completeData, tender, stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const helper = this.ctx.helper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            completeData.id = tender.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            completeData.name = tender.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              * 汇总并合并 相关数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				              * @param {Array} index - 主数据 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -310,7 +334,6 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     loadFields(r.data, r.fields, r.prefix, r.relaId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const billsTree = new Ledger.billsTree(this.ctx, { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 id: 'ledger_id', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 pid: 'ledger_pid', 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -327,9 +350,6 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     node.gather_tp = helper.add(node.contract_tp, node.qc_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            completeData.id = tender.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            completeData.name = tender.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const billsData = await this.ctx.service.ledger.getData(tender.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const dgnData = await this.ctx.service.stageBillsDgn.getDgnData(tender.id); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -343,30 +363,22 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 billsIndexData[indexPre + bd.id] = bd; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const times = zone.split(' - '); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (times.length !== 2) throw '选择的汇总周期无效'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const beginTime = moment(times[0], 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const endTime = moment(times[1], 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const stages = await this._getValidStages(tender.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (const stage of stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                const sTime = moment(stage.s_time, 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (sTime.isBetween(beginTime, endTime, null, '[]')) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    await this.ctx.service.stage.doCheckStage(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (stage.readOnly) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        const curStage = await this.ctx.service.stageBills.getAuditorStageData(tender.id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            stage.id, stage.curTimes, stage.curOrder); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sumAssignRelaData(billsIndexData, [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        const curStage = await this.ctx.service.stageBills.getLastestStageData(tender.id, stage.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sumAssignRelaData(billsIndexData, [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                await this.ctx.service.stage.doCheckStage(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (stage.readOnly) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const curStage = await this.ctx.service.stageBills.getAuditorStageData(tender.id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        stage.id, stage.curTimes, stage.curOrder); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sumAssignRelaData(billsIndexData, [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const curStage = await this.ctx.service.stageBills.getLastestStageData(tender.id, stage.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sumAssignRelaData(billsIndexData, [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        {data: curStage, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp'], prefix: '', relaId: 'lid'} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             billsTree.loadDatas(billsData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             billsTree.calculateAll(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             this.resultTree.loadGatherTree(billsTree, function (gatherNode, sourceNode) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -374,6 +386,32 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherMonthData(sTender, completeData, month, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getValidStages(tender.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stage = this.ctx.helper._.find(stages, {s_time: month}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._gatherStageData(completeData, tender, stage, hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherIndexData(sTender, completeData, index, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getValidStages(tender.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stage = this.ctx.helper._.find(stages, {order: index}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._gatherStageData(completeData, tender, stage, hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherZoneData(sTender, completeData, zone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getTimeZoneStages(tender, zone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._gatherStagesData(completeData, tender, stages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherIndexZoneData(sTender, completeData, stageZone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getOrderZoneStages(tender, stageZone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._gatherStagesData(completeData, tender, stages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async _gatherFinalData(sTender, completeData, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const stages = await this._getValidStages(tender.id); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -458,6 +496,12 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         case 'ledger': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             await this._gatherLedgerData(tender, completeData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 'stage': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherIndexData(tender, completeData, gsCustom.stage, gsSetting.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 'stage-zone': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherIndexZoneData(tender, completeData, gsCustom.stage_zone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     commonIndex++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -522,6 +566,20 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _getStagesTenderInfo(stages, info) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const helper = this.ctx.helper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const stage of stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                await this.ctx.service.stage.doCheckStage(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                await this.ctx.service.stage.checkStageGatherData(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                info.contract_tp = helper.add(info.contract_tp, stage.contract_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                info.qc_tp = helper.add(info.qc_tp, stage.qc_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                info.yf_tp = helper.add(info.yf_tp, stage.yf_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            info.gather_tp = helper.add(info.contract_tp, info.qc_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async _gatherMonthTenderInfo(sTender, index, month, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const info = await this._getBaseTenderInfo(tender); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -531,31 +589,28 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             this.resultTenderInfo.push(info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        async _gatherZoneTenderInfo(sTender, index, zone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const helper = this.ctx.helper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherOrderTenderInfo(sTender, index, order, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const info = await this._getBaseTenderInfo(tender); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getValidStages(tender.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stage = this.ctx.helper._.find(stages, {order: order}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._getStageTenderInfo(stage, info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.resultTenderInfo.push(info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const times = zone.split(' - '); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (times.length !== 2) throw '选择的汇总周期无效'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const beginTime = moment(times[0], 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const endTime = moment(times[1], 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const stages = await this._getValidStages(tender.id, true); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            for (const stage of stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                const sTime = moment(stage.s_time, 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (sTime.isBetween(beginTime, endTime, null, '[]')) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    await this.ctx.service.stage.doCheckStage(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    await this.ctx.service.stage.checkStageGatherData(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    info.contract_tp = helper.add(info.contract_tp, stage.contract_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    info.qc_tp = helper.add(info.qc_tp, stage.qc_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    info.yf_tp = helper.add(info.yf_tp, stage.yf_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            info.gather_tp = helper.add(info.contract_tp, info.qc_tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherZoneTenderInfo(sTender, index, zone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const info = await this._getBaseTenderInfo(tender); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getTimeZoneStages(tender, zone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._getStagesTenderInfo(stages, info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.resultTenderInfo.push(info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherOrderZoneTenderInfo(sTender, index, stageZone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const info = await this._getBaseTenderInfo(tender); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getOrderZoneStages(tender, stageZone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._getStagesTenderInfo(stages, info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             this.resultTenderInfo.push(info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -615,6 +670,12 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         case 'ledger': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             await this._gatherLedgerTenderInfo(tender, commonIndex); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 'stage': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherOrderTenderInfo(tender, commonIndex, gsCustom.stage, gsSetting.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 'stage-zone': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherOrderZoneTenderInfo(tender, commonIndex, gsCustom.stage_zone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     commonIndex++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -685,6 +746,29 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherStagesPay(completeData, tender, stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const helper = this.ctx.helper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            completeData.id = tender.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            completeData.name = tender.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const stage of stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                await this.ctx.service.stage.doCheckStage(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                const dealPay = await this.ctx.service.stagePay.getStagePays(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                await this._checkStagePayCalc(tender, stage, dealPay); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for (const dp of dealPay) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    dp.end_tp = helper.add(dp.pre_tp, dp.tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    this._gatherPayRecord(dp, function (gatherData, sourceData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        gatherData[completeData.prefix + 'id'] = tender.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        gatherData[completeData.prefix + 'name'] = tender.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        gatherData[completeData.prefix + 'tp'] = helper.add(gatherData[completeData.prefix + 'tp'], sourceData.tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        gatherData['s_' + 'tp'] = helper.add(gatherData['s_' + 'tp'], sourceData.tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async _gatherMonthStagePay(sTender, completeData, month, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const stages = await this._getValidStages(tender.id); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -692,38 +776,23 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             await this._gatherStagePay(completeData, tender, stage, hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        async _gatherZoneStagePay(sTender, completeData, zone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const helper = this.ctx.helper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherOrderStagePay(sTender, completeData, order, hasPre) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            completeData.id = tender.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            completeData.name = tender.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const stages = await this._getValidStages(tender.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stage = this.ctx.helper._.find(stages, {order: order}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._gatherStagePay(completeData, tender, stage, hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const times = zone.split(' - '); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (times.length !== 2) throw '选择的汇总周期无效'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const beginTime = moment(times[0], 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const endTime = moment(times[1], 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherZoneStagePay(sTender, completeData, zone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getTimeZoneStages(tender, zone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._gatherStagesPay(completeData, tender, stages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            for (const stage of stages) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                const sTime = moment(stage.s_time, 'YYYY-MM'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (sTime.isBetween(beginTime, endTime, null, '[]')) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    await this.ctx.service.stage.doCheckStage(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    const dealPay = await this.ctx.service.stagePay.getStagePays(stage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    await this._checkStagePayCalc(tender, stage, dealPay); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    for (const dp of dealPay) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        dp.end_tp = helper.add(dp.pre_tp, dp.tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        this._gatherPayRecord(dp, function (gatherData, sourceData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            gatherData[completeData.prefix + 'id'] = tender.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            gatherData[completeData.prefix + 'name'] = tender.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            gatherData[completeData.prefix + 'tp'] = helper.add(gatherData[completeData.prefix + 'tp'], sourceData.tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            gatherData['s_' + 'tp'] = helper.add(gatherData['s_' + 'tp'], sourceData.tp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async _gatherOrderZoneStagePay(sTender, completeData, stageZone) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tender = await this.ctx.service.tender.getCheckTender(sTender.tid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const stages = await this._getOrderZoneStages(tender, stageZone) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            await this._gatherStagesPay(completeData, tender, stages); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async _gatherFinalStagePay(sTender, completeData, hasPre) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -766,6 +835,12 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         case 'checked-final': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             await this._gatherCheckedFinalStagePay(tender, completeData, gsSetting.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 'stage': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherOrderStagePay(tender, completeData, gsCustom.stage, gsSetting.hasPre); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 'stage-zone': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            await this._gatherOrderZoneStagePay(tender, completeData, gsCustom.stage_zone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     commonIndex++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 |