Prechádzať zdrojové kódy

微信通知bug修复

laiguoran 4 rokov pred
rodič
commit
e91d60ab9c

+ 9 - 0
app/const/wechat_template.js

@@ -8,6 +8,14 @@
  * @version
  */
 const template = {
+    stage: 0,
+    change: 1,
+    ledger: 2, // 台账和台账修订共用模板
+    revise: 3,
+    material: 4,
+    advance: 5,
+};
+const templateId = {
     stage: '5vU3WmR90yDajbs4LWIWH4OQhunYlS1HXTiesIGxrsk',
     change: 'nSKl9u4DMvu7KtmFFS9bfVvznRDRpx6L7LlTnVFn4fs',
     ledger: 'ia3ObPVe_0A1GLVpU-jcDe1P6zVriJ36eAijeQvbpFM', // 台账和台账修订共用模板
@@ -30,6 +38,7 @@ const tips = {
 
 module.exports = {
     template,
+    templateId,
     status,
     tips,
 };

+ 9 - 3
app/lib/wechat.js

@@ -34,14 +34,16 @@ class WX {
     async Send(wx_openid, template, data) {
         let flag = false;
         try {
-            const templateId = template;
+            // const templateId = template;
+            let templateId = '';
             const sck = 'https://scn.ink/';
             for (const openid of wx_openid) {
                 let url = '';
                 let msgData = '';
                 let remark = '';
-                switch (templateId) {
+                switch (template) {
                     case wxConst.template.stage :
+                        templateId = wxConst.templateId.stage;
                         url = this.ctx.protocol + '://' + this.ctx.host + '/wx/url2wap?project=' + data.code + '&url=' + sck + data.wap_url;
                         msgData = {
                             first: {
@@ -65,6 +67,7 @@ class WX {
                         };
                         break;
                     case wxConst.template.change:
+                        templateId = wxConst.templateId.change;
                         url = this.ctx.protocol + '://' + this.ctx.host + '/wx/url2wap?project=' + data.code + '&url=' + sck + data.wap_url;
                         remark = data.status === wxConst.status.check ? '微信可快速审批,如需进行详细审批' :
                             (data.status === wxConst.status.success ? '审批已通过,查看审批结果' : '审批被退回,查看退回结果');
@@ -87,6 +90,7 @@ class WX {
                         };
                         break;
                     case wxConst.template.ledger:
+                        templateId = wxConst.templateId.ledger;
                         remark = data.status === wxConst.status.check ? '微信暂无法在线审批' :
                             (data.status === wxConst.status.success ? '审批已通过,查看审批结果' : '审批被退回,查看退回结果');
                         msgData = {
@@ -108,6 +112,7 @@ class WX {
                         };
                         break;
                     case wxConst.template.revise:
+                        templateId = wxConst.templateId.revise;
                         remark = data.status === wxConst.status.check ? '微信暂无法在线审批' :
                             (data.status === wxConst.status.success ? '审批已通过,查看审批结果' :
                                 (data.status === wxConst.status.back ? '审批被退回,查看退回结果' : '审批已上报,查看审批结果'));
@@ -130,6 +135,7 @@ class WX {
                         };
                         break;
                     case wxConst.template.material:
+                        templateId = wxConst.templateId.material;
                         remark = data.status === wxConst.status.check ? '微信暂无法在线审批' :
                             (data.status === wxConst.status.success ? '审批已通过,查看审批结果' : '审批被退回,查看退回结果');
                         msgData = {
@@ -158,7 +164,7 @@ class WX {
                         break;
                     default:break;
                 }
-                if (msgData !== '') {
+                if (msgData !== '' && templateId) {
                     // console.log(openid, templateId, url, msgData);
                     await this.ctx.app.wechat.api.sendTemplate(openid, templateId, url, '', msgData);
                 }

+ 2 - 2
app/service/revise_audit.js

@@ -254,7 +254,7 @@ module.exports = app => {
                 await this.ctx.helper.sendWechat(audit.audit_id, smsTypeConst.const.XD, smsTypeConst.judge.approval.toString(), wxConst.template.revise, wechatData);
                 // 其他参与人
                 const auditList = await this.getAuditors(revise.id, times);
-                const users = this._.pull(this._.map(auditList, 'user_id'), audit.id);
+                const users = this._.pull(this._.map(auditList, 'user_id'), audit.audit_id);
                 // await this.ctx.helper.sendUserSms(users, smsTypeConst.const.XD,
                 //     smsTypeConst.judge.result.toString(), '台账修订已上报。');
                 await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_report);
@@ -264,7 +264,7 @@ module.exports = app => {
                     tips: wxConst.tips.report,
                     begin_time: Date.parse(time),
                 };
-                await this.ctx.helper.sendWechat(audit.audit_id, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData2);
+                await this.ctx.helper.sendWechat(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData2);
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();