|
|
@@ -2,6 +2,9 @@
|
|
|
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 _ = require('lodash');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class WeappTenderController extends app.BaseController {
|
|
|
@@ -141,18 +144,58 @@ module.exports = app => {
|
|
|
|
|
|
async advanceDetail(ctx) {
|
|
|
try {
|
|
|
- // const { advanceType } = ctx.query;
|
|
|
- // const typeCol = advanceConst.typeCol.find(x => x.type === Number(advanceType));
|
|
|
- // if (!typeCol) {
|
|
|
- // ctx.body = { code: -1, msg: '预付款类型错误', data: null };
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // const tenderInfo = await this.service.tenderInfo.getTenderInfo(ctx.tender.id);
|
|
|
- // const { decimal } = tenderInfo;
|
|
|
- // this.decimal = decimal.pay ? decimal.payTp : decimal.tp;
|
|
|
- // const advancePayTotal = ctx.tender.info.deal_param[typeCol.key + 'Advance'];
|
|
|
- // const advances = await ctx.service.advance.getAdvanceList(ctx.tender.id, typeCol.type, this.decimal, advancePayTotal);
|
|
|
- ctx.body = { code: 0, msg: '', data: {} };
|
|
|
+ const { id } = ctx.query;
|
|
|
+ const advance = await this.service.advance.getDataById(id);
|
|
|
+ if (!advance) {
|
|
|
+ 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) && this.tender.info.shenpi.advance !== shenpiConst.sp_status.sqspr) {
|
|
|
+ const shenpi_status = this.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.tender.info.shenpi.advance = shenpiConst.sp_status.sqspr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ // 因为上报人不在审核列表里面单独添加进去
|
|
|
+ // 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);
|
|
|
ctx.body = { code: -1, msg: error.toString(), data: null };
|