12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 'use strict';
- /**
- * 版本数据模型
- *
- * @author CaiAoLin
- * @date 2017/10/25
- * @version
- */
- const auditConst = require('../const/audit').stage;
- module.exports = app => {
- class PaymentRptAudit extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'payment_rpt_audit';
- }
- async updateSignatureMsg(td_id, uid, signature_msg) {
- const transaction = await this.db.beginTransaction();
- try {
- // 判断是否是审批人或非它审批阶段签字签章,如果不是则需要更新到detail中
- const rptAudit = await this.getDataByCondition({ td_id, uid });
- if (!rptAudit) {
- throw '当前人不存在报表角色中';
- }
- if (this.ctx.detail.uid !== uid && this._.findIndex(this.ctx.detail.auditors, { aid: uid }) === -1) {
- let report_json = JSON.parse(this.ctx.detail.report_json);
- report_json = await this.ctx.service.paymentDetail.signOneSignatureData(report_json, rptAudit.signature_name, signature_msg);
- // 同步期信息
- await transaction.update(this.ctx.service.paymentDetail.tableName, {
- id: this.ctx.detail.id,
- report_json: JSON.stringify(report_json),
- });
- }
- await transaction.update(this.tableName, { sign_time: new Date(), signature_msg: JSON.stringify(signature_msg) }, { where: { td_id, uid } });
- await transaction.commit();
- return true;
- } catch (error) {
- await transaction.rollback();
- throw error;
- }
- }
- async clearSignatureMsg(transaction, td_id, uid) {
- return await transaction.update(this.tableName, { sign_time: null, signature_msg: null }, { where: { td_id, uid } });
- }
- async updateAllAuditList(transaction, td_id, newRptList) {
- const oldRptList = await this.getAllDataByCondition({ where: { td_id }, orders: [['id', 'asc']] });
- const updateData = [];
- for (const audit of oldRptList) {
- const uData = {
- id: audit.id,
- signature_msg: null,
- sign_time: null,
- };
- if (audit.uid !== newRptList[audit.signature_index].uid) {
- uData.uid = newRptList[audit.signature_index].uid;
- }
- updateData.push(uData);
- }
- await transaction.updateRows(this.tableName, updateData);
- }
- }
- return PaymentRptAudit;
- };
|