| 
					
				 | 
			
			
				@@ -29,10 +29,11 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number} tid - 标段id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number} sid - 期id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number|Array} lid - 台账节点id(可以为空) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         * @returns {Promise<*>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @return {Promise<*>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getLastestStageData(tid, sid, lid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            let lidSql = '', result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let lidSql = '', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (lid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (lid instanceof Array) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     lidSql = lid.length > 0 ? ' And lid in (' + this.ctx.helper.getInArrStrSqlFilter(lid) + ')' : ''; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -52,9 +53,9 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else if (lid instanceof Array) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -64,7 +65,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number} times - 第几轮 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number} order - 流程 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number|Array} lid - 台账节点id(可以为空) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         * @returns {Promise<*>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @return {Promise<*>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getAuditorStageData(tid, sid, times, order, lid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const lidSql = lid ? ' And Bills.lid in (?)' : ''; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -82,14 +83,15 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else if (lid instanceof Array) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 sqlParam.push(lid.join(', ')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                sqlParam.push(lid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            sqlParam.push(lid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getLastestStageData2(tid, sid, lid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            let lidSql = '', result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let lidSql = '', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (lid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (lid instanceof Array) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     lidSql = lid.length > 0 ? ' And lid in (' + this.ctx.helper.getInArrStrSqlFilter(lid) + ')' : ''; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -109,9 +111,9 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else if (lid instanceof Array) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getStageUsedBills(tid, sid) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -163,9 +165,9 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else if (lid instanceof Array) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return await this.db.queryOne(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getStageBills(tid, sid, lid) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -235,7 +237,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * 前端提交数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Object|Array} data - 提交的数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         * @returns {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @return {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async updateStageData(data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const datas = data instanceof Array ? data : [data]; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -267,7 +269,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param ledgerBills 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param stageBills 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         * @returns {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @return {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @private 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async updateStageBillsQty(transaction, ledgerBills, stageBills, data) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -285,14 +287,14 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 await this._insertStageBillsData(transaction, data, stageBills, ledgerBills); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * 重算 本期计量 数量 (根据部位明细) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number} tid - 标段id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number} id - 需要计算的节点的id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number} lid - 台账id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Object} transaction - 操作所属事务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         * @returns {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @return {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async calc(tid, sid, lid, transaction) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const info = this.ctx.tender.info; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -317,14 +319,14 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (stageBills) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (stageBills.contract_qty === posGather.contract_qty && stageBills.qc_qty === posGather.qc_qty) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (stageBills.times === this.ctx.stage.curTimes && stageBills.order === this.ctx.stage.curOrder) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    posGather.id = stageBills.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    await transaction.update(this.tableName, posGather); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (stageBills.times === this.ctx.stage.curTimes && stageBills.order === this.ctx.stage.curOrder) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        posGather.id = stageBills.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        await transaction.update(this.tableName, posGather); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        await this._insertStageBillsData(transaction, posGather, stageBills, ledgerBills); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    await this._insertStageBillsData(transaction, posGather, stageBills, ledgerBills); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 await this._insertStageBillsData(transaction, posGather, stageBills, ledgerBills); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -332,7 +334,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async updateStageBillsCalcType(data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const stageBills = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, data.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            const updateData = {contract_qty: null, contract_tp: null}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const updateData = { contract_qty: null, contract_tp: null }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const transaction = await this.db.beginTransaction(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -354,7 +356,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const bills = await this.ctx.service.ledger.getDataById(data.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const curStageData = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, [data.id]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return {bills: [bills], curStageData: curStageData}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return { bills: [bills], curStageData }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getSumTotalPrice(stage) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -389,9 +391,9 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getSumTotalPriceGcl(stage, regText) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (regText) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return await this.getSumTotalPriceFilter(stage, 'REGEXP', regText); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return await this.getSumTotalPriceFilter(stage, '<>', this.db.escape('')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return await this.getSumTotalPriceFilter(stage, '<>', this.db.escape('')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getSumTotalPriceNotGcl(stage) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -402,7 +404,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * 多期清单数据整合 (材料调差调用) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {Number} tid - 标段id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {String} stage_id_list - 期id列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         * @returns {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @return {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getStagesData(tid, stage_id_list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let stage_id_listSql = ''; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -419,6 +421,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 stage_id_listSql + ' GROUP BY `lid`'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const sqlParam = [tid]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             const result = await this.db.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            console.log('result', result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -428,7 +431,7 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {String} stage_id_list - 期id列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {String} lid - 台账id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          * @param {String} xid - 项目节id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         * @returns {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         * @return {Promise<void>} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         async getGatherQtyByMaterial(tid, stage_id_list, lid) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             stage_id_list = stage_id_list !== null ? stage_id_list.split(',') : []; 
			 |