瀏覽代碼

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

MaiXinRong 1 年之前
父節點
當前提交
b7d95bd769

+ 30 - 0
app/controller/dashboard_controller.js

@@ -12,6 +12,7 @@ const auditConst = require('../const/audit');
 const officeList = require('../const/cld_office').list;
 const maintainConst = require('../const/maintain');
 const typeColMap = require('../const/advance').typeColMap;
+const moment = require('moment');
 
 module.exports = app => {
 
@@ -207,6 +208,35 @@ module.exports = app => {
                 ctx.helper.validate(rule);
                 const result = await ctx.service.message.save(id, ctx.request.body, ctx.session.sessionUser, ctx.session.sessionProject.id);
                 if (result) {
+                    // 新增的项目通知会发送微信模版消息通知客户
+                    if (id === 0) {
+                        // 获取该项目所有的openid,发送信息
+                        const wechats = await ctx.service.projectAccount.getOpenIdListByPid(ctx.session.sessionProject.id);
+                        if (wechats.length > 0) {
+                            const msgInfo = await ctx.service.message.getDataById(result);
+                            const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
+                            // 绑定成功通知
+                            const templateId = 'VKUo4us4lt2dQY0EaaJxcui2jkjmriN3A0K7i4kpZwY';
+                            const url = ctx.protocol + '://' + ctx.host + '/wap/dashboard/msg/' + msgInfo.id;
+                            const msgData = {
+                                thing21: {
+                                    value: projectData.code,
+                                },
+                                thing2: {
+                                    value: ctx.helper.contentChange(msgInfo.title),
+                                },
+                                thing8: {
+                                    value: msgInfo.creator,
+                                },
+                                time3: {
+                                    value: moment(msgInfo.release_time * 1000).format('YYYY-MM-DD'),
+                                },
+                            };
+                            for (const wx of wechats) {
+                                await app.wechat.api.sendTemplate(wx.wx_openid, templateId, url, '', msgData);
+                            }
+                        }
+                    }
                     ctx.redirect('/dashboard/msg/list');
                 }
             } catch (error) {

+ 0 - 1
app/controller/wap_controller.js

@@ -798,7 +798,6 @@ module.exports = app => {
         async msg(ctx) {
             try {
                 const msgId = parseInt(ctx.params.id) || 0;
-                console.log(msgId);
                 if (!msgId) {
                     throw '参数有误';
                 }

+ 7 - 0
app/extend/helper.js

@@ -1680,4 +1680,11 @@ module.exports = {
         qtys.qc_minus_qty = qtys.qc_minus_qty ? qtys.qc_minus_qty : null;
         return qtys;
     },
+    contentChange(content) {
+        let str = content.replace(/【/g, '(');
+        str = str.replace(/】/g, ')');
+        str = str.replace(/工程款/g, '***');
+        str = str.length > 20 ? str.substring(0, 17) + '...' : str;
+        return str;
+    },
 };

+ 2 - 2
app/public/js/material.js

@@ -2140,7 +2140,7 @@ $(document).ready(() => {
     if (getLocalCache('material_month_' + materialID) && !isStageSelf) {
         const tab = $('.right-nav a[content="#month-tab"]'), tabPanel = $(tab.attr('content'));
         $('a', '.side-menu').removeClass('active');
-        $('.tab-content .tab-pane').removeClass('active');
+        $('#right-view .tab-content .tab-pane').removeClass('active');
         tab.addClass('active');
         tabPanel.addClass('active');
         $('#right-view').width(getLocalCache('material_month_' + materialID) + '%');
@@ -2174,7 +2174,7 @@ $(document).ready(() => {
         $('.sjs-material').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar')));
     }
     function getObjHeight(select) {
-        return select.length > 0 ? select.height() : 0;
+        return select.length > 0 ? select.outerHeight() : 0;
     }
 
     function formatDate(numb, format) {

+ 10 - 8
app/service/change.js

@@ -856,10 +856,12 @@ module.exports = app => {
                     });
                 });
                 await this.transaction.insert('zh_notice', records);
-
+                // 判断是否终审方法需要更改了,因为存在修改审批流程的操作,会使判断是否终审有问题
+                const curAudit = await this.ctx.service.changeAudit.getCurAuditor(changeData.cid, changeData.times);
+                const nextAudit = await this.ctx.service.changeAudit.getDataByCondition({ cid: changeData.cid, times: changeData.times, usort: curAudit.usort + 1, status: audit.flow.auditStatus.uncheck });
                 // 设置审批人通过
                 const audit_update = {
-                    id: postData.audit_id,
+                    id: curAudit.id,
                     sdesc: postData.sdesc,
                     status: audit.flow.auditStatus.checked,
                     sin_time: new Date(),
@@ -896,7 +898,7 @@ module.exports = app => {
                         await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
                     }
                 }
-                if (postData.audit_next_id === undefined) {
+                if (!nextAudit) {
                     // 变更令审批完成
                     change_update.status = audit.flow.status.checked;
                     change_update.p_code = postData.p_code;
@@ -935,20 +937,19 @@ module.exports = app => {
                 } else {
                     // 设置下一个审批人为审批状态
                     const nextAudit_update = {
-                        id: postData.audit_next_id,
+                        id: nextAudit.id,
                         status: audit.flow.auditStatus.checking,
                         sin_time: new Date(),
                     };
                     await this.transaction.update(this.ctx.service.changeAudit.tableName, nextAudit_update);
 
                     // 添加短信通知-需要审批提醒功能
-                    const nextAuditData = await this.ctx.service.changeAudit.getDataById(postData.audit_next_id);
                     const sms = new SMS(this.ctx);
                     const code = await sms.contentChange(changeData.code);
                     const shenpiUrl = await this.ctx.helper.urlToShort(
                         this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/information#shenpi'
                     );
-                    await this.ctx.helper.sendAliSms(nextAuditData.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
+                    await this.ctx.helper.sendAliSms(nextAudit.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
                         biangeng: code,
                         code: shenpiUrl,
                     });
@@ -960,7 +961,7 @@ module.exports = app => {
                         code: this.ctx.session.sessionProject.code,
                         c_name: changeData.name,
                     };
-                    await this.ctx.helper.sendWechat(nextAuditData.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
+                    await this.ctx.helper.sendWechat(nextAudit.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
                 }
                 change_update.total_price = total_price;
                 const options = {
@@ -1690,7 +1691,7 @@ module.exports = app => {
                 const updateChangeList = [];
                 for (const cl of changeList) {
                     const audit_amount = cl.audit_amount.split(',');
-                    const last_amount = audit_amount[audit_amount.length - 1];
+                    const last_amount = audit_amount[audit_amount.length - 1] ? audit_amount[audit_amount.length - 1] : 0;
                     audit_amount.splice(-1, 1);
                     const list_update = {
                         id: cl.id,
@@ -1740,6 +1741,7 @@ module.exports = app => {
                 await this.ctx.helper.sendWechat(zsAudit.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
 
             } catch (error) {
+                console.log(error);
                 await this.transaction.rollback();
                 result = false;
             }

+ 1 - 1
app/service/change_apply_history.js

@@ -45,7 +45,7 @@ module.exports = app => {
             const oldList = JSON.parse(data.list_json);
             // 先删后插
             await transaction.delete(this.ctx.service.changeApplyList.tableName, { caid });
-            await transaction.insert(this.ctx.service.changeApplyList.tableName, oldList);
+            if (oldList.length > 0) await transaction.insert(this.ctx.service.changeApplyList.tableName, oldList);
         }
     }
 

+ 1 - 1
app/service/change_plan_history.js

@@ -45,7 +45,7 @@ module.exports = app => {
             const oldList = JSON.parse(data.list_json);
             // 先删后插
             await transaction.delete(this.ctx.service.changePlanList.tableName, { cpid });
-            await transaction.insert(this.ctx.service.changePlanList.tableName, oldList);
+            if (oldList.length > 0) await transaction.insert(this.ctx.service.changePlanList.tableName, oldList);
         }
     }
 

+ 1 - 1
app/service/change_project.js

@@ -385,7 +385,7 @@ module.exports = app => {
                         change.cancancel = 4;// 审批人撤回退回原报
                     }
                 } else if (change.status === status.checkNo) {
-                    const onAuditor = this._.find(auditors, function(item) {
+                    const onAuditor = this._.findLast(auditors, function(item) {
                         return item.status === status.checkNo;
                     });
                     if (onAuditor && onAuditor.aid === accountId) {

+ 1 - 1
app/service/message.js

@@ -115,7 +115,7 @@ module.exports = app => {
             const operate = id === 0 ? await this.db.insert(this.tableName, data) :
                 await this.db.update(this.tableName, data);
 
-            const result = operate.affectedRows > 0;
+            const result = operate.affectedRows > 0 ? operate.insertId : false;
 
             return result;
         }

+ 6 - 0
app/service/project_account.js

@@ -936,6 +936,12 @@ module.exports = app => {
             const result = await this.getDataById(id);
             return result ? result.self_category_level : '';
         }
+
+        async getOpenIdListByPid(pid) {
+            const sql = 'SELECT `wx_openid` FROM ?? WHERE `project_id` = ? AND `wx_openid` is not null';
+            const param = [this.tableName, pid];
+            return await this.db.query(sql, param);
+        }
     }
 
     return ProjectAccount;

+ 2 - 0
app/view/change/information_modal.ejs

@@ -1518,6 +1518,8 @@
             // 退回选择修改审批人流程
             $('#hideSp').click(function () {
                 $('#sp-list').modal('hide');
+                $('#sp-done').modal('hide');
+                $('#sp-back').modal('hide');
             });
             $('a[f-target]').click(function () {
                 $($(this).attr('f-target')).modal('show');

+ 1 - 1
app/view/change/project_information_modal.ejs

@@ -409,7 +409,7 @@
                                                                 <div class="card-body p-3">
                                                                     <div class="card-text">
                                                                         <p class="mb-1"><span class="h5"><%- auditor.name %></span><span
-                                                                                    class="pull-right <%- auditConst.auditString[auditor.status] %>"><%- auditConst.auditString[auditor.status] %></span>
+                                                                                    class="pull-right <%- auditConst.auditStringClass[auditor.status] %>"><%- auditConst.auditString[auditor.status] %></span>
                                                                         </p>
                                                                         <p class="text-muted mb-0"><%- auditor.role %></p>
                                                                     </div>