weapp_measure_controller.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. 'use strict';
  2. const auditConsts = 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 !== auditConsts.stage.status.checked) {
  24. if (s.status === auditConsts.stage.status.checkNoPre) s.status = auditConsts.stage.status.checking;
  25. if (s.status !== auditConsts.stage.status.checkNo) s.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(s.id, s.status, s.times);
  26. if (s.status === auditConsts.stage.status.checked) {
  27. const final_auditor_str = (s.curAuditors[0].audit_type === auditConsts.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 !== auditConsts.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. stage.auditHistory = stage.auditHistory && stage.auditHistory.length && stage.auditHistory[stage.auditHistory.length - 1].reduce((prev, curr, idx) => {
  63. if (idx === 0) {
  64. const reportor = {
  65. audit_id: stage.user.id,
  66. audit_order: 0,
  67. audit_type: 1,
  68. status: stage.status === auditConsts.stage.status.uncheck ? auditConsts.stage.status.uncheck : auditConsts.stage.status.checked,
  69. times: stage.status === auditConsts.stage.status.checkNo ? stage.times - 1 : stage.times,
  70. begin_time: curr.begin_time,
  71. end_time: curr.begin_time,
  72. name: stage.user.name,
  73. company: stage.user.company,
  74. role: stage.user.role,
  75. mobile: '',
  76. opinion: '',
  77. };
  78. prev.push({
  79. name: '原报',
  80. status: reportor.status,
  81. audit_type: reportor.audit_type,
  82. auditors: [reportor],
  83. });
  84. }
  85. prev.push({
  86. name: curr.is_final ? '终审' : `${curr.audit_order}审`,
  87. audit_type: curr.audit_type,
  88. status: curr.status,
  89. auditors: curr.auditors,
  90. });
  91. return prev;
  92. }, []);
  93. if (!stage.final_auditor_str || stage.status !== auditConsts.stage.status.checked) {
  94. if (stage.status === auditConsts.stage.status.checkNoPre) {
  95. stage.status = auditConsts.stage.status.checking;
  96. }
  97. if (stage.status !== auditConsts.stage.status.checkNo) {
  98. stage.curAuditors = await ctx.service.stageAudit.getAuditorsByStatus(stage.id, stage.status, stage.times);
  99. }
  100. if (stage.status === auditConsts.stage.status.checked) {
  101. const final_auditor_str = (stage.curAuditors[0].audit_type === auditConsts.auditType.key.common)
  102. ? `${stage.curAuditors[0].name}${(stage.curAuditors[0].role ? '-' + stage.curAuditors[0].role : '')}`
  103. : ctx.helper.transFormToChinese(stage.curAuditors[0].audit_order) + '审';
  104. await ctx.service.stage.defaultUpdate({ id: stage.id, final_auditor_str });
  105. }
  106. }
  107. stage.tp = ctx.helper.sum([stage.contract_tp, stage.qc_tp, stage.pc_tp]);
  108. stage.pre_tp = ctx.helper.add(stage.pre_contract_tp, stage.pre_qc_tp);
  109. stage.end_tp = ctx.helper.add(stage.pre_tp, stage.tp);
  110. ctx.body = { code: 0, msg: '', data: stage };
  111. } catch (err) {
  112. this.log(err);
  113. ctx.body = { code: -1, msg: err.toString(), data: null };
  114. }
  115. }
  116. async checkAudit(ctx) {
  117. try {
  118. const stageId = ctx.params.stageId;
  119. const stage = await ctx.service.stage.getDataById(stageId);
  120. if (!stage) {
  121. ctx.body = { code: -1, msg: '计量期不存在', data: null };
  122. return;
  123. }
  124. ctx.stage = stage;
  125. await ctx.service.stage.loadStageUser(stage);
  126. await ctx.service.stage.loadPreCheckedStage(stage);
  127. await ctx.service.stage.doCheckStage(stage);
  128. await ctx.service.stage.loadStageAuditViewData(stage);
  129. if (ctx.stage.readOnly) {
  130. ctx.body = { code: -1, msg: '该计量期当前您无权操作', data: null };
  131. return;
  132. }
  133. if (ctx.stage.revising) {
  134. ctx.body = { code: -1, msg: '台账修订中,请勿修改提交期数据', data: null };
  135. return;
  136. }
  137. if (ctx.stage.assist && ctx.stage.assist.confirm) {
  138. ctx.body = { code: -1, msg: '协同数据已确认,如需修改,请撤销上报或重新审批', data: null };
  139. return;
  140. }
  141. if (ctx.stage.status !== auditConsts.stage.status.checking && ctx.stage.status !== auditConsts.stage.status.checkNoPre) {
  142. ctx.body = { code: -1, msg: '当前期数据有误', data: null };
  143. return;
  144. }
  145. if (ctx.stage.curAuditorIds && ctx.stage.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) < 0) {
  146. ctx.body = { code: -1, msg: '您无权进行该操作', data: null };
  147. return;
  148. }
  149. const data = ctx.request.body;
  150. data.checkType = parseInt(data.checkType);
  151. if (!data.checkType || isNaN(data.checkType)) {
  152. ctx.body = { code: -1, msg: '提交数据错误', data: null };
  153. return;
  154. }
  155. await ctx.service.stageAudit.check(ctx.stage.id, data, ctx.stage.times);
  156. ctx.body = { code: 0, msg: '审批成功', data: null };
  157. } catch (err) {
  158. this.log(err);
  159. ctx.body = { code: -1, msg: err.toString() || '提交失败', data: null };
  160. ctx.session.postError = err.toString();
  161. }
  162. }
  163. }
  164. return WeappMeasureController;
  165. };