123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041 |
- 'use strict';
- /**
- * 与期不同,含原报
- *
- * @author Mai
- * @date
- * @version
- */
- const auditConst = require('../const/audit');
- const auditType = auditConst.auditType;
- const pushType = auditConst.pushType;
- const smsTypeConst = require('../const/sms_type');
- const wxConst = require('../const/wechat_template');
- module.exports = app => {
- class PhasePayAudit extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'phase_pay_audit';
- }
- // ***** 查询审批人相关
- // 获取全部参与人
- async getAuditors(phaseId, auditTimes) {
- return await this.getAllDataByCondition({ where: { phase_id: phaseId, audit_times: auditTimes }, orders: [['active_order', 'asc']] }); // 全部参与的审批人
- }
- // 获取全部参与人 分组
- async getAuditorGroup(phaseId, auditTimes) {
- const auditors = await this.getAuditors(phaseId, auditTimes); // 全部参与的审批人
- return this.ctx.helper.groupAuditors(auditors, 'active_order');
- }
- // 获取全部参与人 去重
- async getUniqAuditors(phasePay) {
- const auditors = await this.getAuditors(phasePay.id, phasePay.audit_times); // 全部参与的审批人
- const result = [];
- auditors.forEach(x => {
- if (result.findIndex(r => { return x.audit_id === r.audit_id && x.audit_order === x.audit_order; }) < 0) {
- result.push(x);
- }
- });
- return result;
- }
- // 获取全部参与人 分组 去重
- async getUniqAuditorsGroup(phaseId, auditTimes) {
- const group = await this.getAuditorGroup(phaseId, auditTimes);
- return this.ctx.helper.groupAuditorsUniq(group);
- }
- // 获取某个状态的审批人
- async getAuditorsByStatus(phaseId, auditStatus, auditTimes) {
- const cur = await this.db.queryOne(`SELECT * From ${this.tableName} where phase_id = ? AND audit_times = ? AND audit_status = ? ORDER By audit_times DESC, active_order DESC `, [phaseId, auditTimes, auditStatus]);
- if (!cur) return [];
- return await this.getAllDataByCondition({ where: { phase_id: phaseId, audit_times: auditTimes, audit_order: cur.audit_order, audit_status: auditStatus}});
- }
- // 获取全部审批历史
- async getAuditorHistory(phaseId, auditTimes, reverse = false) {
- const history = [];
- if (auditTimes < 1) return history;
- for (let i = 1; i <= auditTimes; i++) {
- const auditors = await this.getAuditors(phaseId, i);
- const group = this.ctx.helper.groupAuditors(auditors, 'active_order');
- const historyGroup = [];
- const max_order = group.length > 0 && group[group.length - 1].length > 0 ? group[group.length - 1][0].audit_order : -1;
- for (const g of group) {
- const his = {
- auditYear: '', auditDate: '', auditTime: '', audit_time: null,
- audit_type: g[0].audit_type, audit_order: g[0].audit_order,
- auditors: g
- };
- his.is_final = his.audit_order === max_order;
- his.auditName = his.audit_order === 0 ? '原报' : (his.is_final ? '终审' : his.audit_order + '审');
- his.auditCnName = his.audit_order === 0 ? '原报' : (his.is_final ? '终审' : this.ctx.helper.transFormToChinese(his.audit_order) + '审');
- his.name = his.audit_type === auditType.key.common ? g[0].name : his.auditName;
- let audit_time;
- g.forEach(x => {
- if (x.audit_status === auditConst.phasePay.status.checkSkip) return;
- if (!his.audit_status || x.audit_status === auditConst.phasePay.status.checking) his.audit_status = x.audit_status;
- if (x.audit_time && (!audit_time || x.audit_time > audit_time)) {
- audit_time = x.audit_time;
- if (his.audit_status !== auditConst.phasePay.status.checking) his.audit_status = x.audit_status;
- }
- });
- if (audit_time) {
- his.audit_time = audit_time;
- const auditTime = this.ctx.moment(audit_time);
- his.auditYear = auditTime.format('YYYY');
- his.auditDate = auditTime.format('MM-DD');
- his.auditTime = auditTime.format('HH:mm:ss');
- }
- historyGroup.push(his);
- }
- if (reverse) {
- history.push(historyGroup.reverse());
- } else {
- history.push(historyGroup);
- }
- }
- return history;
- }
- async getAllAuditors(tenderId) {
- const sql =
- 'SELECT audit_id, tid FROM ' + this.tableName +
- ' WHERE tid = ?' +
- ' GROUP BY audit_id';
- const sqlParam = [tenderId];
- return this.db.query(sql, sqlParam);
- }
- // ***** 查询审批人相关
- // ***** 修改审批人相关
- /**
- * 获取 最新审核顺序
- *
- * @param {Number} phaseId - 期id
- * @param {Number} auditTimes - 第几次审批
- * @return {Promise<number>}
- */
- async getNewOrder(phaseId, auditTimes = 1) {
- const sql = `SELECT Max(active_order) As max_order, Max(audit_order) As max_audit_order FROM ${this.tableName} Where phase_id = ? and audit_times = ?`;
- const result = await this.db.queryOne(sql, [phaseId, auditTimes]);
- return result && result.max_order ? [result.max_order + 1, result.max_audit_order + 1] : [1, 1];
- }
- /**
- * 同步审核人order
- * @param transaction - 事务
- * @param {Number} phaseId - 结算期id
- * @param {Number} auditOrder - 审核顺序(实际顺序)
- * @param {Number} auditTimes - 第几次审批
- * @param {String} selfOperate - 操作符(+/-)
- * @return {Promise<*>}
- * @private
- */
- async _syncAuditOrder(transaction, phaseId, auditOrder, auditTimes, selfOperate = '-') {
- const sql = `Update ${this.tableName} SET audit_order = audit_order${selfOperate}1, active_order = active_order${selfOperate}1
- WHERE phase_id = ? and audit_times = ? and active_order >= ?`;
- return await transaction.query(sql, [phaseId, auditTimes, auditOrder]);
- }
- /**
- * 新增审核人
- *
- * @param {Number} phaseId - 期id
- * @param {Number} auditor - 审核人
- * @param {Number} auditTimes - 第几次审批
- * @param {Number} is_gdzs - 是否固定终审
- * @return {Promise<number>}
- */
- async addAuditor(phaseId, auditor, auditTimes = 1, is_gdzs = 0) {
- let [newOrder, newAuditOrder] = await this.getNewOrder(phaseId, auditTimes);
- // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
- newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
- newAuditOrder = is_gdzs === 1 ? newAuditOrder - 1 : newAuditOrder;
- const transaction = await this.db.beginTransaction();
- try {
- if (is_gdzs) await this._syncAuditOrder(transaction, phaseId, newOrder, auditTimes, '+');
- const data = {
- tid: this.ctx.tender.id, phase_id: phaseId, audit_id: auditor.id,
- name: auditor.name, company: auditor.company, role: auditor.role, mobile: auditor.mobile,
- audit_times: auditTimes, active_order: newOrder, audit_status: auditConst.phasePay.status.uncheck,
- audit_order: newAuditOrder, audit_type: auditType.key.common,
- };
- const result = await transaction.insert(this.tableName, data);
- await transaction.commit();
- return result.effectRows = 1;
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- return false;
- }
- /**
- * 移除审核人
- *
- * @param {Number} phaseId - 期id
- * @param {Number} auditorId - 审核人id
- * @param {Number} auditTimes - 第几次审批
- * @return {Promise<boolean>}
- */
- async deleteAuditor(phaseId, auditorId, auditTimes = 1) {
- const transaction = await this.db.beginTransaction();
- try {
- const condition = { phase_id: phaseId, audit_id: auditorId, audit_times: auditTimes };
- const auditor = await this.getDataByCondition(condition);
- if (!auditor) throw '审批人不存在';
- // 移除整个流程的人
- await transaction.delete(this.tableName, { phase_id: phaseId, active_order: auditor.active_order, audit_times: auditTimes});
- await this._syncAuditOrder(transaction, phaseId, auditor.active_order, auditTimes);
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- return true;
- }
- // 拷贝上一期审批流程
- async copyPreAuditors(transaction, prePhasePay, newPhasePay) {
- const auditors = prePhasePay ? await this.getUniqAuditors(prePhasePay) : [];
- const newAuditors = [];
- // 添加原报
- const user = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
- newAuditors.push({
- tid: newPhasePay.tid, phase_id: newPhasePay.id,
- audit_id: this.ctx.session.sessionUser.accountId,
- audit_times: 1, audit_order: 0, audit_type: auditConst.auditType.key.common,
- active_order: 0, audit_status: auditConst.phasePay.status.uncheck,
- name: user.name, company: user.company, role: user.role, mobile: user.mobile,
- });
- // 添加其他参与人
- for (const a of auditors) {
- if (a.audit_order === 0) continue;
- newAuditors.push({
- tid: newPhasePay.tid, phase_id: newPhasePay.id,
- audit_id: a.audit_id,
- audit_times: 1, audit_order: a.audit_order, audit_type: a.audit_type,
- active_order: a.audit_order, audit_status: auditConst.phasePay.status.uncheck,
- name: a.name, company: a.company, role: a.role, mobile: a.mobile,
- });
- }
- const result = await transaction.insert(this.tableName, newAuditors);
- if (result.affectedRows !== newAuditors.length) throw '初始化审批流程错误';
- }
- // 固定审批流-更新
- async updateNewAuditList(phasePay, newList) {
- const newAuditsInfo = newList && newList.length > 0
- ? await this.ctx.service.projectAccount.getAllDataByCondition({ where: { id: newList.map(x => { return x.audit_id; })} })
- : [];
- const transaction = await this.db.beginTransaction();
- try {
- // 先删除旧的审批流,再添加新的
- await transaction.query(`DELETE FROM ${this.tableName} where phase_id = ? and audit_times = ? and audit_order > 0`, [phasePay.id, phasePay.audit_times]);
- const newAuditors = [];
- for (const auditor of newList) {
- const auditorInfo = newAuditsInfo.find(x => { return x.id === auditor.audit_id; });
- if (!auditorInfo) throw '配置的审批人不存在';
- newAuditors.push({
- tid: phasePay.tid, phase_id: phasePay.id, audit_id: auditor.audit_id,
- name: auditorInfo.name, company: auditorInfo.company, role: auditorInfo.role, mobile: auditorInfo.mobile,
- audit_times: phasePay.audit_times, active_order: auditor.audit_order, audit_status: auditConst.phasePay.status.uncheck,
- audit_type: auditor.audit_type, audit_order: auditor.audit_order,
- });
- }
- if(newAuditors.length > 0) await transaction.insert(this.tableName, newAuditors);
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- // 固定终审-更新
- async updateLastAudit(phasePay, auditList, lastId) {
- const lastUser = lastId ? await this.ctx.service.projectAccount.getDataById(lastId) : null;
- const transaction = await this.db.beginTransaction();
- try {
- // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
- const existAudit = lastId ? auditList.find(x => { return x.audit_id === lastId }) : null;
- let auditOrder = auditList.length > 0 ? auditList.reduce((rst, a) => { return Math.max(rst, a.active_order)}, 0) + 1 : 1; // 最大值 + 1
- if (existAudit) {
- await transaction.delete(this.tableName, { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_id: lastId });
- const sameOrder = auditList.filter(x => { return x.active_order === existAudit.active_order });
- if (sameOrder.length === 1) {
- const updateData = [];
- auditList.forEach(x => {
- if (x.active_order <= existAudit.active_order) return;
- updateData.push({id: x.id, active_order: x.active_order - 1, audit_order: x.audit_order - 1});
- });
- if (updateData.length > 0) {
- await transaction.updateRows(updateData);
- }
- auditOrder = auditOrder - 1;
- }
- }
- // 添加终审
- if (lastUser) {
- const newAuditor = {
- tid: phasePay.tid, phase_id: phasePay.id, audit_id: lastId,
- name: lastUser.name, company: lastUser.company, role: lastUser.role, mobile: lastUser.mobile,
- audit_times: phasePay.audit_times, active_order: auditOrder, audit_status: auditConst.phasePay.status.uncheck,
- audit_type: auditType.key.common, audit_order: auditOrder,
- };
- await transaction.insert(this.tableName, newAuditor);
- }
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- // ***** 修改审批人相关
- // ***** 审批操作
- /**
- * 用于添加推送所需的content内容
- * @param {Number} pid 项目id
- * @param {Number} tid 台账id
- * @param {Number} sid 期id
- * @param {Number} uid 审核人id
- */
- async _getNoticeContent(pid, tid, sid, uid, opinion = '') {
- const noticeSql =
- 'SELECT * FROM (SELECT ' +
- ' t.`id` As `tid`, t.`name`, s.`phase_order` as `order`, pa.`name` As `su_name`, pa.role As `su_role`' +
- ` FROM (SELECT * FROM ${this.ctx.service.tender.tableName} WHERE id = ? ) As t` +
- ` LEFT JOIN ${this.ctx.service.phasePay.tableName} As s On s.id = ?` +
- ` LEFT JOIN ${this.ctx.service.projectAccount.tableName} As pa ON pa.id = ?` +
- ' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
- const noticeSqlParam = [tid, sid, uid, pid];
- const content = await this.db.query(noticeSql, noticeSqlParam);
- if (content.length) {
- content[0].opinion = opinion;
- }
- return content.length ? JSON.stringify(content[0]) : '';
- }
- async start(phasePay) {
- const audits = await this.getAllDataByCondition({ where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_order: 1 } });
- if (audits.length === 0) {
- if(this.ctx.tender.info.shenpi.phasePay === shenpiConst.sp_status.gdspl) {
- throw '请联系管理员添加审批人';
- } else {
- throw '请先选择审批人,再上报数据';
- }
- }
- const transaction = await this.db.beginTransaction();
- try {
- const audit_time = new Date();
- // 更新原报数据
- await transaction.update(this.tableName, { audit_status: auditConst.phasePay.status.checked, audit_time },
- { where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_order: 0 } });
- // 更新下一审批人数据
- const updateData = audits.map(x => { return { id: x.id, audit_status: auditConst.phasePay.status.checking } });
- await transaction.updateRows(this.tableName, updateData);
- // 计算合同支付
- const paySum = await this.ctx.service.phasePayDetail.calculateSave(phasePay, transaction);
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_status: auditConst.phasePay.status.checking, audit_max_sort: 1, audit_begin_time: audit_time, ...paySum
- });
- // 拷贝新流程合同支付
- await this.ctx.service.phasePayDetail.initPhaseDataByAudit(transaction, phasePay, phasePay.audit_times, 1);
- // todo 添加短信通知-需要审批提醒功能
- const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + phasePay.tid + '/phasePay/' + phasePay.phase_order);
- const users = this._.map(audits, 'audit_id');
- // 微信模板通知
- const wechatData = {
- wap_url: shenpiUrl,
- qi: phasePay.phase_order,
- status: wxConst.status.check,
- tips: wxConst.tips.check,
- code: this.ctx.session.sessionProject.code,
- };
- await this.ctx.helper.sendWechat(users, smsTypeConst.const.PAY, smsTypeConst.judge.approval.toString(), wxConst.template.phasePay, wechatData);
- for (const a of audits) {
- await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.PAY, {
- pid: this.ctx.session.sessionProject.id,
- tid: phasePay.tid,
- uid: a.audit_id,
- sp_type: 'phasePay',
- sp_id: a.id,
- table_name: this.tableName,
- template: wxConst.template.phasePay,
- wx_data: wechatData,
- });
- }
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- async _checked(phasePay, opinion) {
- const accountId = this.ctx.session.sessionUser.accountId;
- const time = new Date();
- const selfAudit = phasePay.curAuditors.find(x => { return x.audit_id === accountId; });
- if (!selfAudit) throw '当前标段您无权审批';
- const nextAudits = await this.getAllDataByCondition({ where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, active_order: selfAudit.active_order + 1 } });
- const transaction = await this.db.beginTransaction();
- try {
- // 添加通知
- const noticeContent = await this._getNoticeContent(this.ctx.session.sessionProject.id, phasePay.tid, phasePay.id, accountId, opinion);
- const defaultNoticeRecord = {
- pid: this.ctx.session.sessionProject.id,
- type: pushType.phasePay,
- status: auditConst.phasePay.status.checked,
- content: noticeContent,
- };
- const records = phasePay.userIds.map(x => {
- return { uid: x, ...defaultNoticeRecord };
- });
- await transaction.insert('zh_notice', records);
- // 更新本人审批状态
- await transaction.update(this.tableName, {
- id: selfAudit.id,
- audit_status: auditConst.phasePay.status.checked, opinion: opinion,
- audit_time: time,
- });
- await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, selfAudit.id);
- // 计算合同支付
- const paySum = await this.ctx.service.phasePayDetail.calculateSave(phasePay, transaction);
- if (phasePay.curAuditors.length === 1 || selfAudit.audit_type === auditType.key.or) {
- // 或签更新他人审批状态
- if (selfAudit.audit_type === auditType.key.or) {
- const updateOther = [];
- for (const audit of phasePay.curAuditors) {
- if (audit.audit_id === selfAudit.audit_id) continue;
- updateOther.push({
- id: audit.id,
- audit_status: auditConst.phasePay.status.checkSkip,
- opinion: '',
- audit_time: time,
- });
- await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, audit.id);
- }
- if (updateOther.length > 0) transaction.updateRows(this.tableName, updateOther);
- }
- // 无下一审核人表示,审核结束
- if (nextAudits.length > 0) {
- // 流程至下一审批人
- const updateData = nextAudits.map(x => { return { id: x.id, audit_status: auditConst.phasePay.status.checking }; });
- await transaction.updateRows(this.tableName, updateData);
- // 计算合同支付
- const paySum = await this.ctx.service.phasePayDetail.calculateSave(phasePay, transaction);
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_max_sort: selfAudit.active_order + 1, audit_status: auditConst.phasePay.status.checking, ...paySum
- });
- // 拷贝新流程合同支付
- await this.ctx.service.phasePayDetail.initPhaseDataByAudit(transaction, phasePay, phasePay.audit_times, selfAudit.active_order + 1);
- // todo 添加短信通知-需要审批提醒功能
- const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/phasePay/' + phasePay.phase_order);
- const users = this._.map(nextAudits, 'audit_id');
- // 微信模板通知
- const wechatData = {
- wap_url: shenpiUrl,
- qi: phasePay.phase_order,
- status: wxConst.status.check,
- tips: wxConst.tips.check,
- code: this.ctx.session.sessionProject.code,
- };
- await this.ctx.helper.sendWechat(users, smsTypeConst.const.PAY, smsTypeConst.judge.approval.toString(), wxConst.template.phasePay, wechatData);
- for (const a of nextAudits) {
- await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.PAY, {
- pid: this.ctx.session.sessionProject.id,
- tid: this.ctx.tender.id,
- uid: a.audit_id,
- sp_type: 'phasePay',
- sp_id: a.id,
- table_name: this.tableName,
- template: wxConst.template.phasePay,
- wx_data: wechatData,
- });
- }
- } else {
- const final_auditor_str = (selfAudit.audit_type === auditType.key.common)
- ? `${selfAudit.name}${(selfAudit.role ? '-' + selfAudit.role : '')}`
- : ctx.helper.transFormToChinese(selfAudit.audit_order) + '审';
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_end_time: time, audit_status: auditConst.phasePay.status.checked, final_auditor_str, ...paySum
- });
- // 添加短信通知-审批通过提醒功能
- const users = this._.uniq(phasePay.userIds);
- // 微信模板通知
- const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/phasePay/' + phasePay.phase_order);
- const wechatData = {
- wap_url: shenpiUrl,
- qi: phasePay.phase_order,
- status: wxConst.status.success,
- tips: wxConst.tips.success,
- code: this.ctx.session.sessionProject.code,
- };
- await this.ctx.helper.sendWechat(users, smsTypeConst.const.PAY, smsTypeConst.judge.result.toString(), wxConst.template.phasePay, wechatData);
- // todo 审批通过 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.checked);
- }
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- } else {
- // 同步 期信息
- await transaction.update(this.ctx.service.phasePay.tableName, { id: phasePay.id, audit_status: auditConst.phasePay.status.checking, ...paySum });
- }
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- async _checkNo(phasePay, opinion) {
- const pid = this.ctx.session.sessionProject.id;
- const accountId = this.ctx.session.sessionUser.accountId;
- const time = new Date();
- // 整理当前流程审核人状态更新
- const selfAudit = phasePay.curAuditors.find(x => { return x.audit_id === accountId; });
- if (!selfAudit) throw '当前标段您无权审批';
- const auditors = await this.getUniqAuditors(phasePay); // 全部参与的审批人
- const newAuditors = auditors.map(x => {
- return {
- tid: phasePay.tid, phase_id: phasePay.id, audit_id: x.audit_id,
- audit_times: phasePay.audit_times + 1, audit_order: x.audit_order, audit_type: x.audit_type,
- active_order: x.audit_order, audit_status: auditConst.phasePay.status.uncheck,
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- }
- });
- const transaction = await this.db.beginTransaction();
- try {
- // 添加提醒
- const noticeContent = await this._getNoticeContent(pid, selfAudit.tid, phasePay.id, selfAudit.audit_id, opinion);
- const defaultNoticeRecord = { pid, type: pushType.phasePay, status: auditConst.phasePay.status.checkNo, content: noticeContent };
- const records = phasePay.userIds.map(x => {
- return { uid: x, ...defaultNoticeRecord };
- });
- await transaction.insert(this.ctx.service.noticePush.tableName, records);
- // 更新审批人状态数据
- const updateData = [];
- phasePay.curAuditors.forEach(x => {
- if (x.audit_id === selfAudit.audit_id) {
- updateData.push({ id: x.id, audit_status: auditConst.phasePay.status.checkNo, opinion: opinion, audit_time: time});
- } else {
- updateData.push({ id: x.id, audit_status: auditConst.phasePay.status.checkSkip, opinion: '', audit_time: null});
- }
- });
- await transaction.updateRows(this.tableName, updateData);
- await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
- // 更新 期信息
- const paySum = await this.ctx.service.phasePayDetail.calculateSave(phasePay, transaction);
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_status: auditConst.phasePay.status.checkNo, audit_times: phasePay.audit_times + 1, audit_max_sort: 0, ...paySum
- });
- // 拷贝新流程合同支付
- await this.ctx.service.phasePayDetail.initPhaseDataByAudit(transaction, phasePay, phasePay.audit_times + 1, 0);
- // 拷贝新一次审核流程列表
- await transaction.insert(this.tableName, newAuditors);
- // todo 添加短信通知-审批退回提醒功能
- const users = this._.uniq(phasePay.userIds);
- // 微信模板通知
- const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + phasePay.tid + '/phasePay/' + phasePay.phase_order);
- const wechatData = {
- wap_url: shenpiUrl,
- qi: phasePay.phase_order,
- status: wxConst.status.back,
- tips: wxConst.tips.back,
- code: this.ctx.session.sessionProject.code,
- };
- await this.ctx.helper.sendWechat(users, smsTypeConst.const.PAY, smsTypeConst.judge.result.toString(), wxConst.template.phasePay, wechatData);
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- async _checkNoPre(phasePay, opinion) {
- const pid = this.ctx.session.sessionProject.id;
- const accountId = this.ctx.session.sessionUser.accountId;
- const time = new Date();
- // 整理当前流程审核人状态更新
- const selfAudit = phasePay.curAuditors.find(x => { return x.audit_id === accountId; });
- if (!selfAudit) throw '当前标段您无权审批';
- const preAuditors = phasePay.userGroups.find(x => { return x[0].audit_order === selfAudit.audit_order - 1; });
- const transaction = await this.db.beginTransaction();
- try {
- // 添加通知
- const noticeContent = await this._getNoticeContent(pid, phasePay.tid, phasePay.id, selfAudit.audit_id, opinion);
- const defaultNoticeRecord = {
- pid, type: pushType.phasePay, status: auditConst.phasePay.status.checkNoPre, content: noticeContent,
- };
- const records = phasePay.userIds.map(x => {
- return { uid: x, ...defaultNoticeRecord };
- });
- await transaction.insert('zh_notice', records);
- // 更新同一流程所有审批人状态
- const updateData = [];
- for (const audit of phasePay.curAuditors) {
- if (audit.audit_id === selfAudit.audit_id) {
- updateData.push({
- id: audit.id, audit_status: auditConst.phasePay.status.checkNoPre, opinion, audit_time: time,
- });
- } else {
- updateData.push({
- id: audit.id, audit_status: auditConst.phasePay.status.checkSkip, opinion: '', audit_time: null,
- });
- }
- }
- await transaction.updateRows(this.tableName, updateData);
- await this.ctx.service.noticeAgain.stopNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
- // 顺移其后审核人流程顺序
- const sql = 'UPDATE ' + this.tableName + ' SET `active_order` = `active_order` + 2 WHERE phase_id = ? AND audit_times = ? AND `active_order` > ?';
- await transaction.query(sql, [phasePay.id, selfAudit.audit_times, selfAudit.active_order]);
- // 上一审批人,当前审批人 再次添加至流程
- const newAuditors = [], uncheckAuditors = [];
- preAuditors.forEach(x => {
- newAuditors.push({
- tid: x.tid, phase_id: x.phase_id, audit_id: x.audit_id,
- audit_times: x.audit_times, audit_order: selfAudit.audit_order - 1,
- audit_status: auditConst.phasePay.status.checking,
- audit_type: x.audit_type, active_order: selfAudit.active_order + 1,
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- const checkingAuditors_result = await transaction.insert(this.tableName, newAuditors);
- // 获取刚批量添加的所有list
- for (let j = 0; j < newAuditors.length; j++) {
- newAuditors[j].id = checkingAuditors_result.insertId + j;
- }
- phasePay.flowAuditors.forEach(x => {
- uncheckAuditors.push({
- tid: x.tid, phase_id: x.phase_id, audit_id: x.audit_id,
- audit_times: x.audit_times, active_order: selfAudit.active_order + 2,
- audit_status: auditConst.phasePay.status.uncheck,
- audit_type: x.audit_type, audit_order: x.audit_order,
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- await transaction.insert(this.tableName, uncheckAuditors);
- const preAuditorIds = preAuditors.map(x => { return x.audit_id; });
- // 同步 期信息
- const paySum = await this.ctx.service.phasePayDetail.calculateSave(phasePay, transaction);
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_max_sort: selfAudit.active_order + 1, ...paySum,
- });
- // 拷贝新流程合同支付
- await this.ctx.service.phasePayDetail.initPhaseDataByAudit(transaction, phasePay, phasePay.audit_times, selfAudit.active_order + 1);
- const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + phasePay.tid + '/phasePay/' + phasePay.phase_order);
- const users = preAuditorIds;
- // 微信模板通知
- const wechatData = {
- wap_url: shenpiUrl,
- qi: phasePay.phase_order,
- status: wxConst.status.check,
- tips: wxConst.tips.check,
- code: this.ctx.session.sessionProject.code,
- };
- await this.ctx.helper.sendWechat(users, smsTypeConst.const.PAY, smsTypeConst.judge.approval.toString(), wxConst.template.phasePay, wechatData);
- for (const a of newAuditors) {
- await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.PAY, {
- pid: this.ctx.session.sessionProject.id,
- tid: phasePay.tid,
- uid: a.audit_id,
- sp_type: 'phasePay',
- sp_id: a.id,
- table_name: this.tableName,
- template: wxConst.template.phasePay,
- wx_data: wechatData,
- });
- }
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- async check(phasePay, checkType, opinion = '') {
- switch (checkType) {
- case auditConst.phasePay.status.checked:
- await this._checked(phasePay, opinion);
- break;
- case auditConst.phasePay.status.checkNo:
- await this._checkNo(phasePay, opinion);
- break;
- case auditConst.phasePay.status.checkNoPre:
- await this._checkNoPre(phasePay, opinion);
- break;
- default:
- throw '无效审批操作';
- }
- }
- async checkAgain(phasePay, force = false) {
- const accountId = this.ctx.session.sessionUser.accountId;
- const time = new Date();
- // 整理当前流程审核人状态更新
- const finalAudits = phasePay.auditorGroups[phasePay.auditorGroups.length - 1];
- if (!finalAudits || finalAudits.length === 0 || finalAudits[0].audit_order < 1) throw '审核数据错误';
- const selfAudit = finalAudits.find(x => { return x.audit_id === accountId; });
- if (!selfAudit && !force) throw '当前标段您无权审批';
- const finalAudit = selfAudit || finalAudits[0];
- const transaction = await this.db.beginTransaction();
- try {
- // 当前审批人2次添加至流程中
- const checkAgainAuditors = [], checkingAuditors = [];
- finalAudits.forEach(x => {
- checkAgainAuditors.push({
- tid: x.tid, phase_id: x.phase_id, audit_id: x.audit_id,
- audit_type: x.audit_type, audit_order: x.audit_order,
- audit_times: x.audit_times, active_order: x.active_order + 1,
- audit_status: x.audit_id === finalAudit.audit_id ? auditConst.phasePay.status.checkAgain : auditConst.phasePay.status.checkSkip,
- audit_time: time, opinion: '',
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- finalAudits.forEach(x => {
- checkingAuditors.push({
- tid: x.tid, phase_id: x.phase_id, audit_id: x.audit_id,
- audit_type: x.audit_type, audit_order: x.audit_order,
- audit_times: x.audit_times, active_order: x.active_order + 2,
- audit_status: auditConst.phasePay.status.checking, audit_time: time, opinion: '',
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- await transaction.insert(this.tableName, checkAgainAuditors);
- const checkingAuditors_result = await transaction.insert(this.tableName, checkingAuditors);
- // 获取刚批量添加的所有list
- for (let j = 0; j < checkingAuditors.length; j++) {
- checkingAuditors[j].id = checkingAuditors_result.insertId + j;
- }
- // 同步 期信息
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_status: auditConst.phasePay.status.checking, audit_end_time: null, final_auditor_str: '', audit_max_sort: finalAudit.active_order + 2,
- });
- // 拷贝新流程合同支付
- await this.ctx.service.phasePayDetail.initPhaseDataByAudit(transaction, phasePay, phasePay.audit_times + 1, finalAudit.active_order + 2);
- // todo 添加短信通知-需要审批提醒功能
- const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + phasePay.tid + '/phasePay/' + phasePay.phase_order);
- const users = this._.map(phasePay.auditAssists.filter(x => { return phasePay.finalAuditorIds.indexOf(x.user_id) >= 0; }), 'ass_user_id');
- users.push(...phasePay.finalAuditorIds);
- // 微信模板通知
- const wechatData = {
- wap_url: shenpiUrl,
- qi: phasePay.phase_order,
- status: wxConst.status.check,
- tips: wxConst.tips.check,
- code: this.ctx.session.sessionProject.code,
- };
- await this.ctx.helper.sendWechat(users, smsTypeConst.const.PAY, smsTypeConst.judge.approval.toString(), wxConst.template.phasePay, wechatData);
- for (const a of checkingAuditors) {
- await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.PAY, {
- pid: this.ctx.session.sessionProject.id,
- tid: phasePay.tid,
- uid: a.audit_id,
- sp_type: 'phasePay',
- sp_id: a.id,
- table_name: this.tableName,
- template: wxConst.template.phasePay,
- wx_data: wechatData,
- });
- }
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- /**
- * 原报撤回,直接改动审批人状态
- * 如果存在审批人数据,将其改为原报流程数据,但保留原提交人
- *
- * 一审 1 A checking -> A uncheck status改 pay:1->0 删1
- * ...
- *
- * @param phasePay
- * @returns {Promise<void>}
- * @private
- */
- async _userCheckCancel(phasePay) {
- const transaction = await this.db.beginTransaction();
- try {
- // 整理当前流程审核人状态更新
- // 审批人变成待审批状态
- const updateData = phasePay.curAuditors.map(x => {
- return {
- id: x.id, audit_status: auditConst.phasePay.status.uncheck,
- audit_time: null, opinion: '',
- }
- });
- await transaction.updateRows(this.tableName, updateData);
- await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(updateData, 'id'));
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_times: phasePay.audit_times, audit_max_sort: 0,
- audit_status: phasePay.audit_times === 1 ? auditConst.phasePay.status.uncheck : auditConst.phasePay.status.checkNo,
- });
- await transaction.delete(this.ctx.service.phasePayDetail.tableName,
- { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_sort: 0});
- await transaction.update(this.ctx.service.phasePayDetail.tableName,
- { audit_sort: 0, master_id: phasePay.id + '-' + phasePay.audit_times + '-0' },
- { where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_sort: 1 } });
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- await transaction.commit();
- } catch(err) {
- await transaction.rollback();
- throw err;
- }
- }
- /**
- * 审批人撤回审批通过,插入两条数据
- *
- * @param phasePay
- * @returns {Promise<void>}
- * @private
- */
- async _auditCheckCancel(phasePay) {
- if (phasePay.curAuditors.length === 0 || phasePay.curAuditors[0].active_order <= 1) {
- throw '撤回用户数据错误';
- }
- const accountId = this.ctx.session.sessionUser.accountId;
- const selfAuditor = phasePay.preAuditors.find(x => { return x.audit_id === accountId; });
- if (!selfAuditor) throw '撤回用户数据错误';
- const time = new Date();
- const transaction = await this.db.beginTransaction();
- try {
- // 整理当前流程审核人状态更新
- // 顺移其后审核人流程顺序
- const sql = 'UPDATE ' + this.tableName + ' SET `active_order` = `active_order` + 2 WHERE phase_id = ? AND audit_times = ? AND `active_order` > ?';
- await transaction.query(sql, [phasePay.id, selfAuditor.audit_times, phasePay.curAuditors[0].active_order]);
- // 当前审批人2次添加至流程中
- const checkCancelAuditors = [], checkingAuditors = [];
- phasePay.preAuditors.forEach(x => {
- checkCancelAuditors.push({
- tid: phasePay.tid, phase_id: phasePay.id, audit_id: x.audit_id,
- audit_times: x.audit_times, active_order: x.active_order + 1,
- audit_type: x.audit_type, audit_order: x.audit_order,
- audit_status: x.audit_id === selfAuditor.audit_id ? auditConst.phasePay.status.checkCancel : auditConst.phasePay.status.checkSkip,
- audit_time: time, opinion: '',
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- phasePay.preAuditors.forEach(x => {
- checkingAuditors.push({
- tid: phasePay.tid, phase_id: phasePay.id, audit_id: x.audit_id,
- audit_times: x.audit_times, active_order: x.active_order + 2,
- audit_type: x.audit_type, audit_order: x.audit_order,
- audit_status: auditConst.phasePay.status.checking,
- audit_time: time, opinion: '',
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- await transaction.insert(this.tableName, [...checkCancelAuditors, ...checkingAuditors]);
- // 当前审批人变成待审批
- await transaction.updateRows(this.tableName, phasePay.curAuditors.map(x => { return {
- id: x.id, audit_time: null, audit_status: auditConst.phasePay.status.uncheck, active_order: x.active_order + 2
- }}));
- await this.ctx.service.phasePayDetail.initPhaseDataByAuditCancel(transaction, phasePay, phasePay.audit_times, selfAuditor.active_order + 1, phasePay.audit_times, selfAuditor.active_order + 2);
- await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(phasePay.curAuditors, 'id'));
- // 同步 期信息
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_times: phasePay.audit_times,
- });
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- await transaction.commit();
- } catch(err) {
- await transaction.rollback();
- throw err;
- }
- }
- /**
- * 审批人撤回审批退回上一人,插入两条数据
- *
- * @param phasePay
- * @returns {Promise<void>}
- * @private
- */
- async _auditCheckCancelNoPre(phasePay) {
- if (phasePay.curAuditors.length === 0 || phasePay.curAuditors[0].active_order <= 1) {
- throw '撤回用户数据错误';
- }
- const accountId = this.ctx.session.sessionUser.accountId;
- const selfAuditor = phasePay.preAuditors.find(x => { return x.audit_id === accountId; });
- if (!selfAuditor) throw '撤回用户数据错误';
- const time = new Date();
- const transaction = await this.db.beginTransaction();
- try {
- // 整理当前流程审核人状态更新
- // 删除当前审批人
- await transaction.delete(this.tableName, { id: phasePay.curAuditors.map(x => { return x.id; }) });
- await this.ctx.service.noticeAgain.deleteNoticeAgain(transaction, this.tableName, this._.map(phasePay.curAuditors, 'id'));
- // 添加撤回人到审批流程中
- const newAuditors = [];
- phasePay.preAuditors.forEach(x => {
- newAuditors.push({
- tid: phasePay.tid, phase_id: phasePay.id, audit_id: x.audit_id,
- audit_times: x.audit_times, active_order: x.active_order + 1,
- audit_type: x.audit_type, audit_order: x.audit_order,
- audit_status: x.audit_id === selfAuditor.audit_id ? auditConst.phasePay.status.checkCancel : auditConst.phasePay.status.checkSkip,
- audit_time: time, opinion: '',
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- await transaction.insert(this.tableName, newAuditors);
- // 更新上一个人,最新审批状态为审批中
- await transaction.update(this.tableName, { audit_time: null, opinion: '', audit_status: auditConst.phasePay.status.checking }, {
- where: { phase_id: phasePay.id, audit_times: selfAuditor.audit_times, active_order: selfAuditor.active_order + 2 }
- });
- // 同步 期信息
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_times: phasePay.audit_times, audit_status: auditConst.phasePay.status.checking,
- });
- await this.ctx.service.phasePayDetail.initPhaseDataByAuditCancel(transaction, phasePay, phasePay.audit_times, selfAuditor.active_order + 1, phasePay.audit_times, selfAuditor.active_order + 2);
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- await transaction.commit();
- } catch(err) {
- await transaction.rollback();
- throw err;
- }
- }
- /**
- * 审批人撤回审批退回原报
- *
- * @param phasePay
- * @returns {Promise<void>}
- * @private
- */
- async _auditCheckCancelNo(phasePay) {
- const accountId = this.ctx.session.sessionUser.accountId;
- const selfAuditor = phasePay.preAuditors.find(x => { return x.audit_id === accountId && x.audit_status === auditConst.phasePay.status.checkNo; });
- if (!selfAuditor) throw '该标段由他人审批退回,您不可撤回';
- const time = new Date();
- const transaction = await this.db.beginTransaction();
- try {
- // 整理上一个流程审核人状态更新
- // 顺移其后审核人流程顺序
- const sql = 'UPDATE ' + this.tableName + ' SET `active_order` = `active_order` + 2 WHERE phase_id = ? AND audit_times = ? AND `active_order` > ?';
- await transaction.query(sql, [phasePay.id, selfAuditor.audit_times, selfAuditor.active_order]);
- // 当前审批人2次添加至流程中
- const checkCancelAuditors = [], checkingAuditors = [];
- phasePay.preAuditors.forEach(x => {
- checkCancelAuditors.push({
- tid: phasePay.tid, phase_id: phasePay.id, audit_id: x.audit_id,
- audit_times: x.audit_times, active_order: x.active_order + 1,
- audit_type: x.audit_type, audit_order: x.audit_order,
- audit_status: x.audit_id === selfAuditor.audit_id ? auditConst.phasePay.status.checkCancel : auditConst.phasePay.status.checkSkip,
- audit_time: time, opinion: '',
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- phasePay.preAuditors.forEach(x => {
- checkingAuditors.push({
- tid: phasePay.tid, phase_id: phasePay.id, audit_id: x.audit_id,
- audit_times: x.audit_times, active_order: x.active_order + 2,
- audit_type: x.audit_type, audit_order: x.audit_order,
- audit_status: auditConst.phasePay.status.checking,
- audit_time: time, opinion: '',
- name: x.name, company: x.company, role: x.role, mobile: x.mobile,
- });
- });
- await transaction.insert(this.tableName, [...checkCancelAuditors, ...checkingAuditors]);
- // 删除当前次审批流
- await transaction.delete(this.tableName, { phase_id: phasePay.id, audit_times: phasePay.audit_times });
- // 计算并合同支付最终数据
- await transaction.update(this.ctx.service.phasePay.tableName, {
- id: phasePay.id, audit_times: phasePay.audit_times - 1, audit_status: auditConst.phasePay.status.checking,
- });
- await transaction.update(this.ctx.service.phasePayDetail.tableName,
- { audit_times: selfAuditor.audit_times, audit_sort: selfAuditor.active_order + 2, master_id: `${phasePay.id}-${selfAuditor.audit_times}-${selfAuditor.active_order + 2}` },
- { where: { phase_id: phasePay.id, audit_times: phasePay.audit_times, audit_sort: 0 } });
- // todo 上报/审批 - 检查三方特殊推送
- // await this.ctx.service.specMsg.addPhasePayMsg(transaction, this.ctx.session.sessionProject.id, phasePay, pushOperate.phasePay.flow);
- await transaction.commit();
- } catch(err) {
- await transaction.rollback();
- throw err;
- }
- }
- /**
- * 会签未全部审批通过时,撤回仅修改本人状态
- *
- * @param phasePay
- * @returns {Promise<void>}
- * @private
- */
- async _auditCheckCancelAnd(phasePay) {
- const accountId = this.ctx.session.sessionUser.accountId;
- const selfAuditor = phasePay.flowAuditors.find(x => { return x.audit_id === accountId; });
- if (!selfAuditor || selfAuditor.audit_status !== auditConst.phasePay.status.checked) throw '不可撤回';
- const transaction = await this.db.beginTransaction();
- try {
- await transaction.update(this.tableName, {
- id: selfAuditor.id, audit_status: auditConst.phasePay.status.checking, opinion: '', audit_time: null,
- });
- await transaction.commit();
- } catch(err) {
- await transaction.rollback();
- throw err;
- }
- }
- /**
- * 审批撤回
- * @param {Number} phasePay - 结算期
- * @return {Promise<void>}
- */
- async checkCancel(phasePay) {
- // 分5种情况,根据phasePay.cancancel值判断:
- // 1.原报发起撤回,当前流程删除,并回到待上报
- // 2.审批人撤回审批通过,增加流程,并回到它审批中
- // 3.审批人撤回审批退回上一人,并删除退回人,增加流程,并回到它审批中,并更新计量期状态为审批中
- // 4.审批人撤回退回原报操作,删除新增的审批流,增加流程,回滚到它审批中
- // 5.会签审批人撤回审批通过(还有其他审批人未审批通过),仅修改本人流程状态
- if (phasePay.cancancel === 5) {
- await this._auditCheckCancelAnd(phasePay);
- } else {
- switch (phasePay.cancancel) {
- case 1: await this._userCheckCancel(phasePay); break;
- case 2: await this._auditCheckCancel(phasePay); break;
- case 3: await this._auditCheckCancelNoPre(phasePay); break;
- case 4: await this._auditCheckCancelNo(phasePay); break;
- default: throw '不可撤回,请刷新页面重试';
- }
- }
- }
- // ***** 审批操作
- }
- return PhasePayAudit;
- };
|