Просмотр исходного кода

fix(weapp): 变更令审批功能

lanjianrong 4 дней назад
Родитель
Сommit
5fc216bba5
2 измененных файлов с 72 добавлено и 28 удалено
  1. 1 1
      app/const/weapp.js
  2. 71 27
      app/controller/weapp_tender_controller.js

+ 1 - 1
app/const/weapp.js

@@ -12,7 +12,7 @@ const redisExpire = 7 * 24 * 3600; // Redis 7天
 const changeMap = {
     change: {
         service: 'change',
-        auditService: 'changeAudit',
+        auditService: 'change',
         idKey: 'cid',
         pageShowKey: '',
     },

+ 71 - 27
app/controller/weapp_tender_controller.js

@@ -522,13 +522,13 @@ module.exports = app => {
                     subProject.page_show = JSON.parse(subProject.page_show);
                 };
                 if (curChangeMap && curChangeMap.pageShowKey && !subProject.page_show[curChangeMap.pageShowKey]) {
-
                     throw '该功能已关闭';
                 }
                 const id = ctx.request.query.id || ctx.request.body.id;
                 if (!id) {
                     throw '您访问的变更数据不存在';
                 }
+
                 const condition = { [curChangeMap.idKey]: id };
                 const change = await ctx.service[curChangeMap.service].getDataByCondition(condition);
 
@@ -583,8 +583,8 @@ module.exports = app => {
                 // 调差的readOnly 指表格和页面只能看不能改,和审批无关
                 change.readOnly = !((change.status === status.uncheck || change.status === status.checkNo || change.status === status.revise) && accountId === change.uid);
                 change.shenpiPower = change.status === status.checking && change.curAuditorIds.indexOf(accountId) !== -1;
-                this.change = change;
-                await ctx.service[curChangeMap.service].doCheckChangeCanCancel(this.change);
+                ctx.change = change;
+                await ctx.service[curChangeMap.service].doCheckChangeCanCancel(ctx.change);
             } catch (error) {
                 this.log(error);
             }
@@ -600,7 +600,7 @@ module.exports = app => {
                 const subProject = await ctx.service.subProject.getDataById(ctx.tender.data.spid);
                 const fun_set = subProject.fun_set;
 
-                const auditHistory = this.change.auditHistory && this.change.auditHistory.length && this.change.auditHistory[this.change.auditHistory.length - 1].reduce((prev, curr, idx) => {
+                const auditHistory = ctx.change.auditHistory && ctx.change.auditHistory.length && ctx.change.auditHistory[ctx.change.auditHistory.length - 1].reduce((prev, curr, idx) => {
                     prev.push({
                         name: curr.is_final ? '终审' : curr.audit_order === 0 ? '原报' : `${curr.audit_order}审`,
                         audit_type: curr.audit_type,
@@ -609,26 +609,25 @@ module.exports = app => {
                     });
                     return prev;
                 }, []);
-                const curAuditors = this.change.curAuditors;
+                const curAuditors = ctx.change.curAuditors;
 
                 const change = {
-                    id: this.change.id || this.change.cid,
+                    id: ctx.change.id || ctx.change.cid,
                     tid: ctx.tender.id,
-                    name: this.change.name,
-                    status: this.change.status,
-                    code: this.change.code,
-                    p_code: this.change.p_code,
-                    quality: this.change.quality,
+                    name: ctx.change.name,
+                    status: ctx.change.status,
+                    code: ctx.change.code,
+                    p_code: ctx.change.p_code,
+                    quality: ctx.change.quality,
                     auditHistory,
-                    originHistory: this.change.auditHistory,
                     curAuditors: curAuditors.map(a => ({...a, audit_id: a.uid})),
-                    total_price: ctx.helper.add(this.change.total_price, tpUnit),
-                    valuation_tp: ctx.helper.add(this.change.valuation_tp, tpUnit),
-                    unvaluation_tp: ctx.helper.add(this.change.unvaluation_tp, tpUnit),
-                    state_name: subProject.page_show.openChangeState ? ctx.helper._.find(fun_set.change_state, { order: this.change.state }).name : '',
-                    plan_code: this.change.plan_code,
-                    peg: this.change.peg,
-                    org_name: this.change.org_name,
+                    total_price: ctx.helper.add(ctx.change.total_price, tpUnit),
+                    valuation_tp: ctx.helper.add(ctx.change.valuation_tp, tpUnit),
+                    unvaluation_tp: ctx.helper.add(ctx.change.unvaluation_tp, tpUnit),
+                    state_name: subProject.page_show.openChangeState ? ctx.helper._.find(fun_set.change_state, { order: ctx.change.state }).name : '',
+                    plan_code: ctx.change.plan_code,
+                    peg: ctx.change.peg,
+                    org_name: ctx.change.org_name,
                 };
 
                 ctx.body = { code: 0, msg: '', data: {
@@ -647,13 +646,15 @@ module.exports = app => {
             }
             const type = ctx.request.body.type;
             const curChangeMap = changeMap[type];
-            if (!this.change) {
-                const change = await this.service[curChangeMap.service].getDataById(id);
+            if (!ctx.change) {
+                const change = await this.service[curChangeMap.service].getDataByCondition({
+                    [curChangeMap.idKey]: id,
+                });
                 if (!change) throw '变更数据有误';
                 await this.service[curChangeMap.service].loadChangeUser(change);
-                this.change = change;
+                ctx.change = change;
             }
-            const change = this.change;
+            const change = ctx.change;
             const status = auditConst[type].status;
             if ((change.status === status.uncheck || change.status === status.checkNo || change.status === status.revise) && ctx.tender.info.shenpi.change !== shenpiConst.sp_status.sqspr) {
                 const shenpi_status = ctx.tender.info.shenpi.change;
@@ -711,10 +712,10 @@ module.exports = app => {
 
         async changeAudit(ctx) {
             try {
-                const { type } = ctx.request.body;
-                await this.changeCheck(ctx);
-                await this.changeAuditCheck(ctx);
+                const type = ctx.request.body.type;
                 const curChangeMap = changeMap[type];
+                await this.changeCheck(ctx, curChangeMap);
+                await this.changeAuditCheck(ctx);
                 if (!ctx.change || ctx.change.status !== auditConst[type].status.checking) {
                     throw '当前变更申请数据有误';
                 }
@@ -728,7 +729,50 @@ module.exports = app => {
                 if (!data.checkType || isNaN(data.checkType)) {
                     throw '提交数据错误';
                 }
-                await ctx.service[curChangeMap.auditService].check(ctx.change.id, data, ctx.change.times);
+                if (curChangeMap.auditService === 'change') {
+                    // 单独处理变更令审批
+                    const status = parseInt(data.checkType);
+                    // 判断是否到你审批,如果不是则无法审批
+                    const curAuditor = await ctx.service.changeAudit.getCurAuditors(ctx.change.cid, ctx.change.times);
+                    if (!curAuditor || (curAuditor && ctx.helper._.findIndex(curAuditor, { uid: ctx.session.sessionUser.accountId }) === -1)) {
+                        throw '该变更令当前您无权操作';
+                    }
+                    const readySettle = await ctx.service.settle.getReadySettle(ctx.change.tid);
+                    if (readySettle && readySettle.settle_order !== ctx.tender.data.settle_order) {
+                        throw '结算数据发生变化,请刷新页面再提交';
+                    }
+                    let result = false;
+                    const pid = this.ctx.session.sessionProject.id;
+                    const checkData = {
+                        checkType: status,
+                        sdesc: data.opinion,
+                        w_code: ctx.request.body.w_code
+                    }
+                    switch (status) {
+                        case 3:// 审批通过
+                            const revising = await ctx.service.change.checkRevising(ctx.change.tid, ctx.change.cid);
+                            if (revising) {
+                                throw '台账修订中并本变更令存在新增清单,无法审批通过';
+                            }
+                            result = await ctx.service.change.approvalSuccess(pid, checkData, ctx.change);
+                            break;
+                        // case 4:// 审批终止
+                        //     result = await ctx.service.change.approvalStop(ctx.request.body);
+                        //     break;
+                        case 5:// 审批退回到原报人
+                            result = await ctx.service.change.approvalCheckNo(pid, checkData, ctx.change);
+                            break;
+                        case 6:// 审批退回到上一个审批人
+                            result = await ctx.service.change.approvalCheckNoPre(pid, checkData, ctx.change);
+                            break;
+                        default:break;
+                    }
+                    if (!result) {
+                        throw '审批失败';
+                    }
+                } else {
+                  await ctx.service[curChangeMap.auditService].check(ctx.change.id, data, ctx.change.times);
+                }
                 ctx.body = { code: 0, msg: '操作成功', data: null };
             } catch (error) {
                 this.log(error);