change.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/14
  7. * @version
  8. */
  9. const audit = require('../const/audit');
  10. module.exports = app => {
  11. class Change extends app.BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'change';
  21. }
  22. /**
  23. * 查找数据
  24. *
  25. * @param {Object} data - 筛选表单中的get数据
  26. * @return {void}
  27. */
  28. searchFilter(data) {
  29. this.initSqlBuilder();
  30. // this.sqlBuilder.columns = ['id', 'username', 'real_name', 'create_time', 'last_login', 'login_ip',
  31. // 'group_id', 'token', 'can_login'];
  32. data.type = parseInt(data.status);
  33. if (data.keyword !== undefined) {
  34. switch (data.type) {
  35. // 用户名
  36. case 1:
  37. this.sqlBuilder.setAndWhere('username', {
  38. value: this.db.escape(data.keyword + '%'),
  39. operate: 'like',
  40. });
  41. break;
  42. // 姓名
  43. case 2:
  44. this.sqlBuilder.setAndWhere('real_name', {
  45. value: this.db.escape(data.keyword + '%'),
  46. operate: 'like',
  47. });
  48. break;
  49. // 联系电话
  50. case 3:
  51. this.sqlBuilder.setAndWhere('telephone', {
  52. value: this.db.escape(data.keyword + '%'),
  53. operate: 'like',
  54. });
  55. break;
  56. default:
  57. break;
  58. }
  59. }
  60. // 办事处筛选
  61. if (data.office !== undefined && data.office !== '') {
  62. this.sqlBuilder.setAndWhere('office', {
  63. value: this.db.escape(data.office),
  64. operate: '=',
  65. });
  66. }
  67. }
  68. async add(tenderId, userId, code, name) {
  69. const count = await this.count({ tid: tenderId, code });
  70. if (count > 0) {
  71. throw '变更令号重复';
  72. }
  73. // 初始化事务
  74. this.transaction = await this.db.beginTransaction();
  75. let result = false;
  76. try {
  77. const cid = this.uuid.v4();
  78. const change = {
  79. cid,
  80. tid: tenderId,
  81. uid: userId,
  82. status: audit.flow.status.uncheck,
  83. times: 1,
  84. valid: true,
  85. in_time: new Date(),
  86. code,
  87. name,
  88. };
  89. const operate = await this.transaction.insert(this.tableName, change);
  90. if (operate.affectedRows <= 0) {
  91. throw '新建变更令数据失败';
  92. }
  93. // 把提交人信息添加到zh_change_audit
  94. const userInfo = await this.ctx.service.projectAccount.getDataById(userId);
  95. const changeaudit = {
  96. tid: tenderId,
  97. cid,
  98. uid: userId,
  99. name: userInfo.name,
  100. jobs: userInfo.role,
  101. company: userInfo.company,
  102. times: 1,
  103. usite: 0,
  104. usort: 0,
  105. status: 2,
  106. };
  107. await this.transaction.insert(this.ctx.service.changeAudit.tableName, changeaudit);
  108. result = change;
  109. this.transaction.commit();
  110. } catch (error) {
  111. console.log(error);
  112. // 回滚
  113. await this.transaction.rollback();
  114. }
  115. return result;
  116. }
  117. async pendingDatas(tenderId, userId) {
  118. return await this.getAllDataByCondition({
  119. tid: tenderId,
  120. uid: userId,
  121. status: audit.flow.status.checking,
  122. });
  123. }
  124. async uncheckDatas(tenderId, userId) {
  125. return await this.getAllDataByCondition({
  126. tid: tenderId,
  127. uid: userId,
  128. status: audit.flow.status.uncheck,
  129. });
  130. }
  131. async checkingDatas(tenderId, userId) {
  132. return await this.getAllDataByCondition({
  133. tid: tenderId,
  134. uid: userId,
  135. status: audit.flow.status.checking,
  136. });
  137. }
  138. async checkedDatas(tenderId, userId) {
  139. return await this.getAllDataByCondition({
  140. tid: tenderId,
  141. uid: userId,
  142. status: audit.flow.status.checked,
  143. });
  144. }
  145. async checkNoDatas(tenderId, userId) {
  146. return await this.getAllDataByCondition({
  147. tid: tenderId,
  148. uid: userId,
  149. status: audit.flow.status.checkNo,
  150. });
  151. }
  152. async checkNoCount(tenderId, userId) {
  153. return await this.count({
  154. tid: tenderId,
  155. uid: userId,
  156. status: audit.flow.status.checkNo,
  157. });
  158. }
  159. /**
  160. * 获取变更令列表
  161. * @param {int} tenderId - 标段id
  162. * @param {int} status - 状态
  163. * @return {object} list - 列表
  164. */
  165. async getListByStatus(tenderId, status = 0) {
  166. let sql = '';
  167. let sqlParam = '';
  168. switch (status) {
  169. case 0:// 包含你的所有变更令
  170. sql = 'SELECT a.* FROM ?? AS a WHERE a.tid = ? AND ' +
  171. '(a.uid = ? OR (a.status != 1 AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid))) ORDER BY a.in_time DESC';
  172. sqlParam = [this.tableName, tenderId, this.ctx.session.sessionUser.accountId,
  173. this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId];
  174. break;
  175. case 1:// 待处理(你的)
  176. sql = 'SELECT a.* FROM ?? as a WHERE cid in(SELECT b.cid FROM ?? as b WHERE tid = ? AND uid = ? AND status = ?) ORDER BY in_time DESC';
  177. sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName, tenderId, this.ctx.session.sessionUser.accountId, 2];
  178. break;
  179. case 5:// 待上报(所有的)PS:取未上报和退回的变更令
  180. sql = 'SELECT a.* FROM ?? AS a WHERE ' +
  181. 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid) AND ' +
  182. '(a.status = 1 OR a.status = 5) AND a.tid = ? ORDER BY a.in_time DESC';
  183. sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName,
  184. this.ctx.session.sessionUser.accountId, tenderId];
  185. break;
  186. case 2:// 进行中(所有的)
  187. case 3:// 已完成(所有的)
  188. case 4:// 终止(所有的)
  189. sql = 'SELECT a.* FROM ?? AS a WHERE ' +
  190. 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid) AND ' +
  191. 'a.status = ? AND a.tid = ? ORDER BY a.in_time DESC';
  192. sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName,
  193. this.ctx.session.sessionUser.accountId, status, tenderId];
  194. break;
  195. default:
  196. break;
  197. }
  198. const limit = this.app.config.pageSize;
  199. const offset = limit * (this.ctx.page - 1);
  200. const limitString = offset >= 0 ? offset + ',' + limit : limit;
  201. sql += ' LIMIT ' + limitString;
  202. const list = await this.db.query(sql, sqlParam);
  203. return list;
  204. }
  205. /**
  206. * 获取变更令个数
  207. * @param {int} tenderId - 标段id
  208. * @param {int} status - 状态
  209. * @return {void}
  210. */
  211. async getCountByStatus(tenderId, status) {
  212. switch (status) {
  213. case 0:// 包含你的所有变更令
  214. const sql = 'SELECT count(*) AS count FROM ?? AS a WHERE a.tid = ? AND ' +
  215. '(a.uid = ? OR a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid))';
  216. const sqlParam = [this.tableName, tenderId, this.ctx.session.sessionUser.accountId,
  217. this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId];
  218. const result = await this.db.query(sql, sqlParam);
  219. return result[0].count;
  220. case 1:// 待处理(你的)
  221. return await this.ctx.service.changeAudit.count({
  222. tid: tenderId,
  223. uid: this.ctx.session.sessionUser.accountId,
  224. status: 2,
  225. });
  226. case 5:// 待上报(所有的)PS:取未上报和退回的变更令
  227. const sql2 = 'SELECT count(*) AS count FROM ?? AS a WHERE ' +
  228. 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid) ' +
  229. 'AND (a.status = 1 OR a.status = 5) AND a.tid = ?';
  230. const sqlParam2 = [this.tableName, this.ctx.service.changeAudit.tableName,
  231. this.ctx.session.sessionUser.accountId, tenderId];
  232. const result2 = await this.db.query(sql2, sqlParam2);
  233. return result2[0].count;
  234. case 2:// 进行中(所有的)
  235. case 3:// 已完成(所有的)
  236. case 4:// 终止(所有的)
  237. const sql3 = 'SELECT count(*) AS count FROM ?? AS a WHERE ' +
  238. 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid) AND a.status = ? AND a.tid = ?';
  239. const sqlParam3 = [this.tableName, this.ctx.service.changeAudit.tableName,
  240. this.ctx.session.sessionUser.accountId, status, tenderId];
  241. const result3 = await this.db.query(sql3, sqlParam3);
  242. return result3[0].count;
  243. default:
  244. break;
  245. }
  246. }
  247. /**
  248. * 上报或重新上报或保存修改功能
  249. * @param {int} postData - 表单提交的数据
  250. * @param {int} tenderId - 标段id
  251. * @return {void}
  252. */
  253. async save(postData, tenderId) {
  254. // 初始化事务
  255. this.transaction = await this.db.beginTransaction();
  256. let result = false;
  257. try {
  258. // 变更令信息
  259. const changeInfo = await this.getDataByCondition({ cid: postData.cid });
  260. // 该变更令原报人信息
  261. const lastUser = await this.ctx.service.changeAudit.getLastUser(changeInfo.cid, changeInfo.times, 0);
  262. // 先删除本次原有的变更审批人和清单
  263. await this.ctx.service.changeAudit.deleteAuditData(this.transaction, changeInfo.cid, changeInfo.times);
  264. await this.transaction.delete(this.ctx.service.changeAuditList.tableName, { cid: changeInfo.cid });
  265. let change_status = false;
  266. // 获取变更令提交状态
  267. if (postData.changestatus !== undefined && parseInt(postData.changestatus) === 1) {
  268. change_status = true;
  269. // 更新原报人审批状态
  270. await this.transaction.update(this.ctx.service.changeAudit.tableName, { id: lastUser.id, status: 3, sin_time: new Date() });
  271. }
  272. // 再插入postData里的变更审批人和清单
  273. if (postData.changeaudit !== undefined && postData.changeaudit !== '') {
  274. const changeAudit = postData.changeaudit.split(',');
  275. const insertCA = [];
  276. let uSite = 1;
  277. let uSort = parseInt(lastUser.usort) + 1;
  278. for (const [index, ca] of changeAudit.entries()) {
  279. const auditInfo = ca.split('/%/');
  280. const uStatus = change_status && index === 0 ? 2 : 1;
  281. const sin_time = change_status && index === 0 ? new Date() : null;
  282. const caArray = {
  283. tid: tenderId,
  284. cid: changeInfo.cid,
  285. uid: auditInfo[0],
  286. name: auditInfo[1],
  287. jobs: auditInfo[2],
  288. company: auditInfo[3],
  289. times: changeInfo.times,
  290. usite: uSite,
  291. usort: uSort,
  292. status: uStatus,
  293. sin_time,
  294. };
  295. uSite++;
  296. uSort++;
  297. insertCA.push(caArray);
  298. }
  299. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insertCA);
  300. }
  301. let changeList = [];
  302. if (postData.changelist !== undefined && postData.changelist !== '') {
  303. changeList = postData.changelist.split('^_^');
  304. }
  305. let changeWhiteList = [];
  306. if (postData.changewhitelist !== undefined && postData.changewhitelist !== '') {
  307. changeWhiteList = postData.changewhitelist.split('^_^');
  308. }
  309. changeList.push.apply(changeList, changeWhiteList);
  310. const insertCL = [];
  311. let total_price = 0;
  312. if (changeList.length > 0) {
  313. for (const cl of changeList) {
  314. const clInfo = cl.split(';');
  315. const clArray = {
  316. tid: tenderId,
  317. cid: changeInfo.cid,
  318. lid: clInfo[7],
  319. code: clInfo[0],
  320. name: clInfo[1],
  321. unit: clInfo[2],
  322. unit_price: clInfo[3],
  323. oamount: clInfo[4],
  324. camount: clInfo[5],
  325. samount: '',
  326. detail: clInfo[6],
  327. };
  328. insertCL.push(clArray);
  329. total_price = this.ctx.helper.accAdd(total_price, this.ctx.helper.accMul(clArray.unit_price, clArray.camount));
  330. }
  331. await this.transaction.insert(this.ctx.service.changeAuditList.tableName, insertCL);
  332. }
  333. // 修改变更令基本数据
  334. const cArray = {
  335. code: postData.code,
  336. name: postData.name,
  337. peg: postData.peg,
  338. org_name: postData.org_name,
  339. org_code: postData.org_code,
  340. new_name: postData.new_name,
  341. new_code: postData.new_code,
  342. content: postData.content,
  343. basis: postData.basis,
  344. memo: postData.memo,
  345. type: postData.type.join(','),
  346. class: postData.class,
  347. quality: postData.quality,
  348. company: postData.company,
  349. charge: postData.charge,
  350. total_price,
  351. };
  352. const options = {
  353. where: {
  354. cid: changeInfo.cid,
  355. },
  356. };
  357. if (change_status) {
  358. cArray.status = 2;
  359. cArray.cin_time = Date.parse(new Date()) / 1000;
  360. }
  361. await this.transaction.update(this.tableName, cArray, options);
  362. await this.transaction.commit();
  363. result = true;
  364. } catch (error) {
  365. await this.transaction.rollback();
  366. result = false;
  367. }
  368. return result;
  369. }
  370. /**
  371. * 审批通过
  372. * @param {int} postData - 表单提交的数据
  373. * @return {void}
  374. */
  375. async approvalSuccess(postData) {
  376. // 初始化事务
  377. this.transaction = await this.db.beginTransaction();
  378. let result = false;
  379. try {
  380. // 设置审批人通过
  381. const audit_update = {
  382. id: postData.audit_id,
  383. sdesc: postData.sdesc,
  384. status: 3,
  385. sin_time: new Date(),
  386. };
  387. const change_update = {
  388. w_code: postData.w_code,
  389. status: 2,
  390. cin_time: Date.parse(new Date()) / 1000,
  391. };
  392. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  393. // 清单数据更新
  394. const bills_list = postData.bills_list.split(',');
  395. let total_price = 0;
  396. for (const bl of bills_list) {
  397. const listInfo = bl.split('_');
  398. const lid = listInfo[0];
  399. const amount = listInfo[1];
  400. const changeListInfo = await this.ctx.service.changeAuditList.getDataById(lid);
  401. if (changeListInfo !== undefined) {
  402. total_price += this.ctx.helper.accMul(changeListInfo.unit_price, parseFloat(amount));
  403. const audit_amount = changeListInfo.audit_amount !== null && changeListInfo.audit_amount !== '' ? changeListInfo.audit_amount.split(',') : [];
  404. audit_amount.push(amount);
  405. const list_update = {
  406. id: lid,
  407. audit_amount: audit_amount.join(','),
  408. };
  409. if (postData.audit_next_id === undefined) {
  410. list_update.samount = amount;
  411. }
  412. await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
  413. }
  414. }
  415. if (postData.audit_next_id === undefined) {
  416. // 变更令审批完成
  417. change_update.status = 3;
  418. change_update.p_code = postData.p_code;
  419. change_update.sin_time = Date.parse(new Date()) / 1000;
  420. change_update.total_price = total_price;
  421. } else {
  422. // 设置下一个审批人为审批状态
  423. const nextAudit_update = {
  424. id: postData.audit_next_id,
  425. status: 2,
  426. };
  427. await this.transaction.update(this.ctx.service.changeAudit.tableName, nextAudit_update);
  428. }
  429. const options = {
  430. where: {
  431. cid: postData.change_id,
  432. },
  433. };
  434. await this.transaction.update(this.tableName, change_update, options);
  435. await this.transaction.commit();
  436. result = true;
  437. } catch (error) {
  438. await this.transaction.rollback();
  439. result = false;
  440. }
  441. return result;
  442. }
  443. /**
  444. * 审批终止
  445. * @param {int} postData - 表单提交的数据
  446. * @return {void}
  447. */
  448. async approvalStop(postData) {
  449. // 初始化事务
  450. this.transaction = await this.db.beginTransaction();
  451. let result = false;
  452. try {
  453. // 设置审批人终止
  454. const audit_update = {
  455. id: postData.audit_id,
  456. sdesc: postData.sdesc,
  457. status: 4,
  458. sin_time: new Date(),
  459. };
  460. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  461. // 设置变更令终止
  462. const change_update = {
  463. w_code: postData.w_code,
  464. status: 4,
  465. cin_time: Date.parse(new Date()) / 1000,
  466. };
  467. const options = {
  468. where: {
  469. cid: postData.change_id,
  470. },
  471. };
  472. await this.transaction.update(this.tableName, change_update, options);
  473. await this.transaction.commit();
  474. result = true;
  475. } catch (error) {
  476. await this.transaction.rollback();
  477. result = false;
  478. }
  479. return result;
  480. }
  481. /**
  482. * 审批退回到原报人
  483. * @param {int} postData - 表单提交的数据
  484. * @return {void}
  485. */
  486. async approvalBack(postData) {
  487. // 初始化事务
  488. this.transaction = await this.db.beginTransaction();
  489. let result = false;
  490. try {
  491. const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
  492. // 设置审批人退回
  493. const audit_update = {
  494. id: postData.audit_id,
  495. sdesc: postData.sdesc,
  496. status: 5,
  497. sin_time: new Date(),
  498. };
  499. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  500. // 新增新一次的审批人列表
  501. // 获取当前次数审批人列表
  502. const auditList = await this.ctx.service.changeAudit.getListGroupByTimes(changeInfo.cid, changeInfo.times);
  503. const lastauditInfo = await this.ctx.service.changeAudit.getLastUser(changeInfo.cid, changeInfo.times, 1, 0);
  504. let usort = lastauditInfo.usort + 1;
  505. const newTimes = changeInfo.times + 1;
  506. const insert_audit_array = [];
  507. for (const al of auditList) {
  508. const insert_audit = {
  509. tid: al.tid,
  510. cid: al.cid,
  511. uid: al.uid,
  512. name: al.name,
  513. jobs: al.jobs,
  514. company: al.company,
  515. times: newTimes,
  516. usite: al.usite,
  517. usort,
  518. status: al.usite !== 0 ? 1 : 2,
  519. };
  520. insert_audit_array.push(insert_audit);
  521. usort++;
  522. }
  523. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit_array);
  524. // 设置变更令退回
  525. const change_update = {
  526. w_code: postData.w_code,
  527. status: 5,
  528. times: newTimes,
  529. cin_time: Date.parse(new Date()) / 1000,
  530. };
  531. const options = {
  532. where: {
  533. cid: postData.change_id,
  534. },
  535. };
  536. await this.transaction.update(this.tableName, change_update, options);
  537. await this.transaction.commit();
  538. result = true;
  539. } catch (error) {
  540. await this.transaction.rollback();
  541. result = false;
  542. }
  543. return result;
  544. }
  545. /**
  546. * 审批退回到上一个审批人
  547. * @param {int} postData - 表单提交的数据
  548. * @return {void}
  549. */
  550. async approvalBackNew(postData) {
  551. // 初始化事务
  552. this.transaction = await this.db.beginTransaction();
  553. let result = false;
  554. try {
  555. const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
  556. // 设置审批人退回
  557. const audit_update = {
  558. id: postData.audit_id,
  559. sdesc: postData.sdesc,
  560. status: 6,
  561. sin_time: new Date(),
  562. };
  563. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  564. // 获取当前审批人信息
  565. const auditInfo = await this.ctx.service.changeAudit.getDataById(postData.audit_id);
  566. // 获取当前次数审批人列表
  567. const auditList = await this.ctx.service.changeAudit.getNextAuditList(changeInfo.cid, auditInfo.usort);
  568. let usort = auditInfo.usort + 1;
  569. // 获取上一个审批人信息
  570. const lastauditInfo = await this.ctx.service.changeAudit.getDataById(postData.audit_last_id);
  571. // 新增2个审批人到审批列表中
  572. const insert_audit1 = {
  573. tid: lastauditInfo.tid,
  574. cid: lastauditInfo.cid,
  575. uid: lastauditInfo.uid,
  576. name: lastauditInfo.name,
  577. jobs: lastauditInfo.jobs,
  578. company: lastauditInfo.company,
  579. times: lastauditInfo.times,
  580. usite: lastauditInfo.usite,
  581. usort,
  582. status: 2,
  583. };
  584. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit1);
  585. usort++;
  586. // 新增2个审批人到审批列表中
  587. const insert_audit2 = {
  588. tid: auditInfo.tid,
  589. cid: auditInfo.cid,
  590. uid: auditInfo.uid,
  591. name: auditInfo.name,
  592. jobs: auditInfo.jobs,
  593. company: auditInfo.company,
  594. times: auditInfo.times,
  595. usite: auditInfo.usite,
  596. usort,
  597. status: 1,
  598. };
  599. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit2);
  600. // 把接下未审批的审批人排序都加2
  601. for (const al of auditList) {
  602. const audit_update = {
  603. id: al.id,
  604. usort: al.usort + 2,
  605. };
  606. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  607. }
  608. // 审批列表数据也要回退
  609. const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: changeInfo.cid } });
  610. for (const cl of changeList) {
  611. const audit_amount = cl.audit_amount.split(',');
  612. audit_amount.splice(-1, 1);
  613. const list_update = {
  614. id: cl.id,
  615. audit_amount: audit_amount.join(','),
  616. };
  617. await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
  618. }
  619. // 设置变更令退回
  620. const change_update = {
  621. w_code: postData.w_code,
  622. status: 6,
  623. cin_time: Date.parse(new Date()) / 1000,
  624. };
  625. const options = {
  626. where: {
  627. cid: postData.change_id,
  628. },
  629. };
  630. await this.transaction.update(this.tableName, change_update, options);
  631. await this.transaction.commit();
  632. result = true;
  633. } catch (error) {
  634. await this.transaction.rollback();
  635. result = false;
  636. }
  637. return result;
  638. }
  639. }
  640. return Change;
  641. };