change_plan_audit.js 50 KB

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