|
@@ -13,6 +13,7 @@ const smsTypeConst = require('../const/sms_type');
|
|
|
const SMS = require('../lib/sms');
|
|
|
const SmsAliConst = require('../const/sms_alitemplate');
|
|
|
const payConst = require('../const/deal_pay');
|
|
|
+const pushType = require('../const/audit').pushType;
|
|
|
|
|
|
module.exports = app => {
|
|
|
class StageAudit extends app.BaseService {
|
|
@@ -276,7 +277,7 @@ module.exports = app => {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- async _checked(stageId, checkData, times) {
|
|
|
+ async _checked(pid, stageId, checkData, times) {
|
|
|
const time = new Date();
|
|
|
// 整理当前流程审核人状态更新
|
|
|
const audit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
|
|
@@ -389,6 +390,9 @@ module.exports = app => {
|
|
|
const users = this._.pull(this._.map(auditList, 'aid'), stageInfo.user_id);
|
|
|
await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL,
|
|
|
smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, { qi: stageInfo.order, status: SmsAliConst.status.success });
|
|
|
+ // 添加到消息推送表
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
|
|
|
+ await transaction.insert('zh_notice', { pid, type: pushType.stage, uid: this.ctx.stage.user_id, status: auditConst.status.checked, is_read: 0, content: noticeContent });
|
|
|
}
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
@@ -397,7 +401,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async _checkNo(stageId, checkData, times) {
|
|
|
+ async _checkNo(pid, stageId, checkData, times) {
|
|
|
const time = new Date();
|
|
|
// 整理当前流程审核人状态更新
|
|
|
const audit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
|
|
@@ -480,7 +484,9 @@ module.exports = app => {
|
|
|
const users = this._.pull(this._.map(auditList, 'aid'), stageInfo.user_id);
|
|
|
await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL,
|
|
|
smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, { qi: stageInfo.order, status: SmsAliConst.status.back });
|
|
|
-
|
|
|
+ // 添加到消息推送表
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
|
|
|
+ await transaction.insert('zh_notice', { pid, type: pushType.stage, uid: this.ctx.stage.user_id, status: auditConst.status.checkNo, is_read: 0, content: noticeContent });
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
@@ -606,13 +612,13 @@ module.exports = app => {
|
|
|
// throw '审核数据错误';
|
|
|
// }
|
|
|
// const time = new Date();
|
|
|
-
|
|
|
+ const pid = this.ctx.session.sessionProject.id;
|
|
|
switch (checkData.checkType) {
|
|
|
case auditConst.status.checked:
|
|
|
- await this._checked(stageId, checkData, times);
|
|
|
+ await this._checked(pid, stageId, checkData, times);
|
|
|
break;
|
|
|
case auditConst.status.checkNo:
|
|
|
- await this._checkNo(stageId, checkData, times);
|
|
|
+ await this._checkNo(pid, stageId, checkData, times);
|
|
|
break;
|
|
|
case auditConst.status.checkNoPre:
|
|
|
await this._checkNoPre(stageId, checkData, times);
|
|
@@ -834,20 +840,47 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getNoticeStage(pid, uid, time) {
|
|
|
- const sql = 'SELECT * FROM (SELECT t.`name`, t.`project_id`, t.`type`, t.`user_id`, ' +
|
|
|
- ' s.`order` As `s_order`, s.`status` As `s_status`, ' +
|
|
|
- ' sa.`aid`, sa.`times`, sa.`order`, sa.`end_time`, sa.`tid`, sa.`sid`, sa.`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 s On t.`id` = s.`tid`' +
|
|
|
- ' LEFT JOIN ?? As sa ON s.`id` = sa.`sid`' +
|
|
|
- ' LEFT JOIN ?? As pa ON sa.`aid` = pa.`id`' +
|
|
|
- ' WHERE sa.`end_time` > ? and t.`project_id` = ?' +
|
|
|
- ' ORDER By sa.`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.stage.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`, ' +
|
|
|
+ // ' s.`order` As `s_order`, s.`status` As `s_status`, ' +
|
|
|
+ // ' sa.`aid`, sa.`times`, sa.`order`, sa.`end_time`, sa.`tid`, sa.`sid`, sa.`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 s On t.`id` = s.`tid`' +
|
|
|
+ // ' LEFT JOIN ?? As sa ON s.`id` = sa.`sid`' +
|
|
|
+ // ' LEFT JOIN ?? As pa ON sa.`aid` = pa.`id`' +
|
|
|
+ // ' WHERE sa.`end_time` > ? and t.`project_id` = ?' +
|
|
|
+ // ' ORDER By sa.`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.stage.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.stage, uid, is_read: 0 },
|
|
|
+ });
|
|
|
+ notice = notice.map(v => {
|
|
|
+ const extra = JSON.parse(v.content)
|
|
|
+ delete v.content
|
|
|
+ return { ...v, ...extra }
|
|
|
+ })
|
|
|
+ return notice;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用于添加推送所需的content内容
|
|
|
+ * @param {Number} pid 项目id
|
|
|
+ * @param {Number} tid 台账id
|
|
|
+ * @param {Number} sid 期id
|
|
|
+ */
|
|
|
+ async getNoticeContent(pid, tid, sid) {
|
|
|
+ const noticeSql = 'SELECT * FROM (SELECT ' +
|
|
|
+ ' t.`id` As `tid`, t.`name`, s.`order`, pa.`name` As `su_name`, pa.role As `su_role`' +
|
|
|
+ ' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
|
|
|
+ ' LEFT JOIN ?? As s On s.`id` = ?' +
|
|
|
+ ' 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.stage.tableName, sid, this.ctx.service.projectAccount.tableName, pid];
|
|
|
+ const content = await this.db.query(noticeSql, noticeSqlParam);
|
|
|
+ return content.length ? JSON.stringify(content[0]) : '';
|
|
|
}
|
|
|
|
|
|
/**
|