12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040 |
- '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 : '')}`
- : this.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, 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 = 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;
- };
|