|
@@ -267,7 +267,9 @@ module.exports = app => {
|
|
case 0: // 包含你的所有变更令
|
|
case 0: // 包含你的所有变更令
|
|
sql =
|
|
sql =
|
|
'SELECT a.* FROM ?? AS a WHERE a.tid = ? AND ' +
|
|
'SELECT a.* FROM ?? AS a WHERE a.tid = ? AND ' +
|
|
- '(a.uid = ? OR (a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid)) OR a.status = ? )' + stateSql;
|
|
|
|
|
|
+ '(a.uid = ? OR (a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
|
+ ' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid))' +
|
|
|
|
+ 'OR a.status = ? )' + stateSql;
|
|
sqlParam = [
|
|
sqlParam = [
|
|
this.tableName,
|
|
this.tableName,
|
|
tenderId,
|
|
tenderId,
|
|
@@ -275,6 +277,9 @@ module.exports = app => {
|
|
audit.flow.status.uncheck,
|
|
audit.flow.status.uncheck,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.session.sessionUser.accountId,
|
|
this.ctx.session.sessionUser.accountId,
|
|
|
|
+ audit.flow.status.back,
|
|
|
|
+ this.ctx.service.changeAudit.tableName,
|
|
|
|
+ this.ctx.session.sessionUser.accountId,
|
|
audit.flow.status.checked,
|
|
audit.flow.status.checked,
|
|
];
|
|
];
|
|
break;
|
|
break;
|
|
@@ -284,11 +289,17 @@ module.exports = app => {
|
|
break;
|
|
break;
|
|
case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
|
|
case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
|
|
sql =
|
|
sql =
|
|
- 'SELECT a.* FROM ?? AS a WHERE ' +
|
|
|
|
- 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid) AND ' +
|
|
|
|
- '(a.status = ? OR a.status = ? OR a.status = ?) AND a.tid = ?' + stateSql;
|
|
|
|
|
|
+ 'SELECT a.* FROM ?? AS a WHERE' +
|
|
|
|
+ ' ((a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
|
+ ' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid)))' +
|
|
|
|
+ // 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? GROUP BY b.cid)' +
|
|
|
|
+ ' AND (a.status = ? OR a.status = ? OR a.status = ?) AND a.tid = ?' + stateSql;
|
|
sqlParam = [
|
|
sqlParam = [
|
|
this.tableName,
|
|
this.tableName,
|
|
|
|
+ audit.flow.status.uncheck,
|
|
|
|
+ this.ctx.service.changeAudit.tableName,
|
|
|
|
+ this.ctx.session.sessionUser.accountId,
|
|
|
|
+ audit.flow.status.back,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.session.sessionUser.accountId,
|
|
this.ctx.session.sessionUser.accountId,
|
|
audit.flow.status.uncheck,
|
|
audit.flow.status.uncheck,
|
|
@@ -350,7 +361,9 @@ module.exports = app => {
|
|
case 0: // 包含你的所有变更令
|
|
case 0: // 包含你的所有变更令
|
|
const sql =
|
|
const sql =
|
|
'SELECT count(*) AS count FROM ?? AS a WHERE a.tid = ? AND ' +
|
|
'SELECT count(*) AS count FROM ?? AS a WHERE a.tid = ? AND ' +
|
|
- '(a.uid = ? OR (a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid)) OR a.status = ? )' + stateSql;
|
|
|
|
|
|
+ '(a.uid = ? OR (a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
|
+ ' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid))' +
|
|
|
|
+ ' OR a.status = ? )' + stateSql;
|
|
const sqlParam = [
|
|
const sqlParam = [
|
|
this.tableName,
|
|
this.tableName,
|
|
tenderId,
|
|
tenderId,
|
|
@@ -358,6 +371,9 @@ module.exports = app => {
|
|
audit.flow.status.uncheck,
|
|
audit.flow.status.uncheck,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.session.sessionUser.accountId,
|
|
this.ctx.session.sessionUser.accountId,
|
|
|
|
+ audit.flow.status.back,
|
|
|
|
+ this.ctx.service.changeAudit.tableName,
|
|
|
|
+ this.ctx.session.sessionUser.accountId,
|
|
audit.flow.status.checked,
|
|
audit.flow.status.checked,
|
|
];
|
|
];
|
|
const result = await this.db.query(sql, sqlParam);
|
|
const result = await this.db.query(sql, sqlParam);
|
|
@@ -374,11 +390,17 @@ module.exports = app => {
|
|
return result6[0].count;
|
|
return result6[0].count;
|
|
case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
|
|
case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
|
|
const sql2 =
|
|
const sql2 =
|
|
- 'SELECT count(*) AS count FROM ?? AS a WHERE ' +
|
|
|
|
- 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) ' +
|
|
|
|
- 'AND (a.status = ? OR a.status = ? OR a.status = ?) AND a.tid = ?' + stateSql;
|
|
|
|
|
|
+ 'SELECT count(*) AS count FROM ?? AS a WHERE' +
|
|
|
|
+ ' ((a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
|
+ ' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid)))' +
|
|
|
|
+ // 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) ' +
|
|
|
|
+ ' AND (a.status = ? OR a.status = ? OR a.status = ?) AND a.tid = ?' + stateSql;
|
|
const sqlParam2 = [
|
|
const sqlParam2 = [
|
|
this.tableName,
|
|
this.tableName,
|
|
|
|
+ audit.flow.status.uncheck,
|
|
|
|
+ this.ctx.service.changeAudit.tableName,
|
|
|
|
+ this.ctx.session.sessionUser.accountId,
|
|
|
|
+ audit.flow.status.back,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.session.sessionUser.accountId,
|
|
this.ctx.session.sessionUser.accountId,
|
|
audit.flow.status.uncheck,
|
|
audit.flow.status.uncheck,
|
|
@@ -417,7 +439,9 @@ module.exports = app => {
|
|
case 0: // 包含你的所有变更令
|
|
case 0: // 包含你的所有变更令
|
|
const sql =
|
|
const sql =
|
|
'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE a.tid = ? AND ' +
|
|
'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE a.tid = ? AND ' +
|
|
- '(a.uid = ? OR (a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid)) OR a.status = ? )';
|
|
|
|
|
|
+ '(a.uid = ? OR (a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
|
+ ' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid))' +
|
|
|
|
+ ' OR a.status = ? )';
|
|
const sqlParam = [
|
|
const sqlParam = [
|
|
this.tableName,
|
|
this.tableName,
|
|
tenderId,
|
|
tenderId,
|
|
@@ -425,6 +449,9 @@ module.exports = app => {
|
|
audit.flow.status.uncheck,
|
|
audit.flow.status.uncheck,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.session.sessionUser.accountId,
|
|
this.ctx.session.sessionUser.accountId,
|
|
|
|
+ audit.flow.status.back,
|
|
|
|
+ this.ctx.service.changeAudit.tableName,
|
|
|
|
+ this.ctx.session.sessionUser.accountId,
|
|
audit.flow.status.checked,
|
|
audit.flow.status.checked,
|
|
];
|
|
];
|
|
const result = await this.db.query(sql, sqlParam);
|
|
const result = await this.db.query(sql, sqlParam);
|
|
@@ -436,11 +463,17 @@ module.exports = app => {
|
|
return result6[0].total_price ? result6[0].total_price : 0;
|
|
return result6[0].total_price ? result6[0].total_price : 0;
|
|
case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
|
|
case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
|
|
const sql2 =
|
|
const sql2 =
|
|
- 'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE ' +
|
|
|
|
- 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) ' +
|
|
|
|
- 'AND (a.status = ? OR a.status = ? OR a.status = ?) AND a.tid = ?';
|
|
|
|
|
|
+ 'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE' +
|
|
|
|
+ ' ((a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
|
+ ' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid)))' +
|
|
|
|
+ // 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) ' +
|
|
|
|
+ ' AND (a.status = ? OR a.status = ? OR a.status = ?) AND a.tid = ?';
|
|
const sqlParam2 = [
|
|
const sqlParam2 = [
|
|
this.tableName,
|
|
this.tableName,
|
|
|
|
+ audit.flow.status.uncheck,
|
|
|
|
+ this.ctx.service.changeAudit.tableName,
|
|
|
|
+ this.ctx.session.sessionUser.accountId,
|
|
|
|
+ audit.flow.status.back,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.service.changeAudit.tableName,
|
|
this.ctx.session.sessionUser.accountId,
|
|
this.ctx.session.sessionUser.accountId,
|
|
audit.flow.status.uncheck,
|
|
audit.flow.status.uncheck,
|
|
@@ -856,6 +889,8 @@ module.exports = app => {
|
|
};
|
|
};
|
|
if (postData.audit_next_id === undefined) {
|
|
if (postData.audit_next_id === undefined) {
|
|
list_update.samount = amount !== null ? amount : '';
|
|
list_update.samount = amount !== null ? amount : '';
|
|
|
|
+ list_update.checked_amount = amount !== null ? parseFloat(amount) : 0;
|
|
|
|
+ list_update.checked_price = amount !== null ? this.ctx.helper.mul(changeListInfo.unit_price, list_update.checked_amount, tp_decimal) : 0;
|
|
}
|
|
}
|
|
await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
|
|
await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
|
|
}
|
|
}
|
|
@@ -1043,6 +1078,8 @@ module.exports = app => {
|
|
const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({
|
|
const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({
|
|
where: { cid: changeInfo.cid },
|
|
where: { cid: changeInfo.cid },
|
|
});
|
|
});
|
|
|
|
+ // 生成内容保存表至zh_change_history中,用于撤回
|
|
|
|
+ await this.ctx.service.changeHistory.saveHistory(this.transaction, changeData, changeList);
|
|
let total_price = 0;
|
|
let total_price = 0;
|
|
const tp_decimal = changeData.tp_decimal ? changeData.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
const tp_decimal = changeData.tp_decimal ? changeData.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
for (const cl of changeList) {
|
|
for (const cl of changeList) {
|
|
@@ -1189,7 +1226,7 @@ module.exports = app => {
|
|
const tp_decimal = changeData.tp_decimal ? changeData.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
const tp_decimal = changeData.tp_decimal ? changeData.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
for (const cl of changeList) {
|
|
for (const cl of changeList) {
|
|
const audit_amount = cl.audit_amount.split(',');
|
|
const audit_amount = cl.audit_amount.split(',');
|
|
- const last_amount = audit_amount[audit_amount.length - 1];
|
|
|
|
|
|
+ const last_amount = audit_amount[audit_amount.length - 1] ? audit_amount[audit_amount.length - 1] : 0;
|
|
audit_amount.splice(-1, 1);
|
|
audit_amount.splice(-1, 1);
|
|
const list_update = {
|
|
const list_update = {
|
|
id: cl.id,
|
|
id: cl.id,
|
|
@@ -1234,6 +1271,7 @@ module.exports = app => {
|
|
};
|
|
};
|
|
await this.ctx.helper.sendWechat(lastauditInfo.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
|
|
await this.ctx.helper.sendWechat(lastauditInfo.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
+ console.log(error);
|
|
await this.transaction.rollback();
|
|
await this.transaction.rollback();
|
|
result = false;
|
|
result = false;
|
|
}
|
|
}
|
|
@@ -1828,6 +1866,46 @@ module.exports = app => {
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async doCheckChangeCanCancel(change) {
|
|
|
|
+ // 获取当前审批人的上一个审批人,判断是否是当前登录人,并赋予撤回功能,(当审批人存在有审批过时,上一人不允许再撤回)
|
|
|
|
+ const status = audit.flow.status;
|
|
|
|
+ const auditStatus = audit.flow.auditStatus;
|
|
|
|
+ const accountId = this.ctx.session.sessionUser.accountId;
|
|
|
|
+ const auditors = await this.ctx.service.changeAudit.getListOrderByTimes(change.cid, change.times);
|
|
|
|
+ change.cancancel = 0;
|
|
|
|
+ if (change.status !== status.checked && change.status !== status.uncheck) {
|
|
|
|
+ if (change.status !== status.back) {
|
|
|
|
+ // 找出当前操作人上一个审批人,包括审批完成的和退回上一个审批人的,同时当前操作人为第一人时,就是则为原报
|
|
|
|
+ const onAuditor = this._.find(auditors, function(item) {
|
|
|
|
+ return item.uid === change.curAuditor.uid && item.status === auditStatus.checking;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const preAudit = onAuditor.usort > 1 ? this._.find(auditors, { usort: onAuditor.usort - 1 }) : false;
|
|
|
|
+ const preAid = preAudit ? (preAudit.status !== auditStatus.checkAgain ? preAudit.uid : false) : change.uid;
|
|
|
|
+ // console.log(onAuditor, preAudit, auditors);
|
|
|
|
+ if (onAuditor.uid === preAid && preAudit.status === auditStatus.checkCancel) {
|
|
|
|
+ return;// 不可以多次撤回
|
|
|
|
+ } else if (preAid === accountId && (preAid !== change.uid || (preAid === change.uid && preAudit.usite !== 0))) {
|
|
|
|
+ if (preAudit.status === auditStatus.checked) {
|
|
|
|
+ change.cancancel = 2;// 审批人撤回审批通过
|
|
|
|
+ } else if (preAudit.status === auditStatus.backnew) {
|
|
|
|
+ change.cancancel = 3;// 审批人撤回审批退回上一人
|
|
|
|
+ }
|
|
|
|
+ change.preAudit = preAudit;
|
|
|
|
+ } else if (preAid === accountId && preAid === change.uid && preAudit.usite === 0) {
|
|
|
|
+ change.cancancel = 1;// 原报撤回
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ const lastAuditors = await this.service.changeAudit.getAuditors(change.cid, change.times - 1);
|
|
|
|
+ const onAuditor = this._.findLast(lastAuditors, { status: auditStatus.back });
|
|
|
|
+ if (onAuditor.uid === accountId) {
|
|
|
|
+ change.cancancel = 4;// 审批人撤回退回原报
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
return Change;
|
|
return Change;
|