浏览代码

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

Tony Kang 11 月之前
父节点
当前提交
e968b2ce88

+ 2 - 1
app/controller/revise_controller.js

@@ -123,7 +123,8 @@ module.exports = app => {
                 }
                 for (const lr of ledgerRevise) {
                     if (lr.valid) {
-                        lr.curAuditor = await ctx.service.reviseAudit.getAuditorByStatus(lr.id, lr.status, lr.times);
+                        lr.curAuditors = await ctx.service.reviseAudit.getAuditorsByStatus(lr.id, lr.status, lr.times);
+                        lr.curAuditorIds = lr.curAuditors.map(x => { return x.audit_id; });
                     }
                 }
                 const [addVisible, addValid, changeValid] = await this._getAddReviseValid(ctx);

+ 1 - 1
app/service/ledger_history.js

@@ -140,7 +140,7 @@ module.exports = app => {
                 pid: this.ctx.session.sessionProject.id, tid: revise.tid,
                 rid: revise.id, rorder: revise.corder,
                 in_time: now,
-                bills_file: billsHis, pos_file: posHis,
+                bills_file: billsHis, pos_file: posHis, valid: 0,
                 bills_count: bills.length, pos_count: pos.length,
             });
 

+ 135 - 93
app/service/revise_audit.js

@@ -440,8 +440,8 @@ module.exports = app => {
          */
         async start(revise, times = 1) {
             const audits = await this.getAllDataByCondition({ where: { rid: revise.id, times, audit_order: 1 } });
-            if (!audits.length === 0) {
-                if(this.ctx.tender.info.shenpi.revise === shenpiConst.sp_status.gdspl) {
+            if (audits.length === 0) {
+                if (this.ctx.tender.info.shenpi.revise === shenpiConst.sp_status.gdspl) {
                     throw '请联系管理员添加审批人';
                 } else {
                     throw '请先选择审批人,再上报数据';
@@ -603,101 +603,103 @@ module.exports = app => {
                             await transaction.updateRows(this.tableName, updateOther);
                         }
                     }
-                }
 
-                // 无下一审核人表示,审核结束
-                if (nextAuditors.length > 0) {
-                    const nextAuditUpdateData = nextAuditors.map(x => { return { id: x.id, status: auditConst.status.checking, begin_time: time }});
-                    await transaction.updateRows(this.tableName, nextAuditUpdateData);
-
-                    // 短信通知-需要审批提醒功能
-                    const nextAuditorIds = nextAuditors.map(x => { return x.audit_id; });
-                    await this.ctx.helper.sendAliSms(nextAuditorIds, smsTypeConst.const.XD, smsTypeConst.judge.approval.toString(), SmsAliConst.template.revise_check);
-                    // 微信模板通知
-                    const shenpiUrl = await this.ctx.helper.urlToShort(
-                        this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + revise.tid + '/revise/' + revise.id + '/info'
-                    );
-                    const wechatData = {
-                        wap_url: shenpiUrl,
-                        status: wxConst.status.check,
-                        tips: wxConst.tips.check,
-                        code: this.ctx.session.sessionProject.code,
-                        begin_time: Date.parse(revise.begin_time),
-                    };
-                    await this.ctx.helper.sendWechat(nextAuditorIds, smsTypeConst.const.XD, smsTypeConst.judge.approval.toString(), wxConst.template.revise, wechatData);
-                    for (const audit of nextAuditors) {
-                        await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.XD, {
-                            pid: this.ctx.session.sessionProject.id,
-                            tid: this.ctx.tender.id,
-                            uid: audit.audit_id,
-                            sp_type: 'revise',
-                            sp_id: audit.id,
-                            table_name: this.tableName,
-                            template: wxConst.template.revise,
-                            wx_data: wechatData,
+                    // 无下一审核人表示,审核结束
+                    if (nextAuditors.length > 0) {
+                        const nextAuditUpdateData = nextAuditors.map(x => { return { id: x.id, status: auditConst.status.checking, begin_time: time }});
+                        await transaction.updateRows(this.tableName, nextAuditUpdateData);
+
+                        // 短信通知-需要审批提醒功能
+                        const nextAuditorIds = nextAuditors.map(x => { return x.audit_id; });
+                        await this.ctx.helper.sendAliSms(nextAuditorIds, smsTypeConst.const.XD, smsTypeConst.judge.approval.toString(), SmsAliConst.template.revise_check);
+                        // 微信模板通知
+                        const shenpiUrl = await this.ctx.helper.urlToShort(
+                            this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + revise.tid + '/revise/' + revise.id + '/info'
+                        );
+                        const wechatData = {
+                            wap_url: shenpiUrl,
+                            status: wxConst.status.check,
+                            tips: wxConst.tips.check,
+                            code: this.ctx.session.sessionProject.code,
+                            begin_time: Date.parse(revise.begin_time),
+                        };
+                        await this.ctx.helper.sendWechat(nextAuditorIds, smsTypeConst.const.XD, smsTypeConst.judge.approval.toString(), wxConst.template.revise, wechatData);
+                        for (const audit of nextAuditors) {
+                            await this.ctx.service.noticeAgain.addNoticeAgain(transaction, smsTypeConst.const.XD, {
+                                pid: this.ctx.session.sessionProject.id,
+                                tid: this.ctx.tender.id,
+                                uid: audit.audit_id,
+                                sp_type: 'revise',
+                                sp_id: audit.id,
+                                table_name: this.tableName,
+                                template: wxConst.template.revise,
+                                wx_data: wechatData,
+                            });
+                        }
+                        const users = this._.map(auditList.filter(x => { return x.audit_id !== accountId}), 'audit_id');
+                        users.push(revise.uid);
+                        await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, {
+                            status: SmsAliConst.status.success,
                         });
-                    }
-                    const users = this._.map(auditList.filter(x => { return x.audit_id !== accountId}), 'audit_id');
-                    users.push(revise.uid);
-                    await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, {
-                        status: SmsAliConst.status.success,
-                    });
-                } else {
-                    // 同步修订信息
-                    await transaction.update(this.ctx.service.ledgerRevise.tableName, {
-                        id: revise.id, status: auditConst.status.checked, end_time: time,
-                    });
-                    await this.ctx.service.tenderTag.saveTenderTag(revise.tid, {revise_time: new Date()}, transaction);
-                    // 最新一期跟台账相关的缓存数据应过期
-                    const lastStage = await this.ctx.service.stage.getFlowLatestStage(revise.tid, true);
-                    const cacheTime = new Date();
-                    if (lastStage) {
-                        await transaction.update(this.ctx.service.stage.tableName, {
-                            id: lastStage.id,
-                            cache_time_l: cacheTime,
-                            cache_time_r: cacheTime,
+                    } else {
+                        // 修订历史设为有效
+                        if (revise.his_id) await transaction.update(this.ctx.service.ledgerHistory.tableName, { id: revise.his_id, valid: 1 });
+                        // 同步修订信息
+                        await transaction.update(this.ctx.service.ledgerRevise.tableName, {
+                            id: revise.id, status: auditConst.status.checked, end_time: time,
+                        });
+                        await this.ctx.service.tenderTag.saveTenderTag(revise.tid, {revise_time: new Date()}, transaction);
+                        // 最新一期跟台账相关的缓存数据应过期
+                        const lastStage = await this.ctx.service.stage.getFlowLatestStage(revise.tid, true);
+                        const cacheTime = new Date();
+                        if (lastStage) {
+                            await transaction.update(this.ctx.service.stage.tableName, {
+                                id: lastStage.id,
+                                cache_time_l: cacheTime,
+                                cache_time_r: cacheTime,
+                            });
+                        }
+                        // 重算台账、计量、工程变更
+                        const reviseCalc = new RevisePrice(this.ctx);
+                        const pcTp = await reviseCalc.calcRevise(revise, transaction);
+                        const sum = revise.sum || await this.ctx.service.reviseBills.addUp({
+                            tender_id: revise.tid, /* , is_leaf: true*/
+                        });
+                        await transaction.update(this.ctx.service.tender.tableName, {
+                            id: revise.tid,
+                            total_price: sum.total_price, deal_tp: sum.deal_tp,
                         });
+                        // 修订附件取消修订中标记
+                        await transaction.update(this.ctx.service.ledgerAtt.tableName, { revising: 0 }, { where: { revise_id: revise.id } });
+                        // 更新台账缓存
+                        await this.ctx.service.tenderCache.updateStageCache4Revise(transaction, revise.tid, sum, pcTp);
+                        // 清除变更新增部位maxLid缓存,防止树结构混乱
+                        await this.ctx.service.changeLedger._removeCacheMaxLid(revise.tid);
+
+                        // 短信通知-审批通过提醒功能
+                        await this.ctx.helper.sendAliSms(revise.uid, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result, {
+                            status: SmsAliConst.status.success,
+                        });
+                        const users = this._.pull(this._.map(auditList, 'audit_id'), revise.uid);
+                        await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, {
+                            status: SmsAliConst.status.success,
+                        });
+                        users.push(revise.uid);
+                        // 微信模板通知
+                        const shenpiUrl = await this.ctx.helper.urlToShort(
+                            this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + revise.tid + '/revise/' + revise.id + '/info'
+                        );
+                        const wechatData2 = {
+                            wap_url: shenpiUrl,
+                            status: wxConst.status.success,
+                            tips: wxConst.tips.success,
+                            begin_time: Date.parse(revise.begin_time),
+                            code: this.ctx.session.sessionProject.code,
+                        };
+                        await this.ctx.helper.sendWechat(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData2);
+                        // 审批通过 - 检查三方特殊推送
+                        await this.ctx.service.specMsg.addReviseMsg(transaction, pid, revise, pushOperate.ledger.checked);
                     }
-                    // 重算台账、计量、工程变更
-                    const reviseCalc = new RevisePrice(this.ctx);
-                    const pcTp = await reviseCalc.calcRevise(revise, transaction);
-                    const sum = revise.sum || await this.ctx.service.reviseBills.addUp({
-                        tender_id: revise.tid, /* , is_leaf: true*/
-                    });
-                    await transaction.update(this.ctx.service.tender.tableName, {
-                        id: revise.tid,
-                        total_price: sum.total_price, deal_tp: sum.deal_tp,
-                    });
-                    // 修订附件取消修订中标记
-                    await transaction.update(this.ctx.service.ledgerAtt.tableName, { revising: 0 }, { where: { revise_id: revise.id } });
-                    // 更新台账缓存
-                    await this.ctx.service.tenderCache.updateStageCache4Revise(transaction, revise.tid, sum, pcTp);
-                    // 清除变更新增部位maxLid缓存,防止树结构混乱
-                    await this.ctx.service.changeLedger._removeCacheMaxLid(revise.tid);
-
-                    // 短信通知-审批通过提醒功能
-                    await this.ctx.helper.sendAliSms(revise.uid, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result, {
-                        status: SmsAliConst.status.success,
-                    });
-                    const users = this._.pull(this._.map(auditList, 'audit_id'), revise.uid);
-                    await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, {
-                        status: SmsAliConst.status.success,
-                    });
-                    users.push(revise.uid);
-                    // 微信模板通知
-                    const shenpiUrl = await this.ctx.helper.urlToShort(
-                        this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + revise.tid + '/revise/' + revise.id + '/info'
-                    );
-                    const wechatData2 = {
-                        wap_url: shenpiUrl,
-                        status: wxConst.status.success,
-                        tips: wxConst.tips.success,
-                        begin_time: Date.parse(revise.begin_time),
-                        code: this.ctx.session.sessionProject.code,
-                    };
-                    await this.ctx.helper.sendWechat(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData2);
-                    // 审批通过 - 检查三方特殊推送
-                    await this.ctx.service.specMsg.addReviseMsg(transaction, pid, revise, pushOperate.ledger.checked);
                 }
                 await transaction.commit();
             } catch (err) {
@@ -976,6 +978,46 @@ module.exports = app => {
         }
 
         /**
+         * 获取最新的审批人状态
+         *
+         * @param {Number} rid - 修订id
+         * @param {Number} status - 修订状态
+         * @param {Number} times - 修订次数
+         * @return {Promise<boolean>}
+         */
+        async getAuditorsByStatus(rid, status, times = 1) {
+            let cur;
+            let sql = '';
+            let sqlParam = '';
+            switch (status) {
+                case auditConst.status.checking:
+                case auditConst.status.checked:
+                case auditConst.status.checkNoPre:
+                    cur = await this.db.queryOne(`SELECT * From ${this.tableName} where rid = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`audit_order` DESC', [rid, times, status]);
+                    if (!cur) return [];
+
+                    sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.audit_order, la.audit_type, la.audit_ledger_id ' +
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
+                        '  WHERE la.rid = ? and la.`audit_order` = ? and la.`times` = ?';
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, cur.audit_order, times];
+                    return await this.db.query(sql, sqlParam);
+                case auditConst.status.checkNo:
+                    cur = await this.db.queryOne(`SELECT * From ${this.tableName} where rid = ? AND times = ? AND status = ? ORDER By times DESC, ` + '`audit_order` DESC', [rid, parseInt(times) - 1, status]);
+                    if (!cur) return [];
+
+                    sql = 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`tender_id`, la.audit_order, la.audit_type, la.audit_ledger_id ' +
+                        '  FROM ?? AS la Left Join ?? AS pa On la.`audit_id` = pa.`id` ' +
+                        '  WHERE la.rid = ? and la.`audit_order` = ? and la.`times` = ?';
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, cur.audit_order, parseInt(times) - 1];
+                    return await this.db.query(sql, sqlParam);
+                case auditConst.status.uncheck:
+                    return [];
+                default:
+                    return [];
+            }
+        }
+
+        /**
          * 获取审核人流程列表
          *
          * @param auditorId

+ 3 - 3
app/service/rpt_stage_sum_memory.js

@@ -53,8 +53,8 @@ module.exports = app => {
                     : await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, stage.id);
                 const bpcStage = await this.ctx.service.stageBillsPc.getAllDataByCondition({ where: { sid: stage.id } });
                 this.ctx.helper.assignRelaData(billsData, [
-                    {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp'], prefix: prefix, relaId: 'lid', defaultData},
-                    {data: bpcStage, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp'], prefix: prefix, relaId: 'lid', defaultData},
+                    {data: curStage, fields: ['contract_qty', 'contract_tp', 'contract_expr', 'qc_qty', 'qc_tp', 'postil'], prefix: prefix, relaId: 'lid', defaultData},
+                    {data: bpcStage, fields: ['contract_pc_tp', 'qc_pc_tp', 'pc_tp', 'postil'], prefix: prefix, relaId: 'lid', defaultData},
                 ]);
             }
 
@@ -104,7 +104,7 @@ module.exports = app => {
                     ? await this.ctx.service.stagePos.getAuditorStageData2(this.ctx.tender.id, stage.id, stage.curTimes, stage.curOrder)
                     : await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, stage.id);
                 this.ctx.helper.assignRelaData(posData, [
-                    {data: curStage, fields: ['contract_qty', 'qc_qty'], prefix: prefix, relaId: 'pid', defaultData},
+                    {data: curStage, fields: ['contract_qty', 'qc_qty', 'postil'], prefix: prefix, relaId: 'pid', defaultData},
                 ]);
             }
             posData.forEach(x => {

+ 7 - 2
app/view/revise/index.ejs

@@ -66,7 +66,12 @@
                         <% } else { %>
                         <td class="<%- auditConst.auditProgressClass[lr.status] %>">
                             <% if (lr.curAuditor) { %>
-                                <a href="#sp-list" data-toggle="modal" data-target="#sp-list" lr-id="<%- lr.id %>"><%- lr.curAuditor.name %><%if (lr.curAuditor.role !== '' && lr.curAuditor.role !== null) { %>-<%- lr.curAuditor.role %><% } %></a>
+                            <% const curAuditor = lr.curAuditors[0]; %>
+                            <% if (curAuditor.audit_type === auditType.key.common) { %>
+                            <a href="#sp-list" data-toggle="modal" data-target="#sp-list" lr-id="<%- lr.id %>"><%- curAuditor.name %><%if (curAuditor.role !== '' && curAuditor.role !== null) { %>-<%- curAuditor.role %><% } %></a>
+                            <% } else { %>
+                            <a href="#sp-list" data-toggle="modal" data-target="#sp-list" lr-id="<%- lr.id %>"><%- ctx.helper.transFormToChinese(curAuditor.audit_order) + '审' %></a>
+                            <% } %>
                             <% } %>
                             <%- auditConst.auditProgress[lr.status] %>
                         </td>
@@ -77,7 +82,7 @@
                             <% if (lr.status === auditConst.status.uncheck && lr.uid === ctx.session.sessionUser.accountId) { %>
                             <a href="<%- preUrl + '/revise/' + lr.id + '/info' %>" class="btn btn-primary btn-sm">修订</a>
                             <a href="#remove" data-toggle="modal" data-target="#remove" class="btn btn-secondary btn-sm">作废</a>
-                            <% } else if (lr.status === auditConst.status.checking && lr.curAuditor.audit_id === ctx.session.sessionUser.accountId) { %>
+                            <% } else if (lr.status === auditConst.status.checking && lr.curAuditorIds && lr.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) >= 0) { %>
                             <a href="<%- preUrl + '/revise/' + lr.id + '/info' %>" class="btn btn-success btn-sm">审批</a>
                             <% } else if (lr.status === auditConst.status.checkNo && lr.uid === ctx.session.sessionUser.accountId) { %>
                             <a href="<%- preUrl + '/revise/'  + lr.id + '/info' %>" class="btn btn-primary btn-sm">重新上报</a>

+ 2 - 1
app/view/tender/shenpi.ejs

@@ -123,8 +123,9 @@
                                             <span class="col-auto">一审</span>
                                             <span class="col-7 spr-span">
                                                 <span class="d-inline-block">
-                                                    <select class="form-control form-control-sm audit-type-key" data-type="<%- auditType.key.common %>" <% if (['stage', 'change'].indexOf(sp.code) === -1) { %> style="display: none;" <% } %>>
+                                                    <select class="form-control form-control-sm audit-type-key" data-type="<%- auditType.key.common %>">
                                                         <% for (const at of auditType.types) { %>
+                                                        <% if (at.valid && at.valid.indexOf(sp.code) < 0) continue; %>
                                                         <option value="<%- at.value %>" <% if (auditType.key.common === at.value) { %>selected<%} %>><%- at.name %></option>
                                                         <% } %>
                                                     </select>