|
|
@@ -2,7 +2,6 @@
|
|
|
const auditConst = require('../const/audit');
|
|
|
const measureType = require('../const/tender').measureType;
|
|
|
const advanceConst = require('../const/advance');
|
|
|
-const status = require('../const/audit').advance.status;
|
|
|
const shenpiConst = require('../const/shenpi');
|
|
|
const stdConst = require('../const/standard');
|
|
|
const _ = require('lodash');
|
|
|
@@ -149,6 +148,49 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async advanceCheck(advance) {
|
|
|
+ if (!advance) {
|
|
|
+ throw '预付款数据错误';
|
|
|
+ }
|
|
|
+ const times = advance.status === auditConst.advance.status.checkNo ? advance.times - 1 : advance.times;
|
|
|
+
|
|
|
+ advance.user = await this.service.projectAccount.getAccountInfoById(advance.uid);
|
|
|
+ // 读取审核人列表数据
|
|
|
+ advance.auditors = await this.service.advanceAudit.getAuditorsWithOwner(advance.id, advance.status === auditConst.advance.status.checkNo && this.ctx.session.sessionUser.accountId !== advance.uid ? times : advance.times);
|
|
|
+ advance.auditHistory = await this.service.advanceAudit.getAuditors(advance.id, advance.times);
|
|
|
+ advance.curAuditor = await this.service.advanceAudit.getCurAuditor(advance.id, advance.times);
|
|
|
+ // 根据状态判断是否需要更新审批人列表
|
|
|
+ if ((advance.status === auditConst.advance.status.uncheck || advance.status === auditConst.advance.status.checkNo) && this.ctx.tender.info.shenpi.advance !== shenpiConst.sp_status.sqspr) {
|
|
|
+ const shenpi_status = this.ctx.tender.info.shenpi.advance;
|
|
|
+ // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
|
|
|
+ const auditList = await this.service.advanceAudit.getAllDataByCondition({ where: { vid: advance.id, times: advance.times }, orders: [['order', 'asc']] });
|
|
|
+ const auditIdList = _.map(auditList, 'audit_id');
|
|
|
+ if (shenpi_status === shenpiConst.sp_status.gdspl) {
|
|
|
+ const shenpiList = await this.service.shenpiAudit.getAllDataByCondition({ where: { tid: advance.tid, sp_type: shenpiConst.sp_type.advance, sp_status: shenpi_status } });
|
|
|
+ const shenpiIdList = _.map(shenpiList, 'audit_id');
|
|
|
+ // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
|
|
|
+ if (!_.isEqual(auditIdList, shenpiIdList)) {
|
|
|
+ await this.service.advanceAudit.updateNewAuditList(advance, shenpiIdList);
|
|
|
+ }
|
|
|
+ } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
|
|
|
+ const shenpiInfo = await this.service.shenpiAudit.getDataByCondition({ tid: advance.tid, sp_type: shenpiConst.sp_type.advance, sp_status: shenpi_status });
|
|
|
+ // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
|
|
|
+ if (shenpiInfo && shenpiInfo.audit_id !== _.last(auditIdList)) {
|
|
|
+ await this.service.advanceAudit.updateLastAudit(advance, auditList, shenpiInfo.audit_id);
|
|
|
+ } else if (!shenpiInfo) {
|
|
|
+ // 不存在终审人的状态下这里恢复为授权审批人
|
|
|
+ this.ctx.tender.info.shenpi.advance = shenpiConst.sp_status.sqspr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ advance.advancePayTotal = this.ctx.tender.info.deal_param[ advanceConst.typeCol[advance.type].key + 'Advance'];
|
|
|
+ if (advance.status === auditConst.advance.status.checkNo) {
|
|
|
+ advance.curAuditor = await this.service.advanceAudit.getAuditorByStatus(advance.id, advance.status, times);
|
|
|
+ advance.auditHistory = await this.service.advanceAudit.getAuditors(advance.id, times);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async advanceDetail(ctx) {
|
|
|
try {
|
|
|
const { id } = ctx.query;
|
|
|
@@ -157,51 +199,62 @@ module.exports = app => {
|
|
|
throw '预付款数据错误';
|
|
|
}
|
|
|
|
|
|
- advance.user = await this.service.projectAccount.getAccountInfoById(advance.uid);
|
|
|
- // 读取审核人列表数据
|
|
|
- advance.auditors = await this.service.advanceAudit.getAuditors(advance.id, advance.times);
|
|
|
- advance.curAuditor = await this.service.advanceAudit.getCurAuditor(advance.id, advance.times);
|
|
|
- // 根据状态判断是否需要更新审批人列表
|
|
|
- if ((advance.status === status.uncheck || advance.status === status.checkNo) && ctx.tender.info.shenpi.advance !== shenpiConst.sp_status.sqspr) {
|
|
|
- const shenpi_status = this.ctx.tender.info.shenpi.advance;
|
|
|
- // 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
|
|
|
- const auditList = await this.service.advanceAudit.getAllDataByCondition({ where: { vid: advance.id, times: advance.times }, orders: [['order', 'asc']] });
|
|
|
- const auditIdList = _.map(auditList, 'audit_id');
|
|
|
- if (shenpi_status === shenpiConst.sp_status.gdspl) {
|
|
|
- const shenpiList = await this.service.shenpiAudit.getAllDataByCondition({ where: { tid: advance.tid, sp_type: shenpiConst.sp_type.advance, sp_status: shenpi_status } });
|
|
|
- const shenpiIdList = _.map(shenpiList, 'audit_id');
|
|
|
- // 判断2个id数组是否相同,不同则删除原审批流,切换成固定的审批流
|
|
|
- if (!_.isEqual(auditIdList, shenpiIdList)) {
|
|
|
- await this.service.advanceAudit.updateNewAuditList(advance, shenpiIdList);
|
|
|
- }
|
|
|
- } else if (shenpi_status === shenpiConst.sp_status.gdzs) {
|
|
|
- const shenpiInfo = await this.service.shenpiAudit.getDataByCondition({ tid: advance.tid, sp_type: shenpiConst.sp_type.advance, sp_status: shenpi_status });
|
|
|
- // 判断最后一个id是否与固定终审id相同,不同则删除原审批流中如果存在的id和添加终审
|
|
|
- if (shenpiInfo && shenpiInfo.audit_id !== _.last(auditIdList)) {
|
|
|
- await this.service.advanceAudit.updateLastAudit(advance, auditList, shenpiInfo.audit_id);
|
|
|
- } else if (!shenpiInfo) {
|
|
|
- // 不存在终审人的状态下这里恢复为授权审批人
|
|
|
- this.ctx.tender.info.shenpi.advance = shenpiConst.sp_status.sqspr;
|
|
|
- }
|
|
|
+ await this.advanceCheck(advance);
|
|
|
+
|
|
|
+ advance.auditHistory = advance.auditHistory.reduce((prev, curr, idx) => {
|
|
|
+ if (idx === 0) {
|
|
|
+ const reportor = {
|
|
|
+ audit_id: advance.uid,
|
|
|
+ audit_order: 0,
|
|
|
+ audit_type: 1,
|
|
|
+ status: advance.status === auditConst.advance.status.uncheck ? auditConst.advance.status.uncheck : auditConst.advance.status.checked,
|
|
|
+ times: curr.times,
|
|
|
+ begin_time: advance.pay_time,
|
|
|
+ end_time: advance.auditHistory.length ? advance.auditHistory[0].create_time : null,
|
|
|
+ name: advance.user.name,
|
|
|
+ company: advance.user.company,
|
|
|
+ role: advance.user.role,
|
|
|
+ mobile: '',
|
|
|
+ opinion: '',
|
|
|
+
|
|
|
+ };
|
|
|
+ prev.push({
|
|
|
+ name: '原报',
|
|
|
+ status: reportor.status,
|
|
|
+ audit_type: reportor.audit_type,
|
|
|
+ auditors: [reportor],
|
|
|
+ });
|
|
|
}
|
|
|
- }
|
|
|
+ const currentOrder = advance.auditors.find(auditor => auditor.audit_id === curr.audit_id).order;
|
|
|
+ prev.push(
|
|
|
+ {
|
|
|
+ name: currentOrder === curr.max_sort ? '终审' : `${currentOrder}审`,
|
|
|
+ status: curr.status,
|
|
|
+ audit_type: 1,
|
|
|
+ auditors: [{
|
|
|
+ audit_id: curr.audit_id,
|
|
|
+ audit_order: curr.order,
|
|
|
+ audit_type: curr.type,
|
|
|
+ status: curr.status,
|
|
|
+ max_sort: curr.max_sort,
|
|
|
+ begin_time: curr.create_time,
|
|
|
+ end_time: curr.end_time,
|
|
|
+ name: curr.name,
|
|
|
+ company: curr.company,
|
|
|
+ mobile: curr.mobile,
|
|
|
+ opinion: curr.opinion,
|
|
|
+ role: curr.role,
|
|
|
+ times: curr.times,
|
|
|
+ }],
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return prev;
|
|
|
+ }, []);
|
|
|
|
|
|
- advance.advancePayTotal = ctx.tender.info.deal_param[ advanceConst.typeCol[advance.type].key + 'Advance'];
|
|
|
- const times = advance.status === auditConst.advance.status.checkNo ? advance.times - 1 : advance.times;
|
|
|
- if (advance.status === auditConst.advance.status.checkNo) {
|
|
|
- advance.curAuditor = await ctx.service.advanceAudit.getAuditorByStatus(advance.id, advance.status, times);
|
|
|
- advance.auditors = await ctx.service.advanceAudit.getAuditors(advance.id, times);
|
|
|
+ if (advance.curAuditor) {
|
|
|
+ advance.curAuditor.audit_order = advance.auditors.find(auditor => auditor.audit_id === advance.curAuditor.audit_id).order;
|
|
|
}
|
|
|
- // 因为上报人不在审核列表里面单独添加进去
|
|
|
- // advance.auditors.unshirt({
|
|
|
- // audit_id: advance.uid,
|
|
|
- // name: advance.user.name,
|
|
|
- // company: advance.user.company,
|
|
|
- // create_time: advance.pay_time,
|
|
|
- // end_time: advance.auditors.length ? advance.auditors[0].create_time : null,
|
|
|
- // mobile: '',
|
|
|
-
|
|
|
- // })
|
|
|
+
|
|
|
ctx.body = { code: 0, msg: '', data: { advance } };
|
|
|
} catch (error) {
|
|
|
this.log(error);
|
|
|
@@ -209,6 +262,38 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async advanceAudit(ctx) {
|
|
|
+ try {
|
|
|
+ const advance = await this.service.advance.getDataById(ctx.request.body.id);
|
|
|
+ await this.advanceCheck(advance);
|
|
|
+ ctx.advance = advance;
|
|
|
+ const data = {
|
|
|
+ checkType: parseInt(ctx.request.body.checkType),
|
|
|
+ opinion: ctx.request.body.opinion,
|
|
|
+ };
|
|
|
+ if (!advance || advance.status !== auditConst.advance.status.checking) {
|
|
|
+ throw '当前预付款数据有误';
|
|
|
+ }
|
|
|
+ if (!advance.curAuditor || advance.curAuditor.audit_id !== ctx.session.sessionUser.accountId) {
|
|
|
+ throw '您无权进行该操作';
|
|
|
+ }
|
|
|
+ if (!data.checkType || isNaN(data.checkType)) {
|
|
|
+ throw '提交数据错误';
|
|
|
+ }
|
|
|
+ if (data.checkType === auditConst.advance.status.checkNo) {
|
|
|
+ if (!data.checkType || isNaN(data.checkType)) {
|
|
|
+ throw '提交数据错误';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await ctx.service.advanceAudit.check(advance.id, data, advance.times, advance.type);
|
|
|
+ ctx.body = { code: 0, msg: '操作成功', data: null };
|
|
|
+ } catch (error) {
|
|
|
+ this.log(error);
|
|
|
+ ctx.body = { code: -1, msg: error.toString(), data: null };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async reviseDetail(ctx) {
|
|
|
try {
|
|
|
const { rid } = ctx.query;
|