|
@@ -104,7 +104,7 @@ module.exports = app => {
|
|
|
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 });
|
|
|
+ const changeAuditInfo = await this.getAllDataByCondition({ where: { cid: change.cid, times: change.times, uid }, orders: [['usort', 'desc']], limit: 1, offset: 0 });
|
|
|
if (!change.status === statusConst.checked && (changeAuditInfo === null || changeAuditInfo[0] === undefined) && !ctx.tender.isTourist) {
|
|
|
// 无权限查看此变更令
|
|
|
return 0;
|
|
@@ -680,6 +680,350 @@ module.exports = app => {
|
|
|
const result = await this.db.queryOne(sql, sqlParam);
|
|
|
return result ? result.num : 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批撤回
|
|
|
+ * @param {Number} stageId - 标段id
|
|
|
+ * @param {Number} times - 第几次审批
|
|
|
+ * @return {Promise<void>}
|
|
|
+ */
|
|
|
+ async checkCancel(change) {
|
|
|
+
|
|
|
+ // 分4种情况,根据ctx.cancancel值判断:
|
|
|
+ // 1.原报发起撤回,当前流程删除,并回到待上报
|
|
|
+ // 2.审批人撤回审批通过,增加流程,并回到它审批中
|
|
|
+ // 3.审批人撤回审批退回上一人,并删除退回人,增加流程,并回到它审批中,并更新计量期状态为审批中
|
|
|
+ // 4.审批人撤回退回原报操作,删除新增的审批流,增加流程,回滚到它审批中
|
|
|
+ switch (change.cancancel) {
|
|
|
+ case 1: await this._userCheckCancel(change); break;
|
|
|
+ case 2: await this._auditCheckCancel(change); break;
|
|
|
+ case 3: await this._auditCheckCancelNoPre(change); break;
|
|
|
+ case 4: await this._auditCheckCancelNo(change); break;
|
|
|
+ default: throw '不可撤回,请刷新页面重试';
|
|
|
+ }
|
|
|
+ // if (stage.cancancel === 5) {
|
|
|
+ // await this._auditCheckCancelAnd(stage);
|
|
|
+ // } else {
|
|
|
+ // switch (this.ctx.stage.cancancel) {
|
|
|
+ // case 1: await this._userCheckCancel(stage); break;
|
|
|
+ // case 2: await this._auditCheckCancel(stage); break;
|
|
|
+ // case 3: await this._auditCheckCancelNoPre(stage); break;
|
|
|
+ // case 4: await this._auditCheckCancelNo(stage); break;
|
|
|
+ // default: throw '不可撤回,请刷新页面重试';
|
|
|
+ // }
|
|
|
+ // // 通知发送 - 第三方更新
|
|
|
+ // if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
|
|
|
+ // const base_data = {
|
|
|
+ // tid: stage.tid,
|
|
|
+ // sid: stage.id,
|
|
|
+ // op: 'update',
|
|
|
+ // };
|
|
|
+ // this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
|
|
|
+ // base_data.op = 'update';
|
|
|
+ // base_data.sid = -1;
|
|
|
+ // this.ctx.helper.syncNoticeSend(this.ctx.session.sessionProject.customType, JSON.stringify(base_data));
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 原报撤回,直接改动审批人状态
|
|
|
+ * 如果存在审批人数据,将其改为原报流程数据,但保留原提交人
|
|
|
+ *
|
|
|
+ * 一审 1 A checking -> A uncheck status改 pay/jl:删0(jl为增量数据,只删重复部分) 1->0 删1
|
|
|
+ * ...
|
|
|
+ *
|
|
|
+ * @param stage
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ * @private
|
|
|
+ */
|
|
|
+ async _userCheckCancel(change) {
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, status: auditConst.auditStatus.checking });
|
|
|
+ // // 审批人变成待审批状态
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: curAudit.id,
|
|
|
+ status: auditConst.auditStatus.uncheck,
|
|
|
+ sin_time: null,
|
|
|
+ sdesc: null,
|
|
|
+ });
|
|
|
+ // 原报变成checking状态
|
|
|
+ const ybAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, usite: 0, status: auditConst.auditStatus.checked });
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: ybAudit.id,
|
|
|
+ status: auditConst.auditStatus.checking,
|
|
|
+ sin_time: new Date(),
|
|
|
+ });
|
|
|
+ // 变更令变成待上报状态
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: change.cid,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ await transaction.update(this.ctx.service.change.tableName, {
|
|
|
+ status: change.times === 1 ? auditConst.status.uncheck : auditConst.status.back,
|
|
|
+ }, options);
|
|
|
+ await transaction.commit();
|
|
|
+ } catch(err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 审批人撤回审批通过,插入两条数据
|
|
|
+ *
|
|
|
+ * 一审 1 A checked 一审 1 A checked
|
|
|
+ * 二审 2 B checked pre -> 二审 2 B checked
|
|
|
+ * 三审 3 C checking cur 二审 3 B checkCancel 增 增extra_his 增tp_his
|
|
|
+ * 四审 4 D uncheck 二审 4 B checking 增 增pay_cur
|
|
|
+ * 三审 5 C uncheck order、status改
|
|
|
+ * 四审 6 D uncheck order改
|
|
|
+ *
|
|
|
+ * @param stage
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ * @private
|
|
|
+ */
|
|
|
+ async _auditCheckCancel(change) {
|
|
|
+ const time = new Date();
|
|
|
+
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, status: auditConst.status.checking });
|
|
|
+ const preAudit = change.preAudit;
|
|
|
+ if (!curAudit || curAudit.usite <= 1 || !preAudit) {
|
|
|
+ throw '撤回用户数据错误';
|
|
|
+ }
|
|
|
+ // 顺移其后审核人流程顺序
|
|
|
+ const sql = 'UPDATE ' + this.tableName + ' SET `usort` = `usort` + 2 WHERE cid = ? AND times = ? AND `usort` > ?';
|
|
|
+ await transaction.query(sql, [change.cid, change.times, curAudit.usort]);
|
|
|
+ // 当前审批人2次添加至流程中
|
|
|
+ const newAuditors = [];
|
|
|
+ // 先入撤回记录
|
|
|
+ newAuditors.push({
|
|
|
+ tid: change.tid,
|
|
|
+ cid: change.cid,
|
|
|
+ uid: preAudit.uid,
|
|
|
+ name: preAudit.name,
|
|
|
+ jobs: preAudit.jobs,
|
|
|
+ company: preAudit.company,
|
|
|
+ times: change.times,
|
|
|
+ usite: preAudit.usite,
|
|
|
+ usort: curAudit.usort,
|
|
|
+ status: auditConst.auditStatus.checkCancel,
|
|
|
+ sin_time: time,
|
|
|
+ sdesc: '',
|
|
|
+ });
|
|
|
+ newAuditors.push({
|
|
|
+ tid: change.tid,
|
|
|
+ cid: change.cid,
|
|
|
+ uid: preAudit.uid,
|
|
|
+ name: preAudit.name,
|
|
|
+ jobs: preAudit.jobs,
|
|
|
+ company: preAudit.company,
|
|
|
+ times: change.times,
|
|
|
+ usite: preAudit.usite,
|
|
|
+ usort: curAudit.usort + 1,
|
|
|
+ status: auditConst.auditStatus.checking,
|
|
|
+ sin_time: time,
|
|
|
+ });
|
|
|
+ await transaction.insert(this.tableName, newAuditors);
|
|
|
+ // 当前审批人变成待审批
|
|
|
+ await transaction.update(this.tableName, { id: curAudit.id, usort: curAudit.usort + 2, sin_time: null, status: auditConst.auditStatus.uncheck });
|
|
|
+ // 审批列表数据也要回退
|
|
|
+ const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({
|
|
|
+ where: { cid: change.cid },
|
|
|
+ });
|
|
|
+ let total_price = 0;
|
|
|
+ const tp_decimal = change.tp_decimal ? change.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
|
+ const updateList = [];
|
|
|
+ for (const cl of changeList) {
|
|
|
+ const audit_amount = cl.audit_amount.split(',');
|
|
|
+ const last_amount = audit_amount[audit_amount.length - 1] ? audit_amount[audit_amount.length - 1] : 0;
|
|
|
+ audit_amount.splice(-1, 1);
|
|
|
+ const list_update = {
|
|
|
+ id: cl.id,
|
|
|
+ audit_amount: audit_amount.join(','),
|
|
|
+ spamount: parseFloat(last_amount),
|
|
|
+ };
|
|
|
+ total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), tp_decimal));
|
|
|
+ updateList.push(list_update)
|
|
|
+ }
|
|
|
+ if (updateList.length > 0) await transaction.updateRows(this.ctx.service.changeAuditList.tableName, updateList);
|
|
|
+ // 变更令变成待上报状态
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: change.cid,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ await transaction.update(this.ctx.service.change.tableName, {
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ total_price,
|
|
|
+ cin_time: Date.parse(time) / 1000,
|
|
|
+ }, options);
|
|
|
+ await transaction.commit();
|
|
|
+ } catch(err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批人撤回审批退回上一人,插入两条数据
|
|
|
+ *
|
|
|
+ * 一审 1 A checked 一审 1 A checked
|
|
|
+ * 二审 2 B checked 二审 2 B checked
|
|
|
+ * 三审 3 C checkNoPre pre -> 三审 3 C checkNoPre
|
|
|
+ * 二审 4 B checking cur 三审 4 C checkCancel 删4B 增4C 增extra_his 增tp_his
|
|
|
+ * 三审 5 C uncheck 三审 5 C checking status改 增pay_cur
|
|
|
+ * 四审 6 D uncheck 四审 6 D uncheck
|
|
|
+ *
|
|
|
+ * @param stage
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ * @private
|
|
|
+ */
|
|
|
+ async _auditCheckCancelNoPre(change) {
|
|
|
+ const time = new Date();
|
|
|
+
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times, status: auditConst.status.checking });
|
|
|
+ const preAudit = change.preAudit;
|
|
|
+ if (!curAudit || curAudit.order <= 1 || !preAudit) {
|
|
|
+ throw '撤回用户数据错误';
|
|
|
+ }
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ // 删除当前审批人
|
|
|
+ await transaction.delete(this.tableName, { id: curAudit.id });
|
|
|
+ // 添加撤回人到审批流程中
|
|
|
+ const newAuditors = [];
|
|
|
+ newAuditors.push({
|
|
|
+ tid: change.tid,
|
|
|
+ cid: change.cid,
|
|
|
+ uid: preAudit.uid,
|
|
|
+ name: preAudit.name,
|
|
|
+ jobs: preAudit.jobs,
|
|
|
+ company: preAudit.company,
|
|
|
+ times: change.times,
|
|
|
+ usite: preAudit.usite,
|
|
|
+ usort: curAudit.usort,
|
|
|
+ status: auditConst.auditStatus.checkCancel,
|
|
|
+ sin_time: time,
|
|
|
+ sdesc: '',
|
|
|
+ });
|
|
|
+ await transaction.insert(this.tableName, newAuditors);
|
|
|
+ // 更新上一个人,最新审批状态为审批中
|
|
|
+ await transaction.update(this.tableName, { sin_time: time, status: auditConst.status.checking }, {
|
|
|
+ where: { cid: change.cid, times: change.times, usort: curAudit.usort + 1 }
|
|
|
+ });
|
|
|
+ // 回退spamount值数据
|
|
|
+ const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({
|
|
|
+ where: { cid: change.cid },
|
|
|
+ });
|
|
|
+ let total_price = 0;
|
|
|
+ const tp_decimal = change.tp_decimal ? change.tp_decimal : this.ctx.tender.info.decimal.tp;
|
|
|
+ const updateList = [];
|
|
|
+ for (const cl of changeList) {
|
|
|
+ const audit_amount = cl.audit_amount.split(',');
|
|
|
+ const last_amount = audit_amount[audit_amount.length - 1] ? audit_amount[audit_amount.length - 1] : 0;
|
|
|
+ const list_update = {
|
|
|
+ id: cl.id,
|
|
|
+ spamount: parseFloat(last_amount),
|
|
|
+ };
|
|
|
+ total_price = this.ctx.helper.add(total_price, this.ctx.helper.mul(cl.unit_price, parseFloat(last_amount), tp_decimal));
|
|
|
+ updateList.push(list_update);
|
|
|
+ }
|
|
|
+ if (updateList.length > 0) await transaction.updateRows(this.ctx.service.changeAuditList.tableName, updateList);
|
|
|
+ // 变更令变成待上报状态
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: change.cid,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ await transaction.update(this.ctx.service.change.tableName, {
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ total_price,
|
|
|
+ cin_time: Date.parse(time) / 1000,
|
|
|
+ }, options);
|
|
|
+
|
|
|
+ await transaction.commit();
|
|
|
+ } catch(err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批人撤回审批退回原报
|
|
|
+ *
|
|
|
+ * 1# 一审 1 A checked 1# 一审 1 A checked
|
|
|
+ * 二审 2 B checkNo pre -> 二审 2 B checkNo
|
|
|
+ * 三审 3 C uncheck 二审 3 B checkCancel 增 pay: 2#0 -> 1#3 jl: 2#0 -> 1#3 增tp_his 增extra_his
|
|
|
+ * 二审 4 B checking 增 pay: 2#0 -> 1#4
|
|
|
+ * 三审 5 C uncheck order改
|
|
|
+ *
|
|
|
+ * 2# 一审 1 A uncheck 2# 删 pay: 2#0删 jl: 2#0删
|
|
|
+ * 二审 2 B uncheck
|
|
|
+ * 三审 3 C uncheck
|
|
|
+ *
|
|
|
+ * @param stage
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ * @private
|
|
|
+ */
|
|
|
+ async _auditCheckCancelNo(change) {
|
|
|
+
|
|
|
+ const time = new Date();
|
|
|
+
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ const curAudit = await this.getDataByCondition({ cid: change.cid, times: change.times - 1, status: auditConst.auditStatus.back });
|
|
|
+ // 整理上一个流程审核人状态更新
|
|
|
+ // 顺移其后审核人流程顺序
|
|
|
+ const sql = 'UPDATE ' + this.tableName + ' SET `usort` = `usort` + 2 WHERE cid = ? AND times = ? AND `usort` > ?';
|
|
|
+ await transaction.query(sql, [change.cid, change.times -1, curAudit.usort]);
|
|
|
+ // 当前审批人2次添加至流程中
|
|
|
+ const newAuditors = [];
|
|
|
+ newAuditors.push({
|
|
|
+ tid: change.tid,
|
|
|
+ cid: change.cid,
|
|
|
+ uid: curAudit.uid,
|
|
|
+ name: curAudit.name,
|
|
|
+ jobs: curAudit.jobs,
|
|
|
+ company: curAudit.company,
|
|
|
+ times: curAudit.times,
|
|
|
+ usite: curAudit.usite,
|
|
|
+ usort: curAudit.usort + 1,
|
|
|
+ status: auditConst.auditStatus.checkCancel,
|
|
|
+ sin_time: time,
|
|
|
+ sdesc: '',
|
|
|
+ });
|
|
|
+ newAuditors.push({
|
|
|
+ tid: change.tid,
|
|
|
+ cid: change.cid,
|
|
|
+ uid: curAudit.uid,
|
|
|
+ name: curAudit.name,
|
|
|
+ jobs: curAudit.jobs,
|
|
|
+ company: curAudit.company,
|
|
|
+ times: curAudit.times,
|
|
|
+ usite: curAudit.usite,
|
|
|
+ usort: curAudit.usort + 2,
|
|
|
+ status: auditConst.auditStatus.checking,
|
|
|
+ sin_time: time,
|
|
|
+ });
|
|
|
+ await transaction.insert(this.tableName, newAuditors);
|
|
|
+ // 删除当前次审批流
|
|
|
+ await transaction.delete(this.tableName, { cid: change.cid, times: change.times });
|
|
|
+ // 回退数据
|
|
|
+ await this.ctx.service.changeHistory.returnHistory(transaction, change.cid);
|
|
|
+ await transaction.delete(this.ctx.service.changeHistory.tableName, { cid: change.cid });
|
|
|
+ await transaction.commit();
|
|
|
+ } catch(err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return ChangeAudit;
|