Browse Source

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

MaiXinRong 5 years ago
parent
commit
a4ebece722

+ 27 - 0
app/controller/measure_controller.js

@@ -188,6 +188,33 @@ module.exports = app => {
                 ctx.redirect(this.menu.menu.dashboard.url);
             }
         }
+
+        /**
+         * 删除期(Post)
+         * @param ctx
+         * @returns {Promise<void>}
+         */
+        async delete(ctx) {
+            try {
+                const stage_id = ctx.request.body.stage_id;
+                const stageInfo = await ctx.service.stage.getDataById(stage_id);
+                // 获取最新的期数
+                const stage_highOrder = await ctx.service.stage.count({
+                    tid: ctx.tender.id,
+                });
+                if (stageInfo === undefined || ctx.session.sessionUser.accountId !== stageInfo.user_id || stage_highOrder !== stageInfo.order) {
+                    throw '您无权删除计量期';
+                }
+                const result = await ctx.service.stage.deleteStage(stage_id);
+                if (!result) {
+                    throw '删除计量期失败,请重试';
+                }
+                ctx.redirect('/tender/' + ctx.tender.id + '/measure/stage/');
+            } catch (err) {
+                this.log(err);
+                ctx.redirect(ctx.request.header.referer);
+            }
+        }
     }
 
     return MeasureController;

+ 1 - 0
app/router.js

@@ -129,6 +129,7 @@ module.exports = app => {
     app.post('/tender/:id/measure/stage/auditors', sessionAuth, tenderCheck, 'measureController.stageAuditors');
     app.post('/tender/:id/measure/add', sessionAuth, tenderCheck, 'measureController.add');
     app.post('/tender/:id/measure/save', sessionAuth, tenderCheck, 'measureController.save');
+    app.post('/tender/:id/measure/stage/delete', sessionAuth, tenderCheck, 'measureController.delete');
     // 计量台账 -- 清单汇总
     app.get('/tender/:id/measure/gather', sessionAuth, tenderCheck, 'measureController.gather');
     // 计量台账 -- 审核比较

+ 49 - 1
app/service/stage.js

@@ -10,6 +10,8 @@
 
 const auditConst = require('../const/audit').stage;
 const payConst = require('../const/deal_pay.js');
+const fs = require('fs');
+const path = require('path');
 
 module.exports = app => {
     class Stage extends app.BaseService {
@@ -269,7 +271,53 @@ module.exports = app => {
             const result = await this.db.update(this.tableName, {id: sid, check_detail: check});
             return result.affectedRows === 1;
         }
+
+        /**
+         * 删除计量期
+         *
+         * @param {Number} id - 期Id
+         * @returns {Promise<void>}
+         */
+        async deleteStage(id) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.delete(this.tableName, { id });
+                await transaction.delete(this.ctx.service.stageAudit.tableName, { sid: id });
+                await transaction.delete(this.ctx.service.stageBills.tableName, { sid: id });
+                await transaction.delete(this.ctx.service.stageChange.tableName, { sid: id });
+                await transaction.delete(this.ctx.service.stagePos.tableName, { sid: id });
+                await transaction.delete(this.ctx.service.stageDetail.tableName, { sid: id });
+                await transaction.delete(this.ctx.service.stagePosFinal.tableName, { sid: id });
+                await transaction.delete(this.ctx.service.stageBillsFinal.tableName, { sid: id });
+                // 删除计量合同支付附件
+                const payList = await this.ctx.service.stagePay.getAllDataByCondition({ where: { sid: id } });
+                if (payList) {
+                    for (const pt of payList) {
+                        if (pt.attachment !== null && pt.attachment !== '') {
+                            const payAttList = JSON.parse(pt.attachment);
+                            for (const pat of payAttList) {
+                                await fs.unlinkSync(path.join(this.app.baseDir, pat.filepath));
+                            }
+                        }
+                    }
+                }
+                await transaction.delete(this.ctx.service.stagePay.tableName, { sid: id });
+                // 删除计量附件文件
+                const attList = await this.ctx.service.stageAtt.getAllDataByCondition({ where: { sid: id } });
+                if (attList.length !== 0) {
+                    for (const att of attList) {
+                        await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
+                    }
+                }
+                await transaction.delete(this.ctx.service.StageAtt.tableName, { sid: id });
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
     }
 
     return Stage;
-};
+};

+ 3 - 0
app/view/measure/stage.ejs

@@ -62,6 +62,9 @@
                     <% } else { %>
                         <span class="<%- auditConst.auditStringClass[s.status] %>"><%- auditConst.auditString[s.status] %></span>
                     <% } %>
+                    <% if (s.user_id === ctx.session.sessionUser.accountId && s.order === stages.length) { %>
+                        <a href="#del-qi" class="btn btn-outline-danger btn-sm ml-1" data-toggle="modal" data-target="#del-qi">删除</a>
+                    <% } %>
                     </td>
                 </tr>
                 <% } %>

+ 20 - 0
app/view/measure/stage_modal.ejs

@@ -30,6 +30,26 @@
     </div>
 </div>
 <% } %>
+<!--删除期-->
+<div class="modal fade" id="del-qi" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <form class="modal-content" action="<%- preUrl + '/measure/stage/delete' %>" method="post">
+            <div class="modal-header">
+                <h5 class="modal-title">删除期</h5>
+            </div>
+            <div class="modal-body">
+                <h5>确认删除「第<%= stages.length %>期」?</h5>
+                <h5>删除后,数据无法恢复,请谨慎操作。</h5>
+            </div>
+            <div class="modal-footer">
+                <input type="hidden" name="stage_id" value="<%= stages[stages.length-1].id %>">
+                <input type="hidden" name="_csrf" value="<%= ctx.csrf %>" />
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                <button type="submit" class="btn btn-danger">确定删除</button>
+            </div>
+        </form>
+    </div>
+</div>
 <!--审批流程/结果-->
 <div class="modal fade" id="sp-list" data-backdrop="static">
     <div class="modal-dialog modal-lg" role="document">