소스 검색

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

Tony Kang 2 일 전
부모
커밋
3bebd366de
5개의 변경된 파일50개의 추가작업 그리고 13개의 파일을 삭제
  1. 2 1
      app/controller/safe_controller.js
  2. 1 1
      app/service/safe_inspection_audit.js
  3. 19 4
      app/service/safe_stage.js
  4. 20 5
      app/service/safe_stage_audit.js
  5. 8 2
      app/view/safe_calc/stage.ejs

+ 2 - 1
app/controller/safe_controller.js

@@ -162,7 +162,8 @@ module.exports = app => {
                 const attList = await ctx.service.paymentDetailAtt.getPaymentDetailAttachment(ctx.safeStage.id, 'desc');
                 const stdBills = await ctx.service.stdGclList.getSafeGcl();
                 // 流程审批人相关数据
-                const accountList = await ctx.service.projectAccount.getAllSubProjectAccountByPermission(ctx.subProject, 'payment_permission');
+                // const accountList = await ctx.service.projectAccount.getAllSubProjectAccountByPermission(ctx.subProject, 'payment_permission');
+                const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject);
                 const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
                 const accountGroup = unitList.map(item => {
                     const groupList = accountList.filter(item1 => item1.company === item.name);

+ 1 - 1
app/service/safe_inspection_audit.js

@@ -715,7 +715,7 @@ module.exports = app => {
                             times: inspection.times, order: selfAudit.order + 1, status: auditConst.status.rectification,
                             is_rectification: 1, begin_time: time, audit_order: selfAudit.audit_order + 1,
                         });
-                        const auditList = await this.ctx.service.tenderPermission.getPartsPermission(inspection.tid, ['inspection']);
+                        const auditList = await this.ctx.service.tenderPermission.getPartsPermission(inspection.tid, ['safe_inspection']);
                         const addAid = this._.includes(this._.map(auditList, 'uid'), checkData.rectification_uid);
                         if (!addAid) {
                             const insert_members = [{

+ 19 - 4
app/service/safe_stage.js

@@ -141,6 +141,9 @@ module.exports = app => {
             safeStage.userIds = safeStage.audit_status === audit.status.uncheck // 当前流程下全部参与人id
                 ? [safeStage.user_id]
                 : safeStage.auditorIds;
+            if (safeStage.audit_status === audit.status.checkNo) {
+                safeStage.checkNoAuditors = await this.ctx.service.safeStageAudit.getAuditorsByStatus(safeStage.id, audit.status.checkNo, safeStage.audit_times-1);
+            }
         }
         async loadAuditViewData(safeStage) {
             if (!safeStage.user) safeStage.user = await this.ctx.service.projectAccount.getAccountInfoById(safeStage.user_id);
@@ -296,7 +299,7 @@ module.exports = app => {
             return user;
         }
         async copyPaySafeData(payTenderId) {
-            const details = await this.ctx.service.paymentDetail.getAllDataByCondition({ where: { tender_id: payTenderId, type: 1 } });
+            const details = await this.ctx.service.paymentDetail.getAllDataByCondition({ where: { tender_id: payTenderId, type: 1 }, orders: [['order', 'asc']] });
             const tid = this.ctx.tender.id;
             const conn = await this.db.beginTransaction();
             try {
@@ -311,6 +314,12 @@ module.exports = app => {
                     };
                     insertStage.push(stage);
                     const safeBills = await this.ctx.service.paymentSafeBills.getAllDataByCondition({ where: { detail_id: detail.id } });
+                    const exist = safeBills.length > 0 ? await this.ctx.service.safeStageBills.getDataById(safeBills[0].id) : null;
+                    if (exist) {
+                        const existTender = await this.ctx.service.tender.getDataById(exist.tender_id);
+                        throw '该标段安全生产费数据已迁移' + (existTender ? `至标段【${existTender.name}】下,请勿重复迁移` : '');
+                    }
+                    let tp = 0, pre_tp = 0;
                     for (const sb of safeBills) {
                         sb.tender_id = tid;
                         delete sb.detail_id;
@@ -323,8 +332,14 @@ module.exports = app => {
                             delete h.order;
                         }
                         sb.cur_his = JSON.stringify(his);
+                        if (sb.tree_is_leaf) {
+                            pre_tp = this.ctx.helper.add(pre_tp, sb.pre_tp);
+                            tp = this.ctx.helper.add(tp, sb.cur_tp);
+                        }
                         insertBills.push(sb);
                     }
+                    stage.pre_bills_tp = pre_tp;
+                    stage.bills_tp = tp;
                     const user = await this._getUserInfo(detail.uid);
                     const audits = await this.ctx.service.paymentDetailAudit.getAllDataByCondition({ where: { td_id: detail.id }, orders: [['times', 'asc'], ['order', 'asc']]});
                     if (detail.status === audit.status.checked) {
@@ -335,7 +350,7 @@ module.exports = app => {
                         insertAudit.push({
                             tid, stage_id: stage.id, audit_id: user.id,
                             name: user.name, company: user.company, role: user.role, mobile: user.mobile,
-                            audit_times: a.times, audit_order: 0, active_order: 0, audit_type: auditType.key.common,
+                            audit_times: 1, audit_order: 0, active_order: 0, audit_type: auditType.key.common,
                         });
                     }
                     for (const a of audits) {
@@ -369,8 +384,8 @@ module.exports = app => {
                     }
                 }
                 await conn.insert(this.tableName, insertStage);
-                await conn.insert(this.ctx.service.safeStageBills.tableName, insertBills);
-                await conn.insert(this.ctx.service.safeStageAudit.tableName, insertAudit);
+                if (insertBills.length > 0) await conn.insert(this.ctx.service.safeStageBills.tableName, insertBills);
+                if (insertAudit.length > 0) await conn.insert(this.ctx.service.safeStageAudit.tableName, insertAudit);
                 if (insertFile.length > 0) await conn.insert(this.ctx.service.safeStageFile.tableName, insertFile);
                 await conn.commit();
             } catch (err) {

+ 20 - 5
app/service/safe_stage_audit.js

@@ -126,6 +126,7 @@ module.exports = app => {
             return this.db.query(sql, sqlParam);
         }
         async getAuditStage(auditorId, spid = '') {
+            // 查询待审批的期
             const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`audit_id`, sa.`audit_times`, sa.`audit_order`, sa.active_order, sa.`tid`, sa.`stage_id`,' +
@@ -134,13 +135,18 @@ module.exports = app => {
                 `  FROM ${this.tableName} AS sa ` +
                 `    Left Join ${this.ctx.service.safeStage.tableName} AS s On sa.stage_id = s.id ` +
                 `    Left Join ${this.ctx.service.tender.tableName} As t ON sa.tid = t.id `+
-                '  WHERE sa.`audit_id` = ? and sa.`audit_status` = ?' + spSql +
+                '  WHERE sa.`audit_id` = ? and (sa.`audit_status` = ? or (sa.audit_times > 1 and sa.audit_status = ? and sa.audit_order = 0))' + spSql +
                 '  ORDER BY sa.`create_time` DESC';
-            const sqlParam = [auditorId, auditConst.common.status.checking];
+            const sqlParam = [auditorId, auditConst.common.status.checking, auditConst.common.status.uncheck];
             const result = await this.db.query(sql, sqlParam);
             for (const r of result) {
-                const preAuditTime = await this.db.queryOne(`SELECT Max(audit_time) as audit_time FROM ${this.tableName} where stage_id = ? and audit_times = ? and active_order = ?`, [r.stage_id, r.audit_times, r.active_order]);
-                r.begin_time = preAuditTime.audit_time;
+                if (r.audit_order > 0) {
+                    const preAuditTime = await this.db.queryOne(`SELECT Max(audit_time) as audit_time FROM ${this.tableName} where stage_id = ? and audit_times = ? and active_order = ?`, [r.stage_id, r.audit_times, r.active_order]);
+                    r.begin_time = preAuditTime.audit_time;
+                } else {
+                    const checkNoTime = await this.db.queryOne(`SELECT Max(audit_time) as audit_time FROM ${this.tableName} where stage_id = ? and audit_times = ? and audit_status = ?`, [r.stage_id, r.audit_times - 1, auditConst.common.status.checkNo]);
+                    r.begin_time = checkNoTime.audit_time;
+                }
             }
             return result;
         }
@@ -263,6 +269,15 @@ module.exports = app => {
                     audit_order: newAuditOrder, audit_type: auditType.key.common,
                 };
                 const result = await transaction.insert(this.tableName, data);
+                const auditList = await this.ctx.service.tenderPermission.getPartsPermission(this.ctx.tender.id, ['safe_payment']);
+                const addAid = this._.includes(this._.map(auditList, 'uid'), auditor.id);
+                if (!addAid) {
+                    const insert_members = [{
+                        uid: auditor.id,
+                        safe_payment: ['1'],
+                    }];
+                    await this.ctx.service.tenderPermission.saveOnePermission(this.ctx.tender.id, [auditor.id], insert_members, ['safe_payment'], transaction);
+                }
                 await transaction.commit();
                 return result.effectRows = 1;
             } catch (err) {
@@ -426,7 +441,7 @@ module.exports = app => {
         async start(safeStage) {
             const audits = await this.getAllDataByCondition({ where: { stage_id: safeStage.id, audit_times: safeStage.audit_times, audit_order: 1 } });
             if (audits.length === 0) {
-                if(this.ctx.tender.info.shenpi.safeStage === shenpiConst.sp_status.gdspl) {
+                if(this.ctx.tender.info.shenpi.safe_payment === shenpiConst.sp_status.gdspl) {
                     throw '请联系管理员添加审批人';
                 } else {
                     throw '请先选择审批人,再上报数据';

+ 8 - 2
app/view/safe_calc/stage.ejs

@@ -83,14 +83,20 @@
                                     <% } else { %>
                                         <a href="#sp-list" data-toggle="modal" data-target="#sp-list" stage-order="<%- s.stage_order %>"><%- ctx.helper.transFormToChinese(s.curAuditors[0].audit_order) + '审' %></a>
                                     <% } %>
-                                <% } %>
+                                <% } else if (s.audit_status === auditConst.status.checkNo && s.checkNoAuditors.length > 0) { %>
+                                    <% if (s.checkNoAuditors[0].audit_type === auditType.key.common) { %>
+                                        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" stage-order="<%- s.stage_order %>"><%- s.checkNoAuditors[0].name %><%if (s.checkNoAuditors[0].role !== '' && s.checkNoAuditors[0].role !== null) { %>-<%- s.checkNoAuditors[0].role %><% } %></a>
+                                    <% } else { %>
+                                        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" stage-order="<%- s.stage_order %>"><%- ctx.helper.transFormToChinese(s.checkNoAuditors[0].audit_order) + '审' %></a>
+                                    <% } %>
+                                <% }%>
                             <% } %>
                             <%- auditConst.info[s.audit_status].title %>
                         </td>
                         <td class="text-center">
                             <% if (s.audit_status === auditConst.status.uncheck && s.create_user_id === ctx.session.sessionUser.accountId) { %>
                             <a href="<%- `/sp/${ctx.subProject.id}/safe/tender/${ctx.tender.id}/stage/${s.stage_order}/bills` %>" target="_blank" class="btn <%- auditConst.info[s.audit_status].btnClass %> btn-sm"><%- auditConst.info[s.audit_status].btnTitle %></a>
-                            <% } else if (s.audit_status === auditConst.status.checkNo && s.user_id === ctx.session.sessionUser.accountId) { %>
+                            <% } else if (s.audit_status === auditConst.status.checkNo && s.create_user_id === ctx.session.sessionUser.accountId) { %>
                             <a href="<%- `/sp/${ctx.subProject.id}/safe/tender/${ctx.tender.id}/stage/${s.stage_order}/bills` %>" target="_blank" class="btn <%- auditConst.info[s.audit_status].btnClass %> btn-sm"><%- auditConst.info[s.audit_status].btnTitle %></a>
                             <% } else if ((s.audit_status === auditConst.status.checking || s.audit_status === auditConst.status.checkNoPre) && s.curAuditors && s.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) >= 0) { %>
                             <a href="<%- `/sp/${ctx.subProject.id}/safe/tender/${ctx.tender.id}/stage/${s.stage_order}/bills` %>" target="_blank" class="btn <%- auditConst.info[s.audit_status].btnClass %> btn-sm"><%- auditConst.info[s.audit_status].btnTitle %></a>