|
@@ -12,6 +12,7 @@ const auditConst = require('../const/audit').stage;
|
|
|
const smsTypeConst = require('../const/sms_type');
|
|
|
const SMS = require('../lib/sms');
|
|
|
const SmsAliConst = require('../const/sms_alitemplate');
|
|
|
+const payConst = require('../const/deal_pay');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class StageAudit extends app.BaseService {
|
|
@@ -985,6 +986,45 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 删除 某期 某次 全审批流程
|
|
|
+ * 私有,不做判断,不补全最新一轮审批人数据,不计算缓存
|
|
|
+ * @param {Number} sid - 标段id
|
|
|
+ * @param {Number} times - 第几次审批
|
|
|
+ * @param transaction - 删除事务
|
|
|
+ * @return {Promise<void>}
|
|
|
+ */
|
|
|
+ async _timesDelete(sid, times, transaction) {
|
|
|
+ console.log(sid, times);
|
|
|
+ // 审批流程
|
|
|
+ await transaction.delete(this.tableName, { sid: sid, times: times });
|
|
|
+ await transaction.delete(this.ctx.service.pos.tableName, {add_stage: sid, add_times: times});
|
|
|
+ await transaction.delete(this.ctx.service.stageBills.tableName, { sid: sid, times: times });
|
|
|
+ await transaction.delete(this.ctx.service.stagePos.tableName, { sid: sid, times: times });
|
|
|
+ await transaction.delete(this.ctx.service.stageDetail.tableName, { sid: sid, times: times });
|
|
|
+ await transaction.delete(this.ctx.service.stageChange.tableName, { sid: sid, stimes: times });
|
|
|
+ // 合同支付
|
|
|
+ const payList = await this.ctx.service.stagePay.getAllDataByCondition({ where: { sid: sid, stimes: times } });
|
|
|
+ if (payList) {
|
|
|
+ for (const pt of payList) {
|
|
|
+ if (pt.attachment !== null && pt.attachment !== '') {
|
|
|
+ const payAttList = JSON.parse(pt.attachment);
|
|
|
+ for (const pat of payAttList) {
|
|
|
+ if (fs.existsSync(path.join(this.app.baseDir, pat.filepath))) {
|
|
|
+ await fs.unlinkSync(path.join(this.app.baseDir, pat.filepath));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await transaction.delete(this.ctx.service.stagePay.tableName, { sid: sid, stimes: times });
|
|
|
+ await transaction.delete(this.ctx.service.pay.tableName, { csid: sid, cstimes: times });
|
|
|
+ // 其他台账
|
|
|
+ await this.ctx.service.stageJgcl.deleteStageTimesData(sid, times, transaction);
|
|
|
+ await this.ctx.service.stageOther.deleteStageTimesData(sid, times, transaction);
|
|
|
+ await this.ctx.service.stageBonus.deleteStageTimesData(sid, times, transaction);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 删除本次审批流程
|
|
|
* @param {Number} stageId - 标段id
|
|
|
* @param {Number} times - 第几次审批
|
|
@@ -993,12 +1033,13 @@ module.exports = app => {
|
|
|
async timesDelete() {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- // 判断当前期是否是重新上报状态,决定删除times数并获取最新的times
|
|
|
- await transaction.delete(this.tableName, { sid: this.ctx.stage.id, times: this.ctx.stage.times });
|
|
|
+ // 删除最新一次数据
|
|
|
+ await this._timesDelete(this.ctx.stage.id, this.ctx.stage.times, transaction);
|
|
|
+ // 审批退回,未重新上报时,需删除最新两次数据
|
|
|
const isCheckNo = this.ctx.stage.status === auditConst.status.checkNo;
|
|
|
const nowTimes = isCheckNo ? this.ctx.stage.times - 1 : this.ctx.stage.times;
|
|
|
if (isCheckNo) {
|
|
|
- await transaction.delete(this.tableName, { sid: this.ctx.stage.id, times: nowTimes });
|
|
|
+ await this._timesDelete(this.ctx.stage.id, nowTimes, transaction);
|
|
|
}
|
|
|
// 添加上一次审批人
|
|
|
const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid` ORDER BY `id` ASC';
|
|
@@ -1015,24 +1056,35 @@ module.exports = app => {
|
|
|
// 拷贝新一次审核流程列表
|
|
|
await transaction.insert(this.tableName, auditors);
|
|
|
|
|
|
- // 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.curTimes = this.ctx.stage.nowTimes;
|
|
|
+ this.ctx.stage.curOrder = 0;
|
|
|
+ const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
+ // 计算并合同支付最终数据
|
|
|
+ const lastAudit = await this.getDataByCondition({sid: this.ctx.stage.id, times: nowTimes - 1, status: auditConst.status.checkNo});
|
|
|
+ if (!lastAudit) throw '审批数据错误';
|
|
|
+ await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, lastAudit.times, lastAudit.order, transaction);
|
|
|
+ const stagePay = await this.ctx.service.stagePay.getAuditorStageData(this.ctx.stage.id, lastAudit.times, lastAudit.order);
|
|
|
+ const yfPay = stagePay.find(function (x) {
|
|
|
+ return x.ptype === payConst.payType.yf;
|
|
|
+ });
|
|
|
+ const sfPay = stagePay.find(function (x) {
|
|
|
+ return x.ptype === payConst.payType.sf;
|
|
|
+ });
|
|
|
// 同步 期信息
|
|
|
+ const time = new Date();
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: this.ctx.stage.id, status: auditConst.status.checkNo,
|
|
|
- // contract_tp: tpData.contract_tp,
|
|
|
- // qc_tp: tpData.qc_tp,
|
|
|
+ id: this.ctx.stage.id,
|
|
|
+ status: auditConst.status.checkNo,
|
|
|
+ contract_tp: tpData.contract_tp,
|
|
|
+ qc_tp: tpData.qc_tp,
|
|
|
times: nowTimes,
|
|
|
- // 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,
|
|
|
+ yf_tp: yfPay.tp,
|
|
|
+ sf_tp: sfPay.tp,
|
|
|
+ tp_history: JSON.stringify(this.ctx.stage.tp_history),
|
|
|
+ cache_time_l: time,
|
|
|
+ cache_time_r: time,
|
|
|
});
|
|
|
- // 复制一份最新数据给原报
|
|
|
- // await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times + 1, 0, transaction);
|
|
|
- // await this.ctx.service.stageJgcl.updateHistory(this.ctx.stage, transaction);
|
|
|
- // await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|