spec_msg.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class SpecPull extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 's2b_spec_msg';
  20. }
  21. async tenderNeedMsg(pid, tid, timing) {
  22. const specProj = await this.db.get('zh_s2b_spec_proj', { id: pid });
  23. if (!specProj || !specProj.is_push) return false;
  24. switch (specProj.push_tender_type) {
  25. case 1:
  26. const filter = specProj.filter_tender ? specProj.filter_tender.split(',') : [];
  27. if (filter.indexOf(tid + '') >= 0) return false;
  28. break;
  29. case 2:
  30. const access = specProj.access_tender ? specProj.access_tender.split(',') : [];
  31. if (access.indexOf(tid + '') < 0) return false;
  32. break;
  33. }
  34. const soleTender = await this.db.get('zh_s2b_spec_tender', { id: tid, is_valid: 1 });
  35. const specPush = await this.db.get('zh_s2b_spec_push', { pid, tid: soleTender ? tid : 0, valid: 1, push_timing: timing });
  36. return !!specPush;
  37. }
  38. async addLedgerMsg(transaction, pid, tender, timing) {
  39. const needMsg = await this.tenderNeedMsg(pid, tender.id, timing);
  40. if (!needMsg) return;
  41. await transaction.insert(this.tableName, { pid, tid: tender.id, timing });
  42. }
  43. async addReviseMsg(transaction, pid, revise, timing) {
  44. const needMsg = await this.tenderNeedMsg(pid, revise.tid, timing);
  45. if (!needMsg) return;
  46. await transaction.insert(this.tableName, { pid, tid: revise.tid, rid: revise.id, timing });
  47. }
  48. async addStageMsg(transaction, pid, stage, timing) {
  49. const needMsg = await this.tenderNeedMsg(pid, stage.tid, timing);
  50. if (!needMsg) return;
  51. await transaction.insert(this.tableName, { pid, tid: stage.tid, sid: stage.id, timing });
  52. }
  53. async addReportMsg(transaction, pid, tender, stage, timing) {
  54. const needMsg = await this.tenderNeedMsg(pid, stage.tid, timing);
  55. if (!needMsg) return;
  56. if (transaction) {
  57. await transaction.insert(this.tableName, { pid, tid: tender.id, sid: stage ? stage.id : 0, timing });
  58. } else {
  59. await this.db.insert(this.tableName, { pid, tid: tender.id, sid: stage ? stage.id : 0, timing });
  60. }
  61. }
  62. }
  63. return SpecPull;
  64. };