瀏覽代碼

台账修订,短信通知相关

MaiXinRong 5 年之前
父節點
當前提交
9615d6b3c6
共有 3 個文件被更改,包括 68 次插入45 次删除
  1. 10 1
      app/const/sms_type.js
  2. 23 0
      app/extend/helper.js
  3. 35 44
      app/service/revise_audit.js

+ 10 - 1
app/const/sms_type.js

@@ -11,11 +11,12 @@ const smsConst = {
     TZ: 'TZ',
     JL: 'JL',
     BG: 'BG',
+    XD: 'XD'
 };
 const judgeConst = {
     approval: 1,
     result: 2,
-}
+};
 const smsType = {
     TZ: {
         name: '台账审批',
@@ -25,6 +26,14 @@ const smsType = {
             { title: '审批结果', value: 2 },
         ],
     },
+    XD: {
+        name: '修订审批',
+        path: '',
+        children: [
+            { title: '需要我审批', value: 1 },
+            { title: '审批结果', value: 2 },
+        ],
+    },
     JL: {
         name: '计量审批',
         path: '',

+ 23 - 0
app/extend/helper.js

@@ -15,6 +15,7 @@ const _ = require('lodash');
 const bc = require('../lib/base_calc.js');
 const Decimal = require('decimal.js');
 Decimal.set({precision: 50, defaults: true});
+const SMS = require('../lib/sms');
 
 module.exports = {
     _: _,
@@ -762,5 +763,27 @@ module.exports = {
             t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? dot : "");
         }
         return t.split("").reverse().join("") + "." + r;
+    },
+
+    async sendUserSms(userId, type, judge, msg) {
+        const mobiles = [];
+        if (!userId || (userId instanceof Array && userId.length === 0)) return;
+        const smsUser = await this.ctx.service.projectAccount.getAllDataByCondition({where: {id: userId}});
+        for (const su of smsUser) {
+            if (!su.auth_mobile || su.auth_mobile === '') continue;
+            if (!su.sms_type || su.sms_type === '') continue;
+
+            const smsType = JSON.parse(su.sms_type);
+            if (smsType[type] && smsType.indexOf(judge) !== -1) {
+                mobiles.push(su.auth_mobile);
+            }
+        }
+
+        if (mobiles.length > 0) {
+            const sms = new SMS(this.ctx);
+            const tenderName = await sms.contentChange(this.ctx.tender.data.name);
+            const content = '【纵横计量支付】' + tenderName + msg;
+            sms.send(mobiles, content);
+        }
     }
 };

+ 35 - 44
app/service/revise_audit.js

@@ -10,7 +10,6 @@
 
 const auditConst = require('../const/audit').revise;
 const smsTypeConst = require('../const/sms_type');
-const SMS = require('../lib/sms');
 
 module.exports = app => {
     class ReviseAudit extends app.BaseService {
@@ -197,16 +196,14 @@ module.exports = app => {
                 await transaction.update(this.ctx.service.ledgerRevise.tableName, reviseData);
 
                 // 添加短信通知-需要审批提醒功能
-                const smsUser = await this.ctx.service.projectAccount.getDataById(audit.audit_id);
-                if (smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
-                    const smsType = JSON.parse(smsUser.sms_type);
-                    if (smsType[smsTypeConst.const.TZ] !== undefined && smsType[smsTypeConst.const.TZ].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
-                        const sms = new SMS(this.ctx);
-                        const tenderName = await sms.contentChange(this.ctx.tender.data.name);
-                        const content = '【纵横计量支付】' + tenderName + '台账修订需要您审批。';
-                        sms.send(smsUser.auth_mobile, content);
-                    }
-                }
+                // 下一人
+                await this.ctx.helper.sendUserSms(audit.audit_id, smsTypeConst.const.XD,
+                    smsTypeConst.judge.approval.toString(), '台帐修订需要您审批,请登录系统处理。');
+                // 其他参与人
+                const auditList = await this.getAuditors(revise.tid, 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 transaction.commit();
             } catch (err) {
@@ -268,17 +265,16 @@ module.exports = app => {
                     if (nextAudit) {
                         await transaction.update(this.tableName, {id: nextAudit.id, status: auditConst.status.checking, begin_time: time});
 
-                        // 添加短信通知-需要审批提醒功能
-                        const smsUser = await this.ctx.service.projectAccount.getDataById(nextAudit.audit_id);
-                        if (smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
-                            const smsType = JSON.parse(smsUser.sms_type);
-                            if (smsType[smsTypeConst.const.TZ] !== undefined && smsType[smsTypeConst.const.TZ].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
-                                const sms = new SMS(this.ctx);
-                                const tenderName = await sms.contentChange(this.ctx.tender.data.name);
-                                const content = '【纵横计量支付】' + tenderName + '台帐修订需要您审批。';
-                                sms.send(smsUser.auth_mobile, content);
-                            }
-                        }
+                        // 短信通知-需要审批提醒功能
+                        // 下一人
+                        await this.ctx.helper.sendUserSms(nextAudit.user_id, smsTypeConst.const.XD,
+                            smsTypeConst.judge.approval.toString(), '台帐修订需要您审批,请登录系统处理。');
+                        // 其他参与人
+                        const auditList = await this.getAuditors(revise.tid, times);
+                        const users = this._.pull(this._.map(auditList, 'user_id'), audit.id);
+                        users.push(revise.uid);
+                        await this.ctx.helper.sendUserSms(users, smsTypeConst.const.XD,
+                            smsTypeConst.judge.result.toString(), '台账修订审批通过。');
                     } else {
                         // 同步修订信息
                         await transaction.update(this.ctx.service.ledgerRevise.tableName, {id: revise.id, status: checkType, end_time: time});
@@ -289,17 +285,16 @@ module.exports = app => {
                             id: revise.tid, total_price: sum.total_price, deal_tp: sum.deal_tp
                         });
 
-                        // 添加短信通知-审批通过提醒功能
-                        const smsUser = await this.ctx.service.projectAccount.getDataById(revise.uid);
-                        if (smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
-                            const smsType = JSON.parse(smsUser.sms_type);
-                            if (smsType[smsTypeConst.const.TZ] !== undefined && smsType[smsTypeConst.const.TZ].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                                const sms = new SMS(this.ctx);
-                                const tenderName = await sms.contentChange(this.ctx.tender.data.name);
-                                const content = '【纵横计量支付】' + tenderName + '台账修订审批通过,请登录系统处理。';
-                                sms.send(smsUser.auth_mobile, content);
-                            }
-                        }
+                        // 短信通知-审批通过提醒功能
+                        // 下一人
+                        const msg = '台账修订审批通过,请登录系统处理。';
+                        await this.ctx.helper.sendUserSms(revise.uid, smsTypeConst.const.XD,
+                            smsTypeConst.judge.result.toString(), msg);
+                        // 其他参与人
+                        const auditList = await this.getAuditors(revise.tid, 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(), '台账修订审批通过。');
                     }
                 } else {
                     // 同步修订信息
@@ -316,17 +311,13 @@ module.exports = app => {
                     }
                     await transaction.insert(this.tableName, auditors);
 
-                    // 添加短信通知-审批退回提醒功能
-                    const smsUser = await this.ctx.service.projectAccount.getDataById(revise.uid);
-                    if (smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
-                        const smsType = JSON.parse(smsUser.sms_type);
-                        if (smsType[smsTypeConst.const.TZ] !== undefined && smsType[smsTypeConst.const.TZ].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                            const sms = new SMS(this.ctx);
-                            const tenderName = await sms.contentChange(this.ctx.tender.data.name);
-                            const content = '【纵横计量支付】' + tenderName + '台账修订审批退回,请登录系统处理。';
-                            sms.send(smsUser.auth_mobile, content);
-                        }
-                    }
+                    // 短信通知-审批退回提醒功能
+                    // 下一人
+                    await this.ctx.helper.sendUserSms(revise.uid, smsTypeConst.const.XD,
+                        smsTypeConst.judge.result.toString(), '台账修订审批退回,请登录系统处理。');
+                    // 其他参与人
+                    await this.ctx.helper.sendUserSms(this._.map(auditors, 'user_id'),
+                        smsTypeConst.const.XD, smsTypeConst.judge.result.toString(), '台账修订审批退回。');
                 }
 
                 await transaction.commit();