|
@@ -247,29 +247,47 @@ module.exports = app => {
|
|
|
|
|
|
async _checked(pid, materialId, checkData, times) {
|
|
async _checked(pid, materialId, checkData, times) {
|
|
const time = new Date();
|
|
const time = new Date();
|
|
|
|
+
|
|
// 整理当前流程审核人状态更新
|
|
// 整理当前流程审核人状态更新
|
|
const audit = await this.getDataByCondition({ mid: materialId, times, status: auditConst.status.checking });
|
|
const audit = await this.getDataByCondition({ mid: materialId, times, status: auditConst.status.checking });
|
|
if (!audit) {
|
|
if (!audit) {
|
|
throw '审核数据错误';
|
|
throw '审核数据错误';
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 获取审核人列表
|
|
|
|
+ const sql = 'SELECT `tid`, `mid`, `aid`, `order` FROM ?? WHERE `mid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
|
|
|
|
+ const sqlParam = [this.tableName, materialId, times];
|
|
|
|
+ const auditors = await this.db.query(sql, sqlParam);
|
|
|
|
+
|
|
const nextAudit = await this.getDataByCondition({ mid: materialId, times, order: audit.order + 1 });
|
|
const nextAudit = await this.getDataByCondition({ mid: materialId, times, order: audit.order + 1 });
|
|
|
|
|
|
|
|
+
|
|
const transaction = await this.db.beginTransaction();
|
|
const transaction = await this.db.beginTransaction();
|
|
try {
|
|
try {
|
|
await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
|
|
+
|
|
|
|
+ // 获取推送必要信息
|
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId, audit.aid)
|
|
|
|
+ // 添加推送
|
|
|
|
+ const records = [{ pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checked, content: noticeContent }]
|
|
|
|
+ auditors.forEach(audit => {
|
|
|
|
+ records.push({ pid, type: pushType.material, uid: audit.aid, status: auditConst.status.checked, content: noticeContent })
|
|
|
|
+ })
|
|
|
|
+ await transaction.insert('zh_notice', records);
|
|
// 无下一审核人表示,审核结束
|
|
// 无下一审核人表示,审核结束
|
|
if (nextAudit) {
|
|
if (nextAudit) {
|
|
// 复制一份下一审核人数据
|
|
// 复制一份下一审核人数据
|
|
// await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction);
|
|
// await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction);
|
|
// 流程至下一审批人
|
|
// 流程至下一审批人
|
|
await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
|
|
await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
|
|
- // 添加记录到推送表
|
|
|
|
|
|
|
|
// 同步 期信息
|
|
// 同步 期信息
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
id: materialId, status: auditConst.status.checking,
|
|
id: materialId, status: auditConst.status.checking,
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// 添加短信通知-需要审批提醒功能
|
|
// 添加短信通知-需要审批提醒功能
|
|
// const smsUser = await this.ctx.service.projectAccount.getDataById(nextAudit.aid);
|
|
// const smsUser = await this.ctx.service.projectAccount.getDataById(nextAudit.aid);
|
|
// if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
|
|
// if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
|
|
@@ -294,9 +312,6 @@ module.exports = app => {
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
id: materialId, status: checkData.checkType,
|
|
id: materialId, status: checkData.checkType,
|
|
});
|
|
});
|
|
- const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId)
|
|
|
|
- // 审核结束,将原报添加到推送表
|
|
|
|
- await transaction.insert('zh_notice', { pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checked, is_read: 0, content: noticeContent });
|
|
|
|
|
|
|
|
// 添加短信通知-审批通过提醒功能
|
|
// 添加短信通知-审批通过提醒功能
|
|
// const mobile_array = [];
|
|
// const mobile_array = [];
|
|
@@ -354,8 +369,12 @@ module.exports = app => {
|
|
try {
|
|
try {
|
|
await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
// 添加到消息推送表
|
|
// 添加到消息推送表
|
|
- const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId)
|
|
|
|
- await transaction.insert('zh_notice', { pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNo, is_read: 0, content: noticeContent });
|
|
|
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId, audit.aid)
|
|
|
|
+ const records = [{ pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNo, content: noticeContent }]
|
|
|
|
+ auditors.forEach( audit => {
|
|
|
|
+ records.push({ pid, type: pushType.material, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent })
|
|
|
|
+ })
|
|
|
|
+ await transaction.insert('zh_notice', records);
|
|
// 同步期信息
|
|
// 同步期信息
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
id: materialId, status: checkData.checkType,
|
|
id: materialId, status: checkData.checkType,
|
|
@@ -409,7 +428,7 @@ module.exports = app => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- async _checkNoPre(materialId, checkData, times) {
|
|
|
|
|
|
+ async _checkNoPre(pid, materialId, checkData, times) {
|
|
const time = new Date();
|
|
const time = new Date();
|
|
// 整理当前流程审核人状态更新
|
|
// 整理当前流程审核人状态更新
|
|
const audit = await this.getDataByCondition({ mid: materialId, times, status: auditConst.status.checking });
|
|
const audit = await this.getDataByCondition({ mid: materialId, times, status: auditConst.status.checking });
|
|
@@ -422,8 +441,15 @@ module.exports = app => {
|
|
return item.aid === audit.aid;
|
|
return item.aid === audit.aid;
|
|
});
|
|
});
|
|
const preAuditor = auditors2[auditorIndex - 1];
|
|
const preAuditor = auditors2[auditorIndex - 1];
|
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId, audit.aid)
|
|
const transaction = await this.db.beginTransaction();
|
|
const transaction = await this.db.beginTransaction();
|
|
try {
|
|
try {
|
|
|
|
+ // 添加到消息推送表
|
|
|
|
+ const records = [{ pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNoPre, content: noticeContent }]
|
|
|
|
+ auditors2.forEach( audit => {
|
|
|
|
+ records.push({ pid, type: pushType.material, uid: audit.aid, status: auditConst.status.checkNoPre, content: noticeContent })
|
|
|
|
+ })
|
|
|
|
+ await transaction.insert('zh_notice', records);
|
|
await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
// 顺移气候审核人流程顺序
|
|
// 顺移气候审核人流程顺序
|
|
this.initSqlBuilder();
|
|
this.initSqlBuilder();
|
|
@@ -471,7 +497,7 @@ module.exports = app => {
|
|
await this._checkNo(pid, materialId, checkData, times);
|
|
await this._checkNo(pid, materialId, checkData, times);
|
|
break;
|
|
break;
|
|
case auditConst.status.checkNoPre:
|
|
case auditConst.status.checkNoPre:
|
|
- await this._checkNoPre(materialId, checkData, times);
|
|
|
|
|
|
+ await this._checkNoPre(pid, materialId, checkData, times);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
throw '无效审批操作';
|
|
throw '无效审批操作';
|
|
@@ -483,16 +509,17 @@ module.exports = app => {
|
|
* @param {Number} pid 项目id
|
|
* @param {Number} pid 项目id
|
|
* @param {Number} tid 台账id
|
|
* @param {Number} tid 台账id
|
|
* @param {Number} mid 期id
|
|
* @param {Number} mid 期id
|
|
|
|
+ * @param {Number} uid 审批人id
|
|
*/
|
|
*/
|
|
- async getNoticeContent(pid, tid, mid) {
|
|
|
|
|
|
+ async getNoticeContent(pid, tid, mid, uid) {
|
|
const noticeSql = 'SELECT * FROM (SELECT ' +
|
|
const noticeSql = 'SELECT * FROM (SELECT ' +
|
|
' t.`id` As `tid`, ma.`mid`, t.`name`, m.`order`, pa.`name` As `su_name`, pa.role As `su_role`' +
|
|
' t.`id` As `tid`, ma.`mid`, t.`name`, m.`order`, pa.`name` As `su_name`, pa.role As `su_role`' +
|
|
' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
|
|
' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
|
|
' LEFT JOIN ?? As m On t.`id` = m.`tid` AND m.`id` = ?' +
|
|
' LEFT JOIN ?? As m On t.`id` = m.`tid` AND m.`id` = ?' +
|
|
' LEFT JOIN ?? As ma ON m.`id` = ma.`mid`' +
|
|
' LEFT JOIN ?? As ma ON m.`id` = ma.`mid`' +
|
|
- ' LEFT JOIN ?? As pa ON t.`user_id` = pa.`id`' +
|
|
|
|
|
|
+ ' LEFT JOIN ?? As pa ON pa.`id` = ?' +
|
|
' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
|
|
' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
|
|
- const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.material.tableName, mid, this.tableName, this.ctx.service.projectAccount.tableName, pid];
|
|
|
|
|
|
+ const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.material.tableName, mid, this.tableName, this.ctx.service.projectAccount.tableName, uid, pid];
|
|
const content = await this.db.query(noticeSql, noticeSqlParam);
|
|
const content = await this.db.query(noticeSql, noticeSqlParam);
|
|
return content.length ? JSON.stringify(content[0]) : '';
|
|
return content.length ? JSON.stringify(content[0]) : '';
|
|
}
|
|
}
|
|
@@ -598,13 +625,16 @@ module.exports = app => {
|
|
// this.ctx.service.projectAccount.tableName, time, pid];
|
|
// this.ctx.service.projectAccount.tableName, time, pid];
|
|
// return await this.db.query(sql, sqlParam);
|
|
// return await this.db.query(sql, sqlParam);
|
|
let notice = await this.db.select('zh_notice', {
|
|
let notice = await this.db.select('zh_notice', {
|
|
- where: { pid, type: pushType.material, uid, is_read: 0 },
|
|
|
|
|
|
+ where: { pid, type: pushType.material, uid},
|
|
|
|
+ orders: [['create_time', 'desc']],
|
|
|
|
+ limit: 10, offset: 0
|
|
});
|
|
});
|
|
notice = notice.map(v => {
|
|
notice = notice.map(v => {
|
|
const extra = JSON.parse(v.content)
|
|
const extra = JSON.parse(v.content)
|
|
delete v.content
|
|
delete v.content
|
|
return { ...v, ...extra }
|
|
return { ...v, ...extra }
|
|
})
|
|
})
|
|
|
|
+ console.log('notice', notice)
|
|
return notice;
|
|
return notice;
|
|
}
|
|
}
|
|
|
|
|