Explorar o código

调差微信通知模板

laiguoran %!s(int64=4) %!d(string=hai) anos
pai
achega
6f8306e34c

+ 15 - 0
app/const/sms_type.js

@@ -12,6 +12,7 @@ const smsConst = {
     JL: 'JL',
     BG: 'BG',
     XD: 'XD',
+    TC: 'TC',
 };
 const judgeConst = {
     approval: 1,
@@ -22,6 +23,7 @@ const smsType = {
         name: '台账审批',
         path: '',
         wechat: true,
+        sms: true,
         children: [
             { title: '需要我审批', value: 1 },
             { title: '审批结果', value: 2 },
@@ -31,6 +33,7 @@ const smsType = {
         name: '修订审批',
         path: '',
         wechat: true,
+        sms: true,
         children: [
             { title: '需要我审批', value: 1 },
             { title: '审批结果', value: 2 },
@@ -40,6 +43,7 @@ const smsType = {
         name: '计量审批',
         path: '',
         wechat: true,
+        sms: true,
         children: [
             { title: '需要我审批', value: 1 },
             { title: '审批结果', value: 2 },
@@ -49,6 +53,17 @@ const smsType = {
         name: '变更管理',
         path: '',
         wechat: true,
+        sms: true,
+        children: [
+            { title: '需要我审批', value: 1 },
+            { title: '审批结果', value: 2 },
+        ],
+    },
+    TC: {
+        name: '材料调差',
+        path: '',
+        wechat: true,
+        sms: false,
         children: [
             { title: '需要我审批', value: 1 },
             { title: '审批结果', value: 2 },

+ 2 - 1
app/const/wechat_template.js

@@ -12,7 +12,8 @@ const template = {
     change: 'nSKl9u4DMvu7KtmFFS9bfVvznRDRpx6L7LlTnVFn4fs',
     ledger: 'ia3ObPVe_0A1GLVpU-jcDe1P6zVriJ36eAijeQvbpFM', // 台账和台账修订共用模板
     revise: 'ia3ObPVe_0A1GLVpU-jcDe1P6zVriJ36eAijeQvbpFM',
-    material: '',
+    material: 'Y9ov80rev3LHcoM2hOQE6jrK_5xZsqE-PZ0Z6HS9VGA',
+    advance: '',
 };
 const status = {
     check: '待审批',

+ 29 - 4
app/lib/wechat.js

@@ -87,7 +87,7 @@ class WX {
                         };
                         break;
                     case wxConst.template.ledger:
-                        remark = data.status === wxConst.status.check ? '微信暂无法在线审批,请登录PC端系统。' :
+                        remark = data.status === wxConst.status.check ? '微信暂无法在线审批' :
                             (data.status === wxConst.status.success ? '审批已通过,查看审批结果' : '审批被退回,查看退回结果');
                         msgData = {
                             first: {
@@ -108,7 +108,7 @@ class WX {
                         };
                         break;
                     case wxConst.template.revise:
-                        remark = data.status === wxConst.status.check ? '微信暂无法在线审批,请登录PC端系统。' :
+                        remark = data.status === wxConst.status.check ? '微信暂无法在线审批' :
                             (data.status === wxConst.status.success ? '审批已通过,查看审批结果' :
                                 (data.status === wxConst.status.back ? '审批被退回,查看退回结果' : '审批已上报,查看审批结果'));
                         msgData = {
@@ -130,12 +130,37 @@ class WX {
                         };
                         break;
                     case wxConst.template.material:
+                        remark = data.status === wxConst.status.check ? '微信暂无法在线审批' :
+                            (data.status === wxConst.status.success ? '审批已通过,查看审批结果' : '审批被退回,查看退回结果');
+                        msgData = {
+                            first: {
+                                value: '您好,材料调差申请' + data.tips,
+                            },
+                            keyword1: {
+                                value: data.projectName,
+                            },
+                            keyword2: {
+                                value: data.tenderName + '(第' + data.qi + '期)',
+                            },
+                            keyword3: {
+                                value: moment(new Date(data.begin_time)).format('YYYY-MM-DD'),
+                            },
+                            keyword4: {
+                                value: data.m_tp,
+                            },
+                            keyword5: {
+                                value: data.hs_m_tp,
+                            },
+                            remark: {
+                                value: remark + ',请登录PC端系统。',
+                            },
+                        };
                         break;
                     default:break;
                 }
                 if (msgData !== '') {
-                    console.log(openid, templateId, url, msgData);
-                    // await this.ctx.app.wechat.api.sendTemplate(openid, templateId, url, '', msgData);
+                    // console.log(openid, templateId, url, msgData);
+                    await this.ctx.app.wechat.api.sendTemplate(openid, templateId, url, '', msgData);
                 }
             }
             flag = true;

+ 77 - 0
app/service/material_audit.js

@@ -10,6 +10,8 @@
 
 const auditConst = require('../const/audit').material;
 const pushType = require('../const/audit').pushType;
+const smsTypeConst = require('../const/sms_type');
+const wxConst = require('../const/wechat_template');
 
 module.exports = app => {
     class MaterialAudit extends app.BaseService {
@@ -222,6 +224,19 @@ module.exports = app => {
                 }
                 await transaction.insert(this.ctx.service.materialBillsHistory.tableName, mbhList);
 
+                // 微信模板通知
+                const materialInfo = await this.ctx.service.material.getDataById(materialId);
+                const wechatData = {
+                    qi: materialInfo.order,
+                    status: wxConst.status.check,
+                    tips: wxConst.tips.check,
+                    begin_time: Date.parse(new Date()),
+                    m_tp: this.ctx.helper.round(materialInfo.m_tp, 2),
+                    hs_m_tp: this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2),
+                };
+                await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.TC, smsTypeConst.judge.approval.toString(), wxConst.template.material, wechatData);
+
+
                 // 添加短信通知-需要审批提醒功能
                 // const smsUser = await this.ctx.service.projectAccount.getDataById(audit.aid);
                 // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
@@ -274,6 +289,12 @@ module.exports = app => {
                     records.push({ pid, type: pushType.material, uid: audit.aid, status: auditConst.status.checked, content: noticeContent });
                 });
                 await transaction.insert('zh_notice', records);
+                const begin_audit = await this.getDataByCondition({
+                    mid: materialId,
+                    order: 1,
+                });
+                const materialInfo = await this.ctx.service.material.getDataById(materialId);
+
                 // 无下一审核人表示,审核结束
                 if (nextAudit) {
                     // 复制一份下一审核人数据
@@ -286,6 +307,17 @@ module.exports = app => {
                         id: materialId, status: auditConst.status.checking,
                     });
 
+                    // 微信模板通知
+                    const wechatData = {
+                        qi: materialInfo.order,
+                        status: wxConst.status.check,
+                        tips: wxConst.tips.check,
+                        begin_time: Date.parse(begin_audit.begin_time),
+                        m_tp: this.ctx.helper.round(materialInfo.m_tp, 2),
+                        hs_m_tp: this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2),
+                    };
+                    await this.ctx.helper.sendWechat(nextAudit.id, smsTypeConst.const.TC, smsTypeConst.judge.approval.toString(), wxConst.template.material, wechatData);
+
 
                     // 添加短信通知-需要审批提醒功能
                     // const smsUser = await this.ctx.service.projectAccount.getDataById(nextAudit.aid);
@@ -312,6 +344,18 @@ module.exports = app => {
                         id: materialId, status: checkData.checkType,
                     });
 
+                    // 微信模板通知
+                    const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), materialInfo.user_id));
+                    const wechatData = {
+                        qi: materialInfo.order,
+                        status: wxConst.status.success,
+                        tips: wxConst.tips.success,
+                        begin_time: Date.parse(begin_audit.begin_time),
+                        m_tp: this.ctx.helper.round(materialInfo.m_tp, 2),
+                        hs_m_tp: this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2),
+                    };
+                    await this.ctx.helper.sendWechat(users, smsTypeConst.const.TC, smsTypeConst.judge.result.toString(), wxConst.template.material, wechatData);
+
                     // 添加短信通知-审批通过提醒功能
                     // const mobile_array = [];
                     // const stageInfo = await this.ctx.service.stage.getDataById(stageId);
@@ -387,6 +431,23 @@ module.exports = app => {
                     order: this.ctx.material.order,
                 });
 
+                // 微信模板通知
+                const begin_audit = await this.getDataByCondition({
+                    mid: materialId,
+                    order: 1,
+                });
+                const materialInfo = await this.ctx.service.material.getDataById(materialId);
+                const users = this._.uniq(this._.concat(this._.map(auditors, 'aid'), materialInfo.user_id));
+                const wechatData = {
+                    qi: materialInfo.order,
+                    status: wxConst.status.back,
+                    tips: wxConst.tips.back,
+                    begin_time: Date.parse(begin_audit.begin_time),
+                    m_tp: this.ctx.helper.round(materialInfo.m_tp, 2),
+                    hs_m_tp: this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2),
+                };
+                await this.ctx.helper.sendWechat(users, smsTypeConst.const.TC, smsTypeConst.judge.result.toString(), wxConst.template.material, wechatData);
+
                 // 计算该审批人最终数据
                 // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
                 // 复制一份最新数据给原报
@@ -468,6 +529,22 @@ module.exports = app => {
                     times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck,
                 });
 
+                // 微信模板通知
+                const begin_audit = await this.getDataByCondition({
+                    mid: materialId,
+                    order: 1,
+                });
+                const materialInfo = await this.ctx.service.material.getDataById(materialId);
+                const wechatData = {
+                    qi: materialInfo.order,
+                    status: wxConst.status.check,
+                    tips: wxConst.tips.check,
+                    begin_time: Date.parse(begin_audit.begin_time),
+                    m_tp: this.ctx.helper.round(materialInfo.m_tp, 2),
+                    hs_m_tp: this.ctx.helper.round(this.ctx.helper.mul(materialInfo.m_tp, 1+materialInfo.rate/100), 2),
+                };
+                await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.TC, smsTypeConst.judge.approval.toString(), wxConst.template.material, wechatData);
+
                 await transaction.insert(this.tableName, newAuditors);
                 await transaction.commit();
             } catch (error) {

+ 2 - 0
app/view/profile/sms.ejs

@@ -50,6 +50,7 @@
                             <input type="hidden" name="_csrf" value="<%= ctx.csrf %>">
                             <% const user_smsType = accountData.sms_type !== '' ? JSON.parse(accountData.sms_type) : null; %>
                             <% for (const s in smsType) { %>
+                            <% if (smsType[s].sms) { %>
                             <div class="form-group row">
                                 <label class="col-auto col-form-label"><%= smsType[s].name %>
                                     <!--<a href="#sms-view" data-toggle="modal" data-target="#sms-view" class="ml-2"><i class="fa fa-info-circle"></i></a>-->
@@ -64,6 +65,7 @@
                                 </div>
                             </div>
                             <% } %>
+                            <% } %>
                             <input name="type" value="1" type="hidden">
                             <button type="submit" class="btn btn-primary btn-sm">确认修改</button>
                         </form>