|
|
@@ -9,6 +9,7 @@
|
|
|
*/
|
|
|
|
|
|
const audit = require('../const/audit').common;
|
|
|
+const auditType = require('../const/audit').auditType;
|
|
|
const shenpiConst = require('../const/shenpi');
|
|
|
|
|
|
module.exports = app => {
|
|
|
@@ -112,7 +113,7 @@ module.exports = app => {
|
|
|
await conn.delete(this.ctx.service.safeStageFile.tableName, { stage_id: id });
|
|
|
await conn.delete(this.ctx.service.safeStageAudit.tableName, { stage_id: id });
|
|
|
// 记录删除日志
|
|
|
- // await this.ctx.service.projectLog.addProjectLog(conn, projectLogConst.type.safeStage, projectLogConst.status.delete, `第${info.phase_order}期`);
|
|
|
+ // await this.ctx.service.projectLog.addProjectLog(conn, projectLogConst.type.safeStage, projectLogConst.status.delete, `第${info.stage_order}期`);
|
|
|
await conn.commit();
|
|
|
} catch (err) {
|
|
|
await conn.rollback();
|
|
|
@@ -230,7 +231,7 @@ module.exports = app => {
|
|
|
safeStage.curSort = 0;
|
|
|
} else {
|
|
|
const checkNoAudit = await this.service.safeStageAudit.getDataByCondition({
|
|
|
- phase_id: safeStage.id, audit_times: safeStage.audit_times - 1, audit_status: audit.status.checkNo,
|
|
|
+ stage_id: safeStage.id, audit_times: safeStage.audit_times - 1, audit_status: audit.status.checkNo,
|
|
|
});
|
|
|
safeStage.curSort = checkNoAudit.active_order;
|
|
|
}
|
|
|
@@ -251,7 +252,7 @@ module.exports = app => {
|
|
|
const shenpi_status = info.shenpi.safe_stage;
|
|
|
if ((safeStage.audit_status === status.uncheck || safeStage.audit_status === status.checkNo) && shenpi_status !== shenpiConst.sp_status.sqspr) {
|
|
|
// 进一步比较审批流是否与审批流程设置的相同,不同则替换为固定审批流或固定的终审
|
|
|
- const auditList = await this.ctx.service.safeStageAudit.getAllDataByCondition({ where: { phase_id: safeStage.id, audit_times: safeStage.audit_times }, orders: [['audit_order', 'asc']] });
|
|
|
+ const auditList = await this.ctx.service.safeStageAudit.getAllDataByCondition({ where: { stage_id: safeStage.id, audit_times: safeStage.audit_times }, orders: [['audit_order', 'asc']] });
|
|
|
auditList.shift();
|
|
|
if (shenpi_status === shenpiConst.sp_status.gdspl) {
|
|
|
const shenpiList = await this.ctx.service.shenpiAudit.getAllDataByCondition({ where: { tid: safeStage.tid, sp_type: shenpiConst.sp_type.safe_payment, sp_status: shenpi_status } });
|
|
|
@@ -284,6 +285,98 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ async _getUserInfo(id) {
|
|
|
+ if (!this.cacheUserInfo) this.cacheUserInfo = [];
|
|
|
+ const cache = this.cacheUserInfo.find(x => { return x.id === id; });
|
|
|
+ if (cache) return cache;
|
|
|
+ const user = await this.ctx.service.projectAccount.getDataById(id);
|
|
|
+ this.cacheUserInfo.push(user);
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+ async copyPaySafeData(payTenderId) {
|
|
|
+ const details = await this.ctx.service.paymentDetail.getAllDataByCondition({ where: { tender_id: payTenderId, type: 1 } });
|
|
|
+ const tid = this.ctx.tender.id;
|
|
|
+ const conn = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ const insertStage = [], insertBills = [], insertAudit = [], insertFile = [];
|
|
|
+ for (const detail of details) {
|
|
|
+ const stage = {
|
|
|
+ id: this.uuid.v4(), tid, create_user_id: detail.uid, update_user_id: this.ctx.session.sessionUser.accountId,
|
|
|
+ stage_order: detail.order, stage_code: detail.code, stage_date: detail.s_time,
|
|
|
+ audit_times: detail.times, audit_status: detail.status,
|
|
|
+ bills_decimal: detail.bills_decimal || JSON.stringify({ up: 2, tp: 2, qty: 3 }),
|
|
|
+ create_time: detail.in_time, final_auditor_str: '',
|
|
|
+ };
|
|
|
+ insertStage.push(stage);
|
|
|
+ const safeBills = await this.ctx.service.paymentSafeBills.getAllDataByCondition({ where: { detail_id: detail.id } });
|
|
|
+ for (const sb of safeBills) {
|
|
|
+ sb.tender_id = tid;
|
|
|
+ delete sb.detail_id;
|
|
|
+ sb.stage_id = stage.id;
|
|
|
+ const his = sb.cur_his ? JSON.parse(sb.cur_his) : [];
|
|
|
+ for (const h of his) {
|
|
|
+ h.audit_times = h.times;
|
|
|
+ h.active_order = h.order;
|
|
|
+ delete h.times;
|
|
|
+ delete h.order;
|
|
|
+ }
|
|
|
+ sb.cur_his = JSON.stringify(his);
|
|
|
+ insertBills.push(sb);
|
|
|
+ }
|
|
|
+ const user = await this._getUserInfo(detail.uid);
|
|
|
+ const audits = await this.ctx.service.paymentDetailAudit.getAllDataByCondition({ where: { td_id: detail.id }, orders: [['times', 'asc'], ['order', 'asc']]});
|
|
|
+ if (detail.status === audit.status.checked) {
|
|
|
+ const fa = await this._getUserInfo(audits[audits.length - 1].aid);
|
|
|
+ stage.final_auditor_str =`${fa.name}${(fa.role ? '-' + fa.role : '')}`;
|
|
|
+ }
|
|
|
+ if (audits.length === 0) {
|
|
|
+ insertAudit.push({
|
|
|
+ tid, stage_id: stage.id, audit_id: user.id,
|
|
|
+ name: user.name, company: user.company, role: user.role, mobile: user.mobile,
|
|
|
+ audit_times: a.times, audit_order: 0, active_order: 0, audit_type: auditType.key.common,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ for (const a of audits) {
|
|
|
+ const auditor = await this._getUserInfo(a.aid);
|
|
|
+ if (a.order === 1) {
|
|
|
+ insertAudit.push({
|
|
|
+ tid, stage_id: stage.id, audit_id: user.id,
|
|
|
+ name: user.name, company: user.company, role: user.role, mobile: user.mobile,
|
|
|
+ audit_times: a.times, audit_order: 0, active_order: 0, audit_type: auditType.key.common,
|
|
|
+ audit_time: a.begin_time, audit_status: audit.status.checked,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const same = audits.filter(x => { return a.aid === x.aid && a.times === x.times; });
|
|
|
+ const audit_order = this.ctx.helper._.min(same.map(x => { return x.order}));
|
|
|
+ insertAudit.push({
|
|
|
+ tid, stage_id: stage.id, audit_id: auditor.id,
|
|
|
+ name: auditor.name, company: auditor.company, role: auditor.role, mobile: auditor.mobile,
|
|
|
+ audit_times: a.times, audit_order, active_order: a.order, audit_type: auditType.key.common,
|
|
|
+ audit_status: a.status, audit_time: a.end_time, opinion: a.opinion || '',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const files = await this.ctx.service.paymentDetailAtt.getAllDataByCondition({ where: { td_id: detail.id } });
|
|
|
+ for (const f of files) {
|
|
|
+ const fu = await this._getUserInfo(f.uid);
|
|
|
+ insertFile.push({
|
|
|
+ id: this.uuid.v4(), tid, stage_id: stage.id, type: 'bills', rela_id: f.safe_id,
|
|
|
+ filename: f.filename, fileext: f.fileext, filesize: f.filesize, filepath: f.filepath,
|
|
|
+ user_id: fu.id, user_name: fu.name, user_company: fu.company, user_role: fu.role,
|
|
|
+ create_time: fu.upload_time, update_time: fu.upload_time,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await conn.insert(this.tableName, insertStage);
|
|
|
+ await conn.insert(this.ctx.service.safeStageBills.tableName, insertBills);
|
|
|
+ await conn.insert(this.ctx.service.safeStageAudit.tableName, insertAudit);
|
|
|
+ if (insertFile.length > 0) await conn.insert(this.ctx.service.safeStageFile.tableName, insertFile);
|
|
|
+ await conn.commit();
|
|
|
+ } catch (err) {
|
|
|
+ await conn.rollback();
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return SafeStage;
|