change_plan_audit.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/14
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').changePlan;
  10. const pushType = require('../const/audit').pushType;
  11. const pushOperate = require('../const/spec_3f').pushOperate;
  12. const shenpiConst = require('../const/shenpi');
  13. const smsTypeConst = require('../const/sms_type');
  14. const SMS = require('../lib/sms');
  15. const SmsAliConst = require('../const/sms_alitemplate');
  16. const wxConst = require('../const/wechat_template');
  17. module.exports = app => {
  18. class ChangePlanAudit extends app.BaseService {
  19. /**
  20. * 构造函数
  21. *
  22. * @param {Object} ctx - egg全局变量
  23. * @return {void}
  24. */
  25. constructor(ctx) {
  26. super(ctx);
  27. this.tableName = 'change_plan_audit';
  28. }
  29. /**
  30. * 获取 审核列表信息
  31. *
  32. * @param {Number} cpId - 变更立项id
  33. * @param {Number} times - 第几次审批
  34. * @return {Promise<*>}
  35. */
  36. async getAuditors(cpId, times = 1) {
  37. const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
  38. 'FROM ?? AS la, ?? AS pa, (SELECT t1.`aid`,(@i:=@i+1) as `sort` FROM (SELECT t.`aid`, t.`order` FROM (select `aid`, `order` from ?? WHERE `cpid` = ? AND `times` = ? ORDER BY `order` LIMIT 200) t GROUP BY t.`aid` ORDER BY t.`order`) t1, (select @i:=0) as it) as g ' +
  39. 'WHERE la.`cpid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order`';
  40. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, cpId, times, cpId, times];
  41. const result = await this.db.query(sql, sqlParam);
  42. const sql2 = 'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `cpid` = ? AND `times` = ? GROUP BY `aid`) as a';
  43. const sqlParam2 = [this.tableName, cpId, times];
  44. const count = await this.db.queryOne(sql2, sqlParam2);
  45. for (const i in result) {
  46. result[i].max_sort = count.num;
  47. }
  48. return result;
  49. }
  50. /**
  51. * 获取 当前审核人
  52. *
  53. * @param {Number} cpId - 变更立项id
  54. * @param {Number} times - 第几次审批
  55. * @return {Promise<*>}
  56. */
  57. async getCurAuditor(cpId, times = 1) {
  58. const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
  59. ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
  60. ' WHERE la.`cpid` = ? and la.`status` = ? and la.`times` = ?';
  61. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, auditConst.status.checking, times];
  62. return await this.db.queryOne(sql, sqlParam);
  63. }
  64. /**
  65. * 获取审核人流程列表
  66. *
  67. * @param auditorId
  68. * @return {Promise<*>}
  69. */
  70. async getAuditGroupByList(changeId, times) {
  71. const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order` ' +
  72. ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
  73. ' WHERE la.`cpid` = ? and la.`times` = ? and la.`status` != ? and la.`status` != ? GROUP BY la.`aid` ORDER BY la.`order`';
  74. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, changeId, times, auditConst.status.revise, auditConst.status.cancelRevise];
  75. return await this.db.query(sql, sqlParam);
  76. }
  77. /**
  78. * 移除审核人
  79. *
  80. * @param {Number} materialId - 材料调差期id
  81. * @param {Number} status - 期状态
  82. * @param {Number} status - 期次数
  83. * @return {Promise<boolean>}
  84. */
  85. async getAuditorByStatus(cpId, status, times = 1) {
  86. let auditor = null;
  87. let sql = '';
  88. let sqlParam = '';
  89. switch (status) {
  90. case auditConst.status.checking :
  91. case auditConst.status.checked :
  92. case auditConst.status.revise :
  93. case auditConst.status.cancelRevise :
  94. sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order`, la.`status` ' +
  95. ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id` ' +
  96. ' WHERE la.`cpid` = ? and la.`status` = ? ' +
  97. ' ORDER BY la.`times` desc, la.`order` desc';
  98. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, status];
  99. auditor = await this.db.queryOne(sql, sqlParam);
  100. break;
  101. case auditConst.status.checkNo :
  102. sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`cpid`, la.`aid`, la.`order`, la.`status` ' +
  103. ' FROM ?? AS la Left Join ?? AS pa On la.`aid` = pa.`id`' +
  104. ' WHERE la.`cpid` = ? and la.`status` = ? and la.`times` = ?' +
  105. ' ORDER BY la.`times` desc, la.`order` desc';
  106. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cpId, auditConst.status.checkNo, parseInt(times) - 1];
  107. auditor = await this.db.queryOne(sql, sqlParam);
  108. break;
  109. case auditConst.status.uncheck :
  110. break;
  111. default:break;
  112. }
  113. return auditor;
  114. }
  115. async getLastAudit(cpid, times, transaction = null) {
  116. const sql = 'SELECT * FROM ?? WHERE `cpid` = ? AND `times` = ? ORDER BY `order` DESC';
  117. const sqlParam = [this.tableName, cpid, times];
  118. return transaction ? await transaction.queryOne(sql, sqlParam) : await this.db.queryOne(sql, sqlParam);
  119. }
  120. /**
  121. * 获取审核人流程列表(包括原报)
  122. * @param {Number} materialId 调差id
  123. * @param {Number} times 审核次数
  124. * @return {Promise<Array>} 查询结果集(包括原报)
  125. */
  126. async getAuditorsWithOwner(cpId, times = 1) {
  127. const result = await this.getAuditGroupByList(cpId, times);
  128. const sql =
  129. 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As cpid, 0 As `order`' +
  130. ' FROM ' +
  131. this.ctx.service.changePlan.tableName +
  132. ' As s' +
  133. ' LEFT JOIN ' +
  134. this.ctx.service.projectAccount.tableName +
  135. ' As pa' +
  136. ' ON s.uid = pa.id' +
  137. ' WHERE s.id = ?';
  138. const sqlParam = [times, cpId, cpId];
  139. const user = await this.db.queryOne(sql, sqlParam);
  140. result.unshift(user);
  141. return result;
  142. }
  143. /**
  144. * 新增审核人
  145. *
  146. * @param {Number} cpId - 方案id
  147. * @param {Number} auditorId - 审核人id
  148. * @param {Number} times - 第几次审批
  149. * @return {Promise<number>}
  150. */
  151. async addAuditor(cpId, auditorId, times = 1, is_gdzs = 0) {
  152. const transaction = await this.db.beginTransaction();
  153. let flag = false;
  154. try {
  155. let newOrder = await this.getNewOrder(cpId, times);
  156. // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
  157. newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
  158. if (is_gdzs) await this._syncOrderByDelete(transaction, cpId, newOrder, times, '+');
  159. const data = {
  160. tid: this.ctx.tender.id,
  161. cpid: cpId,
  162. aid: auditorId,
  163. times,
  164. order: newOrder,
  165. status: auditConst.status.uncheck,
  166. };
  167. const result = await transaction.insert(this.tableName, data);
  168. await transaction.commit();
  169. flag = result.effectRows = 1;
  170. } catch (err) {
  171. await transaction.rollback();
  172. throw err;
  173. }
  174. return flag;
  175. }
  176. /**
  177. * 获取 最新审核顺序
  178. *
  179. * @param {Number} cpId - 方案id
  180. * @param {Number} times - 第几次审批
  181. * @return {Promise<number>}
  182. */
  183. async getNewOrder(cpId, times = 1) {
  184. const sql = 'SELECT Max(??) As max_order FROM ?? Where `cpid` = ? and `times` = ?';
  185. const sqlParam = ['order', this.tableName, cpId, times];
  186. const result = await this.db.queryOne(sql, sqlParam);
  187. return result && result.max_order ? result.max_order + 1 : 1;
  188. }
  189. /**
  190. * 移除审核人
  191. *
  192. * @param {Number} cpId - 变更方案id
  193. * @param {Number} auditorId - 审核人id
  194. * @param {Number} times - 第几次审批
  195. * @return {Promise<boolean>}
  196. */
  197. async deleteAuditor(cpId, auditorId, times = 1) {
  198. const transaction = await this.db.beginTransaction();
  199. try {
  200. const condition = { cpid: cpId, aid: auditorId, times };
  201. const auditor = await this.getDataByCondition(condition);
  202. if (!auditor) {
  203. throw '该审核人不存在';
  204. }
  205. await this._syncOrderByDelete(transaction, cpId, auditor.order, times);
  206. await transaction.delete(this.tableName, condition);
  207. await transaction.commit();
  208. } catch (err) {
  209. await transaction.rollback();
  210. throw err;
  211. }
  212. return true;
  213. }
  214. /**
  215. * 移除审核人时,同步其后审核人order
  216. * @param transaction - 事务
  217. * @param {Number} cpId - 变更方案id
  218. * @param {Number} auditorId - 审核人id
  219. * @param {Number} times - 第几次审批
  220. * @return {Promise<*>}
  221. * @private
  222. */
  223. async _syncOrderByDelete(transaction, cpId, order, times, selfOperate = '-') {
  224. this.initSqlBuilder();
  225. this.sqlBuilder.setAndWhere('cpid', {
  226. value: cpId,
  227. operate: '=',
  228. });
  229. this.sqlBuilder.setAndWhere('order', {
  230. value: order,
  231. operate: '>=',
  232. });
  233. this.sqlBuilder.setAndWhere('times', {
  234. value: times,
  235. operate: '=',
  236. });
  237. this.sqlBuilder.setUpdateData('order', {
  238. value: 1,
  239. selfOperate,
  240. });
  241. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  242. const data = await transaction.query(sql, sqlParam);
  243. return data;
  244. }
  245. /**
  246. * 开始审批
  247. * @param {Number} cpId - 方案id
  248. * @param {Number} times - 第几次审批
  249. * @return {Promise<boolean>}
  250. */
  251. async start(cpId, times = 1) {
  252. const audit = await this.getDataByCondition({ cpid: cpId, times, order: 1 });
  253. if (!audit) {
  254. // if (this.ctx.tender.info.shenpi.material === shenpiConst.sp_status.gdspl) {
  255. // throw '请联系管理员添加审批人';
  256. // } else {
  257. throw '请先选择审批人,再上报数据';
  258. // }
  259. }
  260. const transaction = await this.db.beginTransaction();
  261. try {
  262. await transaction.update(this.tableName, { id: audit.id, status: auditConst.status.checking, begin_time: new Date() });
  263. await transaction.update(this.ctx.service.changePlan.tableName, {
  264. id: cpId, status: auditConst.status.checking,
  265. });
  266. // 微信模板通知
  267. const shenpiUrl = await this.ctx.helper.urlToShort(
  268. this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/change/plan/' + cpId + '/information#shenpi'
  269. );
  270. const wechatData = {
  271. type: 'plan',
  272. wap_url: shenpiUrl,
  273. status: wxConst.status.check,
  274. tips: wxConst.tips.check,
  275. code: this.ctx.session.sessionProject.code,
  276. c_name: this.ctx.change.name,
  277. };
  278. await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
  279. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.BG, {
  280. pid: this.ctx.session.sessionProject.id,
  281. tid: this.ctx.tender.id,
  282. uid: audit.aid,
  283. sp_type: 'change',
  284. sp_id: audit.id,
  285. table_name: this.tableName,
  286. template: wxConst.template.change,
  287. wx_data: wechatData,
  288. });
  289. // 检查三方特殊推送
  290. await this.ctx.service.specMsg.addChangePlanMsg(transaction, this.ctx.session.sessionProject.id, this.ctx.change, pushOperate.change_plan.flow);
  291. await transaction.delete(this.ctx.service.changePlanHistory.tableName, { cpid: cpId });
  292. // todo 更新标段tender状态 ?
  293. await transaction.commit();
  294. } catch (err) {
  295. await transaction.rollback();
  296. throw err;
  297. }
  298. return true;
  299. }
  300. /**
  301. * 获取审核人需要审核的期列表
  302. *
  303. * @param auditorId
  304. * @return {Promise<*>}
  305. */
  306. async getAuditChangePlan(auditorId) {
  307. const sql = 'SELECT ma.`aid`, ma.`times`, ma.`order`, ma.`begin_time`, ma.`end_time`, ma.`tid`, ma.`cpid`,' +
  308. ' m.`status` As `mstatus`, m.`code` As `mcode`,' +
  309. ' t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
  310. ' FROM ?? AS ma, ?? AS m, ?? As t ' +
  311. ' WHERE ((ma.`aid` = ? and ma.`status` = ?) OR (m.`uid` = ? and ma.`status` = ? and m.`status` = ? and ma.`times` = (m.`times`-1)))' +
  312. ' and ma.`cpid` = m.`id` and ma.`tid` = t.`id` ORDER BY ma.`begin_time` DESC';
  313. const sqlParam = [this.tableName, this.ctx.service.changePlan.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
  314. const result = await this.db.query(sql, sqlParam);
  315. // 过滤result中存在重复sid的值, 保留最新的一条
  316. const filterResult = [];
  317. const cpidArr = [];
  318. for (const r of result) {
  319. if (cpidArr.indexOf(r.cpid) === -1) {
  320. filterResult.push(r);
  321. cpidArr.push(r.cpid);
  322. }
  323. }
  324. return filterResult;
  325. }
  326. /**
  327. * 获取审核人审核的次数
  328. *
  329. * @param auditorId
  330. * @return {Promise<*>}
  331. */
  332. async getCountByChecked(auditorId) {
  333. return await this.db.count(this.tableName, { aid: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
  334. }
  335. /**
  336. * 获取最近一次审批结束时间
  337. *
  338. * @param auditorId
  339. * @return {Promise<*>}
  340. */
  341. async getLastEndTimeByChecked(auditorId) {
  342. const sql = 'SELECT `end_time` FROM ?? WHERE `aid` = ? ' +
  343. 'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
  344. const sqlParam = [this.tableName, auditorId];
  345. const result = await this.db.queryOne(sql, sqlParam);
  346. return result ? result.end_time : null;
  347. }
  348. /**
  349. * 用于添加推送所需的content内容
  350. * @param {Number} pid 项目id
  351. * @param {Number} tid 台账id
  352. * @param {Number} cpId 方案id
  353. * @param {Number} uid 审批人id
  354. */
  355. async getNoticeContent(pid, tid, cpId, uid, opinion = '') {
  356. const noticeSql = 'SELECT * FROM (SELECT ' +
  357. ' t.`id` As `tid`, ma.`cpid`, m.`code` as `c_code`, t.`name`, pa.`name` As `su_name`, pa.role As `su_role`' +
  358. ' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
  359. ' LEFT JOIN ?? As m On t.`id` = m.`tid` AND m.`id` = ?' +
  360. ' LEFT JOIN ?? As ma ON m.`id` = ma.`cpid`' +
  361. ' LEFT JOIN ?? As pa ON pa.`id` = ?' +
  362. ' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
  363. const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.changePlan.tableName, cpId, this.tableName, this.ctx.service.projectAccount.tableName, uid, pid];
  364. const content = await this.db.query(noticeSql, noticeSqlParam);
  365. if (content.length) {
  366. content[0].opinion = opinion;
  367. }
  368. return content.length ? JSON.stringify(content[0]) : '';
  369. }
  370. /**
  371. * 审批
  372. * @param {Number} cpId - 方案id
  373. * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
  374. * @param {Number} times - 第几次审批
  375. * @return {Promise<void>}
  376. */
  377. async check(cpId, checkData, times = 1) {
  378. if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo) {
  379. throw '提交数据错误';
  380. }
  381. const pid = this.ctx.session.sessionProject.id;
  382. switch (checkData.checkType) {
  383. case auditConst.status.checked:
  384. await this._checked(pid, cpId, checkData, times);
  385. break;
  386. case auditConst.status.checkNo:
  387. await this._checkNo(pid, cpId, checkData, times);
  388. break;
  389. default:
  390. throw '无效审批操作';
  391. }
  392. }
  393. async _checked(pid, cpId, checkData, times) {
  394. const time = new Date();
  395. // 整理当前流程审核人状态更新
  396. const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
  397. if (!audit) {
  398. throw '审核数据错误';
  399. }
  400. // 获取审核人列表
  401. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  402. const sqlParam = [this.tableName, cpId, times];
  403. const auditors = await this.db.query(sql, sqlParam);
  404. const nextAudit = await this.getDataByCondition({ cpid: cpId, times, order: audit.order + 1 });
  405. const transaction = await this.db.beginTransaction();
  406. try {
  407. await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
  408. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  409. // 获取推送必要信息
  410. const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid, checkData.opinion);
  411. // 添加推送
  412. const records = [{ pid, type: pushType.changePlan, uid: this.ctx.change.uid, status: auditConst.status.checked, content: noticeContent }];
  413. auditors.forEach(audit => {
  414. records.push({ pid, type: pushType.changePlan, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
  415. });
  416. await transaction.insert('zh_notice', records);
  417. // 清单审批流程修改的数据插入到audit_amount中,审批完成则最后一位并插入到审批后变更值中
  418. await this.ctx.service.changePlanList.insertAuditAmount(transaction, cpId, !nextAudit);
  419. // 无下一审核人表示,审核结束
  420. if (nextAudit) {
  421. // 流程至下一审批人
  422. await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
  423. // 同步 期信息
  424. await transaction.update(this.ctx.service.changePlan.tableName, {
  425. id: cpId, status: auditConst.status.checking,
  426. });
  427. // 微信模板通知
  428. const shenpiUrl = await this.ctx.helper.urlToShort(
  429. this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/change/plan/' + cpId + '/information#shenpi'
  430. );
  431. const wechatData = {
  432. type: 'plan',
  433. wap_url: shenpiUrl,
  434. status: wxConst.status.check,
  435. tips: wxConst.tips.check,
  436. code: this.ctx.session.sessionProject.code,
  437. c_name: this.ctx.change.name,
  438. };
  439. await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
  440. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.BG, {
  441. pid: this.ctx.session.sessionProject.id,
  442. tid: this.ctx.tender.id,
  443. uid: nextAudit.aid,
  444. sp_type: 'change',
  445. sp_id: nextAudit.id,
  446. table_name: this.tableName,
  447. template: wxConst.template.change,
  448. wx_data: wechatData,
  449. });
  450. // 检查三方特殊推送
  451. await this.ctx.service.specMsg.addChangePlanMsg(transaction, pid, this.ctx.change, pushOperate.change_plan.flow);
  452. } else {
  453. // 本期结束
  454. // 生成截止本期数据 final数据
  455. // 同步 期信息
  456. await transaction.update(this.ctx.service.changePlan.tableName, {
  457. id: cpId, status: checkData.checkType,
  458. decimal: JSON.stringify(this.ctx.change.decimal),
  459. });
  460. // 微信模板通知
  461. const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), this.ctx.change.uid));
  462. const shenpiUrl = await this.ctx.helper.urlToShort(
  463. this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/change/plan/' + cpId + '/information#shenpi'
  464. );
  465. const wechatData = {
  466. type: 'plan',
  467. wap_url: shenpiUrl,
  468. status: wxConst.status.success,
  469. tips: wxConst.tips.success,
  470. code: this.ctx.session.sessionProject.code,
  471. c_name: this.ctx.change.name,
  472. };
  473. await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
  474. // 检查三方特殊推送
  475. await this.ctx.service.specMsg.addChangePlanMsg(transaction, pid, this.ctx.change, pushOperate.change_plan.flow);
  476. }
  477. await transaction.commit();
  478. } catch (err) {
  479. await transaction.rollback();
  480. throw err;
  481. }
  482. }
  483. async _checkNo(pid, cpId, checkData, times) {
  484. const time = new Date();
  485. const changeData = await this.ctx.service.changePlan.getDataById(cpId);
  486. // 整理当前流程审核人状态更新
  487. const audit = await this.getDataByCondition({ cpid: cpId, times, status: auditConst.status.checking });
  488. if (!audit) {
  489. throw '审核数据错误';
  490. }
  491. // const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  492. // const sqlParam = [this.tableName, cpId, times];
  493. // const auditors = await this.db.query(sql, sqlParam);
  494. const auditors = await this.getAuditGroupByList(cpId, times);
  495. let order = 1;
  496. const newAuditors = [];
  497. for (const a of auditors) {
  498. a.times = times + 1;
  499. a.order = order;
  500. a.status = auditConst.status.uncheck;
  501. order++;
  502. newAuditors.push({
  503. tid: this.ctx.tender.id,
  504. cpid: cpId,
  505. times: a.times,
  506. order: a.order,
  507. status: a.status,
  508. aid: a.aid,
  509. });
  510. }
  511. const transaction = await this.db.beginTransaction();
  512. try {
  513. await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
  514. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  515. // 添加到消息推送表
  516. const noticeContent = await this.getNoticeContent(pid, audit.tid, cpId, audit.aid, checkData.opinion);
  517. const records = [{ pid, type: pushType.changePlan, uid: this.ctx.change.uid, status: auditConst.status.checkNo, content: noticeContent }];
  518. auditors.forEach(audit => {
  519. records.push({ pid, type: pushType.changePlan, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent });
  520. });
  521. await transaction.insert(this.ctx.service.noticePush.tableName, records);
  522. // 同步期信息
  523. await transaction.update(this.ctx.service.changePlan.tableName, {
  524. id: cpId, status: checkData.checkType,
  525. times: times + 1,
  526. });
  527. // 拷贝新一次审核流程列表
  528. await transaction.insert(this.tableName, newAuditors);
  529. // 清单审批值删除并重算变更金额
  530. await this.ctx.service.changePlanList.delAuditAmount(transaction, cpId);
  531. // 微信模板通知
  532. const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), this.ctx.change.uid));
  533. const shenpiUrl = await this.ctx.helper.urlToShort(
  534. this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/change/plan/' + cpId + '/information#shenpi'
  535. );
  536. const wechatData = {
  537. type: 'plan',
  538. wap_url: shenpiUrl,
  539. status: wxConst.status.back,
  540. tips: wxConst.tips.back,
  541. code: this.ctx.session.sessionProject.code,
  542. c_name: this.ctx.change.name,
  543. };
  544. await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
  545. // 检查三方特殊推送
  546. await this.ctx.service.specMsg.addChangePlanMsg(transaction, pid, this.ctx.change, pushOperate.change_plan.flow);
  547. // 生成内容保存表至zh_change_project_history中,用于撤回
  548. // 回退spamount值数据
  549. const changeList = await this.ctx.service.changePlanList.getAllDataByCondition({
  550. where: { cpid: cpId },
  551. });
  552. await this.ctx.service.changePlanHistory.saveHistory(transaction, changeData, changeList);
  553. await transaction.commit();
  554. } catch (err) {
  555. await transaction.rollback();
  556. throw err;
  557. }
  558. }
  559. /**
  560. * 复制上一期的审批人列表给最新一期
  561. *
  562. * @param transaction - 新增一期的事务
  563. * @param {Object} preMaterial - 上一期
  564. * @param {Object} newaMaterial - 最新一期
  565. * @return {Promise<*>}
  566. */
  567. async copyPreChangePlanAuditors(transaction, preChange, newChange) {
  568. const auditors = await this.getAuditGroupByList(preChange.id, preChange.times);
  569. const newAuditors = [];
  570. for (const a of auditors) {
  571. const na = {
  572. tid: preChange.tid,
  573. cpid: newChange.id,
  574. aid: a.aid,
  575. times: newChange.times,
  576. order: newAuditors.length + 1,
  577. status: auditConst.status.uncheck,
  578. };
  579. newAuditors.push(na);
  580. }
  581. const result = newAuditors.length > 0 ? await transaction.insert(this.tableName, newAuditors) : null;
  582. return result ? result.affectedRows === auditors.length : true;
  583. }
  584. async getAllAuditors(tenderId) {
  585. const sql = 'SELECT ma.aid, ma.tid FROM ' + this.tableName + ' ma' +
  586. ' LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On ma.tid = t.id' +
  587. ' WHERE t.id = ?' +
  588. ' GROUP BY ma.aid';
  589. const sqlParam = [tenderId];
  590. return this.db.query(sql, sqlParam);
  591. }
  592. /**
  593. * 取待审批期列表(wap用)
  594. *
  595. * @param auditorId
  596. * @return {Promise<*>}
  597. */
  598. async getAuditChangePlanByWap(auditorId) {
  599. const sql =
  600. 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`cpid`,' +
  601. ' s.*,' +
  602. ' t.`name` as `t_name`, t.`project_id`, t.`type`, t.`user_id`,' +
  603. ' ti.`deal_info`, ti.`decimal` ' +
  604. ' FROM ?? AS sa' +
  605. ' Left Join ?? AS s On sa.`cpid` = s.`id`' +
  606. ' Left Join ?? As t On sa.`tid` = t.`id`' +
  607. ' Left Join ?? AS ti ON ti.`tid` = t.`id`' +
  608. ' WHERE sa.`aid` = ? and sa.`status` = ?';
  609. const sqlParam = [
  610. this.tableName,
  611. this.ctx.service.changePlan.tableName,
  612. this.ctx.service.tender.tableName,
  613. this.ctx.service.tenderInfo.tableName,
  614. auditorId,
  615. auditConst.status.checking,
  616. ];
  617. return await this.db.query(sql, sqlParam);
  618. }
  619. /**
  620. * 审批撤回
  621. * @param {Number} stageId - 标段id
  622. * @param {Number} times - 第几次审批
  623. * @return {Promise<void>}
  624. */
  625. async checkCancel(change) {
  626. // 分3种情况,根据ctx.cancancel值判断:
  627. // 1.原报发起撤回,当前流程删除,并回到待上报
  628. // 2.审批人撤回审批通过,增加流程,并回到它审批中
  629. // 4.审批人撤回退回原报操作,删除新增的审批流,增加流程,回滚到它审批中
  630. switch (change.cancancel) {
  631. case 1: await this._userCheckCancel(change); break;
  632. case 2: await this._auditCheckCancel(change); break;
  633. case 4: await this._auditCheckCancelNo(change); break;
  634. default: throw '不可撤回,请刷新页面重试';
  635. }
  636. }
  637. /**
  638. * 原报撤回,直接改动审批人状态
  639. * 如果存在审批人数据,将其改为原报流程数据,但保留原提交人
  640. *
  641. * 一审 1 A checking -> A uncheck status改 pay/jl:删0(jl为增量数据,只删重复部分) 1->0 删1
  642. * ...
  643. *
  644. * @param stage
  645. * @returns {Promise<void>}
  646. * @private
  647. */
  648. async _userCheckCancel(change) {
  649. const transaction = await this.db.beginTransaction();
  650. try {
  651. // 整理当前流程审核人状态更新
  652. const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times, status: auditConst.status.checking });
  653. // 审批人变成待审批状态
  654. await transaction.update(this.tableName, {
  655. id: curAudit.id,
  656. status: auditConst.status.uncheck,
  657. begin_time: null,
  658. opinion: null,
  659. });
  660. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
  661. // 清单审批值删除并重算变更金额
  662. await this.ctx.service.changePlanList.delAuditAmount(transaction, change.id);
  663. // 变成待上报状态
  664. await transaction.update(this.ctx.service.changePlan.tableName, {
  665. id: change.id,
  666. status: change.times === 1 ? auditConst.status.uncheck : auditConst.status.checkNo,
  667. });
  668. await transaction.commit();
  669. } catch (err) {
  670. await transaction.rollback();
  671. throw err;
  672. }
  673. }
  674. /**
  675. * 审批人撤回审批通过,插入两条数据
  676. *
  677. * 一审 1 A checked 一审 1 A checked
  678. * 二审 2 B checked pre -> 二审 2 B checked
  679. * 三审 3 C checking cur 二审 3 B checkCancel 增 增extra_his 增tp_his
  680. * 四审 4 D uncheck 二审 4 B checking 增 增pay_cur
  681. * 三审 5 C uncheck order、status改
  682. * 四审 6 D uncheck order改
  683. *
  684. * @param stage
  685. * @returns {Promise<void>}
  686. * @private
  687. */
  688. async _auditCheckCancel(change) {
  689. const time = new Date();
  690. const transaction = await this.db.beginTransaction();
  691. try {
  692. // 整理当前流程审核人状态更新
  693. const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times, status: auditConst.status.checking });
  694. const preAudit = change.preAudit;
  695. if (!curAudit || curAudit.order <= 1 || !preAudit) {
  696. throw '撤回用户数据错误';
  697. }
  698. // 顺移其后审核人流程顺序
  699. const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cpid = ? AND times = ? AND `order` > ?';
  700. await transaction.query(sql, [change.id, change.times, curAudit.order]);
  701. // 当前审批人2次添加至流程中
  702. const newAuditors = [];
  703. // 先入撤回记录
  704. newAuditors.push({
  705. tid: change.tid,
  706. cpid: change.id,
  707. aid: preAudit.aid,
  708. times: change.times,
  709. order: curAudit.order,
  710. status: auditConst.status.checkCancel,
  711. begin_time: time,
  712. end_time: time,
  713. opinion: '',
  714. });
  715. newAuditors.push({
  716. tid: change.tid,
  717. cpid: change.id,
  718. aid: preAudit.aid,
  719. times: change.times,
  720. order: curAudit.order + 1,
  721. status: auditConst.status.checking,
  722. begin_time: time,
  723. });
  724. await transaction.insert(this.tableName, newAuditors);
  725. // 当前审批人变成待审批
  726. await transaction.update(this.tableName, { id: curAudit.id, order: curAudit.order + 2, begin_time: null, status: auditConst.status.uncheck });
  727. await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, curAudit.id);
  728. // 清除上一人的值并调整spamount值
  729. const updateList = [];
  730. const changeList = await this.ctx.service.changePlanList.getAllDataByCondition({
  731. where: { cpid: change.id },
  732. });
  733. for (const cl of changeList) {
  734. const audit_amount = cl.audit_amount.split(',');
  735. const last_amount = audit_amount[audit_amount.length - 1] ? audit_amount[audit_amount.length - 1] : 0;
  736. audit_amount.splice(-1, 1);
  737. const list_update = {
  738. id: cl.id,
  739. audit_amount: audit_amount.join(','),
  740. spamount: parseFloat(last_amount),
  741. };
  742. updateList.push(list_update);
  743. }
  744. if (updateList.length > 0) await transaction.updateRows(this.ctx.service.changePlanList.tableName, updateList);
  745. // 更新total_price
  746. await this.ctx.service.changePlanList.calcCamountSum(transaction);
  747. await transaction.commit();
  748. } catch (err) {
  749. await transaction.rollback();
  750. throw err;
  751. }
  752. }
  753. /**
  754. * 审批人撤回审批退回原报
  755. *
  756. * 1# 一审 1 A checked 1# 一审 1 A checked
  757. * 二审 2 B checkNo pre -> 二审 2 B checkNo
  758. * 三审 3 C uncheck 二审 3 B checkCancel 增 pay: 2#0 -> 1#3 jl: 2#0 -> 1#3 增tp_his 增extra_his
  759. * 二审 4 B checking 增 pay: 2#0 -> 1#4
  760. * 三审 5 C uncheck order改
  761. *
  762. * 2# 一审 1 A uncheck 2# 删 pay: 2#0删 jl: 2#0删
  763. * 二审 2 B uncheck
  764. * 三审 3 C uncheck
  765. *
  766. * @param stage
  767. * @returns {Promise<void>}
  768. * @private
  769. */
  770. async _auditCheckCancelNo(change) {
  771. const time = new Date();
  772. const transaction = await this.db.beginTransaction();
  773. try {
  774. // const curAudit = await this.getDataByCondition({ cpid: change.id, times: change.times - 1, status: auditConst.status.back });
  775. const curAudit = await this.getAuditorByStatus(change.id, auditConst.status.checkNo, change.times);
  776. // 整理上一个流程审核人状态更新
  777. // 顺移其后审核人流程顺序
  778. const sql = 'UPDATE ' + this.tableName + ' SET `order` = `order` + 2 WHERE cpid = ? AND times = ? AND `order` > ?';
  779. await transaction.query(sql, [change.id, change.times - 1, curAudit.order]);
  780. // 当前审批人2次添加至流程中
  781. const newAuditors = [];
  782. newAuditors.push({
  783. tid: change.tid,
  784. cpid: change.id,
  785. aid: curAudit.aid,
  786. times: curAudit.times,
  787. order: curAudit.order + 1,
  788. status: auditConst.status.checkCancel,
  789. begin_time: time,
  790. end_time: time,
  791. opinion: '',
  792. });
  793. newAuditors.push({
  794. tid: change.tid,
  795. cpid: change.id,
  796. aid: curAudit.aid,
  797. times: curAudit.times,
  798. order: curAudit.order + 2,
  799. status: auditConst.status.checking,
  800. begin_time: time,
  801. });
  802. await transaction.insert(this.tableName, newAuditors);
  803. // 删除当前次审批流
  804. await transaction.delete(this.tableName, { cpid: change.id, times: change.times });
  805. // 回退数据
  806. await this.ctx.service.changePlanHistory.returnHistory(transaction, change.id);
  807. await transaction.delete(this.ctx.service.changePlanHistory.tableName, { cpid: change.id });
  808. // // 设置变更立项为审批中
  809. // await transaction.update(this.ctx.service.changeProject.tableName, {
  810. // id: change.id,
  811. // time: change.times - 1,
  812. // status: auditConst.status.checking,
  813. // });
  814. await transaction.commit();
  815. } catch (err) {
  816. await transaction.rollback();
  817. throw err;
  818. }
  819. }
  820. /**
  821. * 重新审批变更令
  822. * @param { string } cid - 查询的清单
  823. * @return {Promise<*>} - 可用的变更令列表
  824. */
  825. async checkRevise(change) {
  826. const time = new Date();
  827. // 初始化事务
  828. const transaction = await this.db.beginTransaction();
  829. let result = false;
  830. try {
  831. const pid = this.ctx.session.sessionProject.id;
  832. // 获取审核人列表
  833. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  834. const sqlParam = [this.tableName, change.id, change.times];
  835. const auditors = await this.db.query(sql, sqlParam);
  836. // 添加到消息推送表
  837. const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '发起修订');
  838. const records = [];
  839. auditors.forEach(auditor => {
  840. records.push({
  841. pid,
  842. type: pushType.changePlan,
  843. uid: auditor.aid,
  844. status: auditConst.status.revise,
  845. content: noticeContent,
  846. });
  847. });
  848. await transaction.insert('zh_notice', records);
  849. // 获取当前次数审批人列表
  850. const auditList = await this.getAuditGroupByList(change.id, change.times);
  851. const lastAudit = await this.getLastAudit(change.id, change.times);
  852. const insert_audit_array = [];
  853. // 新增一个发起修订状态到审批流程中
  854. const revise_audit = {
  855. tid: change.tid,
  856. cpid: change.id,
  857. aid: change.uid,
  858. times: change.times,
  859. order: lastAudit.order + 1,
  860. status: auditConst.status.revise,
  861. begin_time: time,
  862. end_time: time,
  863. opinion: '',
  864. };
  865. insert_audit_array.push(revise_audit);
  866. // 新增新一次的审批人列表
  867. let order = 1;
  868. for (const al of auditList) {
  869. const insert_audit = {
  870. tid: change.tid,
  871. cpid: change.id,
  872. aid: al.aid,
  873. times: change.times + 1,
  874. order,
  875. status: auditConst.status.uncheck,
  876. };
  877. insert_audit_array.push(insert_audit);
  878. order++;
  879. }
  880. await transaction.insert(this.tableName, insert_audit_array);
  881. // 生成内容保存表至zh_change_history中,用于撤销修订回退
  882. const changeData = await transaction.get(this.ctx.service.changePlan.tableName, { id: change.id });
  883. const changeList = await this.ctx.service.changePlanList.getAllDataByCondition({
  884. where: { cpid: change.id },
  885. });
  886. await this.ctx.service.changePlanHistory.saveHistory(transaction, changeData, changeList);
  887. // 清单审批值删除并重算变更金额
  888. await this.ctx.service.changePlanList.delAuditAmount(transaction, change.id);
  889. // 设置变更立项修订状态
  890. await transaction.update(this.ctx.service.changePlan.tableName, {
  891. id: change.id,
  892. decimal: null,
  893. status: auditConst.status.revise,
  894. times: change.times + 1,
  895. });
  896. await transaction.commit();
  897. result = true;
  898. } catch (error) {
  899. console.log(error);
  900. await transaction.rollback();
  901. result = false;
  902. }
  903. return result;
  904. }
  905. /**
  906. * 撤销修订变更令
  907. * @param { string } cid - 查询的清单
  908. * @return {Promise<*>} - 可用的变更令列表
  909. */
  910. async cancelRevise(change) {
  911. const time = new Date();
  912. // 初始化事务
  913. const transaction = await this.db.beginTransaction();
  914. let result = false;
  915. try {
  916. const pid = this.ctx.session.sessionProject.id;
  917. // 获取审核人列表
  918. const sql = 'SELECT `tid`, `cpid`, `aid`, `order` FROM ?? WHERE `cpid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  919. const sqlParam = [this.tableName, change.id, change.times - 1];
  920. const auditors = await this.db.query(sql, sqlParam);
  921. // 添加到消息推送表
  922. const noticeContent = await this.getNoticeContent(pid, change.tid, change.id, this.ctx.session.sessionUser.accountId, '撤销修订');
  923. const records = [];
  924. auditors.forEach(auditor => {
  925. records.push({
  926. pid,
  927. type: pushType.changePlan,
  928. uid: auditor.aid,
  929. status: auditConst.status.cancelRevise,
  930. content: noticeContent,
  931. });
  932. });
  933. await transaction.insert('zh_notice', records);
  934. const lastAudit = await this.getLastAudit(change.id, change.times - 1);
  935. // 新增一个撤销修订状态到审批流程中
  936. const revise_audit = {
  937. tid: change.tid,
  938. cpid: change.id,
  939. aid: this.ctx.session.sessionUser.accountId,
  940. times: change.times - 1,
  941. order: lastAudit.order + 1,
  942. status: auditConst.status.cancelRevise,
  943. begin_time: time,
  944. end_time: time,
  945. opinion: '',
  946. };
  947. await transaction.insert(this.ctx.service.changePlanAudit.tableName, revise_audit);
  948. await transaction.delete(this.ctx.service.changePlanAudit.tableName, { cpid: change.id, times: change.times });
  949. await this.ctx.service.changePlanHistory.returnHistory(transaction, change.id);
  950. await transaction.delete(this.ctx.service.changePlanHistory.tableName, { cpid: change.id });
  951. await transaction.commit();
  952. result = true;
  953. } catch (error) {
  954. console.log(error);
  955. await transaction.rollback();
  956. result = false;
  957. }
  958. return result;
  959. }
  960. /**
  961. * 重新审批变更方案
  962. * @param { string } cid - 查询的清单
  963. * @return {Promise<*>} - 可用的变更令列表
  964. */
  965. async checkAgain(change) {
  966. // 初始化事务
  967. const time = new Date();
  968. const transaction = await this.db.beginTransaction();
  969. let result = false;
  970. try {
  971. // 获取终审
  972. const zsAudit = await this.getAuditorByStatus(change.id, auditConst.status.checked);
  973. const lastAudit = await this.getLastAudit(change.id, change.times);
  974. const insert_audit_array = [];
  975. // 新增2个审批状态到审批列表中
  976. insert_audit_array.push({
  977. tid: change.tid,
  978. cpid: change.id,
  979. aid: zsAudit.aid,
  980. times: zsAudit.times,
  981. order: lastAudit.order + 1,
  982. status: auditConst.status.checkAgain,
  983. begin_time: time,
  984. end_time: time,
  985. opinion: '',
  986. });
  987. // 新增2个审批人到审批列表中
  988. insert_audit_array.push({
  989. tid: change.tid,
  990. cpid: change.id,
  991. aid: zsAudit.aid,
  992. times: zsAudit.times,
  993. order: lastAudit.order + 2,
  994. status: auditConst.status.checking,
  995. begin_time: time,
  996. });
  997. await transaction.insert(this.tableName, insert_audit_array);
  998. // 设置变更令审批中
  999. await transaction.update(this.ctx.service.changePlan.tableName, {
  1000. id: change.id,
  1001. status: auditConst.status.checking,
  1002. });
  1003. // 清除上一人的值并调整spamount值
  1004. const updateList = [];
  1005. const changeList = await this.ctx.service.changePlanList.getAllDataByCondition({
  1006. where: { cpid: change.id },
  1007. });
  1008. for (const cl of changeList) {
  1009. const audit_amount = cl.audit_amount.split(',');
  1010. const last_amount = audit_amount[audit_amount.length - 1] ? audit_amount[audit_amount.length - 1] : 0;
  1011. audit_amount.splice(-1, 1);
  1012. const list_update = {
  1013. id: cl.id,
  1014. audit_amount: audit_amount.join(','),
  1015. spamount: parseFloat(last_amount),
  1016. };
  1017. updateList.push(list_update);
  1018. }
  1019. if (updateList.length > 0) await transaction.updateRows(this.ctx.service.changePlanList.tableName, updateList);
  1020. // 更新total_price
  1021. await this.ctx.service.changePlanList.calcCamountSum(transaction);
  1022. await transaction.commit();
  1023. result = true;
  1024. } catch (error) {
  1025. await transaction.rollback();
  1026. result = false;
  1027. }
  1028. return result;
  1029. }
  1030. }
  1031. return ChangePlanAudit;
  1032. };