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

feat(weapp): 重构修订相关接口,添加修订列表和详情查询功能

lanjianrong 2 дней назад
Родитель
Сommit
1ec88b154b
3 измененных файлов с 140 добавлено и 152 удалено
  1. 0 60
      app/controller/weapp_revise_controller.js
  2. 137 89
      app/controller/weapp_tender_controller.js
  3. 3 3
      app/router.js

+ 0 - 60
app/controller/weapp_revise_controller.js

@@ -1,60 +0,0 @@
-'use strict';
-
-const audit = require('../const/audit');
-
-module.exports = app => {
-    class WeappReviseController extends app.BaseController {
-
-        async index(ctx) {
-            try {
-                const tenderId = ctx.params.id;
-                const show_revise_invalid = 0;
-                const ledgerRevise = await ctx.service.ledgerRevise.getReviseList(tenderId, show_revise_invalid);
-                ctx.body = { code: 0, msg: '', data: ledgerRevise };
-            } catch (err) {
-                this.log(err);
-                ctx.body = { code: -1, msg: err.toString(), data: null };
-            }
-        }
-
-        async check(ctx) {
-            try {
-                const reviseId = ctx.params.rid;
-                const revise = await ctx.service.ledgerRevise.getDataById(reviseId);
-                if (!revise) {
-                    ctx.body = { code: -1, msg: '修订不存在', data: null };
-                    return;
-                }
-                if (revise.status !== audit.revise.status.checking) {
-                    ctx.body = {
-                        code: -1,
-                        msg: `修订状态不正确,当前状态为"${audit.revise.statusString[revise.status] || '未知'}",无法审批`,
-                        data: { currentStatus: revise.status }
-                    };
-                    return;
-                }
-                revise.curHis = revise.his_id ? await ctx.service.ledgerHistory.getDataById(revise.his_id) : null;
-                const curAudits = await ctx.service.reviseAudit.getCurAuditors(revise.id, revise.times);
-                const curAuditorIds = curAudits.map(x => { return x.audit_id; });
-                if (curAuditorIds.indexOf(ctx.session.sessionUser.accountId) < 0) {
-                    ctx.body = { code: -1, msg: '您不是当前审批人,无权进行该操作', data: null };
-                    return;
-                }
-                const data = ctx.request.body;
-                const checkType = parseInt(data.checkType);
-                if (!checkType || isNaN(checkType)) {
-                    ctx.body = { code: -1, msg: '提交数据错误:缺少审批类型参数', data: null };
-                    return;
-                }
-                const opinion = data.opinion || '';
-                await ctx.service.reviseAudit.check(revise, checkType, opinion, revise.times);
-                ctx.body = { code: 0, msg: '审批成功', data: null };
-            } catch (err) {
-                ctx.body = { code: -1, msg: err.toString(), data: null };
-            }
-        }
-
-    }
-
-    return WeappReviseController;
-};

+ 137 - 89
app/controller/weapp_tender_controller.js

@@ -295,95 +295,6 @@ module.exports = app => {
             }
         }
 
-        async reviseDetail(ctx) {
-            try {
-                const { rid } = ctx.query;
-                const revise = rid
-                    ? await ctx.service.ledgerRevise.getRevise(ctx.tender.id, rid)
-                    : ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
-                revise.preHis = revise.pre_his_id ? await ctx.service.ledgerHistory.getDataById(revise.pre_his_id) : null;
-                revise.curHis = revise.his_id ? await ctx.service.ledgerHistory.getDataById(revise.his_id) : null;
-                await ctx.service.reviseAudit.loadReviseUser(revise);
-                await ctx.service.reviseAudit.loadReviseAuditViewData(revise);
-
-                revise.auditHistory = revise.auditors.reduce((prev, curr, idx) => {
-                    if (idx === 0) {
-                        const reportor = {
-                            audit_id: revise.uid,
-                            audit_order: 0,
-                            audit_type: 1,
-                            status: revise.status === auditConst.revise.status.uncheck ? auditConst.revise.status.uncheck : auditConst.revise.status.checked,
-                            times: curr.times,
-                            begin_time: revise.in_time,
-                            end_time: revise.auditors.length ? revise.auditors[0].begin_time : null,
-                            name: revise.user.name,
-                            company: revise.user.company,
-                            role: revise.user.role,
-                            mobile: '',
-                            opinion: '',
-
-                        };
-                        prev.push({
-                            name: '原报',
-                            status: reportor.status,
-                            audit_type: reportor.audit_type,
-                            auditors: [reportor],
-                        });
-                    }
-                    const currentOrder = curr.audit_order;
-                    prev.push(
-                        {
-                            name: currentOrder === curr.max_sort ? '终审' : `${currentOrder}审`,
-                            status: curr.status,
-                            audit_type: 1,
-                            auditors: [{
-                                audit_id: curr.audit_id,
-                                audit_order: curr.audit_order,
-                                audit_type: curr.audit_type,
-                                status: curr.status,
-                                max_sort: curr.max_sort,
-                                begin_time: curr.begin_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;
-                }, []);
-
-                const GclGather = require('../lib/gcl_gather');
-                const gclGatherModal = new GclGather.gclCompareGather(this.ctx);
-                const spec = { zlj: stdConst.zlj, jrg: stdConst.jrg };
-                spec.zlj.deal_bills_tp = ctx.tender.info.deal_param.zanLiePrice;
-                gclGatherModal.init(ctx.tender.info.chapter, spec);
-                const reviseBillsData = revise.readOnly && revise.curHis
-                    ? await ctx.helper.loadLedgerDataFromOss(revise.curHis.bills_file)
-                    : await ctx.service.reviseBills.getAllDataByCondition({ where: { tender_id: ctx.tender.id } });
-                const revisePosData = revise.readOnly && revise.curHis
-                    ? await this.ctx.helper.loadLedgerDataFromOss(revise.curHis.pos_file)
-                    : await ctx.service.revisePos.getAllDataByCondition({ where: { tid: ctx.tender.id } });
-                const price = await this.ctx.service.revisePrice.getAllDataByCondition({ where: { rid: revise.id } });
-                gclGatherModal.gatherReviseLedgerData(reviseBillsData, revisePosData, { prefix: 'new_' }, price, ctx.tender.info.decimal);
-                const billsData = revise.preHis ? await this.ctx.helper.loadLedgerDataFromOss(revise.preHis.bills_file) : [];
-                const posData = revise.preHis ? await this.ctx.helper.loadLedgerDataFromOss(revise.preHis.pos_file) : [];
-                gclGatherModal.gatherLedgerData(billsData, posData, { prefix: 'org_' });
-                revise.chapterList = gclGatherModal.chapterData();
-                revise.new_tp = gclGatherModal.otherChapter.hj.new_total_price || 0;
-                revise.org_tp = gclGatherModal.otherChapter.hj.org_total_price || 0;
-                console.log(ctx.tender.data.name);
-                revise.tenderName = ctx.tender.data.name;
-                ctx.body = { code: 0, msg: '', data: { revise } };
-            } catch (error) {
-                ctx.log(error);
-                ctx.body = { code: -1, msg: error.toString(), data: null };
-            }
-        }
-
         async ledgerAuditCheck(ctx) {
             const tender = ctx.tender.data;
             const info = ctx.tender.info;
@@ -779,6 +690,143 @@ module.exports = app => {
                 ctx.body = { code: -1, msg: error.toString(), data: null };
             }
         }
+
+        async reviseList(ctx) {
+            try {
+                const tenderId = ctx.tender.id;
+                const show_revise_invalid = 0;
+                const ledgerRevise = await ctx.service.ledgerRevise.getReviseList(tenderId, show_revise_invalid);
+                ctx.body = { code: 0, msg: '', data: ledgerRevise };
+            } catch (err) {
+                this.log(err);
+                ctx.body = { code: -1, msg: err.toString(), data: null };
+            }
+        }
+
+        async reviseDetail(ctx) {
+            try {
+                const { rid } = ctx.query;
+                const revise = rid
+                    ? await ctx.service.ledgerRevise.getRevise(ctx.tender.id, rid)
+                    : ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
+                revise.preHis = revise.pre_his_id ? await ctx.service.ledgerHistory.getDataById(revise.pre_his_id) : null;
+                revise.curHis = revise.his_id ? await ctx.service.ledgerHistory.getDataById(revise.his_id) : null;
+                await ctx.service.reviseAudit.loadReviseUser(revise);
+                await ctx.service.reviseAudit.loadReviseAuditViewData(revise);
+
+                revise.auditHistory = revise.auditors.reduce((prev, curr, idx) => {
+                    if (idx === 0) {
+                        const reportor = {
+                            audit_id: revise.uid,
+                            audit_order: 0,
+                            audit_type: 1,
+                            status: revise.status === auditConst.revise.status.uncheck ? auditConst.revise.status.uncheck : auditConst.revise.status.checked,
+                            times: curr.times,
+                            begin_time: revise.in_time,
+                            end_time: revise.auditors.length ? revise.auditors[0].begin_time : null,
+                            name: revise.user.name,
+                            company: revise.user.company,
+                            role: revise.user.role,
+                            mobile: '',
+                            opinion: '',
+
+                        };
+                        prev.push({
+                            name: '原报',
+                            status: reportor.status,
+                            audit_type: reportor.audit_type,
+                            auditors: [reportor],
+                        });
+                    }
+                    const currentOrder = curr.audit_order;
+                    prev.push(
+                        {
+                            name: currentOrder === curr.max_sort ? '终审' : `${currentOrder}审`,
+                            status: curr.status,
+                            audit_type: 1,
+                            auditors: [{
+                                audit_id: curr.audit_id,
+                                audit_order: curr.audit_order,
+                                audit_type: curr.audit_type,
+                                status: curr.status,
+                                max_sort: curr.max_sort,
+                                begin_time: curr.begin_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;
+                }, []);
+
+                const GclGather = require('../lib/gcl_gather');
+                const gclGatherModal = new GclGather.gclCompareGather(this.ctx);
+                const spec = { zlj: stdConst.zlj, jrg: stdConst.jrg };
+                spec.zlj.deal_bills_tp = ctx.tender.info.deal_param.zanLiePrice;
+                gclGatherModal.init(ctx.tender.info.chapter, spec);
+                const reviseBillsData = revise.readOnly && revise.curHis
+                    ? await ctx.helper.loadLedgerDataFromOss(revise.curHis.bills_file)
+                    : await ctx.service.reviseBills.getAllDataByCondition({ where: { tender_id: ctx.tender.id } });
+                const revisePosData = revise.readOnly && revise.curHis
+                    ? await this.ctx.helper.loadLedgerDataFromOss(revise.curHis.pos_file)
+                    : await ctx.service.revisePos.getAllDataByCondition({ where: { tid: ctx.tender.id } });
+                const price = await this.ctx.service.revisePrice.getAllDataByCondition({ where: { rid: revise.id } });
+                gclGatherModal.gatherReviseLedgerData(reviseBillsData, revisePosData, { prefix: 'new_' }, price, ctx.tender.info.decimal);
+                const billsData = revise.preHis ? await this.ctx.helper.loadLedgerDataFromOss(revise.preHis.bills_file) : [];
+                const posData = revise.preHis ? await this.ctx.helper.loadLedgerDataFromOss(revise.preHis.pos_file) : [];
+                gclGatherModal.gatherLedgerData(billsData, posData, { prefix: 'org_' });
+                revise.chapterList = gclGatherModal.chapterData();
+                revise.new_tp = gclGatherModal.otherChapter.hj.new_total_price || 0;
+                revise.org_tp = gclGatherModal.otherChapter.hj.org_total_price || 0;
+                revise.tenderName = ctx.tender.data.name;
+                ctx.body = { code: 0, msg: '', data: { revise } };
+            } catch (error) {
+                ctx.log(error);
+                ctx.body = { code: -1, msg: error.toString(), data: null };
+            }
+        }
+
+        async reviseCheck(ctx) {
+            try {
+                const reviseId = ctx.params.rid;
+                const revise = await ctx.service.ledgerRevise.getDataById(reviseId);
+                if (!revise) {
+                    ctx.body = { code: -1, msg: '修订不存在', data: null };
+                    return;
+                }
+                if (revise.status !== audit.revise.status.checking) {
+                    ctx.body = {
+                        code: -1,
+                        msg: `修订状态不正确,当前状态为"${audit.revise.statusString[revise.status] || '未知'}",无法审批`,
+                        data: { currentStatus: revise.status }
+                    };
+                    return;
+                }
+                revise.curHis = revise.his_id ? await ctx.service.ledgerHistory.getDataById(revise.his_id) : null;
+                const curAudits = await ctx.service.reviseAudit.getCurAuditors(revise.id, revise.times);
+                const curAuditorIds = curAudits.map(x => { return x.audit_id; });
+                if (curAuditorIds.indexOf(ctx.session.sessionUser.accountId) < 0) {
+                    ctx.body = { code: -1, msg: '您不是当前审批人,无权进行该操作', data: null };
+                    return;
+                }
+                const data = ctx.request.body;
+                const checkType = parseInt(data.checkType);
+                if (!checkType || isNaN(checkType)) {
+                    ctx.body = { code: -1, msg: '提交数据错误:缺少审批类型参数', data: null };
+                    return;
+                }
+                const opinion = data.opinion || '';
+                await ctx.service.reviseAudit.check(revise, checkType, opinion, revise.times);
+                ctx.body = { code: 0, msg: '审批成功', data: null };
+            } catch (err) {
+                ctx.body = { code: -1, msg: err.toString(), data: null };
+            }
+        }
     }
 
     return WeappTenderController;

+ 3 - 3
app/router.js

@@ -1250,8 +1250,9 @@ module.exports = app => {
     app.post('/wx/weapp/attention/unfollow', weappAuth, 'weappAttentionController.unfollow');
     app.get('/wx/weapp/attention/list', weappAuth, 'weappAttentionController.followedList');
     app.get('/wx/weapp/attention/check', weappAuth, 'weappAttentionController.checkFollowing');
-    app.get('/wx/weapp/tender/:id/revise', weappAuth, 'weappReviseController.index');
-    app.post('/wx/weapp/tender/:tenderId/revise/:rid/check', weappAuth, weappTenderCheck, 'weappReviseController.check');
+    app.get('/wx/weapp/revise/list', weappAuth, weappTenderCheck, 'weappTenderController.reviseList');
+    app.post('/wx/weapp/revise/check', weappAuth, weappTenderCheck, 'weappTenderController.reviseCheck');
+    app.get('/wx/weapp/revise/detail', weappAuth, weappTenderCheck, 'weappTenderController.reviseDetail');
     app.get('/wx/weapp/tender/detail', weappAuth, weappTenderCheck, 'weappTenderController.detail');
     app.get('/wx/weapp/tender/list/manage', weappAuth, 'weappTenderController.listManage');
     app.get('/wx/weapp/tender/measure/stage', weappAuth, weappTenderCheck, 'weappMeasureController.stage');
@@ -1259,7 +1260,6 @@ module.exports = app => {
     app.post('/wx/weapp/tender/measure/stage/audit/check', weappAuth, weappTenderCheck, 'weappMeasureController.checkAudit');
     app.get('/wx/weapp/advance/list', weappAuth, weappTenderCheck, 'weappTenderController.advanceList');
     app.get('/wx/weapp/advance/detail', weappAuth, weappTenderCheck, 'weappTenderController.advanceDetail');
-    app.get('/wx/weapp/revise/detail', weappAuth, weappTenderCheck, 'weappTenderController.reviseDetail');
     app.post('/wx/weapp/advance/audit', weappAuth, weappTenderCheck, 'weappTenderController.advanceAudit');
     app.get('/wx/weapp/ledger/detail', weappAuth, weappTenderCheck, 'weappTenderController.ledgerDetail');
     app.post('/wx/weapp/ledger/audit', weappAuth, weappTenderCheck, 'weappTenderController.ledgerAudit');