| 
					
				 | 
			
			
				@@ -13,6 +13,7 @@ const PayCalculator = require('../lib/pay_calc'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const auditConst = require('../const/audit'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const payConst = require('../const/deal_pay'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const materialConst = require('../const/material'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const moment = require('moment'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -766,6 +767,56 @@ module.exports = app => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return this.resultDealBills; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async getMaterial(tender_id, material_order, memFieldKeys) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return await this.ctx.service.material.getValidMaterials(tender_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        _completeMaterialGl(materialGl) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const tTypeStr = [], mTypeStr = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const t of materialConst.t_type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                tTypeStr[t.value] = t.text; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const m of materialConst.m_type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                mTypeStr[m.value] = m.text; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (const gl of materialGl) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                gl.tp = this.ctx.helper.mul(gl.quantity, gl.m_spread); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                gl.t_type_str = tTypeStr[gl.t_type]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                gl.m_type_str = tTypeStr[gl.m_type]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        async getMaterialGl(tender_id, material_order, memFieldKeys) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            const materials = await this.ctx.service.material.getAllDataByCondition({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                where: {tid: tender_id}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                orders: [['order', 'desc']], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (materials.length > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                let result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (materials[0].order === material_order) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    result = await this.ctx.service.materialBills.getAllDataByCondition({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        where: {tid: tender_id} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const material = this.ctx.helper.find(materials, {order: material_order}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (!material) return []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const sql = 'SELECT m.id, m.tid, m.mid, m.t_type, m.code, m.name, m.unit, m.spec, m.m_type,' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        '    m.base_price, m.base_times, m.remark, m.in_time,' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        '    mh.quantity, mh.expr, mh.msg_tp, mh.msg_times, mh.msg_spread, mh.m_up_risk, mh.m_down_risk, mh.m_spread' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        '  FROM ' + this.ctx.service.materialBills.tableName + ' m' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        '  LEFT JOIN ' + this.ctx.service.materialBillsHistory.tableName + ' mh' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        '  ON m.id = mh.mb_id' + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        '  WHERE mh.mid = ?'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    const sqlParam = [material.id]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    result = this.ctx.app.mysql.query(sql, sqlParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                this._completeMaterialGl(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     return RptGatherMemory; 
			 |