|
@@ -291,7 +291,7 @@ module.exports = app => {
|
|
|
if (postData.changestatus !== undefined && parseInt(postData.changestatus) === 1) {
|
|
|
change_status = true;
|
|
|
// 更新原报人审批状态
|
|
|
- await this.transaction.update(this.ctx.service.changeAudit.tableName, { id: lastUser.id, status: 3 });
|
|
|
+ await this.transaction.update(this.ctx.service.changeAudit.tableName, { id: lastUser.id, status: 3, sin_time: new Date() });
|
|
|
}
|
|
|
// 再插入postData里的变更审批人和清单
|
|
|
if (postData.changeaudit !== undefined && postData.changeaudit !== '') {
|
|
@@ -390,7 +390,286 @@ module.exports = app => {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
+ * 审批通过
|
|
|
+ * @param {int} postData - 表单提交的数据
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async approvalSuccess(postData) {
|
|
|
+ // 初始化事务
|
|
|
+ this.transaction = await this.db.beginTransaction();
|
|
|
+ let result = false;
|
|
|
+ try {
|
|
|
+ // 设置审批人通过
|
|
|
+ const audit_update = {
|
|
|
+ id: postData.audit_id,
|
|
|
+ sdesc: postData.sdesc,
|
|
|
+ status: 3,
|
|
|
+ sin_time: new Date(),
|
|
|
+ };
|
|
|
+ const change_update = {
|
|
|
+ w_code: postData.w_code,
|
|
|
+ status: 2,
|
|
|
+ cin_time: Date.parse(new Date()) / 1000,
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
|
|
|
+ // 清单数据更新
|
|
|
+ const bills_list = postData.bills_list.split(',');
|
|
|
+ let total_price = 0;
|
|
|
+ for (const bl of bills_list) {
|
|
|
+ const listInfo = bl.split('_');
|
|
|
+ const lid = listInfo[0];
|
|
|
+ const amount = listInfo[1];
|
|
|
+ const changeListInfo = await this.ctx.service.changeAuditList.getDataById(lid);
|
|
|
+ if (changeListInfo !== undefined) {
|
|
|
+ total_price += this.ctx.helper.accMul(changeListInfo.unit_price, parseFloat(amount));
|
|
|
+ const audit_amount = changeListInfo.audit_amount !== null && changeListInfo.audit_amount !== '' ? changeListInfo.audit_amount.split(',') : [];
|
|
|
+ audit_amount.push(amount);
|
|
|
+ const list_update = {
|
|
|
+ id: lid,
|
|
|
+ audit_amount: audit_amount.join(','),
|
|
|
+ };
|
|
|
+ if (postData.audit_next_id === undefined) {
|
|
|
+ list_update.samount = amount;
|
|
|
+ }
|
|
|
+ await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (postData.audit_next_id === undefined) {
|
|
|
+ // 变更令审批完成
|
|
|
+ change_update.status = 3;
|
|
|
+ change_update.p_code = postData.p_code;
|
|
|
+ change_update.sin_time = Date.parse(new Date()) / 1000;
|
|
|
+ change_update.total_price = total_price;
|
|
|
+ } else {
|
|
|
+ // 设置下一个审批人为审批状态
|
|
|
+ const nextAudit_update = {
|
|
|
+ id: postData.audit_next_id,
|
|
|
+ status: 2,
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.ctx.service.changeAudit.tableName, nextAudit_update);
|
|
|
+ }
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: postData.change_id,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.tableName, change_update, options);
|
|
|
+ await this.transaction.commit();
|
|
|
+ result = true;
|
|
|
+ } catch (error) {
|
|
|
+ await this.transaction.rollback();
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批终止
|
|
|
+ * @param {int} postData - 表单提交的数据
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async approvalStop(postData) {
|
|
|
+ // 初始化事务
|
|
|
+ this.transaction = await this.db.beginTransaction();
|
|
|
+ let result = false;
|
|
|
+ try {
|
|
|
+ // 设置审批人终止
|
|
|
+ const audit_update = {
|
|
|
+ id: postData.audit_id,
|
|
|
+ sdesc: postData.sdesc,
|
|
|
+ status: 4,
|
|
|
+ sin_time: new Date(),
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
|
|
|
+ // 设置变更令终止
|
|
|
+ const change_update = {
|
|
|
+ w_code: postData.w_code,
|
|
|
+ status: 4,
|
|
|
+ cin_time: Date.parse(new Date()) / 1000,
|
|
|
+ };
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: postData.change_id,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.tableName, change_update, options);
|
|
|
+ await this.transaction.commit();
|
|
|
+ result = true;
|
|
|
+ } catch (error) {
|
|
|
+ await this.transaction.rollback();
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批退回到原报人
|
|
|
+ * @param {int} postData - 表单提交的数据
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async approvalBack(postData) {
|
|
|
+ // 初始化事务
|
|
|
+ this.transaction = await this.db.beginTransaction();
|
|
|
+ let result = false;
|
|
|
+ try {
|
|
|
+ const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
|
|
|
+ // 设置审批人退回
|
|
|
+ const audit_update = {
|
|
|
+ id: postData.audit_id,
|
|
|
+ sdesc: postData.sdesc,
|
|
|
+ status: 5,
|
|
|
+ sin_time: new Date(),
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
|
|
|
+ // 新增新一次的审批人列表
|
|
|
+ // 获取当前次数审批人列表
|
|
|
+ const auditList = await this.ctx.service.changeAudit.getListGroupByTimes(changeInfo.cid, changeInfo.times);
|
|
|
+ const lastauditInfo = await this.ctx.service.changeAudit.getLastUser(changeInfo.cid, changeInfo.times, 1, 0);
|
|
|
+ let usort = lastauditInfo.usort + 1;
|
|
|
+ const newTimes = changeInfo.times + 1;
|
|
|
+ const insert_audit_array = [];
|
|
|
+ for (const al of auditList) {
|
|
|
+ const insert_audit = {
|
|
|
+ tid: al.tid,
|
|
|
+ cid: al.cid,
|
|
|
+ uid: al.uid,
|
|
|
+ name: al.name,
|
|
|
+ jobs: al.jobs,
|
|
|
+ company: al.company,
|
|
|
+ times: newTimes,
|
|
|
+ usite: al.usite,
|
|
|
+ usort,
|
|
|
+ status: al.usite !== 0 ? 1 : 2,
|
|
|
+ };
|
|
|
+ insert_audit_array.push(insert_audit);
|
|
|
+ usort++;
|
|
|
+ }
|
|
|
+ await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit_array);
|
|
|
+ // 设置变更令退回
|
|
|
+ const change_update = {
|
|
|
+ w_code: postData.w_code,
|
|
|
+ status: 5,
|
|
|
+ times: newTimes,
|
|
|
+ cin_time: Date.parse(new Date()) / 1000,
|
|
|
+ };
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: postData.change_id,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.tableName, change_update, options);
|
|
|
+ await this.transaction.commit();
|
|
|
+ result = true;
|
|
|
+ } catch (error) {
|
|
|
+ await this.transaction.rollback();
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批退回到上一个审批人
|
|
|
+ * @param {int} postData - 表单提交的数据
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async approvalBackNew(postData) {
|
|
|
+ // 初始化事务
|
|
|
+ this.transaction = await this.db.beginTransaction();
|
|
|
+ let result = false;
|
|
|
+ try {
|
|
|
+ const changeInfo = await this.getDataByCondition({ cid: postData.change_id });
|
|
|
+ // 设置审批人退回
|
|
|
+ const audit_update = {
|
|
|
+ id: postData.audit_id,
|
|
|
+ sdesc: postData.sdesc,
|
|
|
+ status: 6,
|
|
|
+ sin_time: new Date(),
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
|
|
|
+ // 获取当前审批人信息
|
|
|
+ const auditInfo = await this.ctx.service.changeAudit.getDataById(postData.audit_id);
|
|
|
+
|
|
|
+ // 获取当前次数审批人列表
|
|
|
+ const auditList = await this.ctx.service.changeAudit.getNextAuditList(changeInfo.cid, auditInfo.usort);
|
|
|
+
|
|
|
+ let usort = auditInfo.usort + 1;
|
|
|
+
|
|
|
+ // 获取上一个审批人信息
|
|
|
+ const lastauditInfo = await this.ctx.service.changeAudit.getDataById(postData.audit_last_id);
|
|
|
+
|
|
|
+ // 新增2个审批人到审批列表中
|
|
|
+ const insert_audit1 = {
|
|
|
+ tid: lastauditInfo.tid,
|
|
|
+ cid: lastauditInfo.cid,
|
|
|
+ uid: lastauditInfo.uid,
|
|
|
+ name: lastauditInfo.name,
|
|
|
+ jobs: lastauditInfo.jobs,
|
|
|
+ company: lastauditInfo.company,
|
|
|
+ times: lastauditInfo.times,
|
|
|
+ usite: lastauditInfo.usite,
|
|
|
+ usort,
|
|
|
+ status: 2,
|
|
|
+ };
|
|
|
+ await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit1);
|
|
|
+ usort++;
|
|
|
+ // 新增2个审批人到审批列表中
|
|
|
+ const insert_audit2 = {
|
|
|
+ tid: auditInfo.tid,
|
|
|
+ cid: auditInfo.cid,
|
|
|
+ uid: auditInfo.uid,
|
|
|
+ name: auditInfo.name,
|
|
|
+ jobs: auditInfo.jobs,
|
|
|
+ company: auditInfo.company,
|
|
|
+ times: auditInfo.times,
|
|
|
+ usite: auditInfo.usite,
|
|
|
+ usort,
|
|
|
+ status: 1,
|
|
|
+ };
|
|
|
+ await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit2);
|
|
|
+
|
|
|
+ // 把接下未审批的审批人排序都加2
|
|
|
+ for (const al of auditList) {
|
|
|
+ const audit_update = {
|
|
|
+ id: al.id,
|
|
|
+ usort: al.usort + 2,
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.ctx.service.changeAudit.tableName, audit_update);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 审批列表数据也要回退
|
|
|
+ const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: changeInfo.cid } });
|
|
|
+ for (const cl of changeList) {
|
|
|
+ const audit_amount = cl.audit_amount.split(',');
|
|
|
+ audit_amount.splice(-1, 1);
|
|
|
+ const list_update = {
|
|
|
+ id: cl.id,
|
|
|
+ audit_amount: audit_amount.join(','),
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置变更令退回
|
|
|
+ const change_update = {
|
|
|
+ w_code: postData.w_code,
|
|
|
+ status: 6,
|
|
|
+ cin_time: Date.parse(new Date()) / 1000,
|
|
|
+ };
|
|
|
+ const options = {
|
|
|
+ where: {
|
|
|
+ cid: postData.change_id,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ await this.transaction.update(this.tableName, change_update, options);
|
|
|
+ await this.transaction.commit();
|
|
|
+ result = true;
|
|
|
+ } catch (error) {
|
|
|
+ await this.transaction.rollback();
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
return Change;
|
|
|
};
|