weapp_measure_controller.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 'use strict';
  2. const audit = require('../const/audit');
  3. module.exports = app => {
  4. class WeappMeasureController extends app.BaseController {
  5. async stage(ctx) {
  6. try {
  7. const tenderId = ctx.params.id;
  8. const tender = await this.ctx.service.tender.getDataById(tenderId);
  9. if (!tender) {
  10. ctx.body = { code: -1, msg: '标段不存在', data: null };
  11. return;
  12. }
  13. const renderData = {
  14. tender: tender.data
  15. };
  16. tender.info = await ctx.service.tenderInfo.getTenderInfo(tenderId);
  17. ctx.tender = tender;
  18. if (!ctx.tender.isTourist) {
  19. ctx.tender.isTourist = false; // 设置默认值
  20. }
  21. renderData.stages = await ctx.service.stage.getValidStages(tenderId, this.ctx.session.sessionUser.is_admin);
  22. for (const s of renderData.stages) {
  23. if (!s.final_auditor_str || s.status !== audit.stage.status.checked) {
  24. if (s.status === audit.stage.status.checkNoPre) s.status = audit.stage.status.checking;
  25. if (s.status !== audit.stage.status.checkNo) s.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(s.id, s.status, s.times);
  26. if (s.status === audit.stage.status.checked) {
  27. const final_auditor_str = (s.curAuditors[0].audit_type === audit.auditType.key.common)
  28. ? `${s.curAuditors[0].name}${(s.curAuditors[0].role ? '-' + s.curAuditors[0].role : '')}`
  29. : ctx.helper.transFormToChinese(s.curAuditors[0].audit_order) + '审';
  30. await ctx.service.stage.defaultUpdate({ id: s.id, final_auditor_str });
  31. }
  32. }
  33. }
  34. renderData.unCompleteStageCount = renderData.stages.filter(s => {
  35. return s.status !== audit.stage.status.checked;
  36. }).length;
  37. ctx.body = { code: 0, msg: '', data: renderData };
  38. } catch (err) {
  39. this.log(err);
  40. ctx.body = { code: 1, msg: err.toString(), data: null };
  41. }
  42. }
  43. async detail(ctx) {
  44. try {
  45. const stageId = ctx.params.stageId;
  46. const stage = await ctx.service.stage.getDataById(stageId);
  47. if (!stage) {
  48. ctx.body = { code: -1, msg: '计量期不存在', data: null };
  49. return;
  50. }
  51. const tender = await ctx.service.tender.getDataById(stage.tid);
  52. if (!tender) {
  53. ctx.body = { code: -1, msg: '标段不存在', data: null };
  54. return;
  55. }
  56. ctx.tender = tender;
  57. if (!ctx.tender.isTourist) {
  58. ctx.tender.isTourist = false;
  59. }
  60. await ctx.service.stage.loadStageUser(stage);
  61. await ctx.service.stage.loadStageAuditViewData(stage);
  62. if (!stage.final_auditor_str || stage.status !== audit.stage.status.checked) {
  63. if (stage.status === audit.stage.status.checkNoPre) {
  64. stage.status = audit.stage.status.checking;
  65. }
  66. if (stage.status !== audit.stage.status.checkNo) {
  67. stage.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(stage.id, stage.status, stage.times);
  68. }
  69. if (stage.status === audit.stage.status.checked) {
  70. const final_auditor_str = (stage.curAuditors[0].audit_type === audit.auditType.key.common)
  71. ? `${stage.curAuditors[0].name}${(stage.curAuditors[0].role ? '-' + stage.curAuditors[0].role : '')}`
  72. : ctx.helper.transFormToChinese(stage.curAuditors[0].audit_order) + '审';
  73. await ctx.service.stage.defaultUpdate({ id: stage.id, final_auditor_str });
  74. }
  75. }
  76. stage.tp = ctx.helper.sum([stage.contract_tp, stage.qc_tp, stage.pc_tp]);
  77. stage.pre_tp = ctx.helper.add(stage.pre_contract_tp, stage.pre_qc_tp);
  78. stage.end_tp = ctx.helper.add(stage.pre_tp, stage.tp);
  79. ctx.body = { code: 0, msg: '', data: stage };
  80. } catch (err) {
  81. this.log(err);
  82. ctx.body = { code: -1, msg: err.toString(), data: null };
  83. }
  84. }
  85. async checkAudit(ctx) {
  86. try {
  87. const stageId = ctx.params.stageId;
  88. const stage = await ctx.service.stage.getDataById(stageId);
  89. if (!stage) {
  90. ctx.body = { code: -1, msg: '计量期不存在', data: null };
  91. return;
  92. }
  93. ctx.stage = stage;
  94. await ctx.service.stage.loadStageUser(stage);
  95. await ctx.service.stage.loadPreCheckedStage(stage);
  96. await ctx.service.stage.doCheckStage(stage);
  97. await ctx.service.stage.loadStageAuditViewData(stage);
  98. if (ctx.stage.readOnly) {
  99. ctx.body = { code: -1, msg: '该计量期当前您无权操作', data: null };
  100. return;
  101. }
  102. if (ctx.stage.revising) {
  103. ctx.body = { code: -1, msg: '台账修订中,请勿修改提交期数据', data: null };
  104. return;
  105. }
  106. if (ctx.stage.assist && ctx.stage.assist.confirm) {
  107. ctx.body = { code: -1, msg: '协同数据已确认,如需修改,请撤销上报或重新审批', data: null };
  108. return;
  109. }
  110. if (ctx.stage.status !== audit.stage.status.checking && ctx.stage.status !== audit.stage.status.checkNoPre) {
  111. ctx.body = { code: -1, msg: '当前期数据有误', data: null };
  112. return;
  113. }
  114. if (ctx.stage.curAuditorIds && ctx.stage.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) < 0) {
  115. ctx.body = { code: -1, msg: '您无权进行该操作', data: null };
  116. return;
  117. }
  118. const data = ctx.request.body;
  119. data.checkType = parseInt(data.checkType);
  120. if (!data.checkType || isNaN(data.checkType)) {
  121. ctx.body = { code: -1, msg: '提交数据错误', data: null };
  122. return;
  123. }
  124. await ctx.service.stageAudit.check(ctx.stage.id, data, ctx.stage.times);
  125. ctx.body = { code: 0, msg: '审批成功', data: null };
  126. } catch (err) {
  127. this.log(err);
  128. ctx.body = { code: -1, msg: err.toString() || '提交失败', data: null };
  129. ctx.session.postError = err.toString();
  130. }
  131. }
  132. }
  133. return WeappMeasureController;
  134. };