|
@@ -8,8 +8,13 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
-const audit = require('../const/audit');
|
|
|
+const auditConst = require('../const/audit').flow;
|
|
|
const pushType = require('../const/audit').pushType;
|
|
|
+const shenpiConst = require('../const/shenpi');
|
|
|
+const smsTypeConst = require('../const/sms_type');
|
|
|
+const SMS = require('../lib/sms');
|
|
|
+const SmsAliConst = require('../const/sms_alitemplate');
|
|
|
+const wxConst = require('../const/wechat_template');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class ChangeAudit extends app.BaseService {
|
|
@@ -96,8 +101,8 @@ module.exports = app => {
|
|
|
* @return {void}
|
|
|
*/
|
|
|
async getStatusByChange(change) {
|
|
|
- const statusConst = audit.flow.status;
|
|
|
- const auditStatusConst = audit.flow.auditStatus;
|
|
|
+ const statusConst = auditConst.status;
|
|
|
+ const auditStatusConst = auditConst.auditStatus;
|
|
|
const uid = this.ctx.session.sessionUser.accountId;
|
|
|
const changeAuditInfo = await this.getAllDataByCondition({ where: { cid: change.cid, times: change.times, uid }, orders: [['id', 'desc']], limit: 1, offset: 0 });
|
|
|
if (!change.status === statusConst.checked && (changeAuditInfo === null || changeAuditInfo[0] === undefined)) {
|
|
@@ -271,10 +276,10 @@ module.exports = app => {
|
|
|
' FROM ?? AS ca, ?? AS c, ?? As t ' +
|
|
|
' WHERE ca.`uid` = ? and ca.`status` = ? and c.`status` != ?' +
|
|
|
' and ca.`cid` = c.`cid` and ca.`tid` = t.`id` ORDER BY ca.`sin_time` DESC';
|
|
|
- const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, uid, 2, audit.flow.status.uncheck];
|
|
|
+ const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, uid, 2, auditConst.status.uncheck];
|
|
|
const changes = await this.db.query(sql, sqlParam);
|
|
|
for (const c of changes) {
|
|
|
- if (c.cstatus === audit.flow.status.back) {
|
|
|
+ if (c.cstatus === auditConst.status.back) {
|
|
|
const preSql = 'SELECT pa.`id`, pa.`account`, pa.`account_group`, pa.`name`, pa.`company`, pa.`role`, pa.`telephone` FROM ?? As ca, ?? As pa ' +
|
|
|
' WHERE ca.cid = ? and ca.times = ? and ca.status = ? and ca.uid = pa.id';
|
|
|
const preSqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, c.cid, c.times - 1, c.cstatus];
|
|
@@ -306,7 +311,7 @@ module.exports = app => {
|
|
|
// ' WHERE t.`project_id` = ? and `ca`.`sin_time` > ? and `ca`.`usite` != 0 and `ca`.`status` != ?' +
|
|
|
// ' ORDER By ca.`sin_time` DESC LIMIT 1000) as new_t GROUP BY new_t.`id`' +
|
|
|
// ' ORDER BY new_t.`cu_time`';
|
|
|
- // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.change.tableName, this.tableName, pid, time, audit.flow.status.checking];
|
|
|
+ // const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.change.tableName, this.tableName, pid, time, auditConst.status.checking];
|
|
|
// return await this.db.query(sql, sqlParam);
|
|
|
let notice = await this.db.select('zh_notice', {
|
|
|
where: { pid, type: pushType.change, uid },
|
|
@@ -345,7 +350,7 @@ module.exports = app => {
|
|
|
' FROM ?? AS ca, ?? AS c, ?? As t, ?? AS ti ' +
|
|
|
' WHERE ca.`uid` = ? and ca.`status` = ? and c.`status` != ? and c.`status` != ?' +
|
|
|
' and ca.`cid` = c.`cid` and ca.`tid` = t.`id` and ti.`tid` = t.`id`';
|
|
|
- const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, uid, audit.flow.auditStatus.checking, audit.flow.status.uncheck, audit.flow.status.back];
|
|
|
+ const sqlParam = [this.tableName, this.ctx.service.change.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, uid, auditConst.auditStatus.checking, auditConst.status.uncheck, auditConst.status.back];
|
|
|
const changes = await this.db.query(sql, sqlParam);
|
|
|
for (const c of changes) {
|
|
|
const preSql = 'SELECT pa.`id`, pa.`account`, pa.`account_group`, pa.`name`, pa.`company`, pa.`role`, pa.`telephone` FROM ?? As ca, ?? As pa ' +
|
|
@@ -372,7 +377,7 @@ module.exports = app => {
|
|
|
newAuditors.push({
|
|
|
tid: change.tid, cid: change.cid, uid: aid,
|
|
|
name: accountInfo.name, jobs: accountInfo.role, company: accountInfo.company,
|
|
|
- times: change.times, usite: order, usort: uSort, status: audit.flow.auditStatus.uncheck,
|
|
|
+ times: change.times, usite: order, usort: uSort, status: auditConst.auditStatus.uncheck,
|
|
|
});
|
|
|
order++;
|
|
|
uSort++;
|
|
@@ -408,7 +413,7 @@ module.exports = app => {
|
|
|
const newAuditor = {
|
|
|
tid: change.tid, cid: change.cid, uid: lastId,
|
|
|
name: userInfo.name, jobs: userInfo.role, company: userInfo.company,
|
|
|
- times: change.times, usite: order, usort: uSort, status: audit.flow.auditStatus.uncheck,
|
|
|
+ times: change.times, usite: order, usort: uSort, status: auditConst.auditStatus.uncheck,
|
|
|
};
|
|
|
await transaction.insert(this.tableName, newAuditor);
|
|
|
await transaction.commit();
|
|
@@ -464,7 +469,7 @@ module.exports = app => {
|
|
|
*/
|
|
|
async getCurAuditor(cid, times = 1) {
|
|
|
const sql = 'SELECT * FROM ?? WHERE `cid` = ? and `status` = ? and `times` = ? and usite != 0';
|
|
|
- const sqlParam = [this.tableName, cid, audit.flow.status.checking, times];
|
|
|
+ const sqlParam = [this.tableName, cid, auditConst.status.checking, times];
|
|
|
return await this.db.queryOne(sql, sqlParam);
|
|
|
}
|
|
|
|
|
@@ -502,7 +507,7 @@ module.exports = app => {
|
|
|
const newAuditor = {
|
|
|
tid: this.ctx.tender.id, cid: cid, uid: auditorId,
|
|
|
name: userInfo.name, jobs: userInfo.role, company: userInfo.company,
|
|
|
- times: times, usite: newOrder, usort: uSort, status: audit.flow.auditStatus.uncheck,
|
|
|
+ times: times, usite: newOrder, usort: uSort, status: auditConst.auditStatus.uncheck,
|
|
|
};
|
|
|
const result = await transaction.insert(this.tableName, newAuditor);
|
|
|
await transaction.commit();
|
|
@@ -540,6 +545,68 @@ module.exports = app => {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始审批
|
|
|
+ * @param {Number} cid - 变更令id
|
|
|
+ * @param {Number} times - 第几次审批
|
|
|
+ * @return {Promise<boolean>}
|
|
|
+ */
|
|
|
+ async start(cid, times = 1) {
|
|
|
+ const audit = await this.getDataByCondition({ cid, times, usite: 1 });
|
|
|
+ const yBAudit = await this.getDataByCondition({ cid, times, usite: 0 });
|
|
|
+ if (!audit) {
|
|
|
+ if(this.ctx.tender.info.shenpi.change === shenpiConst.sp_status.gdspl) {
|
|
|
+ throw '请联系管理员添加审批人';
|
|
|
+ } else {
|
|
|
+ throw '请先选择审批人,再上报数据';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ await transaction.update(this.tableName, { id: audit.id, status: auditConst.auditStatus.checking, sin_time: new Date() });
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: cid,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ await transaction.update(this.ctx.service.change.tableName, {
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ }, options);
|
|
|
+ // 更新原报人审批状态
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: yBAudit.id,
|
|
|
+ status: auditConst.auditStatus.checked,
|
|
|
+ sin_time: new Date(),
|
|
|
+ });
|
|
|
+
|
|
|
+ // 添加短信通知-需要审批提醒功能
|
|
|
+ const sms = new SMS(this.ctx);
|
|
|
+ const code = await sms.contentChange(this.ctx.change.code);
|
|
|
+ const shenpiUrl = await this.ctx.helper.urlToShort(
|
|
|
+ this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.change.tid + '/change/' + cid + '/info#shenpi'
|
|
|
+ );
|
|
|
+ await this.ctx.helper.sendAliSms(audit.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
|
|
|
+ biangeng: code,
|
|
|
+ code: shenpiUrl,
|
|
|
+ });
|
|
|
+ // 微信模板通知
|
|
|
+ const wechatData = {
|
|
|
+ wap_url: shenpiUrl,
|
|
|
+ status: wxConst.status.check,
|
|
|
+ tips: wxConst.tips.check,
|
|
|
+ code: this.ctx.session.sessionProject.code,
|
|
|
+ c_name: this.ctx.change.name,
|
|
|
+ };
|
|
|
+ await this.ctx.helper.sendWechat(audit.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
|
|
|
+ await transaction.commit();
|
|
|
+ } catch (err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return ChangeAudit;
|