payment_rpt_audit.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. /**
  3. * 版本数据模型
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/10/25
  7. * @version
  8. */
  9. const auditConst = require('../const/audit').stage;
  10. module.exports = app => {
  11. class PaymentRptAudit extends app.BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'payment_rpt_audit';
  21. }
  22. async updateSignatureMsg(td_id, uid, signature_msg) {
  23. const transaction = await this.db.beginTransaction();
  24. try {
  25. // 判断是否是审批人或非它审批阶段签字签章,如果不是则需要更新到detail中
  26. const rptAudit = await this.getDataByCondition({ td_id, uid });
  27. if (!rptAudit) {
  28. throw '当前人不存在报表角色中';
  29. }
  30. if (this.ctx.detail.uid !== uid && this._.findIndex(this.ctx.detail.auditors, { aid: uid }) === -1) {
  31. let report_json = JSON.parse(this.ctx.detail.report_json);
  32. report_json = await this.ctx.service.paymentDetail.signOneSignatureData(report_json, rptAudit.signature_name, signature_msg);
  33. // 同步期信息
  34. await transaction.update(this.ctx.service.paymentDetail.tableName, {
  35. id: this.ctx.detail.id,
  36. report_json: JSON.stringify(report_json),
  37. });
  38. }
  39. await transaction.update(this.tableName, { sign_time: new Date(), signature_msg: JSON.stringify(signature_msg) }, { where: { td_id, uid } });
  40. await transaction.commit();
  41. return true;
  42. } catch (error) {
  43. await transaction.rollback();
  44. throw error;
  45. }
  46. }
  47. async clearSignatureMsg(transaction, td_id, uid) {
  48. return await transaction.update(this.tableName, { sign_time: null, signature_msg: null }, { where: { td_id, uid } });
  49. }
  50. async updateAllAuditList(transaction, td_id, newRptList) {
  51. const oldRptList = await this.getAllDataByCondition({ where: { td_id }, orders: [['id', 'asc']] });
  52. const updateData = [];
  53. for (const audit of oldRptList) {
  54. const uData = {
  55. id: audit.id,
  56. signature_msg: null,
  57. sign_time: null,
  58. };
  59. if (audit.uid !== newRptList[audit.signature_index].uid) {
  60. uData.uid = newRptList[audit.signature_index].uid;
  61. }
  62. updateData.push(uData);
  63. }
  64. await transaction.updateRows(this.tableName, updateData);
  65. }
  66. }
  67. return PaymentRptAudit;
  68. };