schedule_controller.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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. await ctx.service.stage.loadPreCheckedStage(stageInfo);
  263. // 当前操作人查看最新数据,其他人查看历史数据
  264. const curStageData = await ctx.service.stageBills.getLastestStageData2(ctx.tender.id, stageInfo.id);
  265. const preStageData = stageInfo.preCheckedStage ? await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.preCheckedStage.order) : [];
  266. const pcData = await ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: stageInfo.id } });
  267. this.ctx.helper.assignRelaData(ledgerData, [
  268. { data: curStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid' },
  269. { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_', relaId: 'lid' },
  270. { data: pcData, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp', 'org_price'], prefix: '', relaId: 'lid' },
  271. ]);
  272. // 获取进度最新期的数据
  273. ledgerData = await this._addFinalStageData(ctx, ledgerData);
  274. return ledgerData;
  275. }
  276. /**
  277. * 添加最新一期的进度期下期数据到台账数据中(Ajax)
  278. *
  279. * @param ctx
  280. * @return {Promise<void>}
  281. */
  282. async _addFinalStageData(ctx, ledgerData) {
  283. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['order', 'desc']] });
  284. if (scheduleStage && scheduleStage.length > 0) {
  285. let prefinalStageData;
  286. const finalStageInfo = await ctx.service.stage.getDataByCondition({
  287. tid: ctx.tender.id,
  288. order: scheduleStage[0].order,
  289. });
  290. const finalStageData = await ctx.service.stageBills.getLastestStageData2(ctx.tender.id, finalStageInfo.id);
  291. if (finalStageInfo.order > 1) {
  292. prefinalStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, finalStageInfo.order - 1);
  293. } else {
  294. prefinalStageData = [];
  295. }
  296. const finalPcData = await ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: finalStageInfo.id } });
  297. this.ctx.helper.assignRelaData(ledgerData, [
  298. { data: finalStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: 'final_', relaId: 'lid' },
  299. { data: prefinalStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_final_', relaId: 'lid' },
  300. { data: finalPcData, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp', 'org_price'], prefix: 'final_', relaId: 'lid' },
  301. ]);
  302. }
  303. return ledgerData;
  304. }
  305. /**
  306. * 获取本期下台账计量和计划数据(Ajax)
  307. *
  308. * @param ctx
  309. * @return {Promise<void>}
  310. */
  311. async _getStageAndPlanData(ctx) {
  312. const tender = ctx.tender;
  313. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  314. const stageOrderList = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 's_time', 'order'], where: { tid: tender.id } });
  315. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'desc']] });
  316. let curScheduleStage = scheduleStage.length > 0 ? _.maxBy(scheduleStage, 'yearmonth') : null;
  317. if (ctx.params.order && scheduleStage.length > 0) {
  318. curScheduleStage = _.find(scheduleStage, { order: parseInt(ctx.params.order) });
  319. }
  320. let slmList = [];
  321. let nextSlmList = [];
  322. let endSlmList = [];
  323. let yearSlmList = [];
  324. let curYearStageData = [];
  325. if (curScheduleStage) {
  326. const newSM = _.sortBy(scheduleMonth, 'yearmonth');
  327. const nowScheduleStage = _.findIndex(newSM, { yearmonth: curScheduleStage.yearmonth });
  328. slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleStage.yearmonth } });
  329. const nextScheduleStage = nowScheduleStage >= 0 && nowScheduleStage + 1 <= newSM.length - 1 ? newSM[nowScheduleStage + 1] : null;
  330. if (nextScheduleStage) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleStage.yearmonth } });
  331. if (nowScheduleStage === 0) {
  332. endSlmList = slmList;
  333. } else if (nowScheduleStage > 0) {
  334. const endYearmonthCollection = _.map(_.take(newSM, nowScheduleStage + 1), 'yearmonth');
  335. endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
  336. }
  337. const yearConllection = _.map(_.filter(newSM, function(item) {
  338. return item.yearmonth.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
  339. }), 'yearmonth');
  340. yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
  341. // 获取本年完成计量数据
  342. const curStage = _.find(stageOrderList, { order: curScheduleStage.order });
  343. const stageList = _.filter(stageOrderList, function(item) {
  344. return item.s_time.indexOf(curStage.s_time.split('-')[0]) !== -1;
  345. });
  346. // const newSS = _.sortBy(scheduleStage, 'yearmonth');
  347. // const stageIdList = _.map(_.filter(stageList, function(item) {
  348. // return _.find(newSS, { order: item.order });
  349. // }), 'id');
  350. const stageIdList = _.map(stageList, 'id');
  351. curYearStageData = await ctx.service.stageBills.getStagesData(tender.id, stageIdList.join(','));
  352. const curYearStagePcData = await ctx.service.stageBillsPc.getStagesData(tender.id, stageIdList.join(','));
  353. for (const cys of curYearStageData) {
  354. const cyspc = ctx.helper._.find(curYearStagePcData, { lid: cys.lid });
  355. if (cyspc) ctx.helper._.assign(cys, cyspc);
  356. }
  357. }
  358. return { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData, scheduleMonth, stageOrderList, scheduleStage, curScheduleStage };
  359. }
  360. /**
  361. * 获取工程量模式汇总下台账的计划数据(Ajax)
  362. *
  363. * @param ctx
  364. * @return {Promise<void>}
  365. */
  366. async _getGclAndPlanData(ctx) {
  367. const tender = ctx.tender;
  368. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  369. let curScheduleMonth = scheduleMonth.length > 0 ? _.maxBy(scheduleMonth, 'order') : null;
  370. const gclScheduleMonth = _.filter(scheduleMonth, { stage_gcl_used: 1 });
  371. if (ctx.params.order && gclScheduleMonth.length > 0) {
  372. curScheduleMonth = _.find(gclScheduleMonth, { id: parseInt(ctx.params.order) });
  373. }
  374. let slmList = [];
  375. let nextSlmList = [];
  376. let endSlmList = [];
  377. let yearSlmList = [];
  378. if (curScheduleMonth) {
  379. const newSM = _.sortBy(scheduleMonth, 'yearmonth');
  380. const nowScheduleMonth = _.findIndex(newSM, { yearmonth: curScheduleMonth.yearmonth });
  381. slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleMonth.yearmonth } });
  382. const nextScheduleMonth = nowScheduleMonth >= 0 && nowScheduleMonth + 1 <= newSM.length - 1 ? newSM[nowScheduleMonth + 1] : null;
  383. if (nextScheduleMonth) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleMonth.yearmonth } });
  384. if (nowScheduleMonth === 0) {
  385. endSlmList = slmList;
  386. } else if (nowScheduleMonth > 0) {
  387. const endYearmonthCollection = _.map(_.take(newSM, nowScheduleMonth + 1), 'yearmonth');
  388. endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
  389. }
  390. const yearConllection = _.map(_.filter(newSM, function(item) {
  391. return item.yearmonth.indexOf(curScheduleMonth.yearmonth.split('-')[0]) !== -1;
  392. }), 'yearmonth');
  393. yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
  394. }
  395. return { slmList, nextSlmList, endSlmList, yearSlmList, scheduleMonth, curScheduleMonth };
  396. }
  397. /**
  398. * 获取台账数据(Ajax)
  399. *
  400. * @param ctx
  401. * @return {Promise<void>}
  402. */
  403. async loadLedgerData(ctx) {
  404. try {
  405. // const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  406. const ledgerData = await this._getAllStageLedgerData(ctx);
  407. // const posData = ctx.tender.data.measure_type === measureType.tz.value
  408. // ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
  409. // const convert = new billsPosConvert(ctx);
  410. // convert.loadData(ledgerData, posData, []);
  411. // const result = await convert.convert();
  412. const scheduleLedgerMonthData = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  413. const scheduleLedgerHistoryData = await ctx.service.scheduleLedgerHistory.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  414. ctx.body = { err: 0, msg: '', data: { bills: ledgerData, slm: scheduleLedgerMonthData, slh: scheduleLedgerHistoryData } };
  415. } catch (err) {
  416. this.log(err);
  417. ctx.body = { err: 1, msg: err.toString(), data: [] };
  418. }
  419. }
  420. /**
  421. * 台账选中提交(Ajax)
  422. *
  423. * @param ctx
  424. * @return {Promise<void>}
  425. */
  426. async saveLedger(ctx) {
  427. try {
  428. await this._checkScheduleCanModify(ctx);
  429. const data = JSON.parse(ctx.request.body.data);
  430. const result = await ctx.service.scheduleLedger.saveLedger(data);
  431. ctx.body = { err: 0, msg: '', data: result };
  432. } catch (err) {
  433. this.log(err);
  434. ctx.body = { err: 1, msg: err.toString(), data: [] };
  435. }
  436. }
  437. /**
  438. * 计划进度计算方式提交(Ajax)
  439. *
  440. * @param ctx
  441. * @return {Promise<void>}
  442. */
  443. async savePlan(ctx) {
  444. try {
  445. await this._checkScheduleCanModify(ctx);
  446. const data = JSON.parse(ctx.request.body.data);
  447. const responseData = {
  448. err: 0,
  449. msg: '',
  450. data: {},
  451. };
  452. switch (data.type) {
  453. case 'mode':
  454. responseData.data = await ctx.service.schedule.saveMode(data.postData);
  455. break;
  456. case 'addmonth':
  457. responseData.data = await ctx.service.scheduleMonth.add(data.postData);
  458. break;
  459. case 'delmonth':
  460. responseData.data = await ctx.service.scheduleMonth.del(data.postData);
  461. break;
  462. case 'ledger_edit':
  463. responseData.data = await ctx.service.scheduleLedgerMonth.save(data.postData);
  464. break;
  465. case 'ledger_paste':
  466. responseData.data = await ctx.service.scheduleLedgerMonth.saveDatas(data.postData);
  467. break;
  468. default: throw '参数有误';
  469. }
  470. ctx.body = responseData;
  471. } catch (err) {
  472. this.log(err);
  473. ctx.body = { err: 1, msg: err.toString(), data: null };
  474. }
  475. }
  476. /**
  477. * 计量进度金额模式计算方式提交(Ajax)
  478. *
  479. * @param ctx
  480. * @return {Promise<void>}
  481. */
  482. async saveStageTp(ctx) {
  483. try {
  484. await this._checkScheduleCanModify(ctx);
  485. const data = JSON.parse(ctx.request.body.data);
  486. const responseData = {
  487. err: 0,
  488. msg: '',
  489. data: {},
  490. };
  491. switch (data.type) {
  492. case 'add_stage':
  493. responseData.data = await ctx.service.scheduleStage.add(data.postData);
  494. break;
  495. case 'del_stage':
  496. responseData.data = await ctx.service.scheduleStage.del(data.postData);
  497. break;
  498. case 'reload_stage':
  499. responseData.data = await ctx.service.scheduleStage.changeOrder(data.postData);
  500. break;
  501. case 'update_tp':
  502. responseData.data = await ctx.service.scheduleStage.updateOneTp(data.postData);
  503. break;
  504. default: throw '参数有误';
  505. }
  506. ctx.body = responseData;
  507. } catch (err) {
  508. this.log(err);
  509. ctx.body = { err: 1, msg: err.toString(), data: null };
  510. }
  511. }
  512. /**
  513. * 计量进度工程量模式计算方式提交(Ajax)
  514. *
  515. * @param ctx
  516. * @return {Promise<void>}
  517. */
  518. async saveStageGcl(ctx) {
  519. try {
  520. await this._checkScheduleCanModify(ctx);
  521. const data = JSON.parse(ctx.request.body.data);
  522. const responseData = {
  523. err: 0,
  524. msg: '',
  525. data: {},
  526. };
  527. switch (data.type) {
  528. case 'add_stage':
  529. responseData.data = await ctx.service.scheduleMonth.addStageUsed(data.postData);
  530. break;
  531. case 'del_stage':
  532. responseData.data = await ctx.service.scheduleMonth.delStageUsed(data.postData);
  533. break;
  534. case 'ledger_edit':
  535. responseData.data = await ctx.service.scheduleLedgerMonth.saveSj(data.postData);
  536. break;
  537. case 'ledger_paste':
  538. responseData.data = await ctx.service.scheduleLedgerMonth.saveSjDatas(data.postData);
  539. break;
  540. default: throw '参数有误';
  541. }
  542. ctx.body = responseData;
  543. } catch (err) {
  544. this.log(err);
  545. ctx.body = { err: 1, msg: err.toString(), data: null };
  546. }
  547. }
  548. async saveAudit(ctx) {
  549. try {
  550. const data = JSON.parse(ctx.request.body.data);
  551. if (!data) {
  552. throw '提交数据错误';
  553. }
  554. // 判断修改权限
  555. if (ctx.session.sessionUser.is_admin === 0) {
  556. throw '你没有权限修改投资进度';
  557. }
  558. let info = '';
  559. switch (data.type) {
  560. case 'add':
  561. const result = await ctx.service.scheduleAudit.addAudit(data);
  562. if (!result) {
  563. throw '添加审批人失败';
  564. }
  565. info = result;
  566. break;
  567. case 'del':
  568. await ctx.service.scheduleAudit.removeAudit(data);
  569. break;
  570. case 'edit':
  571. await ctx.service.scheduleAudit.editAudit(data);
  572. break;
  573. default:break;
  574. }
  575. ctx.body = { err: 0, msg: '', data: info };
  576. } catch (err) {
  577. this.log(err);
  578. ctx.body = this.ajaxErrorBody(err, '保存审批流程设置失败');
  579. }
  580. }
  581. }
  582. return ScheduleController;
  583. };