stage_audit.js 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2019/2/27
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').stage;
  10. const smsTypeConst = require('../const/sms_type');
  11. const SMS = require('../lib/sms');
  12. const SmsAliConst = require('../const/sms_alitemplate');
  13. const wxConst = require('../const/wechat_template');
  14. const shenpiConst = require('../const/shenpi');
  15. const payConst = require('../const/deal_pay');
  16. const pushType = require('../const/audit').pushType;
  17. const syncApiConst = require('../const/sync_api');
  18. module.exports = app => {
  19. class StageAudit extends app.BaseService {
  20. /**
  21. * 构造函数
  22. *
  23. * @param {Object} ctx - egg全局变量
  24. * @return {void}
  25. */
  26. constructor(ctx) {
  27. super(ctx);
  28. this.tableName = 'stage_audit';
  29. }
  30. /**
  31. * 获取 审核人信息
  32. *
  33. * @param {Number} stageId - 期id
  34. * @param {Number} auditorId - 审核人id
  35. * @param {Number} times - 第几次审批
  36. * @return {Promise<*>}
  37. */
  38. async getAuditor(stageId, auditorId, times = 1) {
  39. const sql =
  40. '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` ' +
  41. 'FROM ?? AS la, ?? AS pa ' +
  42. 'WHERE la.`sid` = ? and la.`aid` = ? and la.`times` = ?' +
  43. ' and la.`aid` = pa.`id`';
  44. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditorId, times];
  45. return await this.db.queryOne(sql, sqlParam);
  46. }
  47. async getAuditorByOrder(stageId, order, times) {
  48. const sql =
  49. 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`,' +
  50. ' la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
  51. ' FROM ' + this.tableName + ' AS la' +
  52. ' Left Join ' + this.ctx.service.projectAccount.tableName + ' AS pa ON la.`aid` = pa.`id`' +
  53. ' WHERE la.`sid` = ? and la.`order` = ? and la.`times` = ?' +
  54. ' ORDER BY `order` DESC';
  55. const sqlParam = [stageId, order, times ? times: 1];
  56. return await this.db.queryOne(sql, sqlParam);
  57. }
  58. async getLastestAuditor(stageId, times, status) {
  59. const sql =
  60. 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`,' +
  61. ' la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
  62. ' FROM ' + this.tableName + ' AS la' +
  63. ' Left Join ' + this.ctx.service.projectAccount.tableName + ' AS pa ON la.`aid` = pa.`id`' +
  64. ' WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ?' +
  65. ' ORDER BY `order` DESC';
  66. const sqlParam = [stageId, status, times ? times: 1];
  67. return await this.db.queryOne(sql, sqlParam);
  68. }
  69. /**
  70. * 获取 审核列表信息
  71. *
  72. * @param {Number} stageId - 期id
  73. * @param {Number} times - 第几次审批
  74. * @param {Number} order_sort - 列表排序方式
  75. * @return {Promise<*>}
  76. */
  77. async getAuditors(stageId, times = 1, order_sort = 'asc') {
  78. const sql =
  79. 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, pa.sign_path, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
  80. 'FROM ?? AS la, ?? AS pa, (SELECT `aid`,(@i:=@i+1) as `sort` FROM ??, (select @i:=0) as it WHERE `sid` = ? AND `times` = ? GROUP BY `aid`) as g ' +
  81. 'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order` ' +
  82. order_sort;
  83. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, stageId, times, stageId, times];
  84. const result = await this.db.query(sql, sqlParam);
  85. const sql2 = 'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `sid` = ? AND `times` = ? GROUP BY `aid`) as a';
  86. const sqlParam2 = [this.tableName, stageId, times];
  87. const count = await this.db.queryOne(sql2, sqlParam2);
  88. for (const i in result) {
  89. result[i].max_sort = count.num;
  90. }
  91. return result;
  92. }
  93. async getAllAuditors(tenderId) {
  94. const sql =
  95. 'SELECT sa.aid, sa.tid FROM ' + this.tableName + ' sa' +
  96. ' LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On sa.tid = t.id' +
  97. ' WHERE t.id = ?' +
  98. ' GROUP BY sa.aid';
  99. const sqlParam = [tenderId];
  100. return this.db.query(sql, sqlParam);
  101. }
  102. /**
  103. * 获取标段审核人最后一位的名称
  104. *
  105. * @param {Number} tenderId - 标段id
  106. * @param {Number} auditorId - 审核人id
  107. * @param {Number} times - 第几次审批
  108. * @return {Promise<*>}
  109. */
  110. async getStatusName(stageId) {
  111. const sql =
  112. 'SELECT pa.`name` ' +
  113. 'FROM ?? AS sa, ?? AS pa ' +
  114. 'WHERE sa.`sid` = ?' +
  115. ' and sa.`aid` = pa.`id` and sa.`status` != ? ORDER BY sa.`times` DESC, sa.`order` DESC';
  116. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.uncheck];
  117. return await this.db.queryOne(sql, sqlParam);
  118. }
  119. /**
  120. * 获取 当前审核人
  121. *
  122. * @param {Number} stageId - 期id
  123. * @param {Number} times - 第几次审批
  124. * @return {Promise<*>}
  125. */
  126. async getCurAuditor(stageId, times = 1) {
  127. const sql =
  128. '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` ' +
  129. 'FROM ?? AS la, ?? AS pa ' +
  130. 'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ?' +
  131. ' and la.`aid` = pa.`id`';
  132. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checking, times];
  133. return await this.db.queryOne(sql, sqlParam);
  134. }
  135. /**
  136. * 获取 最新审核顺序
  137. *
  138. * @param {Number} stageId - 期id
  139. * @param {Number} times - 第几次审批
  140. * @return {Promise<number>}
  141. */
  142. async getNewOrder(stageId, times = 1) {
  143. const sql = 'SELECT Max(??) As max_order FROM ?? Where `sid` = ? and `times` = ?';
  144. const sqlParam = ['order', this.tableName, stageId, times];
  145. const result = await this.db.queryOne(sql, sqlParam);
  146. return result && result.max_order ? result.max_order + 1 : 1;
  147. }
  148. /**
  149. * 新增审核人
  150. *
  151. * @param {Number} stageId - 期id
  152. * @param {Number} auditorId - 审核人id
  153. * @param {Number} times - 第几次审批
  154. * @return {Promise<number>}
  155. */
  156. async addAuditor(stageId, auditorId, times = 1, is_gdzs = 0) {
  157. const transaction = await this.db.beginTransaction();
  158. try {
  159. let newOrder = await this.getNewOrder(stageId, times);
  160. // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
  161. newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
  162. if (is_gdzs) await this._syncOrderByDelete(transaction, stageId, newOrder, times, '+');
  163. const data = {
  164. tid: this.ctx.tender.id,
  165. sid: stageId,
  166. aid: auditorId,
  167. times,
  168. order: newOrder,
  169. status: auditConst.status.uncheck,
  170. };
  171. const result = await transaction.insert(this.tableName, data);
  172. await transaction.commit();
  173. return result.effectRows = 1;
  174. } catch (err) {
  175. await transaction.rollback();
  176. throw err;
  177. }
  178. return false;
  179. }
  180. /**
  181. * 移除审核人时,同步其后审核人order
  182. * @param transaction - 事务
  183. * @param {Number} stageId - 标段id
  184. * @param {Number} auditorId - 审核人id
  185. * @param {Number} times - 第几次审批
  186. * @return {Promise<*>}
  187. * @private
  188. */
  189. async _syncOrderByDelete(transaction, stageId, order, times, selfOperate = '-') {
  190. this.initSqlBuilder();
  191. this.sqlBuilder.setAndWhere('sid', {
  192. value: stageId,
  193. operate: '=',
  194. });
  195. this.sqlBuilder.setAndWhere('order', {
  196. value: order,
  197. operate: '>=',
  198. });
  199. this.sqlBuilder.setAndWhere('times', {
  200. value: times,
  201. operate: '=',
  202. });
  203. this.sqlBuilder.setUpdateData('order', {
  204. value: 1,
  205. selfOperate: selfOperate,
  206. });
  207. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  208. const data = await transaction.query(sql, sqlParam);
  209. return data;
  210. }
  211. /**
  212. * 移除审核人
  213. *
  214. * @param {Number} stageId - 期id
  215. * @param {Number} auditorId - 审核人id
  216. * @param {Number} times - 第几次审批
  217. * @return {Promise<boolean>}
  218. */
  219. async deleteAuditor(stageId, auditorId, times = 1) {
  220. const transaction = await this.db.beginTransaction();
  221. try {
  222. const condition = { sid: stageId, aid: auditorId, times };
  223. const auditor = await this.getDataByCondition(condition);
  224. if (!auditor) {
  225. throw '该审核人不存在';
  226. }
  227. await this._syncOrderByDelete(transaction, stageId, auditor.order, times);
  228. await transaction.delete(this.tableName, condition);
  229. await transaction.commit();
  230. } catch (err) {
  231. await transaction.rollback();
  232. throw err;
  233. }
  234. return true;
  235. }
  236. /**
  237. * 开始审批
  238. *
  239. * @param {Number} stageId - 期id
  240. * @param {Number} times - 第几次审批
  241. * @return {Promise<boolean>}
  242. */
  243. async start(stageId, times = 1) {
  244. const audit = await this.getDataByCondition({ sid: stageId, times, order: 1 });
  245. if (!audit) {
  246. if(this.ctx.tender.info.shenpi.stage === shenpiConst.sp_status.gdspl) {
  247. throw '请联系管理员添加审批人';
  248. } else {
  249. throw '请先选择审批人,再上报数据';
  250. }
  251. }
  252. const transaction = await this.db.beginTransaction();
  253. try {
  254. await transaction.update(this.tableName, {
  255. id: audit.id,
  256. status: auditConst.status.checking,
  257. begin_time: new Date(),
  258. });
  259. // 计算原报最终数据
  260. const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
  261. // 复制一份下一审核人数据
  262. await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, 1, transaction);
  263. await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
  264. await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
  265. await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
  266. await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
  267. await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
  268. // 更新期数据
  269. const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
  270. this.ctx.stage.tp_history.push({
  271. times: this.ctx.stage.curTimes,
  272. order: 0,
  273. contract_tp: tpData.contract_tp,
  274. qc_tp: tpData.qc_tp,
  275. yf_tp: yfPay.tp,
  276. sf_tp: sfPay.tp,
  277. });
  278. await transaction.update(this.ctx.service.stage.tableName, {
  279. id: stageId,
  280. status: auditConst.status.checking,
  281. contract_tp: tpData.contract_tp,
  282. qc_tp: tpData.qc_tp,
  283. yf_tp: yfPay.tp,
  284. sf_tp: sfPay.tp,
  285. tp_history: JSON.stringify(this.ctx.stage.tp_history),
  286. cache_time_r: this.ctx.stage.cache_time_l,
  287. });
  288. // 添加短信通知-需要审批提醒功能
  289. // const smsUser = await this.ctx.service.projectAccount.getDataById(audit.aid);
  290. // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  291. // const smsType = JSON.parse(smsUser.sms_type);
  292. // if (smsType[smsTypeConst.const.JL] !== undefined && smsType[smsTypeConst.const.JL].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
  293. // const tenderInfo = await this.ctx.service.tender.getDataById(audit.tid);
  294. // const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
  295. // const sms = new SMS(this.ctx);
  296. // const tenderName = await sms.contentChange(tenderInfo.name);
  297. // const projectName = await sms.contentChange(this.ctx.tender.info.deal_info.buildName);
  298. // const ptmsg = projectName !== '' ? '项目「' + projectName + '」标段「' + tenderName + '」' : tenderName;
  299. // const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  300. // const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,需要您审批。' + result;
  301. // sms.send(smsUser.auth_mobile, content);
  302. // }
  303. // }
  304. const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
  305. const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  306. await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
  307. qi: stageInfo.order,
  308. code: shenpiUrl,
  309. });
  310. // 微信模板通知
  311. const wechatData = {
  312. wap_url: shenpiUrl,
  313. qi: stageInfo.order,
  314. status: wxConst.status.check,
  315. tips: wxConst.tips.check,
  316. code: this.ctx.session.sessionProject.code,
  317. };
  318. await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
  319. // todo 更新标段tender状态 ?
  320. await transaction.commit();
  321. // 通知发送 - 第三方更新
  322. if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
  323. const base_data = {
  324. tid: this.ctx.tender.id,
  325. sid: stageId,
  326. op: 'update',
  327. };
  328. this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  329. base_data.op = 'update';
  330. base_data.sid = -1;
  331. this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  332. }
  333. } catch (err) {
  334. await transaction.rollback();
  335. throw err;
  336. }
  337. return true;
  338. }
  339. async _checked(pid, stageId, checkData, times) {
  340. const time = new Date();
  341. // 整理当前流程审核人状态更新
  342. const audit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
  343. if (!audit) {
  344. throw '审核数据错误';
  345. }
  346. const nextAudit = await this.getDataByCondition({ sid: stageId, times, order: audit.order + 1 });
  347. const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
  348. const transaction = await this.db.beginTransaction();
  349. try {
  350. // 添加推送
  351. const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
  352. const auditors = await this.getAuditGroupByListWithOwner(stageId, times);
  353. const records = [];
  354. auditors.forEach(audit => {
  355. records.push({
  356. pid,
  357. type: pushType.stage,
  358. uid: audit.aid,
  359. status: auditConst.status.checked,
  360. content: noticeContent,
  361. });
  362. });
  363. await transaction.insert('zh_notice', records);
  364. await transaction.update(this.tableName, {
  365. id: audit.id,
  366. status: checkData.checkType,
  367. opinion: checkData.opinion,
  368. end_time: time,
  369. });
  370. // 计算并合同支付最终数据
  371. const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
  372. this.ctx.stage.tp_history.push({
  373. times,
  374. order: audit.order,
  375. contract_tp: tpData.contract_tp,
  376. qc_tp: tpData.qc_tp,
  377. yf_tp: yfPay.tp,
  378. sf_tp: sfPay.tp,
  379. });
  380. // 无下一审核人表示,审核结束
  381. if (nextAudit) {
  382. // 复制一份下一审核人数据
  383. await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction);
  384. await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
  385. await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
  386. await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
  387. await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
  388. await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
  389. // 流程至下一审批人
  390. await transaction.update(this.tableName, {
  391. id: nextAudit.id,
  392. status: auditConst.status.checking,
  393. begin_time: time,
  394. });
  395. // 同步 期信息
  396. await transaction.update(this.ctx.service.stage.tableName, {
  397. id: stageId,
  398. status: auditConst.status.checking,
  399. contract_tp: tpData.contract_tp,
  400. qc_tp: tpData.qc_tp,
  401. yf_tp: yfPay.tp,
  402. sf_tp: sfPay.tp,
  403. tp_history: JSON.stringify(this.ctx.stage.tp_history),
  404. cache_time_r: this.ctx.stage.cache_time_l,
  405. });
  406. // 添加短信通知-需要审批提醒功能
  407. // const smsUser = await this.ctx.service.projectAccount.getDataById(nextAudit.aid);
  408. // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  409. // const smsType = JSON.parse(smsUser.sms_type);
  410. // if (smsType[smsTypeConst.const.JL] !== undefined && smsType[smsTypeConst.const.JL].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
  411. // const tenderInfo = await this.ctx.service.tender.getDataById(nextAudit.tid);
  412. // const stageInfo = await this.ctx.service.stage.getDataById(nextAudit.sid);
  413. // const sms = new SMS(this.ctx);
  414. // const tenderName = await sms.contentChange(tenderInfo.name);
  415. // const projectName = await sms.contentChange(this.ctx.tender.info.deal_info.buildName);
  416. // const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  417. // // const result = '';
  418. // const ptmsg = projectName !== '' ? '项目「' + projectName + '」标段「' + tenderName + '」' : tenderName;
  419. // const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,需要您审批。' + result;
  420. // sms.send(smsUser.auth_mobile, content);
  421. // }
  422. // }
  423. const stageInfo = await this.ctx.service.stage.getDataById(nextAudit.sid);
  424. const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  425. await this.ctx.helper.sendAliSms(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
  426. qi: stageInfo.order,
  427. code: shenpiUrl,
  428. });
  429. // 微信模板通知
  430. const wechatData = {
  431. wap_url: shenpiUrl,
  432. qi: stageInfo.order,
  433. status: wxConst.status.check,
  434. tips: wxConst.tips.check,
  435. code: this.ctx.session.sessionProject.code,
  436. };
  437. await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
  438. } else {
  439. await this.ctx.service.tenderTag.saveTenderTag(this.ctx.tender.id, {stage_time: new Date()}, transaction);
  440. // 本期结束
  441. // 生成截止本期数据 final数据
  442. await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
  443. await this.ctx.service.stagePosFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
  444. await this.ctx.service.stageChangeFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
  445. // 同步 期信息
  446. await transaction.update(this.ctx.service.stage.tableName, {
  447. id: stageId,
  448. status: checkData.checkType,
  449. contract_tp: tpData.contract_tp,
  450. qc_tp: tpData.qc_tp,
  451. yf_tp: yfPay.tp,
  452. sf_tp: sfPay.tp,
  453. tp_history: JSON.stringify(this.ctx.stage.tp_history),
  454. cache_time_r: this.ctx.stage.cache_time_l,
  455. });
  456. // 添加短信通知-审批通过提醒功能
  457. // const mobile_array = [];
  458. const stageInfo = await this.ctx.service.stage.getDataById(stageId);
  459. const auditList = await this.getAuditors(stageId, stageInfo.times);
  460. // const smsUser1 = await this.ctx.service.projectAccount.getDataById(stageInfo.user_id);
  461. // if (smsUser1.auth_mobile !== undefined && smsUser1.sms_type !== '' && smsUser1.sms_type !== null) {
  462. // const smsType = JSON.parse(smsUser1.sms_type);
  463. // if (smsType[smsTypeConst.const.JL] !== undefined && smsType[smsTypeConst.const.JL].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
  464. // mobile_array.push(smsUser1.auth_mobile);
  465. // }
  466. // }
  467. // for (const user of auditList) {
  468. // const smsUser = await this.ctx.service.projectAccount.getDataById(user.aid);
  469. // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  470. // const smsType = JSON.parse(smsUser.sms_type);
  471. // if (mobile_array.indexOf(smsUser.auth_mobile) === -1 && smsType[smsTypeConst.const.JL] !== undefined && smsType[smsTypeConst.const.JL].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
  472. // mobile_array.push(smsUser.auth_mobile);
  473. // }
  474. // }
  475. // }
  476. // if (mobile_array.length > 0) {
  477. // const tenderInfo = await this.ctx.service.tender.getDataById(stageInfo.tid);
  478. // const sms = new SMS(this.ctx);
  479. // const tenderName = await sms.contentChange(tenderInfo.name);
  480. // const projectName = await sms.contentChange(this.ctx.tender.info.deal_info.buildName);
  481. // const ptmsg = projectName !== '' ? '项目「' + projectName + '」标段「' + tenderName + '」' : tenderName;
  482. // const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,审批通过。';
  483. // sms.send(mobile_array, content);
  484. // }
  485. const users = this._.uniq(this._.concat(this._.map(auditList, 'aid'), stageInfo.user_id));
  486. await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, {
  487. qi: stageInfo.order,
  488. status: SmsAliConst.status.success,
  489. });
  490. // 微信模板通知
  491. const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  492. const wechatData = {
  493. wap_url: shenpiUrl,
  494. qi: stageInfo.order,
  495. status: wxConst.status.success,
  496. tips: wxConst.tips.success,
  497. code: this.ctx.session.sessionProject.code,
  498. };
  499. await this.ctx.helper.sendWechat(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
  500. }
  501. await transaction.commit();
  502. } catch (err) {
  503. await transaction.rollback();
  504. throw err;
  505. }
  506. }
  507. async _checkNo(pid, stageId, checkData, times) {
  508. const time = new Date();
  509. // 整理当前流程审核人状态更新
  510. const audit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
  511. if (!audit) {
  512. throw '审核数据错误';
  513. }
  514. const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
  515. const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  516. const sqlParam = [this.tableName, stageId, times];
  517. const auditors = await this.db.query(sql, sqlParam);
  518. let order = 1;
  519. for (const a of auditors) {
  520. a.times = times + 1;
  521. a.order = order;
  522. a.status = auditConst.status.uncheck;
  523. order++;
  524. }
  525. const transaction = await this.db.beginTransaction();
  526. try {
  527. // 添加推送
  528. const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
  529. const records = [
  530. {
  531. pid,
  532. type: pushType.stage,
  533. uid: this.ctx.stage.user_id,
  534. status: auditConst.status.checkNo,
  535. content: noticeContent,
  536. },
  537. ];
  538. auditors.forEach(audit => {
  539. records.push({
  540. pid,
  541. type: pushType.stage,
  542. uid: audit.aid,
  543. status: auditConst.status.checkNo,
  544. content: noticeContent,
  545. });
  546. });
  547. await transaction.insert(this.ctx.service.noticePush.tableName, records);
  548. // 计算并合同支付最终数据
  549. const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
  550. this.ctx.stage.tp_history.push({
  551. times,
  552. order: audit.order,
  553. contract_tp: tpData.contract_tp,
  554. qc_tp: tpData.qc_tp,
  555. yf_tp: yfPay.tp,
  556. sf_tp: sfPay.tp,
  557. });
  558. await transaction.update(this.tableName, {
  559. id: audit.id,
  560. status: checkData.checkType,
  561. opinion: checkData.opinion,
  562. end_time: time,
  563. });
  564. // 同步 期信息
  565. await transaction.update(this.ctx.service.stage.tableName, {
  566. id: stageId,
  567. status: checkData.checkType,
  568. contract_tp: tpData.contract_tp,
  569. qc_tp: tpData.qc_tp,
  570. times: times + 1,
  571. yf_tp: yfPay.tp,
  572. sf_tp: sfPay.tp,
  573. tp_history: JSON.stringify(this.ctx.stage.tp_history),
  574. cache_time_r: this.ctx.stage.cache_time_l,
  575. });
  576. // 拷贝新一次审核流程列表
  577. await transaction.insert(this.tableName, auditors);
  578. // 计算该审批人最终数据
  579. await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
  580. // 复制一份最新数据给原报
  581. await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times + 1, 0, transaction);
  582. await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
  583. await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
  584. await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
  585. await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
  586. await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
  587. // 添加短信通知-审批退回提醒功能
  588. // const mobile_array = [];
  589. const stageInfo = await this.ctx.service.stage.getDataById(stageId);
  590. const auditList = await this.getAuditors(stageId, stageInfo.times);
  591. // const smsUser1 = await this.ctx.service.projectAccount.getDataById(stageInfo.user_id);
  592. // if (smsUser1.auth_mobile !== '' && smsUser1.auth_mobile !== undefined && smsUser1.sms_type !== '' && smsUser1.sms_type !== null) {
  593. // const smsType = JSON.parse(smsUser1.sms_type);
  594. // if (smsType[smsTypeConst.const.JL] !== undefined && smsType[smsTypeConst.const.JL].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
  595. // mobile_array.push(smsUser1.auth_mobile);
  596. // }
  597. // }
  598. // for (const user of auditList) {
  599. // const smsUser = await this.ctx.service.projectAccount.getDataById(user.aid);
  600. // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  601. // const smsType = JSON.parse(smsUser.sms_type);
  602. // if (mobile_array.indexOf(smsUser.auth_mobile) === -1 && smsType[smsTypeConst.const.JL] !== undefined && smsType[smsTypeConst.const.JL].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
  603. // mobile_array.push(smsUser.auth_mobile);
  604. // }
  605. // }
  606. // }
  607. // if (mobile_array.length > 0) {
  608. // const tenderInfo = await this.ctx.service.tender.getDataById(stageInfo.tid);
  609. // const sms = new SMS(this.ctx);
  610. // const tenderName = await sms.contentChange(tenderInfo.name);
  611. // const projectName = await sms.contentChange(this.ctx.tender.info.deal_info.buildName);
  612. // const ptmsg = projectName !== '' ? '项目「' + projectName + '」标段「' + tenderName + '」' : tenderName;
  613. // const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,审批退回。';
  614. // sms.send(mobile_array, content);
  615. // }
  616. const users = this._.uniq(this._.concat(this._.map(auditList, 'aid'), stageInfo.user_id));
  617. await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, {
  618. qi: stageInfo.order,
  619. status: SmsAliConst.status.back,
  620. });
  621. // 微信模板通知
  622. const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  623. const wechatData = {
  624. wap_url: shenpiUrl,
  625. qi: stageInfo.order,
  626. status: wxConst.status.back,
  627. tips: wxConst.tips.back,
  628. code: this.ctx.session.sessionProject.code,
  629. };
  630. await this.ctx.helper.sendWechat(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
  631. await transaction.commit();
  632. } catch (err) {
  633. await transaction.rollback();
  634. throw err;
  635. }
  636. }
  637. async _checkNoPre(pid, stageId, checkData, times) {
  638. const time = new Date();
  639. // 整理当前流程审核人状态更新
  640. const audit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
  641. if (!audit || audit.order <= 1) {
  642. throw '审核数据错误';
  643. }
  644. // 添加重新审批后,不能用order-1,取groupby值里的上一个才对
  645. // const preAuditor = await this.getDataByCondition({sid: stageId, times: times, order: audit.order - 1});
  646. const auditors2 = await this.getAuditGroupByList(stageId, times);
  647. const auditorIndex = await auditors2.findIndex(function(item) {
  648. return item.aid === audit.aid;
  649. });
  650. const preAuditor = auditors2[auditorIndex - 1];
  651. const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
  652. const transaction = await this.db.beginTransaction();
  653. try {
  654. // 添加推送
  655. const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
  656. const records = [
  657. {
  658. pid,
  659. type: pushType.stage,
  660. uid: this.ctx.stage.user_id,
  661. status: auditConst.status.checkNoPre,
  662. content: noticeContent,
  663. },
  664. ];
  665. auditors2.forEach(audit => {
  666. records.push({
  667. pid,
  668. type: pushType.stage,
  669. uid: audit.aid,
  670. status: auditConst.status.checkNoPre,
  671. content: noticeContent,
  672. });
  673. });
  674. await transaction.insert('zh_notice', records);
  675. // 计算并合同支付最终数据
  676. const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
  677. this.ctx.stage.tp_history.push({
  678. times,
  679. order: audit.order,
  680. contract_tp: tpData.contract_tp,
  681. qc_tp: tpData.qc_tp,
  682. yf_tp: yfPay.tp,
  683. sf_tp: sfPay.tp,
  684. });
  685. // 同步 期信息
  686. await transaction.update(this.ctx.service.stage.tableName, {
  687. id: stageId,
  688. contract_tp: tpData.contract_tp,
  689. qc_tp: tpData.qc_tp,
  690. times,
  691. yf_tp: yfPay.tp,
  692. sf_tp: sfPay.tp,
  693. tp_history: JSON.stringify(this.ctx.stage.tp_history),
  694. cache_time_r: this.ctx.stage.cache_time_l,
  695. });
  696. await transaction.update(this.tableName, {
  697. id: audit.id,
  698. status: checkData.checkType,
  699. opinion: checkData.opinion,
  700. end_time: time,
  701. });
  702. // 顺移气候审核人流程顺序
  703. this.initSqlBuilder();
  704. this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=' });
  705. this.sqlBuilder.setAndWhere('order', { value: audit.order, operate: '>' });
  706. this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+' });
  707. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
  708. const data = await transaction.query(sql, sqlParam);
  709. // 上一审批人,当前审批人 再次添加至流程
  710. const newAuditors = [];
  711. newAuditors.push({
  712. tid: audit.tid,
  713. sid: audit.sid,
  714. aid: preAuditor.aid,
  715. times: audit.times,
  716. order: audit.order + 1,
  717. status: auditConst.status.checking,
  718. begin_time: time,
  719. });
  720. newAuditors.push({
  721. tid: audit.tid,
  722. sid: audit.sid,
  723. aid: audit.aid,
  724. times: audit.times,
  725. order: audit.order + 2,
  726. status: auditConst.status.uncheck,
  727. });
  728. await transaction.insert(this.tableName, newAuditors);
  729. // 计算该审批人最终数据
  730. await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
  731. // 复制一份最新数据给下一人
  732. await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction);
  733. await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
  734. await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
  735. await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
  736. await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
  737. await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
  738. // 多人协同数据确认删除本人和上一个审批人确认状态
  739. await this.ctx.service.cooperationConfirm.delBycheckNoPre(audit.aid, this.ctx.stage, transaction);
  740. await this.ctx.service.cooperationConfirm.delBycheckNoPre(preAuditor.aid, this.ctx.stage, transaction);
  741. // 同步 期信息
  742. await transaction.update(this.ctx.service.stage.tableName, {
  743. id: stageId,
  744. status: checkData.checkType,
  745. cache_time_r: this.ctx.stage.cache_time_l,
  746. });
  747. // 添加短信通知-需要审批提醒功能
  748. // const smsUser = await this.ctx.service.projectAccount.getDataById(preAuditor.aid);
  749. // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  750. // const smsType = JSON.parse(smsUser.sms_type);
  751. // if (smsType[smsTypeConst.const.JL] !== undefined && smsType[smsTypeConst.const.JL].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
  752. // const tenderInfo = await this.ctx.service.tender.getDataById(audit.tid);
  753. // const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
  754. // const sms = new SMS(this.ctx);
  755. // const tenderName = await sms.contentChange(tenderInfo.name);
  756. // const projectName = await sms.contentChange(this.ctx.tender.info.deal_info.buildName);
  757. // const ptmsg = projectName !== '' ? '项目「' + projectName + '」标段「' + tenderName + '」' : tenderName;
  758. // const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  759. // // const result = '';
  760. // const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,需要您审批。' + result;
  761. // sms.send(smsUser.auth_mobile, content);
  762. // }
  763. // }
  764. const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
  765. const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  766. await this.ctx.helper.sendAliSms(preAuditor.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
  767. qi: stageInfo.order,
  768. code: shenpiUrl,
  769. });
  770. // 微信模板通知
  771. const wechatData = {
  772. wap_url: shenpiUrl,
  773. qi: stageInfo.order,
  774. status: wxConst.status.check,
  775. tips: wxConst.tips.check,
  776. code: this.ctx.session.sessionProject.code,
  777. };
  778. await this.ctx.helper.sendWechat(preAuditor.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
  779. await transaction.commit();
  780. } catch (err) {
  781. await transaction.rollback();
  782. throw err;
  783. }
  784. }
  785. /**
  786. * 审批
  787. * @param {Number} stageId - 标段id
  788. * @param {auditConst.status.checked|auditConst.status.checkNo} checkType - 审批结果
  789. * @param {Number} times - 第几次审批
  790. * @return {Promise<void>}
  791. */
  792. async check(stageId, checkData, times = 1) {
  793. if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.checkNoPre) {
  794. throw '提交数据错误';
  795. }
  796. // // 整理当前流程审核人状态更新
  797. // const audit = await this.getDataByCondition({sid: stageId, times: times, status: auditConst.status.checking});
  798. // if (!audit) {
  799. // throw '审核数据错误';
  800. // }
  801. // const time = new Date();
  802. const pid = this.ctx.session.sessionProject.id;
  803. switch (checkData.checkType) {
  804. case auditConst.status.checked:
  805. await this._checked(pid, stageId, checkData, times);
  806. break;
  807. case auditConst.status.checkNo:
  808. await this._checkNo(pid, stageId, checkData, times);
  809. break;
  810. case auditConst.status.checkNoPre:
  811. await this._checkNoPre(pid, stageId, checkData, times);
  812. break;
  813. default:
  814. throw '无效审批操作';
  815. }
  816. // 通知发送 - 第三方更新
  817. if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
  818. const base_data = {
  819. tid: this.ctx.tender.id,
  820. sid: stageId,
  821. op: 'update',
  822. };
  823. this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  824. base_data.op = 'update';
  825. base_data.sid = -1;
  826. this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  827. }
  828. }
  829. /**
  830. * 审批
  831. * @param {Number} stageId - 标段id
  832. * @param {Number} times - 第几次审批
  833. * @return {Promise<void>}
  834. */
  835. async checkAgain(stageId, times = 1) {
  836. const time = new Date();
  837. // 整理当前流程审核人状态更新
  838. const audit = (
  839. await this.getAllDataByCondition({
  840. where: { sid: stageId, times },
  841. orders: [['order', 'desc']],
  842. limit: 1,
  843. offset: 0,
  844. })
  845. )[0];
  846. if (!audit || audit.order < 1) {
  847. throw '审核数据错误';
  848. }
  849. const transaction = await this.db.beginTransaction();
  850. try {
  851. // 当前审批人2次添加至流程中
  852. const newAuditors = [];
  853. newAuditors.push({
  854. tid: audit.tid,
  855. sid: audit.sid,
  856. aid: audit.aid,
  857. times: audit.times,
  858. order: audit.order + 1,
  859. status: auditConst.status.checkAgain,
  860. begin_time: time,
  861. end_time: time,
  862. opinion: '',
  863. });
  864. newAuditors.push({
  865. tid: audit.tid,
  866. sid: audit.sid,
  867. aid: audit.aid,
  868. times: audit.times,
  869. order: audit.order + 2,
  870. status: auditConst.status.checking,
  871. begin_time: time,
  872. });
  873. await transaction.insert(this.tableName, newAuditors);
  874. // 复制一份最新数据给下一人
  875. await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction);
  876. await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 2, transaction);
  877. await this.ctx.service.stageJgcl.updateHistory4CheckAgain(this.ctx.stage, transaction);
  878. await this.ctx.service.stageBonus.updateHistory4CheckAgain(this.ctx.stage, transaction);
  879. await this.ctx.service.stageOther.updateHistory4CheckAgain(this.ctx.stage, transaction);
  880. await this.ctx.service.stageSafeProd.updateHistory4CheckAgain(this.ctx.stage, transaction);
  881. await this.ctx.service.stageTempLand.updateHistory4CheckAgain(this.ctx.stage, transaction);
  882. // 本期结束
  883. // 生成截止本期数据 final数据
  884. await this.ctx.service.stageBillsFinal.delGenerateFinalData(transaction, this.ctx.tender, this.ctx.stage);
  885. await this.ctx.service.stagePosFinal.delGenerateFinalData(transaction, this.ctx.tender, this.ctx.stage);
  886. await this.ctx.service.stageChangeFinal.delGenerateFinalData(transaction, this.ctx.tender, this.ctx.stage);
  887. // 同步 期信息
  888. await transaction.update(this.ctx.service.stage.tableName, {
  889. id: stageId,
  890. status: auditConst.status.checking,
  891. cache_time_r: this.ctx.stage.cache_time_l,
  892. });
  893. // 添加短信通知-需要审批提醒功能
  894. // const smsUser = await this.ctx.service.projectAccount.getDataById(audit.aid);
  895. // if (smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  896. // const smsType = JSON.parse(smsUser.sms_type);
  897. // if (smsType[smsTypeConst.const.JL] !== undefined && smsType[smsTypeConst.const.JL].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
  898. // const tenderInfo = await this.ctx.service.tender.getDataById(audit.tid);
  899. // const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
  900. // const sms = new SMS(this.ctx);
  901. // const tenderName = await sms.contentChange(tenderInfo.name);
  902. // const projectName = await sms.contentChange(this.ctx.tender.info.deal_info.buildName);
  903. // const ptmsg = projectName !== '' ? '项目「' + projectName + '」标段「' + tenderName + '」' : tenderName;
  904. // const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  905. // const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,需要您审批。' + result;
  906. // sms.send(smsUser.auth_mobile, content);
  907. // }
  908. // }
  909. const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
  910. const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
  911. await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
  912. qi: stageInfo.order,
  913. code: shenpiUrl,
  914. });
  915. // 微信模板通知
  916. const wechatData = {
  917. wap_url: shenpiUrl,
  918. qi: stageInfo.order,
  919. status: wxConst.status.check,
  920. tips: wxConst.tips.check,
  921. code: this.ctx.session.sessionProject.code,
  922. };
  923. await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
  924. await transaction.commit();
  925. // 通知发送 - 第三方更新
  926. if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
  927. const base_data = {
  928. tid: this.ctx.tender.id,
  929. sid: stageId,
  930. op: 'update',
  931. };
  932. this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  933. base_data.op = 'update';
  934. base_data.sid = -1;
  935. this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  936. }
  937. } catch (err) {
  938. await transaction.rollback();
  939. throw err;
  940. }
  941. }
  942. /**
  943. * 获取审核人需要审核的期列表
  944. *
  945. * @param auditorId
  946. * @return {Promise<*>}
  947. */
  948. async getAuditStage(auditorId) {
  949. const sql =
  950. 'SELECT sa.`aid`, sa.`times`, sa.`order`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
  951. ' s.`order` As `sorder`, s.`status` As `sstatus`,' +
  952. ' t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
  953. ' FROM ?? AS sa, ?? AS s, ?? As t ' +
  954. ' WHERE ((sa.`aid` = ? and sa.`status` = ?) OR (s.`user_id` = ? and sa.`status` = ? and s.`status` = ? and sa.`times` = (s.`times`-1)))' +
  955. ' and sa.`sid` = s.`id` and sa.`tid` = t.`id` ORDER BY sa.`begin_time` DESC';
  956. const sqlParam = [
  957. this.tableName,
  958. this.ctx.service.stage.tableName,
  959. this.ctx.service.tender.tableName,
  960. auditorId,
  961. auditConst.status.checking,
  962. auditorId,
  963. auditConst.status.checkNo,
  964. auditConst.status.checkNo,
  965. ];
  966. return await this.db.query(sql, sqlParam);
  967. }
  968. /**
  969. * 获取 某时间后 审批进度 更新的期
  970. * @param {Number} pid - 查询标段
  971. * @param {Number} uid - 查询人
  972. * @param {Date} time - 查询时间
  973. * @return {Promise<*>}
  974. */
  975. async getNoticeStage(pid, uid, time) {
  976. // const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
  977. // ' s.`order` As `s_order`, s.`status` As `s_status`, ' +
  978. // ' sa.`aid`, sa.`times`, sa.`order`, sa.`end_time`, sa.`tid`, sa.`sid`, sa.`status`, ' +
  979. // ' pa.`name` As `su_name`, pa.role As `su_role`, pa.company As `su_company`' +
  980. // ' FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `aid` = ? GROUP BY `tid`)) As t' +
  981. // ' LEFT JOIN ?? As s On t.`id` = s.`tid`' +
  982. // ' LEFT JOIN ?? As sa ON s.`id` = sa.`sid`' +
  983. // ' LEFT JOIN ?? As pa ON sa.`aid` = pa.`id`' +
  984. // ' WHERE sa.`end_time` > ? and t.`project_id` = ?' +
  985. // ' ORDER By sa.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`tid`' +
  986. // ' ORDER By new_t.`end_time`';
  987. // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.stage.tableName, this.tableName,
  988. // this.ctx.service.projectAccount.tableName, time, pid];
  989. // return await this.db.query(sql, sqlParam);
  990. let notice = await this.db.select('zh_notice', {
  991. where: { pid, type: pushType.stage, uid },
  992. orders: [['create_time', 'desc']],
  993. limit: 10,
  994. offset: 0,
  995. });
  996. notice = notice.map(v => {
  997. const extra = JSON.parse(v.content);
  998. delete v.content;
  999. return { ...v, ...extra };
  1000. });
  1001. return notice;
  1002. }
  1003. /**
  1004. * 用于添加推送所需的content内容
  1005. * @param {Number} pid 项目id
  1006. * @param {Number} tid 台账id
  1007. * @param {Number} sid 期id
  1008. * @param {Number} uid 审核人id
  1009. */
  1010. async getNoticeContent(pid, tid, sid, uid) {
  1011. const noticeSql =
  1012. 'SELECT * FROM (SELECT ' +
  1013. ' t.`id` As `tid`, t.`name`, s.`order`, pa.`name` As `su_name`, pa.role As `su_role`' +
  1014. ' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
  1015. ' LEFT JOIN ?? As s On s.`id` = ?' +
  1016. ' LEFT JOIN ?? As pa ON pa.`id` = ?' +
  1017. ' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
  1018. const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.stage.tableName, sid, this.ctx.service.projectAccount.tableName, uid, pid];
  1019. const content = await this.db.query(noticeSql, noticeSqlParam);
  1020. return content.length ? JSON.stringify(content[0]) : '';
  1021. }
  1022. /**
  1023. * 获取审核人流程列表
  1024. *
  1025. * @param auditorId
  1026. * @return {Promise<*>}
  1027. */
  1028. async getAuditGroupByList(stageId, times) {
  1029. const sql =
  1030. 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`aid`, la.`order` ' +
  1031. 'FROM ?? AS la, ?? AS pa ' +
  1032. 'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` GROUP BY la.`aid` ORDER BY la.`order`';
  1033. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, times];
  1034. return await this.db.query(sql, sqlParam);
  1035. // const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
  1036. // const sqlParam = [this.tableName, stageId, times];
  1037. // return await this.db.query(sql, sqlParam);
  1038. }
  1039. /**
  1040. * 获取审核人流程列表
  1041. *
  1042. * @param auditorId
  1043. * @return {Promise<*>}
  1044. */
  1045. async getAuditGroupByListWithOwner(stageId, times) {
  1046. const result = await this.getAuditGroupByList(stageId, times);
  1047. const sql =
  1048. 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As sid, 0 As `order`' +
  1049. ' FROM ' +
  1050. this.ctx.service.stage.tableName +
  1051. ' As s' +
  1052. ' LEFT JOIN ' +
  1053. this.ctx.service.projectAccount.tableName +
  1054. ' As pa' +
  1055. ' ON s.user_id = pa.id' +
  1056. ' WHERE s.id = ?';
  1057. const sqlParam = [times, stageId, stageId];
  1058. const user = await this.db.queryOne(sql, sqlParam);
  1059. result.unshift(user);
  1060. return result;
  1061. }
  1062. /**
  1063. * 复制上一期的审批人列表给最新一期
  1064. *
  1065. * @param transaction - 新增一期的事务
  1066. * @param {Object} preStage - 上一期
  1067. * @param {Object} newStage - 最新一期
  1068. * @return {Promise<*>}
  1069. */
  1070. async copyPreStageAuditors(transaction, preStage, newStage) {
  1071. const auditors = await this.getAuditGroupByList(preStage.id, preStage.times);
  1072. const newAuditors = [];
  1073. for (const a of auditors) {
  1074. const na = {
  1075. tid: preStage.tid,
  1076. sid: newStage.id,
  1077. aid: a.aid,
  1078. times: newStage.times,
  1079. order: newAuditors.length + 1,
  1080. status: auditConst.status.uncheck,
  1081. };
  1082. newAuditors.push(na);
  1083. }
  1084. const result = await transaction.insert(this.tableName, newAuditors);
  1085. return (result.effectRows = auditors.length);
  1086. }
  1087. /**
  1088. * 移除审核人
  1089. *
  1090. * @param {Number} stageId - 期id
  1091. * @param {Number} status - 期状态
  1092. * @param {Number} status - 期次数
  1093. * @return {Promise<boolean>}
  1094. */
  1095. async getAuditorByStatus(stageId, status, times = 1) {
  1096. let auditor = null;
  1097. let sql = '';
  1098. let sqlParam = '';
  1099. switch (status) {
  1100. case auditConst.status.checking:
  1101. case auditConst.status.checked:
  1102. case auditConst.status.checkNoPre:
  1103. sql =
  1104. 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
  1105. 'FROM ?? AS la, ?? AS pa ' +
  1106. 'WHERE la.`sid` = ? and la.`status` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc';
  1107. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, status];
  1108. auditor = await this.db.queryOne(sql, sqlParam);
  1109. break;
  1110. case auditConst.status.checkNo:
  1111. sql =
  1112. 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
  1113. 'FROM ?? AS la, ?? AS pa ' +
  1114. 'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc';
  1115. sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checkNo, parseInt(times) - 1];
  1116. auditor = await this.db.queryOne(sql, sqlParam);
  1117. break;
  1118. case auditConst.status.uncheck:
  1119. default:
  1120. break;
  1121. }
  1122. return auditor;
  1123. }
  1124. /**
  1125. * 取某一期已批准审核信息(报表用)
  1126. *
  1127. * @param {Number} stageId - 期id
  1128. * @param {Number} times - 期次数
  1129. * @return {Promise<boolean>}
  1130. */
  1131. async getStageAudit(stageId, times = 1) {
  1132. const sql = 'SELECT a1.aid, a1.begin_time, a1.end_time, a1.status, a1.opinion ' + 'FROM ?? AS a1 ' + 'WHERE a1.`sid` = ? and a1.`times` = ? ' + 'ORDER BY a1.order';
  1133. const sqlParam = [this.tableName, stageId, times];
  1134. const rst = await this.db.query(sql, sqlParam);
  1135. return rst;
  1136. }
  1137. /**
  1138. * 取待审批期列表(wap用)
  1139. *
  1140. * @param auditorId
  1141. * @return {Promise<*>}
  1142. */
  1143. async getAuditStageByWap(auditorId) {
  1144. const sql =
  1145. 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
  1146. // ' s.`order` As `sorder`, s.`status` As `sstatus`, s.`s_time`, s.`contract_tp`, s.`qc_tp`, s.`pre_contract_tp`, s.`pre_qc_tp`, s.`yf_tp`, s.`pre_yf_tp`, ' +
  1147. ' s.*,' +
  1148. ' t.`name`, t.`project_id`, t.`type`, t.`user_id`,' +
  1149. ' ti.`deal_info` ' +
  1150. ' FROM ?? AS sa, ?? AS s, ?? As t, ?? AS ti ' +
  1151. ' WHERE sa.`aid` = ? and sa.`status` = ?' +
  1152. ' and sa.`sid` = s.`id` and sa.`tid` = t.`id` and ti.`tid` = t.`id`';
  1153. const sqlParam = [
  1154. this.tableName,
  1155. this.ctx.service.stage.tableName,
  1156. this.ctx.service.tender.tableName,
  1157. this.ctx.service.tenderInfo.tableName,
  1158. auditorId,
  1159. auditConst.status.checking,
  1160. ];
  1161. return await this.db.query(sql, sqlParam);
  1162. }
  1163. /**
  1164. * 删除 某期 某次 全审批流程
  1165. * 私有,不做判断,不补全最新一轮审批人数据,不计算缓存
  1166. * @param {Number} sid - 标段id
  1167. * @param {Number} times - 第几次审批
  1168. * @param transaction - 删除事务
  1169. * @return {Promise<void>}
  1170. */
  1171. async _timesDelete(sid, times, transaction) {
  1172. // 审批流程
  1173. await transaction.delete(this.tableName, { sid, times });
  1174. await transaction.delete(this.ctx.service.pos.tableName, { add_stage: sid, add_times: times });
  1175. await transaction.delete(this.ctx.service.stageBills.tableName, { sid, times });
  1176. await transaction.delete(this.ctx.service.stagePos.tableName, { sid, times });
  1177. await transaction.delete(this.ctx.service.stageDetail.tableName, { sid, times });
  1178. await transaction.delete(this.ctx.service.stageChange.tableName, { sid, stimes: times });
  1179. await transaction.delete(this.ctx.service.stagePay.tableName, { sid, stimes: times });
  1180. await transaction.delete(this.ctx.service.pay.tableName, { csid: sid, cstimes: times });
  1181. // 其他台账
  1182. await this.ctx.service.stageJgcl.deleteStageTimesData(sid, times, transaction);
  1183. await this.ctx.service.stageOther.deleteStageTimesData(sid, times, transaction);
  1184. await this.ctx.service.stageBonus.deleteStageTimesData(sid, times, transaction);
  1185. await this.ctx.service.stageSafeProd.deleteStageTimesData(sid, times, transaction);
  1186. await this.ctx.service.stageTempLand.deleteStageTimesData(sid, times, transaction);
  1187. }
  1188. /**
  1189. * 删除本次审批流程
  1190. * @param {Number} stageId - 标段id
  1191. * @param {Number} times - 第几次审批
  1192. * @return {Promise<void>}
  1193. */
  1194. async timesDelete() {
  1195. const transaction = await this.db.beginTransaction();
  1196. try {
  1197. // 删除最新一次数据
  1198. await this._timesDelete(this.ctx.stage.id, this.ctx.stage.times, transaction);
  1199. // 审批退回,未重新上报时,需删除最新两次数据
  1200. const isCheckNo = this.ctx.stage.status === auditConst.status.checkNo;
  1201. const nowTimes = isCheckNo ? this.ctx.stage.times - 1 : this.ctx.stage.times;
  1202. if (isCheckNo) {
  1203. await this._timesDelete(this.ctx.stage.id, nowTimes, transaction);
  1204. }
  1205. // 添加上一次审批人
  1206. const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
  1207. const sqlParam = [this.tableName, this.ctx.stage.id, nowTimes - 1];
  1208. const auditors = await this.db.query(sql, sqlParam);
  1209. let order = 1;
  1210. for (const a of auditors) {
  1211. a.times = nowTimes;
  1212. a.order = order;
  1213. a.status = auditConst.status.uncheck;
  1214. order++;
  1215. }
  1216. // 拷贝新一次审核流程列表
  1217. await transaction.insert(this.tableName, auditors);
  1218. // 计算缓存
  1219. const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
  1220. // 计算并合同支付最终数据
  1221. const lastAudit = await this.getDataByCondition({
  1222. sid: this.ctx.stage.id,
  1223. times: nowTimes - 1,
  1224. status: auditConst.status.checkNo,
  1225. });
  1226. if (!lastAudit) throw '审批数据错误';
  1227. await this.ctx.service.stagePay.copyStagePays4DeleteTimes(this.ctx.stage, nowTimes, 0, lastAudit.times, lastAudit.order, transaction);
  1228. const stagePay = await this.ctx.service.stagePay.getAuditorStageData(this.ctx.stage.id, lastAudit.times, lastAudit.order);
  1229. const yfPay = stagePay.find(function(x) {
  1230. return x.ptype === payConst.payType.yf;
  1231. });
  1232. console.log(stagePay);
  1233. const sfPay = stagePay.find(function(x) {
  1234. return x.ptype === payConst.payType.sf;
  1235. });
  1236. // 同步 期信息
  1237. const time = new Date();
  1238. await transaction.update(this.ctx.service.stage.tableName, {
  1239. id: this.ctx.stage.id,
  1240. status: auditConst.status.checkNo,
  1241. contract_tp: tpData.contract_tp,
  1242. qc_tp: tpData.qc_tp,
  1243. times: nowTimes,
  1244. yf_tp: yfPay ? yfPay.tp : null,
  1245. sf_tp: sfPay ? sfPay.tp : null,
  1246. tp_history: JSON.stringify(this.ctx.stage.tp_history),
  1247. cache_time_l: time,
  1248. cache_time_r: time,
  1249. });
  1250. await transaction.commit();
  1251. // 通知发送 - 第三方更新
  1252. if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
  1253. const base_data = {
  1254. tid: this.ctx.tender.id,
  1255. sid: this.ctx.stage.id,
  1256. op: 'update',
  1257. };
  1258. this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  1259. base_data.op = 'update';
  1260. base_data.sid = -1;
  1261. this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
  1262. }
  1263. } catch (err) {
  1264. await transaction.rollback();
  1265. throw err;
  1266. }
  1267. }
  1268. // 固定审批流-更新
  1269. async updateNewAuditList(stage, newIdList) {
  1270. const transaction = await this.db.beginTransaction();
  1271. try {
  1272. // 先删除旧的审批流,再添加新的
  1273. await transaction.delete(this.tableName, { sid: stage.id, times: stage.times });
  1274. const newAuditors = [];
  1275. let order = 1;
  1276. for (const aid of newIdList) {
  1277. newAuditors.push({
  1278. tid: stage.tid, sid: stage.id, aid,
  1279. times: stage.times, order, status: auditConst.status.uncheck,
  1280. });
  1281. order++;
  1282. }
  1283. if(newAuditors.length > 0) await transaction.insert(this.tableName, newAuditors);
  1284. await transaction.commit();
  1285. } catch (err) {
  1286. await transaction.rollback();
  1287. throw err;
  1288. }
  1289. }
  1290. // 固定终审-更新
  1291. async updateLastAudit(stage, auditList, lastId) {
  1292. const transaction = await this.db.beginTransaction();
  1293. try {
  1294. // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
  1295. const idList = this._.map(auditList, 'aid');
  1296. let order = idList.length + 1;
  1297. if (idList.indexOf(lastId) !== -1) {
  1298. await transaction.delete(this.tableName, { sid: stage.id, times: stage.times, aid: lastId });
  1299. const audit = this._.find(auditList, { 'aid': lastId });
  1300. // 顺移之后审核人流程顺序
  1301. await this._syncOrderByDelete(transaction, stage.id, audit.order, stage.times);
  1302. order = order - 1;
  1303. }
  1304. // 添加终审
  1305. const newAuditor = {
  1306. tid: stage.tid, sid: stage.id, aid: lastId,
  1307. times: stage.times, order, status: auditConst.status.uncheck,
  1308. };
  1309. await transaction.insert(this.tableName, newAuditor);
  1310. await transaction.commit();
  1311. } catch (err) {
  1312. await transaction.rollback();
  1313. throw err;
  1314. }
  1315. }
  1316. async getFinalAuditGroup(stageId, times) {
  1317. const sql =
  1318. 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, pa.`sign_path`, la.`times`, la.`sid`, Max(la.`order`) as max_order ' +
  1319. 'FROM ?? AS la, ?? AS pa ' +
  1320. 'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` GROUP BY la.`aid` ORDER BY la.`order`';
  1321. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, times];
  1322. const result = await this.db.query(sql, sqlParam);
  1323. for (const r of result) {
  1324. const auditor = await this.getDataByCondition({sid: stageId, times: r.times, order: r.max_order});
  1325. r.status = auditor.status;
  1326. r.opinion = auditor.opinion;
  1327. r.begin_time = auditor.begin_time;
  1328. r.end_time = auditor.end_time;
  1329. }
  1330. return result;
  1331. }
  1332. }
  1333. return StageAudit;
  1334. };