|
@@ -9,10 +9,7 @@
|
|
|
*/
|
|
|
|
|
|
const auditConst = require('../const/audit').material;
|
|
|
-const materialConst = require('../const/material');
|
|
|
-// const smsTypeConst = require('../const/sms_type');
|
|
|
-const SMS = require('../lib/sms');
|
|
|
-
|
|
|
+const pushType = require('../const/audit').pushType;
|
|
|
module.exports = app => {
|
|
|
class MaterialAudit extends app.BaseService {
|
|
|
/**
|
|
@@ -178,7 +175,6 @@ module.exports = app => {
|
|
|
|
|
|
/**
|
|
|
* 开始审批
|
|
|
- *
|
|
|
* @param {Number} materialId - 材料调差期id
|
|
|
* @param {Number} times - 第几次审批
|
|
|
* @return {Promise<boolean>}
|
|
@@ -195,9 +191,6 @@ module.exports = app => {
|
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
|
id: materialId, status: auditConst.status.checking,
|
|
|
});
|
|
|
- // 添加记录至推送表
|
|
|
- await transaction.insert('zh_notice', { type: 'material', uid: audit.aid, status: auditConst.status.checking, is_read: 0, content: '待审核' });
|
|
|
- console.log('1111');
|
|
|
// 本期一些必要数据(如应耗数量和上期调差金额)插入到material_bills_history表里
|
|
|
const materialBillsData = await this.ctx.service.materialBills.getAllDataByCondition({ where: { tid: this.ctx.tender.id } });
|
|
|
if (materialBillsData.length === 0) {
|
|
@@ -251,7 +244,7 @@ module.exports = app => {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- async _checked(materialId, checkData, times) {
|
|
|
+ async _checked(pid, materialId, checkData, times) {
|
|
|
const time = new Date();
|
|
|
// 整理当前流程审核人状态更新
|
|
|
const audit = await this.getDataByCondition({ mid: materialId, times, status: auditConst.status.checking });
|
|
@@ -269,6 +262,8 @@ module.exports = app => {
|
|
|
// 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.ctx.service.material.tableName, {
|
|
|
id: materialId, status: auditConst.status.checking,
|
|
@@ -298,6 +293,9 @@ module.exports = app => {
|
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
|
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 = [];
|
|
@@ -334,7 +332,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async _checkNo(materialId, checkData, times) {
|
|
|
+ async _checkNo(pid, materialId, checkData, times) {
|
|
|
const time = new Date();
|
|
|
// 整理当前流程审核人状态更新
|
|
|
const audit = await this.getDataByCondition({ mid: materialId, times, status: auditConst.status.checking });
|
|
@@ -351,11 +349,13 @@ module.exports = app => {
|
|
|
a.status = auditConst.status.uncheck;
|
|
|
order++;
|
|
|
}
|
|
|
-
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, materialId)
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
|
- // 同步 期信息
|
|
|
+ // 添加到消息推送表
|
|
|
+ await transaction.insert('zh_notice', { pid, type: pushType.material, uid: this.ctx.material.user_id, status: auditConst.status.checkNo, is_read: 0, content: noticeContent });
|
|
|
+ // 同步期信息
|
|
|
await transaction.update(this.ctx.service.material.tableName, {
|
|
|
id: materialId, status: checkData.checkType,
|
|
|
times: times + 1,
|
|
@@ -441,6 +441,7 @@ module.exports = app => {
|
|
|
tid: audit.tid, mid: audit.mid, aid: audit.aid,
|
|
|
times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck,
|
|
|
});
|
|
|
+
|
|
|
await transaction.insert(this.tableName, newAuditors);
|
|
|
await transaction.commit();
|
|
|
} catch (error) {
|
|
@@ -460,12 +461,13 @@ module.exports = app => {
|
|
|
if (checkData.checkType !== auditConst.status.checked && checkData.checkType !== auditConst.status.checkNo && checkData.checkType !== auditConst.status.checkNoPre) {
|
|
|
throw '提交数据错误';
|
|
|
}
|
|
|
+ const pid = this.ctx.session.sessionProject.id;
|
|
|
switch (checkData.checkType) {
|
|
|
case auditConst.status.checked:
|
|
|
- await this._checked(materialId, checkData, times);
|
|
|
+ await this._checked(pid, materialId, checkData, times);
|
|
|
break;
|
|
|
case auditConst.status.checkNo:
|
|
|
- await this._checkNo(materialId, checkData, times);
|
|
|
+ await this._checkNo(pid, materialId, checkData, times);
|
|
|
break;
|
|
|
case auditConst.status.checkNoPre:
|
|
|
await this._checkNoPre(materialId, checkData, times);
|
|
@@ -476,6 +478,26 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 用于添加推送所需的content内容
|
|
|
+ * @param {Number} pid 项目id
|
|
|
+ * @param {Number} tid 台账id
|
|
|
+ * @param {Number} mid 期id
|
|
|
+ */
|
|
|
+ async getNoticeContent(pid, tid, mid) {
|
|
|
+ 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`' +
|
|
|
+ ' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
|
|
|
+ ' LEFT JOIN ?? As m On t.`id` = m.`tid` AND m.`id` = ?' +
|
|
|
+ ' LEFT JOIN ?? As ma ON m.`id` = ma.`mid`' +
|
|
|
+ ' LEFT JOIN ?? As pa ON t.`user_id` = pa.`id`' +
|
|
|
+ ' 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 content = await this.db.query(noticeSql, noticeSqlParam);
|
|
|
+ return content.length ? JSON.stringify(content[0]) : '';
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 审批
|
|
|
* @param {Number} materialId - 材料调差期id
|
|
|
* @param {Number} times - 第几次审批
|
|
@@ -561,20 +583,29 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getNoticeMaterial(pid, uid, time) {
|
|
|
- const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
|
|
|
- ' m.`order` As `m_order`, m.`status` As `m_status`, ' +
|
|
|
- ' ma.`aid`, ma.`times`, ma.`order`, ma.`end_time`, ma.`tid`, ma.`mid`, ma.`status`, ' +
|
|
|
- ' pa.`name` As `su_name`, pa.role As `su_role`, pa.company As `su_company`' +
|
|
|
- ' FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `aid` = ? GROUP BY `tid`)) As t' +
|
|
|
- ' LEFT JOIN ?? As m On t.`id` = m.`tid`' +
|
|
|
- ' LEFT JOIN ?? As ma ON m.`id` = ma.`mid`' +
|
|
|
- ' LEFT JOIN ?? As pa ON ma.`aid` = pa.`id`' +
|
|
|
- ' WHERE ma.`end_time` > ? and t.`project_id` = ?' +
|
|
|
- ' ORDER By ma.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`tid`' +
|
|
|
- ' ORDER BY new_t.`end_time`';
|
|
|
- const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.material.tableName, this.tableName,
|
|
|
- this.ctx.service.projectAccount.tableName, time, pid];
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
+ // const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
|
|
|
+ // ' m.`order` As `m_order`, m.`status` As `m_status`, ' +
|
|
|
+ // ' ma.`aid`, ma.`times`, ma.`order`, ma.`end_time`, ma.`tid`, ma.`mid`, ma.`status`, ' +
|
|
|
+ // ' pa.`name` As `su_name`, pa.role As `su_role`, pa.company As `su_company`' +
|
|
|
+ // ' FROM (SELECT * FROM ?? WHERE `user_id` = ? OR `id` in (SELECT `tid` FROM ?? WHERE `aid` = ? GROUP BY `tid`)) As t' +
|
|
|
+ // ' LEFT JOIN ?? As m On t.`id` = m.`tid`' +
|
|
|
+ // ' LEFT JOIN ?? As ma ON m.`id` = ma.`mid`' +
|
|
|
+ // ' LEFT JOIN ?? As pa ON ma.`aid` = pa.`id`' +
|
|
|
+ // ' WHERE ma.`end_time` > ? and t.`project_id` = ?' +
|
|
|
+ // ' ORDER By ma.`end_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`tid`' +
|
|
|
+ // ' ORDER BY new_t.`end_time`';
|
|
|
+ // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.material.tableName, this.tableName,
|
|
|
+ // this.ctx.service.projectAccount.tableName, time, pid];
|
|
|
+ // return await this.db.query(sql, sqlParam);
|
|
|
+ let notice = await this.db.select('zh_notice', {
|
|
|
+ where: { pid, type: pushType.material, uid, is_read: 0 },
|
|
|
+ });
|
|
|
+ notice = notice.map(v => {
|
|
|
+ const extra = JSON.parse(v.content)
|
|
|
+ delete v.content
|
|
|
+ return { ...v, ...extra }
|
|
|
+ })
|
|
|
+ return notice;
|
|
|
}
|
|
|
|
|
|
/**
|