|
@@ -86,10 +86,10 @@ module.exports = app => {
|
|
|
async getAuditors(stageId, times = 1, order_sort = 'asc') {
|
|
|
const sql =
|
|
|
'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, pa.sign_path, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
|
|
|
- 'FROM ?? AS la, ?? AS pa, (SELECT sa.`aid`,(@i:=@i+1) as `sort` FROM (SELECT * FROM ?? ORDER BY `order` ASC) sa, (select @i:=0) as it WHERE sa.`sid` = ? AND sa.`times` = ? GROUP BY sa.`aid`) as g ' +
|
|
|
+ 'FROM ?? AS la, ?? AS pa, (SELECT sa.`aid`,(@i:=@i+1) as `sort` FROM (SELECT * FROM ?? WHERE `sid` = ? AND `times` = ? GROUP BY `aid` ORDER BY `order` ASC) sa, (select @i:=0) as it WHERE sa.`sid` = ? AND sa.`times` = ? GROUP BY sa.`aid`) as g ' +
|
|
|
'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order` ' +
|
|
|
order_sort;
|
|
|
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, stageId, times, stageId, times];
|
|
|
+ const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, stageId, times, stageId, times, stageId, times];
|
|
|
const result = await this.db.query(sql, sqlParam);
|
|
|
const sql2 = 'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `sid` = ? AND `times` = ? GROUP BY `aid`) as a';
|
|
|
const sqlParam2 = [this.tableName, stageId, times];
|
|
@@ -977,6 +977,319 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 审批撤回
|
|
|
+ * @param {Number} stageId - 标段id
|
|
|
+ * @param {Number} times - 第几次审批
|
|
|
+ * @return {Promise<void>}
|
|
|
+ */
|
|
|
+ async checkCancel(stageId, times = 1) {
|
|
|
+ // 分3种情况,根据ctx.cancancel值判断:
|
|
|
+ // 1.原报发起撤回,当前流程删除,并回到待上报
|
|
|
+ // 2.审批人撤回审批通过,增加流程,并回到它审批中
|
|
|
+ // 3.审批人撤回审批退回上一人,并删除退回人,增加流程,并回到它审批中,并更新计量期状态为审批中
|
|
|
+ // 4.审批人撤回退回原报操作,删除新增的审批流,增加流程,回滚到它审批中
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
+ const time = new Date();
|
|
|
+ try {
|
|
|
+ if (this.ctx.stage.cancancel === 1) {
|
|
|
+ // 原报撤回,判断是否为多次,多次则为退回状态
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ const curAudit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
|
|
|
+ // // 审批人变成待审批状态
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: curAudit.id,
|
|
|
+ status: auditConst.status.uncheck,
|
|
|
+ begin_time: null,
|
|
|
+ opinion: null,
|
|
|
+ });
|
|
|
+ const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // 计算并合同支付最终数据
|
|
|
+ const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ this.ctx.stage.tp_history.push({
|
|
|
+ times,
|
|
|
+ order: curAudit.order,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ positive_qc_tp: tpData.positive_qc_tp,
|
|
|
+ negative_qc_tp: tpData.negative_qc_tp,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ });
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ id: stageId,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ positive_qc_tp: tpData.positive_qc_tp,
|
|
|
+ negative_qc_tp: tpData.negative_qc_tp,
|
|
|
+ times,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ tp_history: JSON.stringify(this.ctx.stage.tp_history),
|
|
|
+ cache_time_r: this.ctx.stage.cache_time_l,
|
|
|
+ status: times === 1 ? auditConst.status.uncheck : auditConst.status.checkNo,
|
|
|
+ });
|
|
|
+ // 计算该审批人最终数据
|
|
|
+ await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // 复制一份最新数据给下一人
|
|
|
+ await this.ctx.service.stagePay.deleteAuditStagePays(this.ctx.stage, this.ctx.stage.times, 1, transaction);
|
|
|
+ await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
|
|
|
+ } else if (this.ctx.stage.cancancel === 2) {
|
|
|
+ const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ const curAudit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
|
|
|
+ const preAudit = this.ctx.stage.preAudit;
|
|
|
+ if (!curAudit || curAudit.order <= 1) {
|
|
|
+ throw '撤回用户数据错误';
|
|
|
+ }
|
|
|
+ // 顺移气候审核人流程顺序
|
|
|
+ this.initSqlBuilder();
|
|
|
+ this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=' });
|
|
|
+ this.sqlBuilder.setAndWhere('order', { value: curAudit.order, operate: '>' });
|
|
|
+ this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+' });
|
|
|
+ const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
+ const data = await transaction.query(sql, sqlParam);
|
|
|
+ // 当前审批人2次添加至流程中
|
|
|
+ const newAuditors = [];
|
|
|
+ newAuditors.push({
|
|
|
+ tid: curAudit.tid,
|
|
|
+ sid: curAudit.sid,
|
|
|
+ aid: preAudit.aid,
|
|
|
+ times: curAudit.times,
|
|
|
+ order: curAudit.order,
|
|
|
+ status: auditConst.status.checkCancel,
|
|
|
+ begin_time: time,
|
|
|
+ end_time: time,
|
|
|
+ opinion: '',
|
|
|
+ });
|
|
|
+ newAuditors.push({
|
|
|
+ tid: curAudit.tid,
|
|
|
+ sid: curAudit.sid,
|
|
|
+ aid: preAudit.aid,
|
|
|
+ times: curAudit.times,
|
|
|
+ order: curAudit.order + 1,
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ begin_time: time,
|
|
|
+ });
|
|
|
+ await transaction.insert(this.tableName, newAuditors);
|
|
|
+ // 当前审批人变成待审批
|
|
|
+ await transaction.update(this.tableName, { id: curAudit.id, order: curAudit.order + 2, begin_time: null, status: auditConst.status.uncheck });
|
|
|
+ // 计算并合同支付最终数据
|
|
|
+ const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ this.ctx.stage.tp_history.push({
|
|
|
+ times,
|
|
|
+ order: curAudit.order,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ positive_qc_tp: tpData.positive_qc_tp,
|
|
|
+ negative_qc_tp: tpData.negative_qc_tp,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ });
|
|
|
+ // 同步 期信息
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ id: stageId,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ positive_qc_tp: tpData.positive_qc_tp,
|
|
|
+ negative_qc_tp: tpData.negative_qc_tp,
|
|
|
+ times,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ tp_history: JSON.stringify(this.ctx.stage.tp_history),
|
|
|
+ cache_time_r: this.ctx.stage.cache_time_l,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 计算该审批人最终数据
|
|
|
+ await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // 复制一份最新数据给下一人
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, curAudit.order + 1, transaction);
|
|
|
+ await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
|
|
|
+
|
|
|
+ // 锁定本人数据,保留锁定数据相关确认状态
|
|
|
+ // await this.ctx.service.stageAuditAss.lockConfirm4CheckNoPre(this.ctx.stage, curAudit.aid, preAudit.aid, transaction);
|
|
|
+ } else if (this.ctx.stage.cancancel === 3) {
|
|
|
+ const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // 整理当前流程审核人状态更新
|
|
|
+ const curAudit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
|
|
|
+ const preAudit = this.ctx.stage.preAudit;
|
|
|
+ if (!curAudit || curAudit.order <= 1) {
|
|
|
+ throw '撤回用户数据错误';
|
|
|
+ }
|
|
|
+ // // 顺移气候审核人流程顺序
|
|
|
+ // this.initSqlBuilder();
|
|
|
+ // this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=' });
|
|
|
+ // this.sqlBuilder.setAndWhere('order', { value: curAudit.order, operate: '>' });
|
|
|
+ // this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+' });
|
|
|
+ // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
+ // const data = await transaction.query(sql, sqlParam);
|
|
|
+ // 添加撤回人到审批流程中
|
|
|
+ const newAuditors = [];
|
|
|
+ newAuditors.push({
|
|
|
+ tid: curAudit.tid,
|
|
|
+ sid: curAudit.sid,
|
|
|
+ aid: preAudit.aid,
|
|
|
+ times: curAudit.times,
|
|
|
+ order: curAudit.order,
|
|
|
+ status: auditConst.status.checkCancel,
|
|
|
+ begin_time: time,
|
|
|
+ end_time: time,
|
|
|
+ opinion: '',
|
|
|
+ });
|
|
|
+ await transaction.insert(this.tableName, newAuditors);
|
|
|
+ // 删除当前审批人
|
|
|
+ await transaction.delete(this.tableName, { id: curAudit.id });
|
|
|
+ // 更新上一个人为审批中
|
|
|
+ await transaction.update(this.tableName, { begin_time: time, status: auditConst.status.checking }, {
|
|
|
+ where: {
|
|
|
+ sid: curAudit.sid,
|
|
|
+ times: curAudit.times,
|
|
|
+ order: curAudit.order + 1,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 修改stage状态为审批中
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, { id: this.ctx.stage.id, status: auditConst.status.checking });
|
|
|
+ // 计算并合同支付最终数据
|
|
|
+ const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ this.ctx.stage.tp_history.push({
|
|
|
+ times,
|
|
|
+ order: curAudit.order,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ positive_qc_tp: tpData.positive_qc_tp,
|
|
|
+ negative_qc_tp: tpData.negative_qc_tp,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ });
|
|
|
+ // 同步 期信息
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ id: stageId,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ positive_qc_tp: tpData.positive_qc_tp,
|
|
|
+ negative_qc_tp: tpData.negative_qc_tp,
|
|
|
+ times,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ tp_history: JSON.stringify(this.ctx.stage.tp_history),
|
|
|
+ cache_time_r: this.ctx.stage.cache_time_l,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 计算该审批人最终数据
|
|
|
+ await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // 复制一份最新数据给下一人
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, curAudit.order + 1, transaction);
|
|
|
+ await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
|
|
|
+
|
|
|
+ // 锁定本人数据,保留锁定数据相关确认状态
|
|
|
+ // await this.ctx.service.stageAuditAss.lockConfirm4CheckNoPre(this.ctx.stage, curAudit.aid, preAudit.aid, transaction);
|
|
|
+ } else if (this.ctx.stage.cancancel === 4) {
|
|
|
+ // 原报撤回,判断是否为多次,多次则为退回状态
|
|
|
+ // 整理上一个流程审核人状态更新
|
|
|
+ const curAudit = await this.getDataByCondition({ sid: stageId, times: times - 1, status: auditConst.status.checkNo });
|
|
|
+ // 顺移气候审核人流程顺序
|
|
|
+ this.initSqlBuilder();
|
|
|
+ this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=' });
|
|
|
+ this.sqlBuilder.setAndWhere('order', { value: curAudit.order, operate: '>' });
|
|
|
+ this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+' });
|
|
|
+ const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
+ const data = await transaction.query(sql, sqlParam);
|
|
|
+ // 当前审批人2次添加至流程中
|
|
|
+ const newAuditors = [];
|
|
|
+ newAuditors.push({
|
|
|
+ tid: curAudit.tid,
|
|
|
+ sid: curAudit.sid,
|
|
|
+ aid: curAudit.aid,
|
|
|
+ times: curAudit.times,
|
|
|
+ order: curAudit.order + 1,
|
|
|
+ status: auditConst.status.checkCancel,
|
|
|
+ begin_time: time,
|
|
|
+ end_time: time,
|
|
|
+ opinion: '',
|
|
|
+ });
|
|
|
+ newAuditors.push({
|
|
|
+ tid: curAudit.tid,
|
|
|
+ sid: curAudit.sid,
|
|
|
+ aid: curAudit.aid,
|
|
|
+ times: curAudit.times,
|
|
|
+ order: curAudit.order + 2,
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ begin_time: time,
|
|
|
+ });
|
|
|
+ await transaction.insert(this.tableName, newAuditors);
|
|
|
+ // 删除当前次审批流
|
|
|
+ await transaction.delete(this.tableName, { sid: stageId, times });
|
|
|
+ const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // 计算并合同支付最终数据
|
|
|
+ const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ this.ctx.stage.tp_history.push({
|
|
|
+ times,
|
|
|
+ order: curAudit.order,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ positive_qc_tp: tpData.positive_qc_tp,
|
|
|
+ negative_qc_tp: tpData.negative_qc_tp,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ });
|
|
|
+ await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
+ id: stageId,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
+ positive_qc_tp: tpData.positive_qc_tp,
|
|
|
+ negative_qc_tp: tpData.negative_qc_tp,
|
|
|
+ times: times - 1,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ tp_history: JSON.stringify(this.ctx.stage.tp_history),
|
|
|
+ cache_time_r: this.ctx.stage.cache_time_l,
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ });
|
|
|
+ // 计算该审批人最终数据
|
|
|
+ await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
+ // 复制一份最新数据给下一人
|
|
|
+ await this.ctx.service.stagePay.deleteAuditStagePays(this.ctx.stage, this.ctx.stage.times, 0, transaction);
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times - 1, curAudit.order + 1, transaction);
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times - 1, curAudit.order + 2, transaction);
|
|
|
+ await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageSafeProd.updateHistory(this.ctx.stage, transaction);
|
|
|
+ await this.ctx.service.stageTempLand.updateHistory(this.ctx.stage, transaction);
|
|
|
+ }
|
|
|
+ // 上报/审批 - 检查三方特殊推送
|
|
|
+ await this.ctx.service.specMsg.addStageMsg(transaction, this.ctx.session.sessionProject.id, this.ctx.stage, pushOperate.stage.flow);
|
|
|
+ await transaction.commit();
|
|
|
+ // 通知发送 - 第三方更新
|
|
|
+ if (this.ctx.session.sessionProject.custom && syncApiConst.notice_type.indexOf(this.ctx.session.sessionProject.customType) !== -1) {
|
|
|
+ const base_data = {
|
|
|
+ tid: this.ctx.tender.id,
|
|
|
+ sid: stageId,
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ await transaction.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取审核人需要审核的期列表
|
|
|
*
|
|
|
* @param auditorId
|