| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | 
							- 'use strict';
 
- /**
 
-  *
 
-  *
 
-  * @author Mai
 
-  * @date
 
-  * @version
 
-  */
 
- module.exports = app => {
 
-     class SpecPull extends app.BaseService {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx);
 
-             this.tableName = 's2b_spec_msg';
 
-         }
 
-         async tenderNeedMsg(pid, tid, timing) {
 
-             const specProj = await this.db.get('zh_s2b_spec_proj', { id: pid });
 
-             if (!specProj || !specProj.is_push) return false;
 
-             switch (specProj.push_tender_type) {
 
-                 case 1:
 
-                     const filter = specProj.filter_tender ? specProj.filter_tender.split(',') : [];
 
-                     if (filter.indexOf(tid + '') >= 0) return false;
 
-                     break;
 
-                 case 2:
 
-                     const access = specProj.access_tender ? specProj.access_tender.split(',') : [];
 
-                     if (access.indexOf(tid + '') < 0) return false;
 
-                     break;
 
-             }
 
-             const soleTender = await this.db.get('zh_s2b_spec_tender', { id: tid, is_valid: 1 });
 
-             const specPush = await this.db.get('zh_s2b_spec_push', { pid, tid: soleTender ? tid : 0, valid: 1, push_timing: timing });
 
-             return !!specPush;
 
-         }
 
-         async addLedgerMsg(transaction, pid, tender, timing) {
 
-             const needMsg = await this.tenderNeedMsg(pid, tender.id, timing);
 
-             if (!needMsg) return;
 
-             await transaction.insert(this.tableName, { pid, tid: tender.id, timing });
 
-         }
 
-         async addReviseMsg(transaction, pid, revise, timing) {
 
-             const needMsg = await this.tenderNeedMsg(pid, revise.tid, timing);
 
-             if (!needMsg) return;
 
-             await transaction.insert(this.tableName, { pid, tid: revise.tid, rid: revise.id, timing });
 
-         }
 
-         async addStageMsg(transaction, pid, stage, timing) {
 
-             const needMsg = await this.tenderNeedMsg(pid, stage.tid, timing);
 
-             if (!needMsg) return;
 
-             await transaction.insert(this.tableName, { pid, tid: stage.tid, sid: stage.id, timing });
 
-         }
 
-         async addReportMsg(transaction, pid, tender, stage, timing) {
 
-             const needMsg = await this.tenderNeedMsg(pid, stage.tid, timing);
 
-             if (!needMsg) return;
 
-             if (transaction) {
 
-                 await transaction.insert(this.tableName, { pid, tid: tender.id, sid: stage ? stage.id : 0, timing });
 
-             } else {
 
-                 await this.db.insert(this.tableName, { pid, tid: tender.id, sid: stage ? stage.id : 0, timing });
 
-             }
 
-         }
 
-     }
 
-     return SpecPull;
 
- };
 
 
  |