stage.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. 'use strict';
  2. /**
  3. * 期计量 数据模型
  4. *
  5. * @author Mai
  6. * @date 2018/8/13
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').stage;
  10. const payConst = require('../const/deal_pay.js');
  11. const roleRelSvr = require('./role_rpt_rel');
  12. const fs = require('fs');
  13. const path = require('path');
  14. const _ = require('lodash');
  15. module.exports = app => {
  16. class Stage extends app.BaseService {
  17. /**
  18. * 构造函数
  19. *
  20. * @param {Object} ctx - egg全局变量
  21. * @return {void}
  22. */
  23. constructor(ctx) {
  24. super(ctx);
  25. this.tableName = 'stage';
  26. }
  27. /**
  28. * 根据id查找数据
  29. *
  30. * @param {Number} id - 数据库中的id
  31. * @return {Object} - 返回单条数据
  32. */
  33. async getDataById(id) {
  34. const result = await this.db.get(this.tableName, { id });
  35. if (result)
  36. result.tp_history = result.tp_history ? JSON.parse(result.tp_history) : [];
  37. return result;
  38. }
  39. /**
  40. * 根据条件查找单条数据
  41. *
  42. * @param {Object} condition - 筛选条件
  43. * @return {Object} - 返回单条数据
  44. */
  45. async getDataByCondition(condition) {
  46. const result = await this.db.get(this.tableName, condition);
  47. if (result)
  48. result.tp_history = result.tp_history ? JSON.parse(result.tp_history) : [];
  49. return result;
  50. }
  51. /**
  52. * 根据条件查找列表数据
  53. *
  54. * @param {Object} condition - 筛选条件
  55. * @return {Array} - 返回数据
  56. */
  57. async getAllDataByCondition(condition) {
  58. const result = await this.db.select(this.tableName, condition);
  59. for (const r of result) {
  60. r.tp_history = r.tp_history ? JSON.parse(r.tp_history) : [];
  61. }
  62. return result;
  63. }
  64. async doCheckStage(stage) {
  65. const status = auditConst.status;
  66. stage.auditors = await this.ctx.service.stageAudit.getAuditors(stage.id, stage.times);
  67. stage.curAuditor = await this.ctx.service.stageAudit.getCurAuditor(stage.id, stage.times);
  68. const accountId = this.ctx.session.sessionUser.accountId, auditorIds = this._.map(stage.auditors, 'aid'), shareIds = [];
  69. const permission = this.ctx.session.sessionUser.permission;
  70. if (accountId === stage.user_id) { // 原报
  71. if (stage.curAuditor) {
  72. stage.readOnly = stage.curAuditor.aid !== accountId;
  73. } else {
  74. stage.readOnly = stage.status !== status.uncheck && stage.status !== status.checkNo;
  75. }
  76. stage.curTimes = stage.times;
  77. if (stage.status === status.uncheck || stage.status === status.checkNo) {
  78. stage.curOrder = 0;
  79. } else if (stage.status === status.checked) {
  80. stage.curOrder = this._.max(this._.map(stage.auditors, 'order'));
  81. } else {
  82. stage.curOrder = stage.curAuditor.aid === accountId ? stage.curAuditor.order : stage.curAuditor.order - 1;
  83. }
  84. } else if (auditorIds.indexOf(accountId) !== -1) { // 审批人
  85. if (stage.status === status.uncheck) {
  86. throw '您无权查看该数据';
  87. }
  88. stage.curTimes = stage.status === status.checkNo ? stage.times - 1 : stage.times;
  89. if (stage.status === status.checked) {
  90. stage.curOrder = this._.max(this._.map(stage.auditors, 'order'));
  91. } else if (stage.status === status.checkNo) {
  92. const audit = await this.service.stageAudit.getDataByCondition({
  93. sid: stage.id, times: stage.times - 1, status: status.checkNo
  94. });
  95. stage.curOrder = audit.order;
  96. } else {
  97. stage.curOrder = accountId === stage.curAuditor.aid ? stage.curAuditor.order : stage.curAuditor.order - 1;
  98. }
  99. stage.readOnly = (stage.status !== status.checking && stage.status !== status.checkNoPre) || accountId !== stage.curAuditor.aid;
  100. } else if (shareIds.indexOf(accountId) !== -1 || (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1)) { // 分享人
  101. if (stage.status === status.uncheck) {
  102. throw '您无权查看该数据';
  103. }
  104. stage.readOnly = true;
  105. stage.curTimes = stage.status === status.checkNo ? stage.times - 1 : stage.times;
  106. if (stage.status === status.checkNo) {
  107. const audit = await this.service.stageAudit.getDataByCondition({
  108. sid: stage.id, times: stage.times - 1, status: status.checkNo,
  109. });
  110. stage.curOrder = audit.order;
  111. } else {
  112. stage.curOrder = stage.status === status.checked ? this._.max(this._.map(stage.auditors, 'order')) : stage.curAuditor.order - 1;
  113. }
  114. }
  115. let time = stage.readOnly ? stage.cache_time_r : stage.cache_time_l;
  116. if (!time) {
  117. time = stage.in_time ? stage.in_time : new Date();
  118. }
  119. stage.cacheTime = time.getTime();//this.ctx.stage.readOnly ? (this.ctx.stage.cache_time_r).getTime(): (this.ctx.stage.cache_time_l).getTime();
  120. return stage;
  121. }
  122. async checkStage(sid) {
  123. if (!this.ctx.stage) {
  124. const stage = await this.ctx.service.stage.getDataById(sid);
  125. await this.doCheckStage(stage);
  126. this.ctx.stage = stage;
  127. }
  128. }
  129. /**
  130. * 获取 最新一期 期计量
  131. * @param tenderId
  132. * @param includeUnCheck
  133. * @returns {Promise<*>}
  134. */
  135. async getLastestStage(tenderId, includeUnCheck = false) {
  136. this.initSqlBuilder();
  137. this.sqlBuilder.setAndWhere('tid', {
  138. value: tenderId,
  139. operate: '=',
  140. });
  141. if (!includeUnCheck) {
  142. this.sqlBuilder.setAndWhere('status', {
  143. value: auditConst.status.uncheck,
  144. operate: '!=',
  145. });
  146. }
  147. this.sqlBuilder.orderBy = [['order', 'desc']];
  148. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  149. const stage = await this.db.queryOne(sql, sqlParam);
  150. if (stage) stage.tp_history = stage.tp_history ? JSON.parse(stage.tp_history) : [];
  151. return stage;
  152. }
  153. /**
  154. * 获取 最新一期 审批完成的 期计量
  155. * @param tenderId
  156. * @returns {Promise<*>}
  157. */
  158. async getLastestCompleteStage(tenderId) {
  159. this.initSqlBuilder();
  160. this.sqlBuilder.setAndWhere('tid', {
  161. value: tenderId,
  162. operate: '=',
  163. });
  164. this.sqlBuilder.setAndWhere('status', {
  165. value: auditConst.status.checked,
  166. operate: '=',
  167. });
  168. this.sqlBuilder.orderBy = [['order', 'desc']];
  169. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  170. const stage = await this.db.queryOne(sql, sqlParam);
  171. if (stage) stage.tp_history = stage.tp_history ? JSON.parse(stage.tp_history) : [];
  172. return stage;
  173. }
  174. /**
  175. * 获取标段下的期列表(报表选择用,只需要一些key信息,不需要计算详细数据,也懒得一个个字段写了,用*来处理)
  176. * @param tenderId
  177. * @returns {Promise<void>}
  178. */
  179. async getValidStagesShort(tenderId) {
  180. const sql = 'select * from zh_stage where tid = ? order by zh_stage.order';
  181. const sqlParam = [tenderId];
  182. return await this.db.query(sql, sqlParam);
  183. }
  184. /**
  185. * 获取某一期信息(报表用)
  186. * @param stageId
  187. * @returns {Promise<void>}
  188. */
  189. async getStageById(stageId) {
  190. const sql = 'select * from zh_stage where id = ? order by zh_stage.order';
  191. const sqlParam = [stageId];
  192. return await this.db.query(sql, sqlParam);
  193. }
  194. async checkStageGatherData(stage) {
  195. // 最新一期计量(未审批完成),当前操作人的期详细数据,应实时计算
  196. if (stage.status !== auditConst.status.checked && stage.check_calc) {
  197. const curAuditor = await this.ctx.service.stageAudit.getCurAuditor(stage.id, stage.times);
  198. const isActive = curAuditor ? curAuditor.aid === this.ctx.session.sessionUser.accountId : stage.user_id === this.ctx.session.sessionUser.accountId;
  199. stage.curTimes = stage.status === auditConst.status.checkNo ? stage.times - 1 : stage.times;
  200. stage.curOrder = curAuditor ? curAuditor.order : 0;
  201. if (isActive) {
  202. const tpData = await this.ctx.service.stageBills.getSumTotalPrice(stage);
  203. stage.contract_tp = tpData.contract_tp;
  204. stage.qc_tp = tpData.qc_tp;
  205. const tp = await this.ctx.service.stagePay.getSpecialTotalPrice(stage);
  206. stage.yf_tp = tp.yf;
  207. stage.sf_tp = tp.sf;
  208. }
  209. }
  210. }
  211. /**
  212. * 获取标段下的全部计量期,按倒序
  213. * @param tenderId
  214. * @returns {Promise<void>}
  215. */
  216. async getValidStages(tenderId) {
  217. const stages = await this.db.select(this.tableName, {
  218. where: { tid: tenderId },
  219. orders: [['order', 'desc']],
  220. });
  221. for (const s of stages) {
  222. s.tp = this.ctx.helper.add(s.contract_tp, s.qc_tp);
  223. s.pre_tp = this.ctx.helper.add(s.pre_contract_tp, s.pre_qc_tp);
  224. s.end_tp = this.ctx.helper.add(s.pre_tp, s.tp);
  225. s.tp_history = s.tp_history ? JSON.parse(s.tp_history) : [];
  226. }
  227. if (stages.length !== 0) {
  228. const lastStage = stages[stages.length - 1];
  229. if (lastStage.status === auditConst.status.uncheck && lastStage.user_id !== this.ctx.session.sessionUser.accountId) {
  230. stages.splice(stages.length - 1, 1);
  231. }
  232. }
  233. // 最新一期计量(未审批完成),当前操作人的期详细数据,应实时计算
  234. if (stages.length === 0) return stages;
  235. if (stages[0].status !== auditConst.status.checked) {
  236. const stage = stages[0];
  237. await this.doCheckStage(stage);
  238. if (!stage.readOnly) {
  239. const tpData = await this.ctx.service.stageBills.getSumTotalPrice(stage);
  240. stage.contract_tp = tpData.contract_tp;
  241. stage.qc_tp = tpData.qc_tp;
  242. const tp = await this.ctx.service.stagePay.getSpecialTotalPrice(stage);
  243. stage.yf_tp = tp.yf;
  244. stage.sf_tp = tp.sf;
  245. stage.tp = this.ctx.helper.add(stage.contract_tp, stage.qc_tp);
  246. stage.end_tp = this.ctx.helper.add(stage.pre_tp, stage.tp);
  247. } else {
  248. const his = this.ctx.helper._.find(stage.tp_history, {times: stage.curTimes, order: stage.curOrder});
  249. if (his) {
  250. stage.contract_tp = his.contract_tp;
  251. stage.qc_tp = his.qc_tp;
  252. stage.yf_tp = his.yf_tp;
  253. stage.sf_tp = his.sf_tp;
  254. stage.tp = this.ctx.helper.add(stage.contract_tp, stage.qc_tp);
  255. stage.end_tp = this.ctx.helper.add(stage.pre_tp, stage.tp);
  256. }
  257. }
  258. }
  259. for (const s of stages) {
  260. if (s.yf_tp && s.sf_tp === 0) {
  261. const sf = await this.ctx.service.stagePay.getHistorySf(s);
  262. if (sf && s.readOnly) {
  263. await this.ctx.service.stage.update({ sf_tp: sf.tp, pre_sf_tp: sf.pre_tp}, {id: s.id});
  264. }
  265. s.sf_tp = sf.tp;
  266. }
  267. }
  268. return stages;
  269. }
  270. /**
  271. *
  272. * @param tenderId - 标段id
  273. * @param date - 计量年月
  274. * @param period - 开始-截止日期
  275. * @returns {Promise<void>}
  276. */
  277. async addStage(tenderId, date, period) {
  278. const stages = await this.getAllDataByCondition({
  279. where: { tid: tenderId },
  280. order: ['order'],
  281. });
  282. const preStage = stages[stages.length - 1];
  283. if (stages.length > 0 && stages[stages.length - 1].status !== auditConst.status.checked) {
  284. throw '上一期未审批通过,请等待上一期审批通过后,再新增数据';
  285. }
  286. const order = stages.length + 1;
  287. const newStage = {
  288. sid: this.uuid.v4(),
  289. tid: tenderId,
  290. order,
  291. in_time: new Date(),
  292. s_time: date,
  293. period,
  294. times: 1,
  295. status: auditConst.status.uncheck,
  296. user_id: this.ctx.session.sessionUser.accountId,
  297. check_calc: false,
  298. };
  299. newStage.cache_time_l = newStage.in_time;
  300. newStage.cache_time_r = newStage.in_time;
  301. if (preStage) {
  302. newStage.im_type = preStage.im_type;
  303. newStage.im_pre = preStage.im_pre;
  304. newStage.im_gather = preStage.im_gather;
  305. newStage.im_gather_node = preStage.im_gather_node;
  306. newStage.pre_contract_tp = this.ctx.helper.add(preStage.pre_contract_tp, preStage.contract_tp);
  307. newStage.pre_qc_tp = this.ctx.helper.add(preStage.pre_qc_tp, preStage.qc_tp);
  308. newStage.pre_yf_tp = this.ctx.helper.add(preStage.pre_yf_tp, preStage.yf_tp);
  309. }
  310. const transaction = await this.db.beginTransaction();
  311. try {
  312. // 新增期记录
  313. const result = await transaction.insert(this.tableName, newStage);
  314. if (result.affectedRows === 1) {
  315. newStage.id = result.insertId;
  316. } else {
  317. throw '新增期数据失败';
  318. }
  319. // 存在上一期时,复制上一期审批流程
  320. if (preStage) {
  321. const auditResult = await this.ctx.service.stageAudit.copyPreStageAuditors(transaction, preStage, newStage);
  322. if (!auditResult) {
  323. throw '复制上一期审批流程失败';
  324. }
  325. }
  326. // 新增期合同支付数据
  327. const dealResult = await this.ctx.service.stagePay.addInitialStageData(newStage, transaction);
  328. if (!dealResult) {
  329. throw '新增期合同支付数据失败';
  330. }
  331. // 新增期其他台账数据
  332. if (preStage) {
  333. const jgclResult = await this.ctx.service.stageJgcl.addInitialStageData(newStage, preStage, transaction);
  334. if (!jgclResult) throw '初始化甲供材料数据失败';
  335. const otherResult = await this.ctx.service.stageOther.addInitialStageData(newStage, preStage, transaction);
  336. if (!otherResult) throw '初始化其他台账数据失败';
  337. }
  338. // 新增期拷贝报表相关配置/签名角色 等
  339. if (preStage) {
  340. const rptResult = await this.ctx.service.rptCustomDefine.addInitialStageData(newStage, preStage, transaction);
  341. await this.ctx.service.roleRptRel.addInitialStageData(tenderId, newStage, preStage);
  342. }
  343. await transaction.commit();
  344. return newStage;
  345. } catch (err) {
  346. await transaction.rollback();
  347. throw err;
  348. }
  349. }
  350. /**
  351. * 编辑计量期
  352. *
  353. * @param {Number} tenderId - 标段Id
  354. * @param {Number} order - 第N期
  355. * @param {String} date - 计量年月
  356. * @param {String} period - 开始-截止时间
  357. * @returns {Promise<void>}
  358. */
  359. async saveStage(tenderId, order, date, period) {
  360. await this.db.update(this.tableName, {
  361. s_time: date,
  362. period,
  363. }, { where: { tid: tenderId, order } });
  364. }
  365. /**
  366. * 设置 中间计量 生成规则,并生成数据
  367. * @param {Number} tenderId - 标段id
  368. * @param {Number} order - 期序号
  369. * @param {Number} data - 中间计量生成规则
  370. * @returns {Promise<void>}
  371. */
  372. async buildDetailData(tenderId, order, data) {
  373. const conn = await this.db.beginTransaction();
  374. try {
  375. await conn.update(this.tableName, { im_type: data.im_type, im_pre: data.im_pre }, { where: { tid: tenderId, order } });
  376. // to do 生成中间计量数据
  377. await conn.commit();
  378. } catch (err) {
  379. await conn.rollback();
  380. throw err;
  381. }
  382. }
  383. /**
  384. * 获取 当期的 计算基数
  385. * @returns {Promise<any>}
  386. */
  387. async getStagePayCalcBase(stage, tenderInfo) {
  388. const calcBase = JSON.parse(JSON.stringify(payConst.calcBase));
  389. const param = tenderInfo.deal_param;
  390. for (const cb of calcBase) {
  391. const sum = await this.ctx.service.stageBills.getSumTotalPrice(stage);
  392. switch (cb.code) {
  393. case 'htj':
  394. cb.value = param.contractPrice;
  395. break;
  396. case 'zlje':
  397. cb.value = param.zanLiePrice;
  398. break;
  399. case 'htjszl':
  400. cb.value = this.ctx.helper.sub(param.contractPrice, param.zanLiePrice);
  401. break;
  402. case 'kgyfk':
  403. cb.value = param.startAdvance;
  404. break;
  405. case 'clyfk':
  406. cb.value = param.materialAdvance;
  407. break;
  408. case 'bqwc':
  409. cb.value = this.ctx.helper.add(sum.contract_tp, sum.qc_tp);
  410. break;
  411. case 'bqht':
  412. cb.value = sum.contract_tp;
  413. break;
  414. case 'bqbg':
  415. cb.value = sum.qc_tp;
  416. break;
  417. case 'ybbqwc':
  418. const sumGcl = await this.ctx.service.stageBills.getSumTotalPriceGcl(stage, '^1[0-9]{2}-');
  419. cb.value = this.ctx.helper.add(sumGcl.contract_tp, sumGcl.qc_tp);
  420. break;
  421. default:
  422. cb.value = 0;
  423. }
  424. }
  425. return calcBase;
  426. }
  427. async updateCheckCalcFlag(stage, check) {
  428. const result = await this.db.update(this.tableName, {id: stage.id, check_calc: check});
  429. return result.affectedRows === 1;
  430. }
  431. async updateCacheTime(sid) {
  432. const result = await this.db.update(this.tableName, {id: sid, cache_time_l: new Date()});
  433. return result.affectedRows === 1;
  434. }
  435. /**
  436. * 删除计量期
  437. *
  438. * @param {Number} id - 期Id
  439. * @returns {Promise<void>}
  440. */
  441. async deleteStage(id) {
  442. const transaction = await this.db.beginTransaction();
  443. try {
  444. const stageInfo = await transaction.getDataById(id);
  445. await transaction.delete(this.tableName, { id });
  446. await transaction.delete(this.ctx.service.stageAudit.tableName, { sid: id });
  447. await transaction.delete(this.ctx.service.stageBills.tableName, { sid: id });
  448. await transaction.delete(this.ctx.service.stageChange.tableName, { sid: id });
  449. await transaction.delete(this.ctx.service.stagePos.tableName, { sid: id });
  450. await transaction.delete(this.ctx.service.stageDetail.tableName, { sid: id });
  451. await transaction.delete(this.ctx.service.stagePosFinal.tableName, { sid: id });
  452. await transaction.delete(this.ctx.service.stageBillsFinal.tableName, { sid: id });
  453. // 删除计量合同支付附件
  454. const payList = await this.ctx.service.stagePay.getAllDataByCondition({ where: { sid: id } });
  455. if (payList) {
  456. for (const pt of payList) {
  457. if (pt.attachment !== null && pt.attachment !== '') {
  458. const payAttList = JSON.parse(pt.attachment);
  459. for (const pat of payAttList) {
  460. if (fs.existsSync(path.join(this.app.baseDir, pat.filepath))) {
  461. await fs.unlinkSync(path.join(this.app.baseDir, pat.filepath));
  462. }
  463. }
  464. }
  465. }
  466. }
  467. await transaction.delete(this.ctx.service.stagePay.tableName, { sid: id });
  468. await transaction.delete(this.ctx.service.pay.tableName, { csid: id });
  469. // 删除计量附件文件
  470. const attList = await this.ctx.service.stageAtt.getAllDataByCondition({ where: { tid: stageInfo.tid, sid: stageInfo.order } });
  471. if (attList.length !== 0) {
  472. for (const att of attList) {
  473. if (fs.existsSync(path.join(this.app.baseDir, att.filepath))) {
  474. await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
  475. }
  476. }
  477. }
  478. await transaction.delete(this.ctx.service.stageAtt.tableName, { tid: stageInfo.tid, sid: stageInfo.order });
  479. // 其他台账
  480. await transaction.delete(this.ctx.service.stageJgcl.tableName, { sid: id });
  481. const bonus = await this.ctx.service.stageBonus.getStageData(id);
  482. if (bonus && bonus.length > 0) {
  483. for (const b of bonus) {
  484. for (const f of b.proof_file) {
  485. if (fs.existsSync(path.join(this.app.baseDir, f.filepath))) {
  486. await fs.unlinkSync(path.join(this.app.baseDir, f.filepath));
  487. }
  488. }
  489. }
  490. }
  491. await transaction.delete(this.ctx.service.stageBonus.tableName, { sid: id });
  492. await transaction.delete(this.ctx.service.stageOther.tableName, { sid: id });
  493. await transaction.commit();
  494. return true;
  495. } catch (err) {
  496. await transaction.rollback();
  497. throw err;
  498. }
  499. }
  500. /**
  501. * 获取 多期的 计算基数 -(材料调差调用)
  502. * @returns {Promise<any>}
  503. */
  504. async getMaterialCalcBase(stage_list, tenderInfo) {
  505. const calcBase = JSON.parse(JSON.stringify(payConst.calcBase));
  506. const param = tenderInfo.deal_param;
  507. const sum = await this.ctx.service.stageBills.getSumTotalPriceByMaterial(stage_list);
  508. for (const cb of calcBase) {
  509. switch (cb.code) {
  510. case 'htj':
  511. cb.value = param.contractPrice;
  512. break;
  513. case 'zlje':
  514. cb.value = param.zanLiePrice;
  515. break;
  516. case 'htjszl':
  517. cb.value = this.ctx.helper.sub(param.contractPrice, param.zanLiePrice);
  518. break;
  519. case 'kgyfk':
  520. cb.value = param.startAdvance;
  521. break;
  522. case 'clyfk':
  523. cb.value = param.materialAdvance;
  524. break;
  525. case 'bqwc':
  526. cb.value = this.ctx.helper.add(sum.contract_tp, sum.qc_tp);
  527. break;
  528. case 'bqht':
  529. cb.value = sum.contract_tp;
  530. break;
  531. case 'bqbg':
  532. cb.value = sum.qc_tp;
  533. break;
  534. case 'ybbqwc':
  535. const sumGcl = await this.ctx.service.stageBills.getSumTotalPriceGclByMaterial(stage_list, '^1[0-9]{2}-');
  536. cb.value = this.ctx.helper.add(sumGcl.contract_tp, sumGcl.qc_tp);
  537. break;
  538. default:
  539. cb.value = 0;
  540. }
  541. }
  542. return calcBase;
  543. }
  544. /**
  545. * 获取必要的stage信息调用curTimes, curOrder, id , times, curAuditor(材料调差)
  546. * @param stage_id_list
  547. * @returns {Promise<void>}
  548. */
  549. async getStageMsgByStageId(stage_id_list) {
  550. const list = [];
  551. stage_id_list = stage_id_list.split(',');
  552. for (const sid of stage_id_list) {
  553. const stage = await this.getDataById(sid);
  554. stage.auditors = await this.service.stageAudit.getAuditors(stage.id, stage.times);
  555. stage.curAuditor = await this.service.stageAudit.getCurAuditor(stage.id, stage.times);
  556. stage.curOrder = _.max(_.map(stage.auditors, 'order'));
  557. stage.curTimes = stage.times;
  558. list.push(stage);
  559. }
  560. return list;
  561. }
  562. }
  563. return Stage;
  564. };