change.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/14
  7. * @version
  8. */
  9. const audit = require('../const/audit');
  10. const fs = require('fs');
  11. const path = require('path');
  12. const smsTypeConst = require('../const/sms_type');
  13. const SMS = require('../lib/sms');
  14. module.exports = app => {
  15. class Change extends app.BaseService {
  16. /**
  17. * 构造函数
  18. *
  19. * @param {Object} ctx - egg全局变量
  20. * @return {void}
  21. */
  22. constructor(ctx) {
  23. super(ctx);
  24. this.tableName = 'change';
  25. }
  26. /**
  27. * 查找数据
  28. *
  29. * @param {Object} data - 筛选表单中的get数据
  30. * @return {void}
  31. */
  32. searchFilter(data) {
  33. this.initSqlBuilder();
  34. // this.sqlBuilder.columns = ['id', 'username', 'real_name', 'create_time', 'last_login', 'login_ip',
  35. // 'group_id', 'token', 'can_login'];
  36. data.type = parseInt(data.status);
  37. if (data.keyword !== undefined) {
  38. switch (data.type) {
  39. // 用户名
  40. case 1:
  41. this.sqlBuilder.setAndWhere('username', {
  42. value: this.db.escape(data.keyword + '%'),
  43. operate: 'like',
  44. });
  45. break;
  46. // 姓名
  47. case 2:
  48. this.sqlBuilder.setAndWhere('real_name', {
  49. value: this.db.escape(data.keyword + '%'),
  50. operate: 'like',
  51. });
  52. break;
  53. // 联系电话
  54. case 3:
  55. this.sqlBuilder.setAndWhere('telephone', {
  56. value: this.db.escape(data.keyword + '%'),
  57. operate: 'like',
  58. });
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. // 办事处筛选
  65. if (data.office !== undefined && data.office !== '') {
  66. this.sqlBuilder.setAndWhere('office', {
  67. value: this.db.escape(data.office),
  68. operate: '=',
  69. });
  70. }
  71. }
  72. async add(tenderId, userId, code, name) {
  73. const sql = 'SELECT COUNT(*) as count FROM ?? WHERE `tid` = ? AND ((`code` = ? AND `status` != ?) OR (`p_code` = ? AND `status` = ?))';
  74. const sqlParam = [this.tableName, tenderId, code, audit.flow.status.checked, code, audit.flow.status.checked];
  75. const codeCount = await this.db.queryOne(sql, sqlParam);
  76. const count = codeCount.count;
  77. if (count > 0) {
  78. throw '变更令号重复';
  79. }
  80. // 初始化事务
  81. this.transaction = await this.db.beginTransaction();
  82. let result = false;
  83. try {
  84. const cid = this.uuid.v4();
  85. const change = {
  86. cid,
  87. tid: tenderId,
  88. uid: userId,
  89. status: audit.flow.status.uncheck,
  90. times: 1,
  91. valid: true,
  92. in_time: new Date(),
  93. code,
  94. name,
  95. };
  96. const operate = await this.transaction.insert(this.tableName, change);
  97. if (operate.affectedRows <= 0) {
  98. throw '新建变更令数据失败';
  99. }
  100. // 把提交人信息添加到zh_change_audit
  101. const userInfo = await this.ctx.service.projectAccount.getDataById(userId);
  102. const changeaudit = [{
  103. tid: tenderId,
  104. cid,
  105. uid: userId,
  106. name: userInfo.name,
  107. jobs: userInfo.role,
  108. company: userInfo.company,
  109. times: 1,
  110. usite: 0,
  111. usort: 0,
  112. status: 2,
  113. }];
  114. // 并把之前存在的变更令审批人添加到zh_change_audit
  115. // 先找出标段最近存在的变更令审批人的变更令info
  116. const changeInfo = await this.ctx.service.change.getHaveAuditLastInfo(tenderId);
  117. if (changeInfo) {
  118. // 再获取非原报审批人
  119. const auditList = await this.ctx.service.changeAudit.getListGroupByTimes(changeInfo.cid, changeInfo.times);
  120. let sort = 1;
  121. for (const audit of auditList) {
  122. if (audit.usite !== 0) {
  123. const oneaudit = {
  124. tid: tenderId,
  125. cid,
  126. uid: audit.uid,
  127. name: audit.name,
  128. jobs: audit.jobs,
  129. company: audit.company,
  130. times: 1,
  131. usite: audit.usite,
  132. usort: sort++,
  133. status: 1,
  134. };
  135. changeaudit.push(oneaudit);
  136. }
  137. }
  138. }
  139. await this.transaction.insert(this.ctx.service.changeAudit.tableName, changeaudit);
  140. result = change;
  141. this.transaction.commit();
  142. } catch (error) {
  143. console.log(error);
  144. // 回滚
  145. await this.transaction.rollback();
  146. }
  147. return result;
  148. }
  149. async getHaveAuditLastInfo(tenderId) {
  150. const sql = 'SELECT * FROM ?? as a LEFT JOIN ?? as b ON a.`cid` = b.`cid` WHERE a.`tid` = ? AND b.`usite` > 0 ORDER BY a.`in_time` DESC';
  151. const sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName, tenderId];
  152. return await this.db.queryOne(sql, sqlParam);
  153. }
  154. async pendingDatas(tenderId, userId) {
  155. return await this.getAllDataByCondition({
  156. tid: tenderId,
  157. uid: userId,
  158. status: audit.flow.status.checking,
  159. });
  160. }
  161. async uncheckDatas(tenderId, userId) {
  162. return await this.getAllDataByCondition({
  163. tid: tenderId,
  164. uid: userId,
  165. status: audit.flow.status.uncheck,
  166. });
  167. }
  168. async checkingDatas(tenderId, userId) {
  169. return await this.getAllDataByCondition({
  170. tid: tenderId,
  171. uid: userId,
  172. status: audit.flow.status.checking,
  173. });
  174. }
  175. async checkedDatas(tenderId, userId) {
  176. return await this.getAllDataByCondition({
  177. tid: tenderId,
  178. uid: userId,
  179. status: audit.flow.status.checked,
  180. });
  181. }
  182. async checkNoDatas(tenderId, userId) {
  183. return await this.getAllDataByCondition({
  184. tid: tenderId,
  185. uid: userId,
  186. status: audit.flow.status.checkNo,
  187. });
  188. }
  189. async checkNoCount(tenderId, userId) {
  190. return await this.count({
  191. tid: tenderId,
  192. uid: userId,
  193. status: audit.flow.status.checkNo,
  194. });
  195. }
  196. /**
  197. * 获取变更令列表
  198. * @param {int} tenderId - 标段id
  199. * @param {int} status - 状态
  200. * @return {object} list - 列表
  201. */
  202. async getListByStatus(tenderId, status = 0, hadlimit = 1) {
  203. let sql = '';
  204. let sqlParam = '';
  205. switch (status) {
  206. case 0:// 包含你的所有变更令
  207. sql = 'SELECT a.* FROM ?? AS a WHERE a.tid = ? AND ' +
  208. '(a.uid = ? OR (a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid)) OR a.status = ? ) ORDER BY a.in_time DESC';
  209. sqlParam = [this.tableName, tenderId, this.ctx.session.sessionUser.accountId, audit.flow.status.uncheck,
  210. this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId, audit.flow.status.checked];
  211. break;
  212. case 1:// 待处理(你的)
  213. sql = 'SELECT a.* FROM ?? as a WHERE cid in(SELECT b.cid FROM ?? as b WHERE tid = ? AND uid = ? AND status = ?) ORDER BY in_time DESC';
  214. sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName, tenderId, this.ctx.session.sessionUser.accountId, audit.flow.auditStatus.checking];
  215. break;
  216. case 5:// 待上报(所有的)PS:取未上报和退回的变更令
  217. sql = 'SELECT a.* FROM ?? AS a WHERE ' +
  218. 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid) AND ' +
  219. '(a.status = ? OR a.status = ?) AND a.tid = ? ORDER BY a.in_time DESC';
  220. sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName,
  221. this.ctx.session.sessionUser.accountId, audit.flow.status.uncheck, audit.flow.status.back, tenderId];
  222. break;
  223. case 2:// 进行中(所有的)
  224. case 4:// 终止(所有的)
  225. sql = 'SELECT a.* FROM ?? AS a WHERE ' +
  226. 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) AND ' +
  227. 'a.status = ? AND a.tid = ? ORDER BY a.in_time DESC';
  228. sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName,
  229. this.ctx.session.sessionUser.accountId, status, tenderId];
  230. break;
  231. case 3:// 已完成(所有的)
  232. sql = 'SELECT a.* FROM ?? AS a WHERE ' +
  233. 'a.status = ? AND a.tid = ? ORDER BY a.in_time DESC';
  234. sqlParam = [this.tableName, status, tenderId];
  235. break;
  236. default:
  237. break;
  238. }
  239. if (hadlimit) {
  240. const limit = this.app.config.pageSize;
  241. const offset = limit * (this.ctx.page - 1);
  242. const limitString = offset >= 0 ? offset + ',' + limit : limit;
  243. sql += ' LIMIT ' + limitString;
  244. }
  245. const list = await this.db.query(sql, sqlParam);
  246. return list;
  247. }
  248. /**
  249. * 获取变更令个数
  250. * @param {int} tenderId - 标段id
  251. * @param {int} status - 状态
  252. * @return {void}
  253. */
  254. async getCountByStatus(tenderId, status) {
  255. switch (status) {
  256. case 0:// 包含你的所有变更令
  257. const sql = 'SELECT count(*) AS count FROM ?? AS a WHERE a.tid = ? AND ' +
  258. '(a.uid = ? OR a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))';
  259. const sqlParam = [this.tableName, tenderId, this.ctx.session.sessionUser.accountId,
  260. this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId];
  261. const result = await this.db.query(sql, sqlParam);
  262. return result[0].count;
  263. case 1:// 待处理(你的)
  264. return await this.ctx.service.changeAudit.count({
  265. tid: tenderId,
  266. uid: this.ctx.session.sessionUser.accountId,
  267. status: 2,
  268. });
  269. case 5:// 待上报(所有的)PS:取未上报和退回的变更令
  270. const sql2 = 'SELECT count(*) AS count FROM ?? AS a WHERE ' +
  271. 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) ' +
  272. 'AND (a.status = ? OR a.status = ?) AND a.tid = ?';
  273. const sqlParam2 = [this.tableName, this.ctx.service.changeAudit.tableName,
  274. this.ctx.session.sessionUser.accountId, audit.flow.status.uncheck, audit.flow.status.back, tenderId];
  275. const result2 = await this.db.query(sql2, sqlParam2);
  276. return result2[0].count;
  277. case 2:// 进行中(所有的)
  278. case 4:// 终止(所有的)
  279. const sql3 = 'SELECT count(*) AS count FROM ?? AS a WHERE ' +
  280. 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) AND a.status = ? AND a.tid = ?';
  281. const sqlParam3 = [this.tableName, this.ctx.service.changeAudit.tableName,
  282. this.ctx.session.sessionUser.accountId, status, tenderId];
  283. const result3 = await this.db.query(sql3, sqlParam3);
  284. return result3[0].count;
  285. case 3:// 已完成(所有的)
  286. const sql4 = 'SELECT count(*) AS count FROM ?? WHERE status = ? AND tid = ?';
  287. const sqlParam4 = [this.tableName, status, tenderId];
  288. const result4 = await this.db.query(sql4, sqlParam4);
  289. return result4[0].count;
  290. default:
  291. break;
  292. }
  293. }
  294. /**
  295. * 上报或重新上报或保存修改功能
  296. * @param {int} postData - 表单提交的数据
  297. * @param {int} tenderId - 标段id
  298. * @return {void}
  299. */
  300. async save(postData, tenderId) {
  301. const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
  302. // 初始化事务
  303. this.transaction = await this.db.beginTransaction();
  304. let result = false;
  305. try {
  306. // 变更令信息
  307. const changeInfo = await this.getDataByCondition({ cid: postData.cid });
  308. // 该变更令原报人信息
  309. const lastUser = await this.ctx.service.changeAudit.getLastUser(changeInfo.cid, changeInfo.times, 0);
  310. // 先删除本次原有的变更审批人和清单
  311. await this.ctx.service.changeAudit.deleteAuditData(this.transaction, changeInfo.cid, changeInfo.times);
  312. await this.transaction.delete(this.ctx.service.changeAuditList.tableName, { cid: changeInfo.cid });
  313. let change_status = false;
  314. // 获取变更令提交状态
  315. if (postData.changestatus !== undefined && parseInt(postData.changestatus) === 1) {
  316. change_status = true;
  317. // 更新原报人审批状态
  318. await this.transaction.update(this.ctx.service.changeAudit.tableName, { id: lastUser.id, status: audit.flow.auditStatus.checked, sin_time: new Date() });
  319. }
  320. // 再插入postData里的变更审批人和清单
  321. if (postData.changeaudit !== undefined && postData.changeaudit !== '') {
  322. const changeAudit = postData.changeaudit.split(',');
  323. const insertCA = [];
  324. let uSite = 1;
  325. let uSort = parseInt(lastUser.usort) + 1;
  326. for (const [index, ca] of changeAudit.entries()) {
  327. const auditInfo = ca.split('/%/');
  328. const uStatus = change_status && index === 0 ? audit.flow.auditStatus.checking : audit.flow.auditStatus.uncheck;
  329. const sin_time = change_status && index === 0 ? new Date() : null;
  330. const caArray = {
  331. tid: tenderId,
  332. cid: changeInfo.cid,
  333. uid: auditInfo[0],
  334. name: auditInfo[1],
  335. jobs: auditInfo[2],
  336. company: auditInfo[3],
  337. times: changeInfo.times,
  338. usite: uSite,
  339. usort: uSort,
  340. status: uStatus,
  341. sin_time,
  342. };
  343. uSite++;
  344. uSort++;
  345. insertCA.push(caArray);
  346. // 添加短信通知-需要审批提醒功能
  347. if (change_status && index === 0) {
  348. const smsUser = await this.ctx.service.projectAccount.getDataById(auditInfo[0]);
  349. if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  350. const smsType = JSON.parse(smsUser.sms_type);
  351. if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
  352. const sms = new SMS(this.ctx);
  353. const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi');
  354. const content = '【纵横计量支付】' + changeInfo.code + '变更需要您审批。' + result;
  355. sms.send(smsUser.auth_mobile, content);
  356. }
  357. }
  358. }
  359. }
  360. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insertCA);
  361. }
  362. let changeList = [];
  363. if (postData.changelist !== undefined && postData.changelist !== '') {
  364. changeList = postData.changelist.split('^_^');
  365. }
  366. let changeWhiteList = [];
  367. if (postData.changewhitelist !== undefined && postData.changewhitelist !== '') {
  368. changeWhiteList = postData.changewhitelist.split('^_^');
  369. }
  370. changeList.push.apply(changeList, changeWhiteList);
  371. const insertCL = [];
  372. let total_price = 0;
  373. if (changeList.length > 0) {
  374. for (const cl of changeList) {
  375. const clInfo = cl.split(';');
  376. const clArray = {
  377. tid: tenderId,
  378. cid: changeInfo.cid,
  379. lid: clInfo[8],
  380. code: clInfo[0],
  381. name: clInfo[1],
  382. bwmx: clInfo[2],
  383. unit: clInfo[3],
  384. unit_price: clInfo[4],
  385. oamount: clInfo[5],
  386. camount: clInfo[6],
  387. samount: '',
  388. detail: clInfo[7],
  389. spamount: clInfo[6],
  390. };
  391. if (clInfo[4] === '') {
  392. delete clArray.unit_price;
  393. }
  394. insertCL.push(clArray);
  395. total_price = this.ctx.helper.accAdd(total_price,
  396. this.ctx.helper.mul(clArray.unit_price, clArray.spamount, tenderInfo.decimal.tp));
  397. }
  398. await this.transaction.insert(this.ctx.service.changeAuditList.tableName, insertCL);
  399. }
  400. // 修改变更令基本数据
  401. const cArray = {
  402. code: postData.code,
  403. name: postData.name,
  404. peg: postData.peg,
  405. org_name: postData.org_name,
  406. org_code: postData.org_code,
  407. new_name: postData.new_name,
  408. new_code: postData.new_code,
  409. content: postData.content,
  410. basis: postData.basis,
  411. expr: postData.expr,
  412. memo: postData.memo,
  413. type: postData.type.join(','),
  414. class: postData.class,
  415. quality: postData.quality,
  416. company: postData.company,
  417. charge: postData.charge,
  418. total_price,
  419. };
  420. const options = {
  421. where: {
  422. cid: changeInfo.cid,
  423. },
  424. };
  425. if (change_status) {
  426. cArray.status = audit.flow.status.checking;
  427. cArray.cin_time = Date.parse(new Date()) / 1000;
  428. }
  429. await this.transaction.update(this.tableName, cArray, options);
  430. await this.transaction.commit();
  431. result = true;
  432. } catch (error) {
  433. await this.transaction.rollback();
  434. result = false;
  435. }
  436. return result;
  437. }
  438. /**
  439. * 审批通过
  440. * @param {int} postData - 表单提交的数据
  441. * @param {int} changeData - 变更令的数据
  442. * @return {void}
  443. */
  444. async approvalSuccess(postData, changeData) {
  445. let tenderInfo;
  446. // 初始化事务
  447. this.transaction = await this.db.beginTransaction();
  448. let result = false;
  449. try {
  450. // 设置审批人通过
  451. const audit_update = {
  452. id: postData.audit_id,
  453. sdesc: postData.sdesc,
  454. status: audit.flow.auditStatus.checked,
  455. sin_time: new Date(),
  456. };
  457. const change_update = {
  458. w_code: postData.w_code,
  459. status: audit.flow.status.checking,
  460. cin_time: Date.parse(new Date()) / 1000,
  461. };
  462. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  463. // 清单数据更新
  464. const bills_list = postData.bills_list.split(',');
  465. let total_price = 0;
  466. for (const bl of bills_list) {
  467. const listInfo = bl.split('_');
  468. const lid = listInfo[0];
  469. const amount = listInfo[1];
  470. const changeListInfo = await this.ctx.service.changeAuditList.getDataById(lid);
  471. if (!tenderInfo) {
  472. tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeListInfo.tid);
  473. }
  474. if (changeListInfo !== undefined) {
  475. total_price = this.ctx.helper.add(total_price,
  476. this.ctx.helper.mul(changeListInfo.unit_price, amount, tenderInfo.decimal.tp));
  477. const audit_amount = changeListInfo.audit_amount !== null && changeListInfo.audit_amount !== '' ? changeListInfo.audit_amount.split(',') : [];
  478. audit_amount.push(amount);
  479. const list_update = {
  480. id: lid,
  481. audit_amount: audit_amount.join(','),
  482. spamount: parseFloat(amount),
  483. };
  484. if (postData.audit_next_id === undefined) {
  485. list_update.samount = amount;
  486. }
  487. await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
  488. }
  489. }
  490. if (postData.audit_next_id === undefined) {
  491. // 变更令审批完成
  492. change_update.status = audit.flow.status.checked;
  493. change_update.p_code = postData.p_code;
  494. change_update.sin_time = Date.parse(new Date()) / 1000;
  495. // 添加短信通知-审批通过提醒功能
  496. const mobile_array = [];
  497. const auditList = await this.ctx.service.changeAudit.getListGroupByTimes(changeData.cid, changeData.times);
  498. for (const user of auditList) {
  499. const smsUser = await this.ctx.service.projectAccount.getDataById(user.uid);
  500. if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  501. const smsType = JSON.parse(smsUser.sms_type);
  502. if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
  503. mobile_array.push(smsUser.auth_mobile);
  504. }
  505. }
  506. }
  507. if (mobile_array.length > 0) {
  508. const sms = new SMS(this.ctx);
  509. const content = '【纵横计量支付】' + changeData.code + '变更,审批通过。';
  510. sms.send(mobile_array, content);
  511. }
  512. } else {
  513. // 设置下一个审批人为审批状态
  514. const nextAudit_update = {
  515. id: postData.audit_next_id,
  516. status: audit.flow.auditStatus.checking,
  517. };
  518. await this.transaction.update(this.ctx.service.changeAudit.tableName, nextAudit_update);
  519. // 添加短信通知-需要审批提醒功能
  520. const nextAuditData = await this.ctx.service.changeAudit.getDataById(postData.audit_next_id);
  521. const smsUser = await this.ctx.service.projectAccount.getDataById(nextAuditData.uid);
  522. if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  523. const smsType = JSON.parse(smsUser.sms_type);
  524. if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
  525. const sms = new SMS(this.ctx);
  526. const code = await sms.contentChange(changeData.code);
  527. const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi');
  528. const content = '【纵横计量支付】' + code + '变更需要您审批。' + result;
  529. sms.send(smsUser.auth_mobile, content);
  530. }
  531. }
  532. }
  533. change_update.total_price = total_price;
  534. const options = {
  535. where: {
  536. cid: postData.change_id,
  537. },
  538. };
  539. await this.transaction.update(this.tableName, change_update, options);
  540. await this.transaction.commit();
  541. result = true;
  542. } catch (error) {
  543. console.log(error);
  544. await this.transaction.rollback();
  545. result = false;
  546. }
  547. return result;
  548. }
  549. /**
  550. * 审批终止
  551. * @param {int} postData - 表单提交的数据
  552. * @return {void}
  553. */
  554. async approvalStop(postData) {
  555. // 初始化事务
  556. this.transaction = await this.db.beginTransaction();
  557. let result = false;
  558. try {
  559. // 设置审批人终止
  560. const audit_update = {
  561. id: postData.audit_id,
  562. sdesc: postData.sdesc,
  563. status: 4,
  564. sin_time: new Date(),
  565. };
  566. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  567. // 设置变更令终止
  568. const change_update = {
  569. w_code: postData.w_code,
  570. status: 4,
  571. cin_time: Date.parse(new Date()) / 1000,
  572. };
  573. const options = {
  574. where: {
  575. cid: postData.change_id,
  576. },
  577. };
  578. await this.transaction.update(this.tableName, change_update, options);
  579. await this.transaction.commit();
  580. result = true;
  581. } catch (error) {
  582. await this.transaction.rollback();
  583. result = false;
  584. }
  585. return result;
  586. }
  587. /**
  588. * 审批退回到原报人
  589. * @param {int} postData - 表单提交的数据
  590. * @param {int} changeData - 变更令的数据
  591. * @return {void}
  592. */
  593. async approvalBack(postData, changeData) {
  594. // 初始化事务
  595. this.transaction = await this.db.beginTransaction();
  596. let result = false;
  597. try {
  598. const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
  599. const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeInfo.tid);
  600. // 设置审批人退回
  601. const audit_update = {
  602. id: postData.audit_id,
  603. sdesc: postData.sdesc,
  604. status: audit.flow.auditStatus.back,
  605. sin_time: new Date(),
  606. };
  607. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  608. // 新增新一次的审批人列表
  609. // 获取当前次数审批人列表
  610. const auditList = await this.ctx.service.changeAudit.getListGroupByTimes(changeInfo.cid, changeInfo.times);
  611. const lastauditInfo = await this.ctx.service.changeAudit.getLastUser(changeInfo.cid, changeInfo.times, 1, 0);
  612. let usort = lastauditInfo.usort + 1;
  613. const newTimes = changeInfo.times + 1;
  614. const insert_audit_array = [];
  615. for (const al of auditList) {
  616. const insert_audit = {
  617. tid: al.tid,
  618. cid: al.cid,
  619. uid: al.uid,
  620. name: al.name,
  621. jobs: al.jobs,
  622. company: al.company,
  623. times: newTimes,
  624. usite: al.usite,
  625. usort,
  626. status: al.usite !== 0 ? audit.flow.auditStatus.uncheck : audit.flow.auditStatus.checking,
  627. };
  628. insert_audit_array.push(insert_audit);
  629. usort++;
  630. }
  631. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit_array);
  632. // 变更金额也退回
  633. const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: changeInfo.cid } });
  634. let total_price = 0;
  635. for (const cl of changeList) {
  636. total_price = this.ctx.helper.add(total_price,
  637. this.ctx.helper.mul(cl.unit_price, cl.camount, tenderInfo.decimal.tp));
  638. }
  639. // 设置变更令退回
  640. const change_update = {
  641. w_code: postData.w_code,
  642. status: audit.flow.status.back,
  643. times: newTimes,
  644. cin_time: Date.parse(new Date()) / 1000,
  645. total_price,
  646. };
  647. const options = {
  648. where: {
  649. cid: postData.change_id,
  650. },
  651. };
  652. await this.transaction.update(this.tableName, change_update, options);
  653. await this.transaction.commit();
  654. result = true;
  655. // 添加短信通知-审批退回提醒功能
  656. const mobile_array = [];
  657. for (const user of insert_audit_array) {
  658. const smsUser = await this.ctx.service.projectAccount.getDataById(user.uid);
  659. if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  660. const smsType = JSON.parse(smsUser.sms_type);
  661. if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
  662. mobile_array.push(smsUser.auth_mobile);
  663. }
  664. }
  665. }
  666. if (mobile_array.length > 0) {
  667. const sms = new SMS(this.ctx);
  668. const code = await sms.contentChange(changeData.code);
  669. const content = '【纵横计量支付】' + code + '变更,审批退回。';
  670. sms.send(mobile_array, content);
  671. }
  672. } catch (error) {
  673. await this.transaction.rollback();
  674. result = false;
  675. }
  676. return result;
  677. }
  678. /**
  679. * 审批退回到上一个审批人
  680. * @param {int} postData - 表单提交的数据
  681. * @param {int} changeData - 变更令的数据
  682. * @return {void}
  683. */
  684. async approvalBackNew(postData, changeData) {
  685. // 初始化事务
  686. this.transaction = await this.db.beginTransaction();
  687. let result = false;
  688. try {
  689. const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
  690. const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeInfo.tid);
  691. // 设置审批人退回
  692. const audit_update = {
  693. id: postData.audit_id,
  694. sdesc: postData.sdesc,
  695. status: audit.flow.auditStatus.backnew,
  696. sin_time: new Date(),
  697. };
  698. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  699. // 获取当前审批人信息
  700. const auditInfo = await this.ctx.service.changeAudit.getDataById(postData.audit_id);
  701. // 获取当前次数审批人列表
  702. const auditList = await this.ctx.service.changeAudit.getNextAuditList(changeInfo.cid, auditInfo.usort);
  703. let usort = auditInfo.usort + 1;
  704. // 获取上一个审批人信息
  705. const lastauditInfo = await this.ctx.service.changeAudit.getDataById(postData.audit_last_id);
  706. // 新增2个审批人到审批列表中
  707. const insert_audit1 = {
  708. tid: lastauditInfo.tid,
  709. cid: lastauditInfo.cid,
  710. uid: lastauditInfo.uid,
  711. name: lastauditInfo.name,
  712. jobs: lastauditInfo.jobs,
  713. company: lastauditInfo.company,
  714. times: lastauditInfo.times,
  715. usite: lastauditInfo.usite,
  716. usort,
  717. status: audit.flow.auditStatus.checking,
  718. };
  719. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit1);
  720. usort++;
  721. // 新增2个审批人到审批列表中
  722. const insert_audit2 = {
  723. tid: auditInfo.tid,
  724. cid: auditInfo.cid,
  725. uid: auditInfo.uid,
  726. name: auditInfo.name,
  727. jobs: auditInfo.jobs,
  728. company: auditInfo.company,
  729. times: auditInfo.times,
  730. usite: auditInfo.usite,
  731. usort,
  732. status: audit.flow.auditStatus.uncheck,
  733. };
  734. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit2);
  735. // 把接下未审批的审批人排序都加2
  736. for (const al of auditList) {
  737. const audit_update = {
  738. id: al.id,
  739. usort: al.usort + 2,
  740. };
  741. await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
  742. }
  743. // 审批列表数据也要回退
  744. const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: changeInfo.cid } });
  745. let total_price = 0;
  746. for (const cl of changeList) {
  747. const audit_amount = cl.audit_amount.split(',');
  748. const last_amount = audit_amount[audit_amount.length - 1];
  749. audit_amount.splice(-1, 1);
  750. const list_update = {
  751. id: cl.id,
  752. audit_amount: audit_amount.join(','),
  753. spamount: parseFloat(last_amount),
  754. };
  755. total_price = this.ctx.helper.add(total_price,
  756. this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), tenderInfo.decimal.tp));
  757. await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
  758. }
  759. // 设置变更令退回
  760. const change_update = {
  761. w_code: postData.w_code,
  762. status: audit.flow.status.backnew,
  763. cin_time: Date.parse(new Date()) / 1000,
  764. total_price,
  765. };
  766. const options = {
  767. where: {
  768. cid: postData.change_id,
  769. },
  770. };
  771. await this.transaction.update(this.tableName, change_update, options);
  772. await this.transaction.commit();
  773. result = true;
  774. // 添加短信通知-需要审批提醒功能
  775. const smsUser = await this.ctx.service.projectAccount.getDataById(lastauditInfo.uid);
  776. if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  777. const smsType = JSON.parse(smsUser.sms_type);
  778. if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
  779. const sms = new SMS(this.ctx);
  780. const code = await sms.contentChange(changeData.code);
  781. const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi');
  782. const content = '【纵横计量支付】' + code + '变更需要您审批。' + result;
  783. sms.send(smsUser.auth_mobile, content);
  784. }
  785. }
  786. } catch (error) {
  787. await this.transaction.rollback();
  788. result = false;
  789. }
  790. return result;
  791. }
  792. /**
  793. * 查询可用的变更令
  794. * @param bills - 查询的清单
  795. * @param pos - 查询的部位
  796. * @returns {Promise<*>} - 可用的变更令列表
  797. */
  798. async getValidChanges(tid, bills, pos) {
  799. const timesLen = 100;
  800. const filter = 'cb.`code` = ' + this.db.escape(bills.b_code) +
  801. ' And cb.`name` = ' + this.db.escape(bills.name) +
  802. ' And cb.`unit` = ' + this.db.escape(bills.unit) +
  803. ' And cb.`unit_price` = ' + this.db.escape(bills.unit_price) +
  804. (pos ? ' And cb.`bwmx` = ' + this.db.escape(pos.name) : '');
  805. const sql = 'SELECT c.cid, c.code, c.name, c.w_code, c.p_code, c.peg, c.org_name, c.org_code, c.new_name, c.new_code,' +
  806. ' c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
  807. ' cb.id As cbid, cb.code As b_code, cb.name As b_name, cb.unit As b_unit, cb.samount As b_amount, cb.detail As b_detail, cb.bwmx As b_bwmx, ' +
  808. ' scb.used_amount' +
  809. ' FROM ' + this.tableName + ' As c ' +
  810. ' Left Join ' + this.ctx.service.changeAuditList.tableName +' As cb On c.cid = cb.cid ' +
  811. ' Left Join (' +
  812. ' SELECT SUM(sc.qty) As used_amount, sc.cbid' +
  813. ' FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
  814. ' INNER JOIN (SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, cbid, sid ' +
  815. ' FROM ' + this.ctx.service.stageChange.tableName +
  816. ' WHERE tid = ?' +
  817. ' GROUP BY cbid, sid' +
  818. ' ) As MF' +
  819. ' ON (sc.stimes * ' + timesLen + ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
  820. ' GROUP BY sc.cbid' +
  821. ' ) As scb ON cb.id = scb.cbid' +
  822. ' WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
  823. ' ORDER BY c.in_time';
  824. const sqlParam = [tid, tid, audit.flow.status.checked];
  825. const changes = await this.db.query(sql, sqlParam);
  826. for (const c of changes) {
  827. const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
  828. ' FROM ?? As ca ' +
  829. ' Left Join ?? As pa ' +
  830. ' On ca.uid = pa.id ' +
  831. ' Where ca.cid = ?';
  832. const aSqlParam = [this.ctx.service.changeAtt.tableName, this.ctx.service.projectAccount.tableName, c.cid];
  833. c.attachments = await this.db.query(aSql, aSqlParam);
  834. }
  835. return changes;
  836. }
  837. /**
  838. * 查询变更令 + 变更令执行
  839. * @param tid
  840. * @returns {Promise<void>}
  841. */
  842. async getChangeAndUsedInfo(tid) {
  843. const lastStage = await this.ctx.service.stage.getLastestStage(tid, true);
  844. let filter;
  845. if (lastStage.id === this.ctx.stage.id) {
  846. filter = this.db.format(' And (s.`order` < ? OR (s.`order` = ? And (sChange.`stimes` < ? OR (sChange.`stimes` = ? And sChange.`sorder` <= ?))))',
  847. [lastStage.order, lastStage.order, this.ctx.stage.curTimes, this.ctx.stage.curTimes, this.ctx.stage.curOrder]);
  848. } else {
  849. if (lastStage.status === audit.stage.status.uncheck) {
  850. filter = ' And s.order < ' + lastStage.order;
  851. } else if (lastStage.status === audit.stage.status.checked) {
  852. filter = '';
  853. } else if (lastStage.status === audit.stage.status.checkNo) {
  854. filter = this.db.format(' And (s.`order` < ? OR (s.`order` = ? And sChange.`stimes` <= ?))',
  855. [lastStage.order, lastStage.order, lastStage.times])
  856. } else {
  857. const curAuditor = await this.ctx.service.stageAudit.getCurAuditor(lastStage.id, lastStage.times);
  858. filter = this.db.format(' And (s.`order` < ? OR (s.`order` = ? And (sChange.`stimes` < ? OR (sChange.`stimes` = ? And sChange.`sorder` <= ?))))',
  859. [lastStage.order, lastStage.order, lastStage.times, lastStage.times, curAuditor.order - 1]);
  860. }
  861. }
  862. const sql = 'SELECT C.*, Sum(U.utp) As used_tp, Round(Sum(U.utp) / C.total_price * 100, 2) As used_pt' +
  863. ' FROM ' + this.tableName + ' As C' +
  864. ' LEFT JOIN (SELECT sc.tid, sc.cid, sc.cbid, Round(SUM(sc.qty) * cb.unit_price, ?) As utp' +
  865. ' FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
  866. ' INNER JOIN (' +
  867. ' SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `cbid`, sChange.`sid` ' +
  868. ' FROM ' + this.ctx.service.stageChange.tableName + ' As sChange ' +
  869. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' As s' +
  870. ' ON sChange.sid = s.id' +
  871. ' WHERE sChange.tid = ?' + filter +
  872. ' GROUP By `lid`, `pid`, `cbid`, `sid`' +
  873. ' ) As m' +
  874. ' ON sc.stimes = m.stimes And sc.sorder = m.sorder And sc.`cbid` = m.`cbid` AND sc.`sid` = m.`sid` And sc.`lid` = m.`lid` And sc.`pid` = m.`pid`' +
  875. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As cb ON sc.cbid = cb.id' +
  876. ' GROUP By sc.`cbid`' +
  877. ' ) As U ON C.cid = U.cid' +
  878. ' WHERE C.tid = ? And C.status = ? And C.valid' +
  879. ' GROUP By C.cid' +
  880. ' ORDER By in_time';
  881. const sqlParam = [this.ctx.tender.info.decimal.tp, tid, tid, audit.flow.status.checked];
  882. return await this.db.query(sql, sqlParam);
  883. }
  884. /**
  885. * 查询可用的变更令
  886. * @param { string } cid - 查询的清单
  887. * @return {Promise<*>} - 可用的变更令列表
  888. */
  889. async delete(cid) {
  890. // 初始化事务
  891. this.transaction = await this.db.beginTransaction();
  892. let result = false;
  893. try {
  894. // 先删除清单,审批人列表
  895. await this.transaction.delete(this.ctx.service.changeAuditList.tableName, { cid });
  896. await this.transaction.delete(this.ctx.service.changeAudit.tableName, { cid });
  897. // 再删除附件和附件文件ni zuo
  898. const attList = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { cid } });
  899. if (attList.length !== 0) {
  900. for (const att of attList) {
  901. await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
  902. }
  903. await this.transaction.delete(this.ctx.service.changeAtt.tableName, { cid });
  904. }
  905. // 最后删除变更令
  906. await this.transaction.delete(this.tableName, { cid });
  907. await this.transaction.commit();
  908. result = true;
  909. } catch (e) {
  910. await this.transaction.rollback();
  911. result = false;
  912. }
  913. return result;
  914. }
  915. /**
  916. * 重新审批变更令
  917. * @param { string } cid - 查询的清单
  918. * @return {Promise<*>} - 可用的变更令列表
  919. */
  920. async checkAgain(cid) {
  921. // 初始化事务
  922. this.transaction = await this.db.beginTransaction();
  923. let result = false;
  924. try {
  925. const changeInfo = await this.getDataByCondition({ cid });
  926. const tenderInfo = await this.ctx.service.tenderInfo.getTenderInfo(changeInfo.tid);
  927. // 获取终审
  928. const auditInfo = (await this.ctx.service.changeAudit.getAllDataByCondition({ where: { cid }, orders: [['usort', 'desc']], limit: 1, offset: 0 }))[0];
  929. let usort = auditInfo.usort + 1;
  930. // 新增2个审批状态到审批列表中
  931. const insert_audit1 = {
  932. tid: auditInfo.tid,
  933. cid: auditInfo.cid,
  934. uid: auditInfo.uid,
  935. name: auditInfo.name,
  936. jobs: auditInfo.jobs,
  937. company: auditInfo.company,
  938. times: auditInfo.times,
  939. usite: auditInfo.usite,
  940. usort,
  941. sin_time: new Date(),
  942. status: audit.flow.auditStatus.checkAgain,
  943. };
  944. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit1);
  945. usort++;
  946. // 新增2个审批人到审批列表中
  947. const insert_audit2 = {
  948. tid: auditInfo.tid,
  949. cid: auditInfo.cid,
  950. uid: auditInfo.uid,
  951. name: auditInfo.name,
  952. jobs: auditInfo.jobs,
  953. company: auditInfo.company,
  954. times: auditInfo.times,
  955. usite: auditInfo.usite,
  956. usort,
  957. status: audit.flow.auditStatus.checking,
  958. };
  959. await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit2);
  960. // 审批列表数据也要回退
  961. let total_price = 0;
  962. const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: changeInfo.cid } });
  963. for (const cl of changeList) {
  964. const audit_amount = cl.audit_amount.split(',');
  965. const last_amount = audit_amount[audit_amount.length - 1];
  966. audit_amount.splice(-1, 1);
  967. const list_update = {
  968. id: cl.id,
  969. audit_amount: audit_amount.join(','),
  970. samount: '',
  971. };
  972. total_price = this.ctx.helper.add(total_price,
  973. this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), tenderInfo.decimal.tp));
  974. await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
  975. }
  976. // 设置变更令审批中
  977. const change_update = {
  978. p_code: null,
  979. status: audit.flow.status.checking,
  980. cin_time: Date.parse(new Date()) / 1000,
  981. sin_time: null,
  982. total_price,
  983. };
  984. const options = {
  985. where: {
  986. cid: changeInfo.cid,
  987. },
  988. };
  989. await this.transaction.update(this.tableName, change_update, options);
  990. await this.transaction.commit();
  991. result = true;
  992. // 添加短信通知-需要审批提醒功能
  993. const smsUser = await this.ctx.service.projectAccount.getDataById(auditInfo.uid);
  994. if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
  995. const smsType = JSON.parse(smsUser.sms_type);
  996. if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
  997. const sms = new SMS(this.ctx);
  998. const code = await sms.contentChange(changeInfo.code);
  999. const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi');
  1000. const content = '【纵横计量支付】' + code + '变更需要您审批。' + result;
  1001. sms.send(smsUser.auth_mobile, content);
  1002. }
  1003. }
  1004. } catch (error) {
  1005. await this.transaction.rollback();
  1006. result = false;
  1007. }
  1008. return result;
  1009. }
  1010. /**
  1011. * 判断是否有重名的变更令
  1012. * @param cid
  1013. * @param code
  1014. * @param tid
  1015. * @returns {Promise<void>}
  1016. */
  1017. async isRepeat(cid, code, tid) {
  1018. const sql = 'SELECT COUNT(*) as count FROM ?? WHERE ((`code` = ? AND `status` != ?) OR (`p_code` = ? AND `status` = ?)) AND `cid` != ? AND `tid` = ?';
  1019. const sqlParam = [this.tableName, code, audit.flow.status.checked, code, audit.flow.status.checked, cid, tid];
  1020. const result = await this.db.queryOne(sql, sqlParam);
  1021. return result.count !== 0;
  1022. }
  1023. async getAllCheckedChanges(tid) {
  1024. return await this.getAllDataByCondition({
  1025. where: {tid: tid, status: audit.flow.status.checked},
  1026. orders: [['in_time', 'desc']]
  1027. })
  1028. }
  1029. }
  1030. return Change;
  1031. };