schedule_controller.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/7/2
  7. * @version
  8. */
  9. const moment = require('moment');
  10. const reviseStatus = require('../const/audit').revise.status;
  11. const measureType = require('../const/tender').measureType;
  12. const scheduleConst = require('../const/schedule');
  13. const billsPosConvert = require('../lib/bills_pos_convert');
  14. const _ = require('lodash');
  15. module.exports = app => {
  16. class ScheduleController extends app.BaseController {
  17. async _getSelectedLedgerList(ctx) {
  18. const scheduleLedgerList = await ctx.service.scheduleLedger.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  19. return _.map(scheduleLedgerList, 'ledger_id');
  20. }
  21. async _getLastPlanMonth(ctx) {
  22. const lastMonth = await ctx.service.scheduleMonth.getLastPlanMonth();
  23. return lastMonth && lastMonth[0] && lastMonth[0].yearmonth ? lastMonth[0].yearmonth : null;
  24. }
  25. async _getLastReviseStatus(ctx) {
  26. const lastRevise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
  27. return (lastRevise && lastRevise.status !== reviseStatus.checked) || false;
  28. }
  29. async _checkScheduleCanModify(ctx) {
  30. if (await this._getLastReviseStatus(ctx)) {
  31. throw '台账修订中,请勿修改提交进度数据';
  32. }
  33. if (ctx.tender.schedule_permission !== scheduleConst.permission.edit) {
  34. throw '权限不足,无法修改进度数据';
  35. }
  36. }
  37. async index(ctx) {
  38. try {
  39. const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
  40. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
  41. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
  42. // 汇总并统计前几个计划月总计划额
  43. for (const i in scheduleStage) {
  44. let nowIndex = 0;
  45. let lastIndex = 0;
  46. if (i > 0) {
  47. nowIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i].yearmonth }) + 1;
  48. lastIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i - 1].yearmonth }) + 1;
  49. } else {
  50. nowIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i].yearmonth }) + 1;
  51. }
  52. // 获取新计划月数组
  53. const newSm = scheduleMonth.slice(lastIndex, nowIndex);
  54. scheduleStage[i].plan_tp = _.sumBy(newSm, 'plan_tp');
  55. }
  56. const renderData = {
  57. schedule,
  58. scheduleMonth,
  59. scheduleStage,
  60. tender: ctx.tender.data,
  61. tenderMenu: this.menu.tenderMenu,
  62. planMonth: await this._getLastPlanMonth(ctx),
  63. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  64. preUrl: '/tender/' + ctx.tender.id,
  65. scPermission: scheduleConst.permission,
  66. revising: await this._getLastReviseStatus(ctx),
  67. };
  68. await this.layout('schedule/index.ejs', renderData, 'schedule/modal.ejs');
  69. } catch (err) {
  70. this.log(err);
  71. ctx.redirect(this.menu.menu.dashboard.url);
  72. }
  73. }
  74. async ledger(ctx) {
  75. const tender = ctx.tender;
  76. const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
  77. const scheduleLedgerList = await this._getSelectedLedgerList(ctx);
  78. const allSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  79. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
  80. const hadDataLidList = [];
  81. for (const sl of scheduleLedgerList) {
  82. const info = _.find(allSlmList, function(item) {
  83. return item.lid === sl && ((item.plan_tp !== null && item.plan_tp !== 0) ||
  84. (item.plan_gcl !== null && item.plan_gcl !== 0) ||
  85. (item.sj_tp !== null && item.sj_tp !== 0) ||
  86. (item.sj_gcl !== null && item.sj_gcl !== 0));
  87. });
  88. if (info) {
  89. hadDataLidList.push(info.lid);
  90. }
  91. }
  92. const renderData = {
  93. schedule,
  94. tender: tender.data,
  95. tenderInfo: tender.info,
  96. measureType,
  97. scheduleLedgerList,
  98. hadDataLidList,
  99. scheduleStage,
  100. scPermission: scheduleConst.permission,
  101. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.ledger),
  102. revising: await this._getLastReviseStatus(ctx),
  103. };
  104. await this.layout('schedule/ledger.ejs', renderData, 'schedule/modal.ejs');
  105. }
  106. async plan(ctx) {
  107. const tender = ctx.tender;
  108. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  109. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  110. const renderData = {
  111. tender: tender.data,
  112. tenderInfo: tender.info,
  113. schedule,
  114. scheduleMonth,
  115. planMonth: await this._getLastPlanMonth(ctx),
  116. measureType,
  117. mode: scheduleConst.plan_mode,
  118. scPermission: scheduleConst.permission,
  119. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  120. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.plan),
  121. revising: await this._getLastReviseStatus(ctx),
  122. };
  123. await this.layout('schedule/plan.ejs', renderData, 'schedule/plan_modal.ejs');
  124. }
  125. async stageTp(ctx) {
  126. const tender = ctx.tender;
  127. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  128. const { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData,
  129. scheduleMonth, stageOrderList, scheduleStage, curScheduleStage } = await this._getStageAndPlanData(ctx);
  130. const renderData = {
  131. tender: tender.data,
  132. tenderInfo: tender.info,
  133. schedule,
  134. scheduleMonth,
  135. measureType,
  136. stageOrderList,
  137. scheduleStage,
  138. curScheduleStage,
  139. slmList,
  140. nextSlmList,
  141. endSlmList,
  142. yearSlmList,
  143. curYearStageData,
  144. scPermission: scheduleConst.permission,
  145. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  146. revising: await this._getLastReviseStatus(ctx),
  147. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.stageTp),
  148. };
  149. await this.layout('schedule/stage_tp.ejs', renderData, 'schedule/stage_tp_modal.ejs');
  150. }
  151. async stageGcl(ctx) {
  152. const tender = ctx.tender;
  153. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  154. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  155. // const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
  156. const gclScheduleMonth = _.orderBy(_.filter(scheduleMonth, { stage_gcl_used: 1 }), ['yearmonth'], ['desc']);
  157. const curScheduleMonth = scheduleMonth.length > 0 ? _.maxBy(gclScheduleMonth, 'yearmonth') : null;
  158. const renderData = {
  159. tender: tender.data,
  160. tenderInfo: tender.info,
  161. schedule,
  162. scheduleMonth,
  163. measureType,
  164. // scheduleStage,
  165. curScheduleMonth,
  166. gclScheduleMonth,
  167. scPermission: scheduleConst.permission,
  168. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  169. revising: await this._getLastReviseStatus(ctx),
  170. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.stageGcl),
  171. };
  172. await this.layout('schedule/stage_gcl.ejs', renderData, 'schedule/stage_gcl_modal.ejs');
  173. }
  174. /**
  175. * 获取金额模式下台账数据(Ajax)
  176. *
  177. * @param ctx
  178. * @return {Promise<void>}
  179. */
  180. async loadTpLedgerData(ctx) {
  181. try {
  182. const ledgerData = await this._getStageLedgerData(ctx, ctx.params.order);
  183. const postData = { ledgerData };
  184. const data = JSON.parse(ctx.request.body.data);
  185. if (data.filter && data.filter === 'gcl') {
  186. const { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData } = await this._getStageAndPlanData(ctx);
  187. _.assignIn(postData, { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData });
  188. }
  189. ctx.body = { err: 0, msg: '', data: postData };
  190. } catch (err) {
  191. this.log(err);
  192. ctx.body = { err: 1, msg: err.toString(), data: [] };
  193. }
  194. }
  195. /**
  196. * 获取工程量模式下台账数据(Ajax)
  197. *
  198. * @param ctx
  199. * @return {Promise<void>}
  200. */
  201. async loadGclLedgerData(ctx) {
  202. try {
  203. const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  204. const postData = { ledgerData };
  205. const { slmList, nextSlmList, endSlmList, yearSlmList } = await this._getGclAndPlanData(ctx);
  206. _.assignIn(postData, { slmList, nextSlmList, endSlmList, yearSlmList });
  207. ctx.body = { err: 0, msg: '', data: postData };
  208. } catch (err) {
  209. this.log(err);
  210. ctx.body = { err: 1, msg: err.toString(), data: [] };
  211. }
  212. }
  213. /**
  214. * 获取所有期下台账数据(Ajax)
  215. *
  216. * @param ctx
  217. * @return {Promise<void>}
  218. */
  219. async _getAllStageLedgerData(ctx) {
  220. let ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  221. const stageList = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['order', 'desc']] });
  222. if (stageList.length > 0) {
  223. const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
  224. for (const d of dgnData) {
  225. const l = ctx.app._.find(ledgerData, { id: d.id });
  226. ctx.app._.assignIn(l, d);
  227. }
  228. for (const s of stageList) {
  229. const stageInfo = await ctx.service.stage.getDataByCondition({
  230. tid: ctx.tender.id,
  231. order: s.order,
  232. });
  233. // let preStageData;
  234. // 当前操作人查看最新数据,其他人查看历史数据
  235. const curStageData = await ctx.service.stageBills.getLastestStageData2(ctx.tender.id, stageInfo.id);
  236. // // 查询截止上期数据
  237. // if (stageInfo.order > 1) {
  238. // preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.order - 1);
  239. // } else {
  240. // preStageData = [];
  241. // }
  242. this.ctx.helper.assignRelaData(ledgerData, [
  243. { data: curStageData, fields: ['contract_tp', 'qc_tp'], prefix: s.order + '_', relaId: 'lid' },
  244. // { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: s.order + '_pre_', relaId: 'lid' },
  245. ]);
  246. }
  247. ledgerData = await this._addFinalStageData(ctx, ledgerData);
  248. }
  249. return ledgerData;
  250. }
  251. async _getStageLedgerData(ctx, stageOrder) {
  252. let ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  253. const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
  254. for (const d of dgnData) {
  255. const l = ctx.app._.find(ledgerData, { id: d.id });
  256. ctx.app._.assignIn(l, d);
  257. }
  258. const stageInfo = await ctx.service.stage.getDataByCondition({
  259. tid: ctx.tender.id,
  260. order: stageOrder,
  261. });
  262. let preStageData;
  263. // 当前操作人查看最新数据,其他人查看历史数据
  264. const curStageData = await ctx.service.stageBills.getLastestStageData2(ctx.tender.id, stageInfo.id);
  265. // 查询截止上期数据
  266. if (stageInfo.order > 1) {
  267. preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.order - 1);
  268. } else {
  269. preStageData = [];
  270. }
  271. const pcData = await ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: stageInfo.id } });
  272. this.ctx.helper.assignRelaData(ledgerData, [
  273. { data: curStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid' },
  274. { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_', relaId: 'lid' },
  275. { data: pcData, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp', 'org_price'], prefix: '', relaId: 'lid' },
  276. ]);
  277. // 获取进度最新期的数据
  278. ledgerData = await this._addFinalStageData(ctx, ledgerData);
  279. return ledgerData;
  280. }
  281. /**
  282. * 添加最新一期的进度期下期数据到台账数据中(Ajax)
  283. *
  284. * @param ctx
  285. * @return {Promise<void>}
  286. */
  287. async _addFinalStageData(ctx, ledgerData) {
  288. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['order', 'desc']] });
  289. if (scheduleStage && scheduleStage.length > 0) {
  290. let prefinalStageData;
  291. const finalStageInfo = await ctx.service.stage.getDataByCondition({
  292. tid: ctx.tender.id,
  293. order: scheduleStage[0].order,
  294. });
  295. const finalStageData = await ctx.service.stageBills.getLastestStageData2(ctx.tender.id, finalStageInfo.id);
  296. if (finalStageInfo.order > 1) {
  297. prefinalStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, finalStageInfo.order - 1);
  298. } else {
  299. prefinalStageData = [];
  300. }
  301. this.ctx.helper.assignRelaData(ledgerData, [
  302. { data: finalStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: 'final_', relaId: 'lid' },
  303. { data: prefinalStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_final_', relaId: 'lid' },
  304. ]);
  305. }
  306. return ledgerData;
  307. }
  308. /**
  309. * 获取本期下台账计量和计划数据(Ajax)
  310. *
  311. * @param ctx
  312. * @return {Promise<void>}
  313. */
  314. async _getStageAndPlanData(ctx) {
  315. const tender = ctx.tender;
  316. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  317. const stageOrderList = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 's_time', 'order'], where: { tid: tender.id } });
  318. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'desc']] });
  319. let curScheduleStage = scheduleStage.length > 0 ? _.maxBy(scheduleStage, 'yearmonth') : null;
  320. if (ctx.params.order && scheduleStage.length > 0) {
  321. curScheduleStage = _.find(scheduleStage, { order: parseInt(ctx.params.order) });
  322. }
  323. let slmList = [];
  324. let nextSlmList = [];
  325. let endSlmList = [];
  326. let yearSlmList = [];
  327. let curYearStageData = [];
  328. if (curScheduleStage) {
  329. const newSM = _.sortBy(scheduleMonth, 'yearmonth');
  330. const nowScheduleStage = _.findIndex(newSM, { yearmonth: curScheduleStage.yearmonth });
  331. slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleStage.yearmonth } });
  332. const nextScheduleStage = nowScheduleStage >= 0 && nowScheduleStage + 1 <= newSM.length - 1 ? newSM[nowScheduleStage + 1] : null;
  333. if (nextScheduleStage) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleStage.yearmonth } });
  334. if (nowScheduleStage === 0) {
  335. endSlmList = slmList;
  336. } else if (nowScheduleStage > 0) {
  337. const endYearmonthCollection = _.map(_.take(newSM, nowScheduleStage + 1), 'yearmonth');
  338. endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
  339. }
  340. const yearConllection = _.map(_.filter(newSM, function(item) {
  341. return item.yearmonth.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
  342. }), 'yearmonth');
  343. yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
  344. // 获取本年完成计量数据
  345. const curStage = _.find(stageOrderList, { order: curScheduleStage.order });
  346. const stageList = _.filter(stageOrderList, function(item) {
  347. return item.s_time.indexOf(curStage.s_time.split('-')[0]) !== -1;
  348. });
  349. // const newSS = _.sortBy(scheduleStage, 'yearmonth');
  350. // const stageIdList = _.map(_.filter(stageList, function(item) {
  351. // return _.find(newSS, { order: item.order });
  352. // }), 'id');
  353. const stageIdList = _.map(stageList, 'id');
  354. curYearStageData = await ctx.service.stageBills.getStagesData(tender.id, stageIdList.join(','));
  355. const curYearStagePcData = await ctx.service.stageBillsPc.getStagesData(tender.id, stageIdList.join(','));
  356. for (const cys of curYearStageData) {
  357. const cyspc = ctx.helper._.find(curYearStagePcData, { lid: cys.lid });
  358. if (cyspc) ctx.helper._.assign(cys, cyspc);
  359. }
  360. }
  361. return { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData, scheduleMonth, stageOrderList, scheduleStage, curScheduleStage };
  362. }
  363. /**
  364. * 获取工程量模式汇总下台账的计划数据(Ajax)
  365. *
  366. * @param ctx
  367. * @return {Promise<void>}
  368. */
  369. async _getGclAndPlanData(ctx) {
  370. const tender = ctx.tender;
  371. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  372. let curScheduleMonth = scheduleMonth.length > 0 ? _.maxBy(scheduleMonth, 'order') : null;
  373. const gclScheduleMonth = _.filter(scheduleMonth, { stage_gcl_used: 1 });
  374. if (ctx.params.order && gclScheduleMonth.length > 0) {
  375. curScheduleMonth = _.find(gclScheduleMonth, { id: parseInt(ctx.params.order) });
  376. }
  377. let slmList = [];
  378. let nextSlmList = [];
  379. let endSlmList = [];
  380. let yearSlmList = [];
  381. if (curScheduleMonth) {
  382. const newSM = _.sortBy(scheduleMonth, 'yearmonth');
  383. const nowScheduleMonth = _.findIndex(newSM, { yearmonth: curScheduleMonth.yearmonth });
  384. slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleMonth.yearmonth } });
  385. const nextScheduleMonth = nowScheduleMonth >= 0 && nowScheduleMonth + 1 <= newSM.length - 1 ? newSM[nowScheduleMonth + 1] : null;
  386. if (nextScheduleMonth) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleMonth.yearmonth } });
  387. if (nowScheduleMonth === 0) {
  388. endSlmList = slmList;
  389. } else if (nowScheduleMonth > 0) {
  390. const endYearmonthCollection = _.map(_.take(newSM, nowScheduleMonth + 1), 'yearmonth');
  391. endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
  392. }
  393. const yearConllection = _.map(_.filter(newSM, function(item) {
  394. return item.yearmonth.indexOf(curScheduleMonth.yearmonth.split('-')[0]) !== -1;
  395. }), 'yearmonth');
  396. yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
  397. }
  398. return { slmList, nextSlmList, endSlmList, yearSlmList, scheduleMonth, curScheduleMonth };
  399. }
  400. /**
  401. * 获取台账数据(Ajax)
  402. *
  403. * @param ctx
  404. * @return {Promise<void>}
  405. */
  406. async loadLedgerData(ctx) {
  407. try {
  408. // const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  409. const ledgerData = await this._getAllStageLedgerData(ctx);
  410. // const posData = ctx.tender.data.measure_type === measureType.tz.value
  411. // ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
  412. // const convert = new billsPosConvert(ctx);
  413. // convert.loadData(ledgerData, posData, []);
  414. // const result = await convert.convert();
  415. const scheduleLedgerMonthData = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  416. const scheduleLedgerHistoryData = await ctx.service.scheduleLedgerHistory.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  417. ctx.body = { err: 0, msg: '', data: { bills: ledgerData, slm: scheduleLedgerMonthData, slh: scheduleLedgerHistoryData } };
  418. } catch (err) {
  419. this.log(err);
  420. ctx.body = { err: 1, msg: err.toString(), data: [] };
  421. }
  422. }
  423. /**
  424. * 台账选中提交(Ajax)
  425. *
  426. * @param ctx
  427. * @return {Promise<void>}
  428. */
  429. async saveLedger(ctx) {
  430. try {
  431. await this._checkScheduleCanModify(ctx);
  432. const data = JSON.parse(ctx.request.body.data);
  433. const result = await ctx.service.scheduleLedger.saveLedger(data);
  434. ctx.body = { err: 0, msg: '', data: result };
  435. } catch (err) {
  436. this.log(err);
  437. ctx.body = { err: 1, msg: err.toString(), data: [] };
  438. }
  439. }
  440. /**
  441. * 计划进度计算方式提交(Ajax)
  442. *
  443. * @param ctx
  444. * @return {Promise<void>}
  445. */
  446. async savePlan(ctx) {
  447. try {
  448. await this._checkScheduleCanModify(ctx);
  449. const data = JSON.parse(ctx.request.body.data);
  450. const responseData = {
  451. err: 0,
  452. msg: '',
  453. data: {},
  454. };
  455. switch (data.type) {
  456. case 'mode':
  457. responseData.data = await ctx.service.schedule.saveMode(data.postData);
  458. break;
  459. case 'addmonth':
  460. responseData.data = await ctx.service.scheduleMonth.add(data.postData);
  461. break;
  462. case 'delmonth':
  463. responseData.data = await ctx.service.scheduleMonth.del(data.postData);
  464. break;
  465. case 'ledger_edit':
  466. responseData.data = await ctx.service.scheduleLedgerMonth.save(data.postData);
  467. break;
  468. case 'ledger_paste':
  469. responseData.data = await ctx.service.scheduleLedgerMonth.saveDatas(data.postData);
  470. break;
  471. default: throw '参数有误';
  472. }
  473. ctx.body = responseData;
  474. } catch (err) {
  475. this.log(err);
  476. ctx.body = { err: 1, msg: err.toString(), data: null };
  477. }
  478. }
  479. /**
  480. * 计量进度金额模式计算方式提交(Ajax)
  481. *
  482. * @param ctx
  483. * @return {Promise<void>}
  484. */
  485. async saveStageTp(ctx) {
  486. try {
  487. await this._checkScheduleCanModify(ctx);
  488. const data = JSON.parse(ctx.request.body.data);
  489. const responseData = {
  490. err: 0,
  491. msg: '',
  492. data: {},
  493. };
  494. switch (data.type) {
  495. case 'add_stage':
  496. responseData.data = await ctx.service.scheduleStage.add(data.postData);
  497. break;
  498. case 'del_stage':
  499. responseData.data = await ctx.service.scheduleStage.del(data.postData);
  500. break;
  501. case 'reload_stage':
  502. responseData.data = await ctx.service.scheduleStage.changeOrder(data.postData);
  503. break;
  504. case 'update_tp':
  505. responseData.data = await ctx.service.scheduleStage.updateOneTp(data.postData);
  506. break;
  507. default: throw '参数有误';
  508. }
  509. ctx.body = responseData;
  510. } catch (err) {
  511. this.log(err);
  512. ctx.body = { err: 1, msg: err.toString(), data: null };
  513. }
  514. }
  515. /**
  516. * 计量进度工程量模式计算方式提交(Ajax)
  517. *
  518. * @param ctx
  519. * @return {Promise<void>}
  520. */
  521. async saveStageGcl(ctx) {
  522. try {
  523. await this._checkScheduleCanModify(ctx);
  524. const data = JSON.parse(ctx.request.body.data);
  525. const responseData = {
  526. err: 0,
  527. msg: '',
  528. data: {},
  529. };
  530. switch (data.type) {
  531. case 'add_stage':
  532. responseData.data = await ctx.service.scheduleMonth.addStageUsed(data.postData);
  533. break;
  534. case 'del_stage':
  535. responseData.data = await ctx.service.scheduleMonth.delStageUsed(data.postData);
  536. break;
  537. case 'ledger_edit':
  538. responseData.data = await ctx.service.scheduleLedgerMonth.saveSj(data.postData);
  539. break;
  540. case 'ledger_paste':
  541. responseData.data = await ctx.service.scheduleLedgerMonth.saveSjDatas(data.postData);
  542. break;
  543. default: throw '参数有误';
  544. }
  545. ctx.body = responseData;
  546. } catch (err) {
  547. this.log(err);
  548. ctx.body = { err: 1, msg: err.toString(), data: null };
  549. }
  550. }
  551. async saveAudit(ctx) {
  552. try {
  553. const data = JSON.parse(ctx.request.body.data);
  554. if (!data) {
  555. throw '提交数据错误';
  556. }
  557. // 判断修改权限
  558. if (ctx.session.sessionUser.is_admin === 0) {
  559. throw '你没有权限修改投资进度';
  560. }
  561. let info = '';
  562. switch (data.type) {
  563. case 'add':
  564. const result = await ctx.service.scheduleAudit.addAudit(data);
  565. if (!result) {
  566. throw '添加审批人失败';
  567. }
  568. info = result;
  569. break;
  570. case 'del':
  571. await ctx.service.scheduleAudit.removeAudit(data);
  572. break;
  573. case 'edit':
  574. await ctx.service.scheduleAudit.editAudit(data);
  575. break;
  576. default:break;
  577. }
  578. ctx.body = { err: 0, msg: '', data: info };
  579. } catch (err) {
  580. this.log(err);
  581. ctx.body = this.ajaxErrorBody(err, '保存审批流程设置失败');
  582. }
  583. }
  584. }
  585. return ScheduleController;
  586. };