schedule_controller.js 30 KB

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