ledger_audit.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. 'use strict';
  2. /**
  3. * 台账审批流程表
  4. *
  5. * @author Mai
  6. * @date 2018/5/25
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').ledger;
  10. const auditType = require('../const/audit').auditType;
  11. const smsTypeConst = require('../const/sms_type');
  12. const SMS = require('../lib/sms');
  13. const SmsAliConst = require('../const/sms_alitemplate');
  14. const wxConst = require('../const/wechat_template');
  15. const shenpiConst = require('../const/shenpi');
  16. const pushType = require('../const/audit').pushType;
  17. const pushOperate = require('../const/spec_3f').pushOperate;
  18. module.exports = app => {
  19. class LedgerAudit extends app.BaseService {
  20. /**
  21. * 构造函数
  22. *
  23. * @param {Object} ctx - egg全局变量
  24. * @return {void}
  25. */
  26. constructor(ctx) {
  27. super(ctx);
  28. this.tableName = 'ledger_audit';
  29. }
  30. /**
  31. * 获取标段审核人信息
  32. *
  33. * @param {Number} tenderId - 标段id
  34. * @param {Number} auditorId - 审核人id
  35. * @param {Number} times - 第几次审批
  36. * @return {Promise<*>}
  37. */
  38. async getAuditor(tenderId, auditorId, times = 1) {
  39. const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`audit_type`, la.`audit_ledger_id`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
  40. ' FROM ?? AS la Left Join ?? AS pa ON la.`audit_id` = pa.`id`' +
  41. ' WHERE la.`tender_id` = ? and la.`audit_id` = ? and la.`times` = ?';
  42. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditorId, times];
  43. return await this.db.queryOne(sql, sqlParam);
  44. }
  45. async getAuditorByOrder(tenderId, order, times = 1) {
  46. const sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`audit_type`, la.`audit_ledger_id`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
  47. ' FROM ?? AS la Left Join ?? AS pa ON la.`audit_id` = pa.`id`' +
  48. ' WHERE la.`tender_id` = ? and la.`audit_order` = ? and la.`times` = ?';
  49. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, order, times];
  50. return await this.db.queryOne(sql, sqlParam);
  51. }
  52. async getAuditorsByOrder(tenderId, order, times) {
  53. const sql =
  54. 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`,' +
  55. ' la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, la.audit_type, la.audit_ledger_id ' +
  56. ' FROM ' + this.tableName + ' AS la' +
  57. ' Left Join ' + this.ctx.service.projectAccount.tableName + ' AS pa ON la.`audit_id` = pa.`id`' +
  58. ' WHERE la.`tender_id` = ? and la.`audit_order` = ? and la.`times` = ?' +
  59. ' ORDER BY `audit_order` DESC';
  60. const sqlParam = [tenderId, order, times ? times: 1];
  61. return await this.db.query(sql, sqlParam);
  62. }
  63. async getLastestAuditor(tenderId, times, status) {
  64. const sql =
  65. 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`,' +
  66. ' la.`times`, la.`audit_order`, la.`audit_type`, la.`audit_ledger_id`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
  67. ' FROM ' + this.tableName + ' AS la' +
  68. ' Left Join ' + this.ctx.service.projectAccount.tableName + ' AS pa ON la.`audit_id` = pa.`id`' +
  69. ' WHERE la.`tender_id` = ? and la.`status` = ? and la.`times` = ?' +
  70. ' ORDER BY `audit_order` DESC';
  71. const sqlParam = [tenderId, status, times ? times : 1];
  72. return await this.db.queryOne(sql, sqlParam);
  73. }
  74. async getLastestAuditors(tenderId, times, status) {
  75. const sql =
  76. 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.audit_type, la.audit_order, la.audit_ledger_id,' +
  77. ' la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
  78. ' FROM ' + this.tableName + ' AS la' +
  79. ' Left Join ' + this.ctx.service.projectAccount.tableName + ' AS pa ON la.`audit_id` = pa.`id`' +
  80. ' WHERE la.`tender_id` = ? and la.`status` = ? and la.`times` = ?' +
  81. ' ORDER BY `audit_order` DESC';
  82. const sqlParam = [tenderId, status, times ? times: 1];
  83. const result = await this.db.query(sql, sqlParam);
  84. if (result.length === 0) return [];
  85. return result.filter(x => { return x.audit_order === result[0].audit_order });
  86. }
  87. /**
  88. * 获取标段审核列表信息
  89. *
  90. * @param {Number} tenderId - 标段id
  91. * @param {Number} times - 第几次审批
  92. * @return {Promise<*>}
  93. */
  94. async getAuditors(tenderId, times = 1, order_sort = 'asc') {
  95. const sql = 'SELECT la.id, la.audit_id, la.times, la.audit_order, la.audit_type, la.audit_ledger_id, la.status, la.opinion, la.begin_time, la.end_time, ' +
  96. ' pa.name, pa.company, pa.role, pa.mobile, pa.telephone, pa.sign_path' +
  97. ` FROM ${this.tableName} la LEFT JOIN ${this.ctx.service.projectAccount.tableName} pa ON la.audit_id = pa.id` +
  98. ' WHERE la.tender_id = ? AND la.times = ?' +
  99. ' ORDER BY la.audit_order ' + order_sort;
  100. const sqlParam = [tenderId, times];
  101. const result = await this.db.query(sql, sqlParam);
  102. const max_sort = this._.max(result.map(x => { return x.audit_order; }));
  103. for (const i in result) {
  104. result[i].max_sort = max_sort;
  105. }
  106. return result;
  107. }
  108. /**
  109. * 获取标段当前审核人
  110. *
  111. * @param {Number} tenderId - 标段id
  112. * @param {Number} times - 第几次审批
  113. * @return {Promise<*>}
  114. */
  115. async getCurAuditor(tenderId, times = 1) {
  116. const sql =
  117. 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`audit_type`, la.`audit_ledger_id`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
  118. ' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
  119. ' WHERE la.`tender_id` = ? and la.`status` = ? and la.`times` = ?';
  120. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditConst.status.checking, times];
  121. return await this.db.queryOne(sql, sqlParam);
  122. }
  123. async getCurAuditors(tenderId, times = 1) {
  124. const sql =
  125. 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, la.audit_type, la.audit_order, la.audit_ledger_id ' +
  126. ' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
  127. ' WHERE la.`tender_id` = ? and la.`status` = ? and la.`times` = ?';
  128. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditConst.status.checking, times];
  129. return await this.db.query(sql, sqlParam);
  130. }
  131. async getAuditorGroup(tenderId, times) {
  132. const auditors = await this.getAuditors(tenderId, times); // 全部参与的审批人
  133. return this.ctx.helper.groupAuditors(auditors, 'audit_order');
  134. }
  135. async getUserGroup(tenderId, times) {
  136. const group = await this.getAuditorGroup(tenderId, times);
  137. const sql =
  138. 'SELECT pa.`id` As audit_id, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As tender_id, 0 As audit_order, 1 As audit_type' +
  139. ' FROM ' + this.ctx.service.tender.tableName + ' As t' +
  140. ' LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
  141. ' ON t.user_id = pa.id' +
  142. ' WHERE t.id = ?';
  143. const sqlParam = [times, tenderId, tenderId];
  144. const user = await this.db.queryOne(sql, sqlParam);
  145. group.unshift([ user ]);
  146. return group;
  147. }
  148. async getUniqUserGroup(tenderId, times) {
  149. const group = await this.getAuditorGroup(tenderId, times);
  150. const sql =
  151. 'SELECT pa.`id` As audit_id, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As tender_id, 0 As audit_order, 1 As audit_type' +
  152. ' FROM ' + this.ctx.service.tender.tableName + ' As t' +
  153. ' LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
  154. ' ON t.user_id = pa.id' +
  155. ' WHERE t.id = ?';
  156. const sqlParam = [times, tenderId, tenderId];
  157. const user = await this.db.queryOne(sql, sqlParam);
  158. group.unshift([ user ]);
  159. return this.ctx.helper.groupAuditorsUniq(group, 'audit_order');
  160. }
  161. async getAuditorHistory(tenderId, times, reverse = false) {
  162. const history = [];
  163. if (times >= 1) {
  164. for (let i = 1; i <= times; i++) {
  165. const auditors = await this.getAuditors(tenderId, i);
  166. const group = this.ctx.helper.groupAuditors(auditors, 'audit_order');
  167. const historyGroup = [];
  168. const max_order = group.length > 0 && group[group.length - 1].length > 0 ? group[group.length - 1][0].audit_order : -1;
  169. for (const g of group) {
  170. const his = {
  171. beginYear: '', beginDate: '', beginTime: '', endYear: '', endDate: '', endTime: '', begin_time: null, end_time: null,
  172. audit_type: g[0].audit_type, audit_order: g[0].audit_order,
  173. auditors: g
  174. };
  175. if (his.audit_type === auditType.key.common) {
  176. his.name = g[0].name;
  177. } else {
  178. his.name = this.ctx.helper.transFormToChinese(his.audit_order) + '审';
  179. }
  180. his.is_final = his.audit_order === max_order;
  181. if (g[0].begin_time) {
  182. his.begin_time = g[0].begin_time;
  183. const beginTime = this.ctx.moment(g[0].begin_time);
  184. his.beginYear = beginTime.format('YYYY');
  185. his.beginDate = beginTime.format('MM-DD');
  186. his.beginTime = beginTime.format('HH:mm:ss');
  187. }
  188. let end_time;
  189. g.forEach(x => {
  190. if (x.status === auditConst.status.checkSkip) return;
  191. if (!his.status || x.status === auditConst.status.checking) his.status = x.status;
  192. if (x.end_time && (!end_time || x.end_time > end_time)) {
  193. end_time = x.end_time;
  194. if (his.status !== auditConst.status.checking) his.status = x.status;
  195. }
  196. });
  197. if (end_time) {
  198. his.end_time = end_time;
  199. const endTime = this.ctx.moment(end_time);
  200. his.endYear = endTime.format('YYYY');
  201. his.endDate = endTime.format('MM-DD');
  202. his.endTime = endTime.format('HH:mm:ss');
  203. }
  204. historyGroup.push(his);
  205. }
  206. if (reverse) {
  207. history.push(historyGroup.reverse());
  208. } else {
  209. history.push(historyGroup);
  210. }
  211. }
  212. }
  213. return history;
  214. }
  215. async getUniqAuditor(tenderId, times) {
  216. const auditors = await this.getAuditors(tenderId, times); // 全部参与的审批人
  217. const result = [];
  218. auditors.forEach(x => {
  219. if (result.findIndex(r => { return x.audit_id === r.audit_id && x.audit_order === r.audit_order; }) < 0) {
  220. result.push(x);
  221. }
  222. });
  223. return result;
  224. }
  225. async loadLedgerUser(tender) {
  226. const status = auditConst.status;
  227. const accountId = this.ctx.session.sessionUser.accountId;
  228. tender.user = await this.ctx.service.projectAccount.getAccountInfoById(tender.user_id);
  229. tender.auditors = await this.getAuditors(tender.id, tender.ledger_times); // 全部参与的审批人
  230. tender.auditorIds = this._.map(tender.auditors, 'audit_id');
  231. tender.curAuditors = tender.auditors.filter(x => { return x.status === status.checking; }); // 当前流程中审批中的审批人
  232. tender.curAuditorIds = this._.map(tender.curAuditors, 'audit_id');
  233. tender.flowAuditors = tender.curAuditors.length > 0 ? tender.auditors.filter(x => { return x.audit_order === tender.curAuditors[0].audit_order; }) : []; // 当前流程中参与的审批人(包含会签时,审批通过的人)
  234. tender.flowAuditorIds = this._.map(tender.flowAuditors, 'audit_id');
  235. tender.nextAuditors = tender.curAuditors.length > 0 ? tender.auditors.filter(x => { return x.audit_order === tender.curAuditors[0].audit_order + 1; }) : [];
  236. tender.nextAuditorIds = this._.map(tender.nextAuditors, 'audit_id');
  237. tender.auditorGroups = this.ctx.helper.groupAuditors(tender.auditors, 'audit_order');
  238. tender.userGroups = this.ctx.helper.groupAuditorsUniq(tender.auditorGroups);
  239. tender.userGroups.unshift([{
  240. aid: tender.user.id, order: 0, times: tender.ledger_times, audit_order: 0, audit_type: auditType.key.common,
  241. name: tender.user.name, role: tender.user.role, company: tender.user.company
  242. }]);
  243. tender.finalAuditorIds = tender.userGroups[tender.userGroups.length - 1].map(x => { return x.aid; });
  244. tender.relaAuditor = tender.auditors.find(x => { return x.aid === accountId });
  245. tender.assists = [];// await this.service.ledgerAuditAss.getData(tender); // 全部协同人
  246. tender.assists = tender.assists.filter(x => {
  247. return x.user_id === tender.user_id || tender.auditorIds.indexOf(x.user_id) >= 0;
  248. }); // 过滤无效协同人
  249. tender.userAssists = tender.assists.filter(x => { return x.user_id === tender.user_id; }); // 原报协同人
  250. tender.userAssistIds = this._.map(tender.userAssists, 'ass_user_id');
  251. tender.auditAssists = tender.assists.filter(x => { return x.user_id !== tender.user_id; }); // 审批协同人
  252. tender.auditAssistIds = this._.map(tender.auditAssists, 'ass_user_id');
  253. tender.relaAssists = tender.assists.filter(x => { return x.user_id === accountId }); // 登录人的协同人
  254. tender.userIds = tender.ledger_status === status.uncheck // 当前流程下全部参与人id
  255. ? [tender.user_id]
  256. : [tender.user_id, ...tender.userAssistIds, ...tender.auditorIds, ...tender.auditAssistIds];
  257. }
  258. async loadLedgerAuditViewData(tender) {
  259. const times = tender.ledger_status === auditConst.status.checkNo ? tender.ledger_times - 1 : tender.ledger_times;
  260. if (!tender.user) tender.user = await this.ctx.service.projectAccount.getAccountInfoById(tender.user_id);
  261. tender.auditHistory = await this.getAuditorHistory(tender.id, times);
  262. // 获取审批流程中左边列表
  263. if (tender.status === auditConst.status.checkNo && tender.user_id !== this.ctx.session.sessionUser.accountId) {
  264. const auditors = await this.getAuditors(tender.id, times); // 全部参与的审批人
  265. const auditorGroups = this.ctx.helper.groupAuditors(auditors, 'audit_order');
  266. tender.auditors2 = this.ctx.helper.groupAuditorsUniq(auditorGroups, 'audit_order');
  267. tender.auditors2.unshift([{
  268. aid: tender.user.id, order: 0, times: tender.ledger_times - 1, audit_order: 0, audit_type: auditConst.auditType.key.common,
  269. name: tender.user.name, role: tender.user.role, company: tender.user.company
  270. }]);
  271. } else {
  272. tender.auditors2 = tender.userGroups;
  273. }
  274. if (tender.ledger_status === auditConst.status.uncheck || tender.ledger_status === auditConst.status.checkNo) {
  275. tender.auditorList = await this.getAuditors(tender.id, tender.ledger_times);
  276. }
  277. }
  278. /**
  279. * 获取标段审核人最后一位的名称
  280. *
  281. * @param {Number} tenderId - 标段id
  282. * @param {Number} auditorId - 审核人id
  283. * @param {Number} times - 第几次审批
  284. * @return {Promise<*>}
  285. */
  286. async getStatusName(tenderId, times) {
  287. const sql = 'SELECT pa.`name` FROM ?? AS la Left Join ?? AS pa ON la.`audit_id` = pa.`id`' +
  288. ' WHERE la.`tender_id` = ? and la.`status` != ? ORDER BY la.`times` DESC, la.`audit_order` DESC';
  289. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, auditConst.status.uncheck];
  290. return await this.db.queryOne(sql, sqlParam);
  291. }
  292. async getFinalAuditGroup(tenderId, times = 1) {
  293. const sql =
  294. 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, pa.`sign_path`, la.`times`, la.`tender_id`, Max(la.`audit_order`) as max_order ' +
  295. ' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
  296. ' WHERE la.`tender_id` = ? and la.`times` = ? GROUP BY la.`audit_id` ORDER BY la.`audit_order`';
  297. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tenderId, times];
  298. const result = await this.db.query(sql, sqlParam);
  299. for (const r of result) {
  300. const auditor = await this.getDataByCondition({tender_id: tenderId, times: r.times, audit_order: r.max_order});
  301. r.status = auditor.status;
  302. r.opinion = auditor.opinion;
  303. r.begin_time = auditor.begin_time;
  304. r.end_time = auditor.end_time;
  305. }
  306. return result;
  307. }
  308. /**
  309. * 获取最新审核顺序
  310. *
  311. * @param {Number} tenderId - 标段id
  312. * @param {Number} times - 第几次审批
  313. * @return {Promise<number>}
  314. */
  315. async getNewOrder(tenderId, times = 1) {
  316. const sql = 'SELECT Max(??) As max_order FROM ?? Where `tender_id` = ? and `times` = ?';
  317. const sqlParam = ['audit_order', this.tableName, tenderId, times];
  318. const result = await this.db.queryOne(sql, sqlParam);
  319. return result && result.max_order ? result.max_order + 1 : 1;
  320. }
  321. /**
  322. * 新增审核人
  323. *
  324. * @param {Number} tenderId - 标段id
  325. * @param {Number} auditorId - 审核人id
  326. * @param {Number} times - 第几次审批
  327. * @return {Promise<number>}
  328. */
  329. async addAuditor(tenderId, auditorId, times = 1, is_gdzs = 0) {
  330. const transaction = await this.db.beginTransaction();
  331. try {
  332. let newOrder = await this.getNewOrder(tenderId, times);
  333. // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
  334. newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
  335. if (is_gdzs) await this._syncOrderByDelete(transaction, tenderId, newOrder, times, '+');
  336. const data = {
  337. tender_id: tenderId,
  338. audit_id: auditorId,
  339. times,
  340. audit_order: newOrder,
  341. status: auditConst.status.uncheck,
  342. };
  343. const result = await transaction.insert(this.tableName, data);
  344. await transaction.commit();
  345. return (result.effectRows = 1);
  346. } catch (err) {
  347. await transaction.rollback();
  348. throw err;
  349. }
  350. return false;
  351. }
  352. /**
  353. * 移除审核人时,同步其后审核人order
  354. * @param transaction - 事务
  355. * @param {Number} tenderId - 标段id
  356. * @param {Number} auditorId - 审核人id
  357. * @param {Number} times - 第几次审批
  358. * @return {Promise<*>}
  359. * @private
  360. */
  361. async _syncOrderByDelete(transaction, tenderId, order, times, selfOperate = '-') {
  362. this.initSqlBuilder();
  363. this.sqlBuilder.setAndWhere('tender_id', {
  364. value: tenderId,
  365. operate: '=',
  366. });
  367. this.sqlBuilder.setAndWhere('audit_order', {
  368. value: order,
  369. operate: '>=',
  370. });
  371. this.sqlBuilder.setAndWhere('times', {
  372. value: times,
  373. operate: '=',
  374. });
  375. this.sqlBuilder.setUpdateData('audit_order', {
  376. value: 1,
  377. selfOperate: selfOperate,
  378. });
  379. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  380. const data = await transaction.query(sql, sqlParam);
  381. return data;
  382. }
  383. /**
  384. * 移除审核人
  385. *
  386. * @param {Number} tenderId - 标段id
  387. * @param {Number} auditorId - 审核人id
  388. * @param {Number} times - 第几次审批
  389. * @return {Promise<boolean>}
  390. */
  391. async deleteAuditor(tenderId, auditorId, times = 1) {
  392. const transaction = await this.db.beginTransaction();
  393. try {
  394. const condition = { tender_id: tenderId, audit_id: auditorId, times };
  395. const auditor = await this.getDataByCondition(condition);
  396. if (!auditor) {
  397. throw '该审核人不存在';
  398. }
  399. await this._syncOrderByDelete(transaction, tenderId, auditor.audit_order, times);
  400. await transaction.delete(this.tableName, condition);
  401. await transaction.commit();
  402. } catch (err) {
  403. await transaction.rollback();
  404. throw err;
  405. }
  406. return true;
  407. }
  408. /**
  409. * 开始审批
  410. *
  411. * @param {Number} tenderId - 标段id
  412. * @param {Number} times - 第几次审批
  413. * @return {Promise<boolean>}
  414. */
  415. async start(tenderId, times = 1) {
  416. const audits = await this.getAllDataByCondition({ where: { tender_id: tenderId, times, audit_order: 1 } });
  417. if (audits.length === 0) {
  418. if(this.ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.gdspl) {
  419. throw '请联系管理员添加审批人';
  420. } else {
  421. throw '请先选择审批人,再上报数据';
  422. }
  423. }
  424. const sum = await this.ctx.service.ledger.addUp({ tender_id: tenderId /* , is_leaf: true*/ });
  425. // 拷贝备份台账数据
  426. const his_id = await this.ctx.service.ledgerHistory.backupLedgerHistory(this.ctx.tender.data);
  427. const transaction = await this.db.beginTransaction();
  428. try {
  429. const begin_time = new Date();
  430. const updateAuditData = audits.map(a => { return { id: a.id, status: auditConst.status.checking, begin_time }; });
  431. await transaction.updateRows(this.tableName, updateAuditData);
  432. await transaction.update(this.ctx.service.tender.tableName, {
  433. id: tenderId,
  434. ledger_status: auditConst.status.checking,
  435. total_price: sum.total_price,
  436. deal_tp: sum.deal_tp,
  437. his_id: his_id,
  438. });
  439. await this.ctx.service.tenderCache.updateLedgerCache4Start(transaction, tenderId, auditConst.status.checking, audits, sum);
  440. // 添加短信通知-需要审批提醒功能
  441. const auditorIds = audits.map(x => { return x.audit_id; });
  442. await this.ctx.helper.sendAliSms(auditorIds, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), SmsAliConst.template.ledger_check);
  443. // 微信模板通知
  444. const wechatData = {
  445. status: wxConst.status.check,
  446. tips: wxConst.tips.check,
  447. begin_time: Date.parse(new Date()),
  448. };
  449. await this.ctx.helper.sendWechat(auditorIds, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), wxConst.template.ledger, wechatData);
  450. for (const audit of audits) {
  451. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.TZ, {
  452. pid: this.ctx.session.sessionProject.id,
  453. tid: tenderId,
  454. uid: audit.audit_id,
  455. sp_type: 'ledger',
  456. sp_id: audit.id,
  457. table_name: this.tableName,
  458. template: wxConst.template.ledger,
  459. wx_data: wechatData,
  460. });
  461. }
  462. await transaction.commit();
  463. } catch (err) {
  464. await transaction.rollback();
  465. throw err;
  466. }
  467. return true;
  468. }
  469. /**
  470. * 审批
  471. * @param {Number} tenderId - 标段id
  472. * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
  473. * @param {String} opinion 审批意见
  474. * @param {Number} times - 第几次审批
  475. * @return {Promise<void>}
  476. */
  477. async check(tenderId, checkType, opinion, times = 1) {
  478. const accountId = this.ctx.session.sessionUser.accountId;
  479. if (checkType !== auditConst.status.checked && checkType !== auditConst.status.checkNo) {
  480. throw '提交数据错误';
  481. }
  482. const pid = this.ctx.session.sessionProject.id;
  483. const auditors = await this.getAllDataByCondition({ where: { tender_id: tenderId, times, status: auditConst.status.checking } });
  484. if (auditors.length === 0) throw '审核数据错误';
  485. const selfAuditor = auditors.find(x => { return x.audit_id === accountId; });
  486. if (!selfAuditor) throw '当前标段您无权审批';
  487. const flowAuditors = await this.getAllDataByCondition({ where: { tender_id: tenderId, times, audit_order: selfAuditor.audit_order } });
  488. const nextAuditors = await this.getAllDataByCondition({ where: { tender_id: tenderId, times, audit_order: selfAuditor.audit_order + 1 } });
  489. const beginAuditors = await this.getAllDataByCondition({ where: { tender_id: tenderId, audit_order: 1, times } });
  490. const time = new Date();
  491. const noticeContent = await this.getNoticeContent(selfAuditor.tender_id, pid, accountId, opinion);
  492. const defaultNoticeRecord = { pid, type: pushType.ledger, status: checkType, content: noticeContent };
  493. const transaction = await this.db.beginTransaction();
  494. try {
  495. // 获取审核人列表,添加提醒
  496. const records = [{ uid: this.ctx.tender.data.user_id, ...defaultNoticeRecord } ];
  497. const auditList = await this.getAuditors(tenderId, times);
  498. auditList.forEach(audit => {
  499. records.push({ uid: audit.audit_id, ...defaultNoticeRecord});
  500. });
  501. await transaction.insert('zh_notice', records);
  502. const users = this._.uniq(this._.concat(this._.map(auditList, 'audit_id'), this.ctx.tender.data.user_id));
  503. // 更新当前审核流程
  504. await transaction.update(this.tableName, { id: selfAuditor.id, status: checkType, opinion, end_time: time });
  505. // 审批提醒
  506. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, selfAuditor.id);
  507. if (checkType === auditConst.status.checked) {
  508. if (auditors.length === 1 || selfAuditor.audit_type === auditType.key.or) {
  509. // 或签更新他人审批状态
  510. if (selfAuditor.audit_type === auditType.key.or) {
  511. const updateOther = [];
  512. for (const audit of auditors) {
  513. if (audit.audit_id === selfAuditor.audit_id) continue;
  514. updateOther.push({
  515. id: audit.id,
  516. status: auditConst.status.checkSkip,
  517. opinion: '',
  518. end_time: time,
  519. });
  520. await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
  521. }
  522. if (updateOther.length > 0) transaction.updateRows(this.tableName, updateOther);
  523. }
  524. // 无下一审核人表示,审核结束
  525. if (nextAuditors.length > 0) {
  526. const nextAuditUpdateData = nextAuditors.map(x => { return {id: x.id, status: auditConst.status.checking, begin_time: time }; });
  527. await transaction.updateRows(this.tableName, nextAuditUpdateData);
  528. await this.ctx.service.tenderCache.updateLedgerCache(transaction, tenderId, auditConst.status.checking, checkType, nextAuditors);
  529. const nextAuditorIds = nextAuditors.map(x => { return x.audit_id; });
  530. await this.ctx.helper.sendAliSms(nextAuditorIds, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), SmsAliConst.template.ledger_check);
  531. // 微信模板通知
  532. const wechatData = {
  533. status: wxConst.status.check,
  534. tips: wxConst.tips.check,
  535. begin_time: Date.parse(beginAuditors[0].begin_time),
  536. };
  537. await this.ctx.helper.sendWechat(nextAuditorIds, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), wxConst.template.ledger, wechatData);
  538. for (const audit of nextAuditors) {
  539. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.TZ, {
  540. pid: this.ctx.session.sessionProject.id,
  541. tid: tenderId,
  542. uid: audit.audit_id,
  543. sp_type: 'ledger',
  544. sp_id: audit.id,
  545. table_name: this.tableName,
  546. template: wxConst.template.ledger,
  547. wx_data: wechatData,
  548. });
  549. }
  550. } else {
  551. // 同步标段信息
  552. await transaction.update(this.ctx.service.tender.tableName, {
  553. id: tenderId, ledger_status: checkType,
  554. });
  555. await this.ctx.service.tenderCache.updateLedgerCache(transaction, tenderId, checkType, checkType);
  556. // 审批通过,添加标记
  557. await this.ctx.service.tenderTag.saveTenderTag(tenderId, { ledger_time: time }, transaction);
  558. await this.ctx.helper.sendAliSms(users, smsTypeConst.const.TZ, smsTypeConst.judge.result.toString(), SmsAliConst.template.ledger_result, {
  559. status: SmsAliConst.status.success,
  560. });
  561. // 微信模板通知
  562. const wechatData = {
  563. status: wxConst.status.success,
  564. tips: wxConst.tips.success,
  565. begin_time: Date.parse(beginAuditors[0].begin_time),
  566. };
  567. await this.ctx.helper.sendWechat(users, smsTypeConst.const.TZ, smsTypeConst.judge.result.toString(), wxConst.template.ledger, wechatData);
  568. // 审批通过 - 检查三方特殊推送
  569. await this.ctx.service.specMsg.addLedgerMsg(transaction, pid, this.ctx.tender, pushOperate.ledger.checked);
  570. }
  571. }
  572. } else {
  573. // 同步标段信息
  574. await transaction.update(this.ctx.service.tender.tableName, {
  575. id: tenderId, ledger_times: times + 1, ledger_status: checkType,
  576. });
  577. await this.ctx.service.tenderCache.updateLedgerCache(transaction, tenderId, checkType, checkType, [{ audit_id: this.ctx.tender.data.user_id }]);
  578. // 拷贝新一次审核流程列表
  579. const auditors = await this.getAllDataByCondition({
  580. where: { tender_id: tenderId, times },
  581. columns: ['tender_id', 'audit_order', 'audit_id', 'audit_type', 'audit_ledger_id'],
  582. });
  583. const insertAuditors = auditors.map(x => {
  584. return { ...x, times: times + 1, status: auditConst.status.uncheck };
  585. });
  586. await transaction.insert(this.tableName, insertAuditors);
  587. await this.ctx.helper.sendAliSms(users, smsTypeConst.const.TZ, smsTypeConst.judge.result.toString(), SmsAliConst.template.ledger_result, {
  588. status: SmsAliConst.status.back,
  589. });
  590. // 微信模板通知
  591. const wechatData = {
  592. status: wxConst.status.back,
  593. tips: wxConst.tips.back,
  594. begin_time: Date.parse(beginAuditors[0].begin_time),
  595. };
  596. await this.ctx.helper.sendWechat(users, smsTypeConst.const.TZ, smsTypeConst.judge.result.toString(), wxConst.template.ledger, wechatData);
  597. }
  598. await transaction.commit();
  599. } catch (err) {
  600. await transaction.rollback();
  601. throw err;
  602. }
  603. }
  604. /**
  605. * 重新审批
  606. * @param {Number} tenderId - 标段id
  607. * @param {Number} times - 第几次审批
  608. * @return {Promise<void>}
  609. */
  610. async checkAgain(tenderId, times = 1) {
  611. const time = new Date();
  612. // 整理当前流程审核人状态更新
  613. const auditors = await this.getAllDataByCondition({
  614. where: { tender_id: tenderId, times },
  615. orders: [['audit_order', 'desc']],
  616. });
  617. if (auditors.length <= 0) throw '台账审核数据错误';
  618. const selfAudit = auditors[0];
  619. if (selfAudit.audit_id !== this.ctx.session.sessionUser.accountId) throw '当前台账您无权重审';
  620. const tender = this.ctx.service.tender.getDataById(tenderId);
  621. if (!tender) throw '标段数据错误';
  622. let otherAuditIds = [tender.user_id, ...auditors.map(x => { return x.audit_id })];
  623. otherAuditIds = this._.uniq(otherAuditIds).filter(x => { return x !== selfAudit.audit_id; });
  624. const checkAgainAuditor = {
  625. tender_id: tenderId, times, audit_order: selfAudit.audit_order + 1, audit_id: selfAudit.audit_id,
  626. begin_time: time, end_time: time, opinion: '', status: auditConst.status.checkAgain,
  627. };
  628. const checkingAuditor = {
  629. tender_id: tenderId, times, audit_order: selfAudit.audit_order + 2, audit_id: selfAudit.audit_id,
  630. begin_time: time, end_time: null, opinion: '', status: auditConst.status.checking,
  631. };
  632. const transaction = await this.db.beginTransaction();
  633. try {
  634. // 当前审批人2次添加至流程中
  635. await transaction.insert(this.tableName, checkAgainAuditor);
  636. const checking_result = await transaction.insert(this.tableName, checkingAuditor);
  637. // 同步标段信息
  638. await transaction.update(this.ctx.service.tender.tableName, {
  639. id: tenderId,
  640. ledger_status: auditConst.status.checking,
  641. });
  642. await this.ctx.service.tenderCache.updateLedgerCache(transaction, tenderId, auditConst.status.checking, auditConst.status.checkAgain, checkingAuditor);
  643. if (otherAuditIds.length > 0) {
  644. await this.ctx.helper.sendAliSms(otherAuditIds, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), SmsAliConst.template.ledger_check);
  645. // 微信模板通知
  646. const wechatData = {
  647. status: wxConst.status.check,
  648. tips: wxConst.tips.check,
  649. begin_time: Date.parse(time),
  650. };
  651. await this.ctx.helper.sendWechat(selfAudit.audit_id, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), wxConst.template.ledger, wechatData);
  652. await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.TZ, {
  653. pid: this.ctx.session.sessionProject.id,
  654. tid: this.ctx.tender.id,
  655. uid: selfAudit.audit_id,
  656. sp_type: 'ledger',
  657. sp_id: checking_result.insertId,
  658. table_name: this.tableName,
  659. template: wxConst.template.ledger,
  660. wx_data: wechatData,
  661. });
  662. }
  663. await transaction.commit();
  664. } catch (err) {
  665. await transaction.rollback();
  666. throw err;
  667. }
  668. }
  669. /**
  670. * 获取审核人需要审核的标段列表
  671. *
  672. * @param auditorId
  673. * @return {Promise<*>}
  674. */
  675. async getAuditTender(auditorId) {
  676. const sql =
  677. 'SELECT la.`audit_id`, la.`times`, la.`audit_order`, la.`begin_time`, la.`end_time`, t.`id`, t.`name`, t.`project_id`, t.`type`, t.`user_id`, t.`ledger_status` ' +
  678. ' FROM ?? AS la Left Join ?? AS t ON la.`tender_id` = t.`id` ' +
  679. ' WHERE ((la.`audit_id` = ? and la.`status` = ?) OR (t.`user_id` = ? and t.`ledger_status` = ? and la.`status` = ? and la.`times` = (t.`ledger_times`-1)))' +
  680. ' ORDER BY la.`begin_time` DESC';
  681. const sqlParam = [
  682. this.tableName,
  683. this.ctx.service.tender.tableName,
  684. auditorId,
  685. auditConst.status.checking,
  686. auditorId,
  687. auditConst.status.checkNo,
  688. auditConst.status.checkNo,
  689. ];
  690. return await this.db.query(sql, sqlParam);
  691. }
  692. /**
  693. * 获取审核人审核的次数
  694. *
  695. * @param auditorId
  696. * @return {Promise<*>}
  697. */
  698. async getCountByChecked(auditorId) {
  699. return await this.db.count(this.tableName, { audit_id: auditorId, status: [auditConst.status.checked, auditConst.status.checkNo] });
  700. }
  701. /**
  702. * 获取最近一次审批结束时间
  703. *
  704. * @param auditorId
  705. * @return {Promise<*>}
  706. */
  707. async getLastEndTimeByChecked(auditorId) {
  708. const sql = 'SELECT `end_time` FROM ?? WHERE `audit_id` = ? ' +
  709. 'AND `status` in (' + this.ctx.helper.getInArrStrSqlFilter([auditConst.status.checked, auditConst.status.checkNo]) + ') ORDER BY `end_time` DESC';
  710. const sqlParam = [this.tableName, auditorId];
  711. const result = await this.db.queryOne(sql, sqlParam);
  712. return result ? result.end_time : null;
  713. }
  714. /**
  715. * 用于添加推送所需的content内容
  716. * @param {Number} id 标段id
  717. * @param {Number} pid 项目id
  718. * @param {Number} uid 审核人id
  719. */
  720. async getNoticeContent(id, pid, uid, opinion = '') {
  721. const noticeSql =
  722. 'SELECT * FROM (SELECT ' +
  723. ' t.`id` As `tid`, t.`name`, pa.`name` As `su_name`, pa.role As `su_role`' +
  724. ' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
  725. ' LEFT JOIN ?? As pa ON pa.`id` = ?' +
  726. ' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
  727. const noticeSqlParam = [this.ctx.service.tender.tableName, id, this.ctx.service.projectAccount.tableName, uid, pid];
  728. const content = await this.db.query(noticeSql, noticeSqlParam);
  729. if (content.length) {
  730. content[0].opinion = opinion;
  731. }
  732. return content.length ? JSON.stringify(content[0]) : '';
  733. }
  734. /**
  735. * 获取审核人流程列表
  736. * @param {Number} tender_id - 标段id
  737. * @param {Number} times 审核次数
  738. * @return {Promise<Array>} 查询结果集
  739. */
  740. async getAuditGroupByList(tender_id, times = 1, transaction = null) {
  741. // const sql =
  742. // 'SELECT la.`audit_id`, la.`status`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.`audit_order` ' +
  743. // ' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
  744. // ' WHERE la.`tender_id` = ? and la.`times` = ? GROUP BY la.`audit_id` ORDER BY la.`audit_order`';
  745. // const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tender_id, times];
  746. // return transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
  747. const sql =
  748. 'SELECT la.`audit_id`, la.`status`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.`audit_order` ' +
  749. ' FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id`' +
  750. ' WHERE la.`tender_id` = ? and la.`times` = ? ORDER BY la.`audit_order` DESC';
  751. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tender_id, times];
  752. const result = transaction ? await transaction.query(sql, sqlParam) : await this.db.query(sql, sqlParam);
  753. const audits = [];
  754. for (const r of result) {
  755. if (audits.findIndex(a => a.audit_id === r.audit_id) === -1) {
  756. audits.push(r);
  757. }
  758. }
  759. return audits.reverse();
  760. }
  761. /**
  762. * 获取审核人流程列表(包括原报)
  763. * @param {Number} tender_id - 标段id
  764. * @param {Number} times 审核次数
  765. * @return {Promise<Array>} 查询结果集(包括原报)
  766. */
  767. async getAuditorsWithOwner(tender_id, times = 1) {
  768. const result = await this.getAuditGroupByList(tender_id, times);
  769. const sql =
  770. 'SELECT pa.`id` As audit_id, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As tender_id, 0 As `audit_order`' +
  771. ' FROM ' + this.ctx.service.tender.tableName + ' As s' +
  772. ' LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
  773. ' ON s.user_id = pa.id' +
  774. ' WHERE s.id = ?';
  775. const sqlParam = [times, tender_id, tender_id];
  776. const user = await this.db.queryOne(sql, sqlParam);
  777. result.unshift(user);
  778. return result;
  779. }
  780. async updateNewAuditList(tender, newList) {
  781. const transaction = await this.db.beginTransaction();
  782. try {
  783. // 先删除旧的审批流,再添加新的
  784. await transaction.delete(this.tableName, { tender_id: tender.id, times: tender.ledger_times });
  785. const newAuditors = [];
  786. for (const auditor of newList) {
  787. newAuditors.push({
  788. tender_id: tender.id, audit_id: auditor.audit_id,
  789. times: tender.ledger_times, audit_order: auditor.audit_order, status: auditConst.status.uncheck,
  790. audit_type: auditor.audit_type, audit_ledger_id: auditor.audit_type === auditType.key.union ? auditor.audit_ledger_id : '',
  791. })
  792. }
  793. if(newAuditors.length > 0) await transaction.insert(this.tableName, newAuditors);
  794. await transaction.commit();
  795. } catch (err) {
  796. await transaction.rollback();
  797. throw err;
  798. }
  799. }
  800. async updateLastAudit(tender, auditList, lastId) {
  801. const transaction = await this.db.beginTransaction();
  802. try {
  803. // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
  804. const existAudit = auditList.find(x => { return x.aid === lastId });
  805. let order = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.audit_order)}, 0) + 1 : 1; // 最大值 + 1
  806. if (existAudit) {
  807. await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, audit_id: lastId });
  808. const sameOrder = auditList.filter(x => { return x.audit_order === existAudit.audit_order });
  809. if (sameOrder.length === 1) {
  810. const updateData = [];
  811. auditList.forEach(x => {
  812. if (x.audit_order <= existAudit.audit_order) return;
  813. updateData.push({id: x.id, audit_order: x.audit_order - 1});
  814. });
  815. if (updateData.length > 0) {
  816. await transaction.updateRows(updateData);
  817. }
  818. order = order - 1;
  819. }
  820. }
  821. // 添加终审
  822. const newAuditor = {
  823. tender_id: tender.id, audit_id: lastId,
  824. times: tender.ledger_times, audit_order: order, status: auditConst.status.uncheck,
  825. };
  826. await transaction.insert(this.tableName, newAuditor);
  827. await transaction.commit();
  828. } catch (err) {
  829. await transaction.rollback();
  830. throw err;
  831. }
  832. }
  833. /**
  834. * 删除本次审批流程
  835. * @param {Number} tenderId - 标段id
  836. * @param {Number} times - 第几次审批
  837. * @param {Object} data - 更改参数
  838. * @return {Promise<void>}
  839. */
  840. async saveAudit(tenderId, times, data) {
  841. const transaction = await this.db.beginTransaction();
  842. try {
  843. const auditors = await this.getAuditGroupByList(tenderId, times);
  844. const now_audit = this._.find(auditors, { audit_id: data.old_aid });
  845. if (data.operate === 'add') {
  846. if (now_audit.status !== auditConst.status.uncheck && now_audit.status !== auditConst.status.checking) {
  847. throw '当前人下无法操作新增';
  848. }
  849. const newAudit = {
  850. tender_id: tenderId,
  851. audit_id: data.new_aid,
  852. audit_order: now_audit.audit_order + 1,
  853. times,
  854. status: auditConst.status.uncheck,
  855. };
  856. // order+1
  857. await this._syncOrderByDelete(transaction, tenderId, now_audit.audit_order + 1, times, '+');
  858. await transaction.insert(this.tableName, newAudit);
  859. // 更新审批流程页数据,如果存在
  860. } else if (data.operate === 'del') {
  861. if (now_audit.status !== auditConst.status.uncheck) {
  862. throw '当前人无法操作删除';
  863. }
  864. await transaction.delete(this.tableName, { tender_id: tenderId, times, audit_id: now_audit.audit_id, audit_order: now_audit.audit_order });
  865. await this._syncOrderByDelete(transaction, tenderId, now_audit.audit_order, times);
  866. } else if (data.operate === 'change') {
  867. const nowAudit = await this.getDataByCondition({ tender_id: tenderId, times, audit_id: now_audit.audit_id, audit_order: now_audit.audit_order });
  868. if (now_audit.status !== auditConst.status.uncheck || !nowAudit) {
  869. throw '当前人无法操作替换';
  870. }
  871. nowAudit.audit_id = data.new_aid;
  872. await transaction.update(this.tableName, nowAudit);
  873. }
  874. if (this.ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.gdspl || this.ctx.tender.info.shenpi.ledger === shenpiConst.sp_status.gdzs) {
  875. const newAuditors = await this.getAuditGroupByList(tenderId, times, transaction);
  876. await this.ctx.service.shenpiAudit.updateAuditList(transaction, this.ctx.tender.id, this.ctx.tender.info.shenpi.ledger, shenpiConst.sp_type.ledger, this._.map(newAuditors, 'audit_id'));
  877. }
  878. // 更新到审批流程方法
  879. await transaction.commit();
  880. } catch (err) {
  881. await transaction.rollback();
  882. throw err;
  883. }
  884. }
  885. }
  886. return LedgerAudit;
  887. };