123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- '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 '当前人不存在报表角色中';
- }
- let sign_time = null;
- if ((this.ctx.detail.status !== auditConst.status.uncheck && this.ctx.detail.status !== auditConst.status.checkNo && this.ctx.detail.uid === uid) ||
- (this._.findIndex(this.ctx.detail.auditors, { aid: uid }) === -1 && this.ctx.detail.uid !== uid) ||
- (this._.findIndex(this.ctx.detail.auditors, { aid: uid }) !== -1 &&
- ((this.ctx.detail.status === auditConst.status.checked && !this.ctx.detail.curAuditor) ||
- (this.ctx.detail.curAuditor && this.ctx.detail.curAuditor.aid !== uid)))) {
- 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),
- });
- sign_time = new Date();
- }
- await transaction.update(this.tableName, { sign_time, signature_msg: JSON.stringify(signature_msg) }, { where: { td_id, uid } });
- await transaction.commit();
- return true;
- } catch (error) {
- await transaction.rollback();
- throw error;
- }
- }
- async updateSignTime(transaction, id) {
- return await transaction.update(this.tableName, { id, sign_time: new Date() });
- }
- 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);
- }
- async getListByDetail(td_id) {
- const sql = 'SELECT pra.*, pa.name as user_name FROM ?? as pra LEFT JOIN ?? as pa ON pra.`uid` = pa.`id` WHERE td_id = ?';
- const params = [this.tableName, this.ctx.service.projectAccount.tableName, td_id];
- const list = await this.db.query(sql, params);
- if (list.length > 0) {
- for (const ra of list) {
- ra.signature_msg = ra.signature_msg ? JSON.parse(ra.signature_msg) : null;
- }
- }
- return list;
- }
- async haveEmptySign(td_id) {
- const count = await this.count({ td_id, signature_msg: null });
- return count > 0;
- }
- }
- return PaymentRptAudit;
- };
|