Browse Source

微信通知添加变更,修订和台账

laiguoran 5 years ago
parent
commit
e84c2ab061

+ 2 - 2
app/const/sms_type.js

@@ -21,7 +21,7 @@ const smsType = {
     TZ: {
         name: '台账审批',
         path: '',
-        wechat: false,
+        wechat: true,
         children: [
             { title: '需要我审批', value: 1 },
             { title: '审批结果', value: 2 },
@@ -30,7 +30,7 @@ const smsType = {
     XD: {
         name: '修订审批',
         path: '',
-        wechat: false,
+        wechat: true,
         children: [
             { title: '需要我审批', value: 1 },
             { title: '审批结果', value: 2 },

+ 6 - 1
app/const/wechat_template.js

@@ -9,17 +9,22 @@
  */
 const template = {
     stage: '5vU3WmR90yDajbs4LWIWH4OQhunYlS1HXTiesIGxrsk',
-    change: '',
+    change: 'nSKl9u4DMvu7KtmFFS9bfVvznRDRpx6L7LlTnVFn4fs',
+    ledger: 'ia3ObPVe_0A1GLVpU-jcDe1P6zVriJ36eAijeQvbpFM', // 台账和台账修订共用模板
+    revise: 'ia3ObPVe_0A1GLVpU-jcDe1P6zVriJ36eAijeQvbpFM',
+    material: '',
 };
 const status = {
     check: '待审批',
     back: '退回',
     success: '通过',
+    report: '已上报',
 };
 const tips = {
     check: '需要您审批',
     back: '审批退回',
     success: '审批通过',
+    report: '已上报',
 };
 
 module.exports = {

+ 8 - 5
app/controller/profile_controller.js

@@ -403,20 +403,23 @@ module.exports = app => {
                     throw '解绑微信失败!';
                 }
                 // 解绑成功通知
-                const templateId = 'gsYUIt5CFY1uJQhiqnkhu38yi0adkZtEH9fGI49g_Lk';
+                const templateId = '0w0Yp65X4PHccTLeAyE5aQhS-blS-bylwxAPYEGy3CI';
                 const url = '';
                 const msgData = {
                     first: {
-                        value: '你已成功与纵横云计量帐号解除绑定',
+                        value: '您好,纵横云计量与微信解绑成功。',
                     },
                     keyword1: {
-                        value: sessionUser.account,
+                        value: ctx.session.sessionProject.code,
                     },
                     keyword2: {
-                        value: '项目编号' + ctx.session.sessionProject.code + ' 账号' + sessionUser.account + ' 解绑成功',
+                        value: sessionUser.account,
+                    },
+                    keyword3: {
+                        value: moment(new Date()).format('YYYY-MM-DD'),
                     },
                     remark: {
-                        value: '欢迎使用纵横云计量,我们竭诚为您服务。',
+                        value: '感谢您的使用,要接收通知请重新绑定。',
                     },
                 };
                 await app.wechat.api.sendTemplate(accountData.wx_openid, templateId, url, '', msgData);

+ 8 - 5
app/controller/wechat_controller.js

@@ -113,20 +113,23 @@ module.exports = app => {
                 }
                 const projectData = await ctx.service.project.getDataById(accountData.project_id);
                 // 绑定成功通知
-                const templateId = 'ElT988uf7EV8ROPKSAX7z7tN9ZxZCDMaXK5ouc9N49E';
+                const templateId = 'JGJeWU2FT4syWKUE5haEf3iiqaRJ1XrsxY1PKixqLpw';
                 const url = '';
                 const msgData = {
                     first: {
-                        value: '微信绑定成功',
+                        value: '您好,纵横云计量与微信绑定成功',
                     },
                     keyword1: {
-                        value: accountData.account,
+                        value: projectData.code,
                     },
                     keyword2: {
-                        value: '项目编号' + projectData.code + ' 账号' + accountData.account + ' 绑定成功',
+                        value: accountData.account,
+                    },
+                    keyword3: {
+                        value: moment(new Date()).format('YYYY-MM-DD'),
                     },
                     remark: {
-                        value: '欢迎使用纵横云计量,我们竭诚为您服务。',
+                        value: '感谢您的使用。',
                     },
                 };
                 await app.wechat.api.sendTemplate(ctx.session.wechatToken.openid, templateId, url, '', msgData);

+ 101 - 28
app/lib/wechat.js

@@ -9,6 +9,7 @@
  */
 
 // const xmlReader = require('xmlreader');
+const moment = require('moment');
 const wxConst = require('../const/wechat_template.js');
 class WX {
 
@@ -23,46 +24,118 @@ class WX {
     }
 
     /**
-     * 发送微信模板
+     * 发送微信审批通知模板
      *
      * @param {Array} wx_openid - 发送的微信账号
      * @param {String} template - 模板id
-     * @param {String} wap_url - wap页面地址
-     * @param {String} tips - 状态文字说明
-     * @param {String} status - 状态
      * @param {Object} data - 一些模板展示数据
      * @return {Boolean} - 发送结果
      */
     async Send(wx_openid, template, data) {
         let flag = false;
         try {
-            // 解绑成功通知
             const templateId = template;
             const sck = 'https://scn.ink/';
-            const url = this.ctx.protocol + '://' + this.ctx.host + '/wx/url2wap?project=' + data.code + '&url=' + sck + data.wap_url;
             for (const openid of wx_openid) {
-                if (template === wxConst.template.stage) {
-                    const msgData = {
-                        first: {
-                            value: '您好,本期计量' + data.tips,
-                        },
-                        keyword1: {
-                            value: data.projectName,
-                        },
-                        keyword2: {
-                            value: data.tenderName,
-                        },
-                        keyword3: {
-                            value: '第' + data.qi + '期',
-                        },
-                        keyword4: {
-                            value: data.status,
-                        },
-                        remark: {
-                            value: '查看审批详情,请登录PC端系统。',
-                        },
-                    };
-                    await this.ctx.app.wechat.api.sendTemplate(openid, templateId, url, '', msgData);
+                let url = '';
+                let msgData = '';
+                let remark = '';
+                switch (templateId) {
+                    case wxConst.template.stage :
+                        url = this.ctx.protocol + '://' + this.ctx.host + '/wx/url2wap?project=' + data.code + '&url=' + sck + data.wap_url;
+                        msgData = {
+                            first: {
+                                value: '您好,本期计量' + data.tips,
+                            },
+                            keyword1: {
+                                value: data.projectName,
+                            },
+                            keyword2: {
+                                value: data.tenderName,
+                            },
+                            keyword3: {
+                                value: '第' + data.qi + '期',
+                            },
+                            keyword4: {
+                                value: data.status,
+                            },
+                            remark: {
+                                value: '查看审批详情,请登录PC端系统。',
+                            },
+                        };
+                        break;
+                    case wxConst.template.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 ? '审批已通过,查看审批结果' : '审批被退回,查看退回结果');
+                        msgData = {
+                            first: {
+                                value: '您好,工程变更申请' + data.tips,
+                            },
+                            keyword1: {
+                                value: data.projectName,
+                            },
+                            keyword2: {
+                                value: data.tenderName,
+                            },
+                            keyword3: {
+                                value: data.c_name,
+                            },
+                            remark: {
+                                value: remark + ',请登录PC端系统。',
+                            },
+                        };
+                        break;
+                    case wxConst.template.ledger:
+                        remark = data.status === wxConst.status.check ? '微信暂无法在线审批,请登录PC端系统。' :
+                            (data.status === wxConst.status.success ? '审批已通过,查看审批结果' : '审批被退回,查看退回结果');
+                        msgData = {
+                            first: {
+                                value: '您好,台帐' + data.tips,
+                            },
+                            keyword1: {
+                                value: data.projectName,
+                            },
+                            keyword2: {
+                                value: data.tenderName,
+                            },
+                            keyword3: {
+                                value: moment(new Date(data.begin_time)).format('YYYY-MM-DD'),
+                            },
+                            remark: {
+                                value: remark + ',请登录PC端系统。',
+                            },
+                        };
+                        break;
+                    case wxConst.template.revise:
+                        remark = data.status === wxConst.status.check ? '微信暂无法在线审批,请登录PC端系统。' :
+                            (data.status === wxConst.status.success ? '审批已通过,查看审批结果' :
+                                (data.status === wxConst.status.back ? '审批被退回,查看退回结果' : '审批已上报,查看审批结果'));
+                        msgData = {
+                            first: {
+                                value: '您好,台帐修订' + data.tips,
+                            },
+                            keyword1: {
+                                value: data.projectName,
+                            },
+                            keyword2: {
+                                value: data.tenderName,
+                            },
+                            keyword3: {
+                                value: moment(new Date(data.begin_time)).format('YYYY-MM-DD'),
+                            },
+                            remark: {
+                                value: remark + ',请登录PC端系统。',
+                            },
+                        };
+                        break;
+                    case wxConst.template.material:
+                        break;
+                    default:break;
+                }
+                if (msgData !== '') {
+                    console.log(openid, templateId, url, msgData);
+                    // await this.ctx.app.wechat.api.sendTemplate(openid, templateId, url, '', msgData);
                 }
             }
             flag = true;

+ 68 - 84
app/service/change.js

@@ -14,6 +14,7 @@ const path = require('path');
 const smsTypeConst = require('../const/sms_type');
 const SMS = require('../lib/sms');
 const SmsAliConst = require('../const/sms_alitemplate');
+const wxConst = require('../const/wechat_template');
 const pushType = require('../const/audit').pushType;
 
 module.exports = app => {
@@ -269,7 +270,7 @@ module.exports = app => {
                     sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId, status, tenderId];
                     break;
                 case 3: // 已完成(所有的)
-                    sql = 'SELECT a.* FROM ?? AS a WHERE ' + 'a.status = ? AND a.tid = ? ORDER BY a.in_time DESC';
+                    sql = 'SELECT a.* FROM ?? AS a WHERE a.status = ? AND a.tid = ? ORDER BY a.in_time DESC';
                     sqlParam = [this.tableName, status, tenderId];
                     break;
                 default:
@@ -405,25 +406,24 @@ module.exports = app => {
 
                         // 添加短信通知-需要审批提醒功能
                         if (change_status && index === 0) {
-                            // const smsUser = await this.ctx.service.projectAccount.getDataById(auditInfo[0]);
-                            // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
-                            //     const smsType = JSON.parse(smsUser.sms_type);
-                            //     if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
-                            //         const sms = new SMS(this.ctx);
-                            //         const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi');
-                            //         const content = '【纵横计量支付】' + changeInfo.code + '变更需要您审批。' + result;
-                            //         sms.send(smsUser.auth_mobile, content);
-                            //     }
-                            // }
                             const sms = new SMS(this.ctx);
                             const code = await sms.contentChange(changeInfo.code);
                             const shenpiUrl = await this.ctx.helper.urlToShort(
-                                'http://' + this.ctx.request.header.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi'
+                                this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi'
                             );
                             await this.ctx.helper.sendAliSms(auditInfo[0], smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
                                 biangeng: code,
                                 code: shenpiUrl,
                             });
+                            // 微信模板通知
+                            const wechatData = {
+                                wap_url: shenpiUrl,
+                                status: wxConst.status.check,
+                                tips: wxConst.tips.check,
+                                code: this.ctx.session.sessionProject.code,
+                                c_name: changeInfo.name,
+                            };
+                            await this.ctx.helper.sendWechat(auditInfo[0], smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
                         }
                     }
                     await this.transaction.insert(this.ctx.service.changeAudit.tableName, insertCA);
@@ -583,20 +583,6 @@ module.exports = app => {
                     // 添加短信通知-审批通过提醒功能
                     // const mobile_array = [];
                     const auditList = await this.ctx.service.changeAudit.getListGroupByTimes(changeData.cid, changeData.times);
-                    // for (const user of auditList) {
-                    //     const smsUser = await this.ctx.service.projectAccount.getDataById(user.uid);
-                    //     if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
-                    //         const smsType = JSON.parse(smsUser.sms_type);
-                    //         if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                    //             mobile_array.push(smsUser.auth_mobile);
-                    //         }
-                    //     }
-                    // }
-                    // if (mobile_array.length > 0) {
-                    //     const sms = new SMS(this.ctx);
-                    //     const content = '【纵横计量支付】' + changeData.code + '变更,审批通过。';
-                    //     sms.send(mobile_array, content);
-                    // }
                     const users = this._.map(auditList, 'uid');
                     const sms = new SMS(this.ctx);
                     const code = await sms.contentChange(changeData.code);
@@ -604,6 +590,18 @@ module.exports = app => {
                         biangeng: code,
                         status: SmsAliConst.status.success,
                     });
+                    // 微信模板通知
+                    const shenpiUrl = await this.ctx.helper.urlToShort(
+                        this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi'
+                    );
+                    const wechatData = {
+                        wap_url: shenpiUrl,
+                        status: wxConst.status.success,
+                        tips: wxConst.tips.success,
+                        code: this.ctx.session.sessionProject.code,
+                        c_name: changeData.name,
+                    };
+                    await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
                 } else {
                     // 设置下一个审批人为审批状态
                     const nextAudit_update = {
@@ -616,24 +614,22 @@ module.exports = app => {
                     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 smsUser = await this.ctx.service.projectAccount.getDataById(nextAuditData.uid);
-                    // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
-                    //     const smsType = JSON.parse(smsUser.sms_type);
-                    //     if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
-                    //         const sms = new SMS(this.ctx);
-                    //         const code = await sms.contentChange(changeData.code);
-                    //         const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi');
-                    //         const content = '【纵横计量支付】' + code + '变更需要您审批。' + result;
-                    //         sms.send(smsUser.auth_mobile, content);
-                    //     }
-                    // }
                     const shenpiUrl = await this.ctx.helper.urlToShort(
-                        'http://' + this.ctx.request.header.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi'
+                        this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi'
                     );
                     await this.ctx.helper.sendAliSms(nextAuditData.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
                         biangeng: code,
                         code: shenpiUrl,
                     });
+                    // 微信模板通知
+                    const wechatData = {
+                        wap_url: shenpiUrl,
+                        status: wxConst.status.check,
+                        tips: wxConst.tips.check,
+                        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);
                 }
                 change_update.total_price = total_price;
                 const options = {
@@ -777,24 +773,6 @@ module.exports = app => {
 
                 await this.transaction.commit();
                 result = true;
-
-                // 添加短信通知-审批退回提醒功能
-                // const mobile_array = [];
-                // for (const user of insert_audit_array) {
-                //     const smsUser = await this.ctx.service.projectAccount.getDataById(user.uid);
-                //     if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
-                //         const smsType = JSON.parse(smsUser.sms_type);
-                //         if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                //             mobile_array.push(smsUser.auth_mobile);
-                //         }
-                //     }
-                // }
-                // if (mobile_array.length > 0) {
-                //     const sms = new SMS(this.ctx);
-                //     const code = await sms.contentChange(changeData.code);
-                //     const content = '【纵横计量支付】' + code + '变更,审批退回。';
-                //     sms.send(mobile_array, content);
-                // }
                 const users = this._.map(insert_audit_array, 'uid');
                 const sms = new SMS(this.ctx);
                 const code = await sms.contentChange(changeData.code);
@@ -802,6 +780,18 @@ module.exports = app => {
                     biangeng: code,
                     status: SmsAliConst.status.back,
                 });
+                // 微信模板通知
+                const shenpiUrl = await this.ctx.helper.urlToShort(
+                    this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi'
+                );
+                const wechatData = {
+                    wap_url: shenpiUrl,
+                    status: wxConst.status.back,
+                    tips: wxConst.tips.back,
+                    code: this.ctx.session.sessionProject.code,
+                    c_name: changeInfo.name,
+                };
+                await this.ctx.helper.sendWechat(users, smsTypeConst.const.BG, smsTypeConst.judge.result.toString(), wxConst.template.change, wechatData);
             } catch (error) {
                 await this.transaction.rollback();
                 result = false;
@@ -930,28 +920,24 @@ module.exports = app => {
                 await this.transaction.update(this.tableName, change_update, options);
                 await this.transaction.commit();
                 result = true;
-
-                // 添加短信通知-需要审批提醒功能
-                // const smsUser = await this.ctx.service.projectAccount.getDataById(lastauditInfo.uid);
-                // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
-                //     const smsType = JSON.parse(smsUser.sms_type);
-                //     if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
-                //         const sms = new SMS(this.ctx);
-                //         const code = await sms.contentChange(changeData.code);
-                //         const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi');
-                //         const content = '【纵横计量支付】' + code + '变更需要您审批。' + result;
-                //         sms.send(smsUser.auth_mobile, content);
-                //     }
-                // }
                 const sms = new SMS(this.ctx);
                 const code = await sms.contentChange(changeData.code);
                 const shenpiUrl = await this.ctx.helper.urlToShort(
-                    'http://' + this.ctx.request.header.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi'
+                    this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + changeData.tid + '/change/' + changeData.cid + '/info#shenpi'
                 );
                 await this.ctx.helper.sendAliSms(lastauditInfo.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
                     biangeng: code,
                     code: shenpiUrl,
                 });
+                // 微信模板通知
+                const wechatData = {
+                    wap_url: shenpiUrl,
+                    status: wxConst.status.check,
+                    tips: wxConst.tips.check,
+                    code: this.ctx.session.sessionProject.code,
+                    c_name: changeInfo.name,
+                };
+                await this.ctx.helper.sendWechat(lastauditInfo.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
             } catch (error) {
                 await this.transaction.rollback();
                 result = false;
@@ -1209,28 +1195,26 @@ module.exports = app => {
                 await this.transaction.update(this.tableName, change_update, options);
                 await this.transaction.commit();
                 result = true;
-
-                // 添加短信通知-需要审批提醒功能
-                // const smsUser = await this.ctx.service.projectAccount.getDataById(auditInfo.uid);
-                // if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
-                //     const smsType = JSON.parse(smsUser.sms_type);
-                //     if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
-                //         const sms = new SMS(this.ctx);
-                //         const code = await sms.contentChange(changeInfo.code);
-                //         const result = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi');
-                //         const content = '【纵横计量支付】' + code + '变更需要您审批。' + result;
-                //         sms.send(smsUser.auth_mobile, content);
-                //     }
-                // }
                 const sms = new SMS(this.ctx);
                 const code = await sms.contentChange(changeInfo.code);
                 const shenpiUrl = await this.ctx.helper.urlToShort(
-                    'http://' + this.ctx.request.header.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi'
+                    this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + changeInfo.tid + '/change/' + changeInfo.cid + '/info#shenpi'
                 );
                 await this.ctx.helper.sendAliSms(auditInfo.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), SmsAliConst.template.change_check, {
                     biangeng: code,
                     code: shenpiUrl,
                 });
+
+                // 微信模板通知
+                const wechatData = {
+                    wap_url: shenpiUrl,
+                    status: wxConst.status.check,
+                    tips: wxConst.tips.check,
+                    code: this.ctx.session.sessionProject.code,
+                    c_name: changeInfo.name,
+                };
+                await this.ctx.helper.sendWechat(auditInfo.uid, smsTypeConst.const.BG, smsTypeConst.judge.approval.toString(), wxConst.template.change, wechatData);
+
             } catch (error) {
                 await this.transaction.rollback();
                 result = false;

+ 33 - 64
app/service/ledger_audit.js

@@ -12,6 +12,7 @@ const auditConst = require('../const/audit').ledger;
 const smsTypeConst = require('../const/sms_type');
 const SMS = require('../lib/sms');
 const SmsAliConst = require('../const/sms_alitemplate');
+const wxConst = require('../const/wechat_template');
 const pushType = require('../const/audit').pushType;
 
 module.exports = app => {
@@ -226,9 +227,14 @@ module.exports = app => {
                 });
 
                 // 添加短信通知-需要审批提醒功能
-                // await this.ctx.helper.sendUserSms(audit.audit_id, smsTypeConst.const.TZ,
-                //     smsTypeConst.judge.approval.toString(), '台帐需要您审批。');
                 await this.ctx.helper.sendAliSms(audit.audit_id, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), SmsAliConst.template.ledger_check);
+                // 微信模板通知
+                const wechatData = {
+                    status: wxConst.status.check,
+                    tips: wxConst.tips.check,
+                    begin_time: Date.parse(new Date()),
+                };
+                await this.ctx.helper.sendWechat(audit.audit_id, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), wxConst.template.ledger, wechatData);
 
                 await transaction.commit();
             } catch (err) {
@@ -289,6 +295,10 @@ module.exports = app => {
                 await transaction.insert('zh_notice', records);
                 // 更新当前审核流程
                 await transaction.update(this.tableName, { id: audit.id, status: checkType, opinion, end_time: time });
+                const begin_audit = await this.getDataByCondition({
+                    tender_id: tenderId,
+                    audit_order: 1,
+                });
                 if (checkType === auditConst.status.checked) {
                     const nextAudit = await this.getDataByCondition({
                         tender_id: tenderId,
@@ -302,50 +312,31 @@ module.exports = app => {
                             status: auditConst.status.checking,
                             begin_time: time,
                         });
-                        // await this.ctx.helper.sendUserSms(nextAudit.audit_id, smsTypeConst.const.TZ,
-                        //     smsTypeConst.judge.approval.toString(), '台帐需要您审批。');
                         await this.ctx.helper.sendAliSms(nextAudit.audit_id, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), SmsAliConst.template.ledger_check);
+                        // 微信模板通知
+                        const wechatData = {
+                            status: wxConst.status.check,
+                            tips: wxConst.tips.check,
+                            begin_time: Date.parse(begin_audit.begin_time),
+                        };
+                        await this.ctx.helper.sendWechat(nextAudit.audit_id, smsTypeConst.const.TZ, smsTypeConst.judge.approval.toString(), wxConst.template.ledger, wechatData);
                     } else {
                         // 同步标段信息
                         await transaction.update(this.ctx.service.tender.tableName, {
                             id: tenderId,
                             ledger_status: checkType,
                         });
-
-                        // 添加短信通知-审批通过提醒功能
-                        // const mobile_array = [];
-                        // const tenderInfo = await this.ctx.service.tender.getDataById(tenderId);
-                        // const smsUser1 = await this.ctx.service.projectAccount.getDataById(tenderInfo.user_id);
-                        // if (smsUser1.auth_mobile !== '' && smsUser1.auth_mobile !== undefined && smsUser1.sms_type !== '' && smsUser1.sms_type !== null) {
-                        //     const smsType = JSON.parse(smsUser1.sms_type);
-                        //     if (smsType[smsTypeConst.const.TZ] !== undefined && smsType[smsTypeConst.const.TZ].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                        //         mobile_array.push(smsUser1.auth_mobile);
-                        //     }
-                        // }
-                        // const auditList = await this.getAuditors(tenderId, times);
-                        // for (const user of auditList) {
-                        //     const smsUser = await this.ctx.service.projectAccount.getDataById(user.audit_id);
-                        //     if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
-                        //         const smsType = JSON.parse(smsUser.sms_type);
-                        //         if (mobile_array.indexOf(smsUser.auth_mobile) === -1 && smsType[smsTypeConst.const.TZ] !== undefined && smsType[smsTypeConst.const.TZ].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                        //             mobile_array.push(smsUser.auth_mobile);
-                        //         }
-                        //     }
-                        // }
-                        // if (mobile_array.length > 0) {
-                        //     const sms = new SMS(this.ctx);
-                        //     const tenderName = await sms.contentChange(tenderInfo.name);
-                        //     const projectName = await sms.contentChange(this.ctx.tender.info.deal_info.buildName);
-                        //     const ptmsg = projectName !== '' ? '项目「' + projectName + '」标段「' + tenderName + '」' : tenderName;
-                        //     const content = '【纵横计量支付】' + ptmsg + '台账审批通过,请登录系统处理。';
-                        //     sms.send(mobile_array, content);
-                        // }
                         const users = this._.pull(this._.map(auditList, 'audit_id'), audit.id);
-                        // await this.ctx.helper.sendUserSms(users, smsTypeConst.const.TZ,
-                        //     smsTypeConst.judge.result.toString(), '台账审批通过,请登录系统处理。');
                         await this.ctx.helper.sendAliSms(users, smsTypeConst.const.TZ, smsTypeConst.judge.result.toString(), SmsAliConst.template.ledger_result, {
                             status: SmsAliConst.status.success,
                         });
+                        // 微信模板通知
+                        const wechatData = {
+                            status: wxConst.status.success,
+                            tips: wxConst.tips.success,
+                            begin_time: Date.parse(begin_audit.begin_time),
+                        };
+                        await this.ctx.helper.sendWechat(users, smsTypeConst.const.TZ, smsTypeConst.judge.result.toString(), wxConst.template.ledger, wechatData);
                     }
                 } else {
                     // 同步标段信息
@@ -365,39 +356,17 @@ module.exports = app => {
                     }
                     await transaction.insert(this.tableName, auditors);
 
-                    // 添加短信通知-审批退回提醒功能
-                    // const mobile_array = [];
-                    // const tenderInfo = await this.ctx.service.tender.getDataById(tenderId);
-                    // const smsUser1 = await this.ctx.service.projectAccount.getDataById(tenderInfo.user_id);
-                    // if (smsUser1.auth_mobile !== '' && smsUser1.auth_mobile !== undefined && smsUser1.sms_type !== '' && smsUser1.sms_type !== null) {
-                    //     const smsType = JSON.parse(smsUser1.sms_type);
-                    //     if (smsType[smsTypeConst.const.TZ] !== undefined && smsType[smsTypeConst.const.TZ].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                    //         mobile_array.push(smsUser1.auth_mobile);
-                    //     }
-                    // }
-                    // for (const user of auditors) {
-                    //     const smsUser = await this.ctx.service.projectAccount.getDataById(user.audit_id);
-                    //     if (smsUser.auth_mobile !== '' && smsUser.auth_mobile !== undefined && smsUser.sms_type !== '' && smsUser.sms_type !== null) {
-                    //         const smsType = JSON.parse(smsUser.sms_type);
-                    //         if (mobile_array.indexOf(smsUser.auth_mobile) === -1 && smsType[smsTypeConst.const.TZ] !== undefined && smsType[smsTypeConst.const.TZ].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                    //             mobile_array.push(smsUser.auth_mobile);
-                    //         }
-                    //     }
-                    // }
-                    // if (mobile_array.length > 0) {
-                    //     const sms = new SMS(this.ctx);
-                    //     const tenderName = await sms.contentChange(tenderInfo.name);
-                    //     const projectName = await sms.contentChange(this.ctx.tender.info.deal_info.buildName);
-                    //     const ptmsg = projectName !== '' ? '项目「' + projectName + '」标段「' + tenderName + '」' : tenderName;
-                    //     const content = '【纵横计量支付】' + ptmsg + '台账审批退回,请登录系统处理。';
-                    //     sms.send(mobile_array, content);
-                    // }
                     const users = this._.pull(this._.map(auditList, 'audit_id'), audit.id);
-                    // await this.ctx.helper.sendUserSms(users, smsTypeConst.const.TZ,
-                    //     smsTypeConst.judge.result.toString(), '台账审批退回,请登录系统处理。');
                     await this.ctx.helper.sendAliSms(users, smsTypeConst.const.TZ, smsTypeConst.judge.result.toString(), SmsAliConst.template.ledger_result, {
                         status: SmsAliConst.status.back,
                     });
+                    // 微信模板通知
+                    const wechatData = {
+                        status: wxConst.status.back,
+                        tips: wxConst.tips.back,
+                        begin_time: Date.parse(begin_audit.begin_time),
+                    };
+                    await this.ctx.helper.sendWechat(audit.audit_id, smsTypeConst.const.TZ, smsTypeConst.judge.result.toString(), wxConst.template.ledger, wechatData);
                 }
 
                 await transaction.commit();

+ 158 - 104
app/service/revise_audit.js

@@ -8,10 +8,11 @@
  * @version
  */
 
-const auditConst = require('../const/audit').revise
-const smsTypeConst = require('../const/sms_type')
-const SmsAliConst = require('../const/sms_alitemplate')
-const pushType = require('../const/audit').pushType
+const auditConst = require('../const/audit').revise;
+const smsTypeConst = require('../const/sms_type');
+const SmsAliConst = require('../const/sms_alitemplate');
+const wxConst = require('../const/wechat_template');
+const pushType = require('../const/audit').pushType;
 
 module.exports = app => {
     class ReviseAudit extends app.BaseService {
@@ -22,8 +23,8 @@ module.exports = app => {
          * @return {void}
          */
         constructor(ctx) {
-            super(ctx)
-            this.tableName = 'revise_audit'
+            super(ctx);
+            this.tableName = 'revise_audit';
         }
 
         /**
@@ -39,9 +40,9 @@ module.exports = app => {
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
                 'FROM ?? AS la, ?? AS pa ' +
                 'WHERE la.`rid` = ? and la.`audit_id` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`'
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditorId, times]
-            return await this.db.queryOne(sql, sqlParam)
+                '    and la.`audit_id` = pa.`id`';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditorId, times];
+            return await this.db.queryOne(sql, sqlParam);
         }
 
         /**
@@ -61,9 +62,9 @@ module.exports = app => {
                 '  INNER JOIN ' +
                 this.ctx.service.projectAccount.tableName +
                 ' AS pa ON la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id`' +
-                '  ORDER BY la.`audit_order`'
-            const sqlParam = [reviseId, times]
-            return await this.db.query(sql, sqlParam)
+                '  ORDER BY la.`audit_order`';
+            const sqlParam = [reviseId, times];
+            return await this.db.query(sql, sqlParam);
         }
 
         /**
@@ -77,16 +78,16 @@ module.exports = app => {
             const sql =
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
                 'FROM ?? AS la, ?? AS pa, (SELECT `audit_id`,(@i:=@i+1) as `sort` FROM ??, (select @i:=0) as it WHERE `rid` = ? AND `times` = ? GROUP BY `audit_id`) as g ' +
-                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` and g.`audit_id` = la.`audit_id` order by la.`audit_order`'
+                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` and g.`audit_id` = la.`audit_id` order by la.`audit_order`';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, rid, times, rid, times]
-            const result = await this.db.query(sql, sqlParam)
-            const sql2 = 'SELECT COUNT(a.`audit_id`) as num FROM (SELECT `audit_id` FROM ?? WHERE `rid` = ? AND `times` = ? GROUP BY `audit_id`) as a'
-            const sqlParam2 = [this.tableName, rid, times]
-            const count = await this.db.queryOne(sql2, sqlParam2)
+            const result = await this.db.query(sql, sqlParam);
+            const sql2 = 'SELECT COUNT(a.`audit_id`) as num FROM (SELECT `audit_id` FROM ?? WHERE `rid` = ? AND `times` = ? GROUP BY `audit_id`) as a';
+            const sqlParam2 = [this.tableName, rid, times];
+            const count = await this.db.queryOne(sql2, sqlParam2);
             for (const i in result) {
-                result[i].max_sort = count.num
+                result[i].max_sort = count.num;
             }
-            return result
+            return result;
         }
 
         /**
@@ -101,9 +102,9 @@ module.exports = app => {
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`audit_order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
                 'FROM ?? AS la, ?? AS pa ' +
                 'WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ?' +
-                '    and la.`audit_id` = pa.`id`'
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditConst.status.checking, times]
-            return await this.db.queryOne(sql, sqlParam)
+                '    and la.`audit_id` = pa.`id`';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, reviseId, auditConst.status.checking, times];
+            return await this.db.queryOne(sql, sqlParam);
         }
 
         /**
@@ -114,10 +115,10 @@ module.exports = app => {
          * @returns {Promise<number>}
          */
         async getNewOrder(reviseId, times = 1) {
-            const sql = 'SELECT Max(??) As max_order FROM ?? Where `rid` = ? and `times` = ?'
-            const sqlParam = ['audit_order', this.tableName, reviseId, times]
-            const result = await this.db.queryOne(sql, sqlParam)
-            return result && result.max_order ? result.max_order + 1 : 1
+            const sql = 'SELECT Max(??) As max_order FROM ?? Where `rid` = ? and `times` = ?';
+            const sqlParam = ['audit_order', this.tableName, reviseId, times];
+            const result = await this.db.queryOne(sql, sqlParam);
+            return result && result.max_order ? result.max_order + 1 : 1;
         }
 
         /**
@@ -129,8 +130,8 @@ module.exports = app => {
          * @returns {Promise<number>}
          */
         async addAuditor(revise, auditorId) {
-            const times = revise.times ? revise.times : 1
-            const newOrder = await this.getNewOrder(revise.id, times)
+            const times = revise.times ? revise.times : 1;
+            const newOrder = await this.getNewOrder(revise.id, times);
             const data = {
                 tender_id: revise.tid,
                 audit_id: auditorId,
@@ -139,9 +140,9 @@ module.exports = app => {
                 status: auditConst.status.uncheck,
                 rid: revise.id,
                 in_time: new Date()
-            }
-            const result = await this.db.insert(this.tableName, data)
-            return (result.effectRows = 1)
+            };
+            const result = await this.db.insert(this.tableName, data);
+            return (result.effectRows = 1);
         }
 
         /**
@@ -154,27 +155,27 @@ module.exports = app => {
          * @private
          */
         async _syncOrderByDelete(transaction, reviseId, order, times) {
-            this.initSqlBuilder()
+            this.initSqlBuilder();
             this.sqlBuilder.setAndWhere('rid', {
                 value: this.db.escape(reviseId),
                 operate: '='
-            })
+            });
             this.sqlBuilder.setAndWhere('audit_order', {
                 value: order,
                 operate: '>='
-            })
+            });
             this.sqlBuilder.setAndWhere('times', {
                 value: times,
                 operate: '='
-            })
+            });
             this.sqlBuilder.setUpdateData('audit_order', {
                 value: 1,
                 selfOperate: '-'
-            })
-            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update')
-            const data = await transaction.query(sql, sqlParam)
+            });
+            const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
+            const data = await transaction.query(sql, sqlParam);
 
-            return data
+            return data;
         }
 
         /**
@@ -186,22 +187,22 @@ module.exports = app => {
          * @returns {Promise<boolean>}
          */
         async deleteAuditor(revise, auditorId) {
-            const times = revise.times ? revise.times : 1
-            const transaction = await this.db.beginTransaction()
+            const times = revise.times ? revise.times : 1;
+            const transaction = await this.db.beginTransaction();
             try {
-                const condition = { rid: revise.id, audit_id: auditorId, times }
-                const auditor = await this.getDataByCondition(condition)
+                const condition = { rid: revise.id, audit_id: auditorId, times };
+                const auditor = await this.getDataByCondition(condition);
                 if (!auditor) {
                     throw '该审核人不存在'
                 }
-                await this._syncOrderByDelete(transaction, revise.id, auditor.audit_order, times)
-                await transaction.delete(this.tableName, condition)
-                await transaction.commit()
+                await this._syncOrderByDelete(transaction, revise.id, auditor.audit_order, times);
+                await transaction.delete(this.tableName, condition);
+                await transaction.commit();
             } catch (err) {
-                await transaction.rollback()
-                throw err
+                await transaction.rollback();
+                throw err;
             }
-            return true
+            return true;
         }
 
         /**
@@ -235,7 +236,7 @@ module.exports = app => {
                     pos_file: posHis
                 };
                 if (revise.times === 1) {
-                    reviseData.begin_time = time
+                    reviseData.begin_time = time;
                 }
                 await transaction.update(this.ctx.service.ledgerRevise.tableName, reviseData);
 
@@ -244,19 +245,32 @@ module.exports = app => {
                 // await this.ctx.helper.sendUserSms(audit.audit_id, smsTypeConst.const.XD,
                 //     smsTypeConst.judge.approval.toString(), '台帐修订需要您审批,请登录系统处理。');
                 await this.ctx.helper.sendAliSms(audit.audit_id, smsTypeConst.const.XD, smsTypeConst.judge.approval.toString(), SmsAliConst.template.revise_check);
+                // 微信模板通知
+                const wechatData = {
+                    status: wxConst.status.check,
+                    tips: wxConst.tips.check,
+                    begin_time: Date.parse(time),
+                };
+                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)
                 // 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);
-
-                await transaction.commit()
+                // 微信模板通知
+                const wechatData2 = {
+                    status: wxConst.status.report,
+                    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 transaction.commit();
             } catch (err) {
-                await transaction.rollback()
-                throw err
+                await transaction.rollback();
+                throw err;
             }
-            return true
+            return true;
         }
 
         async _replaceLedgerByRevise(transaction, revise) {
@@ -307,14 +321,14 @@ module.exports = app => {
                 rid: revise.id,
                 times,
                 status: auditConst.status.checking
-            })
-            if (!audit) throw '审核数据错误'
-            const pid = this.ctx.session.sessionProject.id
-            const transaction = await this.db.beginTransaction()
+            });
+            if (!audit) throw '审核数据错误';
+            const pid = this.ctx.session.sessionProject.id;
+            const transaction = await this.db.beginTransaction();
             try {
-                const auditList = await this.getAuditors(revise.id, times)
+                const auditList = await this.getAuditors(revise.id, times);
                 // 审核通过添加到推送表
-                const noticeContent = await this.getNoticeContent(pid, audit.tender_id, audit.rid, audit.audit_id)
+                const noticeContent = await this.getNoticeContent(pid, audit.tender_id, audit.rid, audit.audit_id);
                 const records = [
                     {
                         pid,
@@ -323,7 +337,7 @@ module.exports = app => {
                         status: checkType,
                         content: noticeContent
                     }
-                ]
+                ];
                 auditList.forEach(audit => {
                     records.push({
                         pid,
@@ -333,7 +347,7 @@ module.exports = app => {
                         content: noticeContent
                     })
                 });
-                await transaction.insert('zh_notice', records)
+                await transaction.insert('zh_notice', records);
 
                 // 整理当前流程审核人状态更新
                 const time = new Date();
@@ -362,9 +376,14 @@ module.exports = app => {
                         // 下一人
                         // await this.ctx.helper.sendUserSms(nextAudit.user_id, smsTypeConst.const.XD,
                         //     smsTypeConst.judge.approval.toString(), '台帐修订需要您审批,请登录系统处理。');
-                        await this.ctx.helper.sendAliSms(nextAudit.user_id, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result, {
-                            status: SmsAliConst.status.success
-                        });
+                        await this.ctx.helper.sendAliSms(nextAudit.user_id, smsTypeConst.const.XD, smsTypeConst.judge.approval.toString(), SmsAliConst.template.revise_check);
+                        // 微信模板通知
+                        const wechatData = {
+                            status: wxConst.status.check,
+                            tips: wxConst.tips.check,
+                            begin_time: Date.parse(revise.begin_time),
+                        };
+                        await this.ctx.helper.sendWechat(nextAudit.user_id, smsTypeConst.const.XD, smsTypeConst.judge.approval.toString(), wxConst.template.revise, wechatData);
                         // 其他参与人
                         const users = this._.pull(this._.map(auditList, 'user_id'), audit.id);
                         users.push(revise.uid);
@@ -373,6 +392,13 @@ module.exports = app => {
                         await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, {
                             status: SmsAliConst.status.success
                         })
+                        // 微信模板通知
+                        const wechatData2 = {
+                            status: wxConst.status.success,
+                            tips: wxConst.tips.success,
+                            begin_time: Date.parse(revise.begin_time),
+                        };
+                        await this.ctx.helper.sendWechat(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData2);
                     } else {
                         // 同步修订信息
                         await transaction.update(this.ctx.service.ledgerRevise.tableName, {
@@ -407,6 +433,13 @@ module.exports = app => {
                         await this.ctx.helper.sendAliSms(revise.uid, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result, {
                             status: SmsAliConst.status.success
                         });
+                        // 微信模板通知
+                        const wechatData = {
+                            status: wxConst.status.success,
+                            tips: wxConst.tips.success,
+                            begin_time: Date.parse(revise.begin_time),
+                        };
+                        await this.ctx.helper.sendWechat(revise.uid, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData);
                         // 其他参与人
                         const users = this._.pull(this._.map(auditList, 'user_id'), audit.id)
                         // await this.ctx.helper.sendUserSms(users, smsTypeConst.const.XD,
@@ -414,6 +447,13 @@ module.exports = app => {
                         await this.ctx.helper.sendAliSms(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result2, {
                             status: SmsAliConst.status.success
                         })
+                        // 微信模板通知
+                        const wechatData2 = {
+                            status: wxConst.status.success,
+                            tips: wxConst.tips.success,
+                            begin_time: Date.parse(revise.begin_time),
+                        };
+                        await this.ctx.helper.sendWechat(users, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData2);
                     }
                 } else {
                     // 同步修订信息
@@ -440,7 +480,14 @@ module.exports = app => {
                     //     smsTypeConst.judge.result.toString(), '台账修订审批退回,请登录系统处理。');
                     await this.ctx.helper.sendAliSms(revise.uid, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), SmsAliConst.template.revise_result, {
                         status: SmsAliConst.status.back
-                    })
+                    });
+                    // 微信模板通知
+                    const wechatData = {
+                        status: wxConst.status.back,
+                        tips: wxConst.tips.back,
+                        begin_time: Date.parse(revise.begin_time),
+                    };
+                    await this.ctx.helper.sendWechat(revise.uid, smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData);
                     // 其他参与人
                     // await this.ctx.helper.sendUserSms(this._.map(auditors, 'user_id'),
                     //     smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), '台账修订审批退回。');
@@ -452,13 +499,20 @@ module.exports = app => {
                         {
                             status: SmsAliConst.status.back
                         }
-                    )
+                    );
+                    // 微信模板通知
+                    const wechatData2 = {
+                        status: wxConst.status.back,
+                        tips: wxConst.tips.back,
+                        begin_time: Date.parse(revise.begin_time),
+                    };
+                    await this.ctx.helper.sendWechat(this._.map(auditors, 'user_id'), smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), wxConst.template.revise, wechatData2);
                 }
 
-                await transaction.commit()
+                await transaction.commit();
             } catch (err) {
-                await transaction.rollback()
-                throw err
+                await transaction.rollback();
+                throw err;
             }
         }
 
@@ -487,9 +541,9 @@ module.exports = app => {
                 this.ctx.service.projectAccount.tableName +
                 ' As p On ra.audit_id = p.id' +
                 '  WHERE r.`valid` != 0 and ((ra.`audit_id` = ? and ra.`status` = ?) OR' +
-                '    (r.`uid` = ? and r.`status` = ? and ra.`status` = ? and ra.`times` = (r.`times`-1)))'
-            const sqlParam = [auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo]
-            return await this.db.query(sql, sqlParam)
+                '    (r.`uid` = ? and r.`status` = ? and ra.`status` = ? and ra.`times` = (r.`times`-1)))';
+            const sqlParam = [auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
+            return await this.db.query(sql, sqlParam);
         }
 
         /**
@@ -518,13 +572,13 @@ module.exports = app => {
                 orders: [['create_time', 'desc']],
                 limit: 10,
                 offset: 0
-            })
+            });
             notice = notice.map(v => {
-                const extra = JSON.parse(v.content)
-                delete v.content
-                return { ...v, ...extra }
-            })
-            return notice
+                const extra = JSON.parse(v.content);
+                delete v.content;
+                return { ...v, ...extra };
+            });
+            return notice;
         }
 
         /**
@@ -541,10 +595,10 @@ module.exports = app => {
                 '  FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
                 '  LEFT JOIN ?? As r On r.`id` = ? ' +
                 '  LEFT JOIN ?? As pa ON pa.`id` = ? ' +
-                '  WHERE  t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`'
-            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.ledgerRevise.tableName, rid, this.ctx.service.projectAccount.tableName, uid, pid]
-            const content = await this.db.query(noticeSql, noticeSqlParam)
-            return content.length ? JSON.stringify(content[0]) : ''
+                '  WHERE  t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
+            const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.ledgerRevise.tableName, rid, this.ctx.service.projectAccount.tableName, uid, pid];
+            const content = await this.db.query(noticeSql, noticeSqlParam);
+            return content.length ? JSON.stringify(content[0]) : '';
         }
 
         /**
@@ -556,9 +610,9 @@ module.exports = app => {
          * @return {Promise<boolean>}
          */
         async getAuditorByStatus(rid, status, times = 1) {
-            let auditor = null
-            let sql = ''
-            let sqlParam = ''
+            let auditor = null;
+            let sql = '';
+            let sqlParam = '';
             switch (status) {
                 case auditConst.status.checking:
                 case auditConst.status.checked:
@@ -566,23 +620,23 @@ module.exports = app => {
                     sql =
                         'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
                         'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`rid` = ? and la.`status` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc'
-                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, status]
-                    auditor = await this.db.queryOne(sql, sqlParam)
-                    break
+                        'WHERE la.`rid` = ? and la.`status` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc';
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, status];
+                    auditor = await this.db.queryOne(sql, sqlParam);
+                    break;
                 case auditConst.status.checkNo:
                     sql =
                         'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
                         'FROM ?? AS la, ?? AS pa ' +
-                        'WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc'
-                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, auditConst.status.checkNo, parseInt(times) - 1]
-                    auditor = await this.db.queryOne(sql, sqlParam)
-                    break
+                        'WHERE la.`rid` = ? and la.`status` = ? and la.`times` = ? and la.`audit_id` = pa.`id` order by la.`times` desc, la.`audit_order` desc';
+                    sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, auditConst.status.checkNo, parseInt(times) - 1];
+                    auditor = await this.db.queryOne(sql, sqlParam);
+                    break;
                 case auditConst.status.uncheck:
                 default:
-                    break
+                    break;
             }
-            return auditor
+            return auditor;
         }
 
         /**
@@ -595,9 +649,9 @@ module.exports = app => {
             const sql =
                 'SELECT la.`audit_id`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`rid`, la.`audit_order` ' +
                 'FROM ?? AS la, ?? AS pa ' +
-                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` GROUP BY la.`audit_id` ORDER BY la.`audit_order`'
-            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, times]
-            return await this.db.query(sql, sqlParam)
+                'WHERE la.`rid` = ? and la.`times` = ? and la.`audit_id` = pa.`id` GROUP BY la.`audit_id` ORDER BY la.`audit_order`';
+            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, rid, times];
+            return await this.db.query(sql, sqlParam);
             // const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
             // const sqlParam = [this.tableName, stageId, times];
             // return await this.db.query(sql, sqlParam);
@@ -612,11 +666,11 @@ module.exports = app => {
                 this.ctx.service.tender.tableName +
                 ' t On ra.tender_id = t.id' +
                 '  WHERE t.id = ?' +
-                '  GROUP BY ra.audit_id'
-            const sqlParam = [tenderId]
-            return this.db.query(sql, sqlParam)
+                '  GROUP BY ra.audit_id';
+            const sqlParam = [tenderId];
+            return this.db.query(sql, sqlParam);
         }
     }
 
     return ReviseAudit
-}
+};