Ver código fonte

Merge branch 'master' of http://192.168.1.41:3000/SmartCost/YangHuCost

zhangweicheng 5 anos atrás
pai
commit
304eb317e6

+ 2 - 1
modules/all_models/user.js

@@ -29,7 +29,8 @@ let upgrade = mongoose.Schema({
     compilationID:String,//编办ID
     upgrade_time:Number,
     isUpgrade:Boolean,
-    remark:String//描述:广东办刘飞 2018-06-17 启用/关闭
+    remark:String, //描述:广东办刘飞 2018-06-17 启用/关闭
+    deadline: String,
 }, { _id: false })
 
 const userdList = mongoose.Schema({

+ 13 - 3
modules/users/controllers/cld_controller.js

@@ -106,6 +106,9 @@ class CLDController {
     async setUsersUpgrade(request, response) {
         let ssoID = request.body.ssoId;
         let compilationID = request.body.cid;
+        let deadline = request.body.deadline || '';
+        let status = parseInt(request.body.status);
+        let smssend = parseInt(request.body.smssend);
         try {
 
             let userModel = new UserModel();
@@ -114,7 +117,7 @@ class CLDController {
 
             let compilationModel = new CompilationModel();
 
-            let compilationData = compilationModel.getCompilationById(compilationID);
+            let compilationData = await compilationModel.getCompilationById(compilationID);
 
             if (compilationData === null || compilationData === undefined) {
                 throw '不存在该编办或者编办未发布';
@@ -129,8 +132,9 @@ class CLDController {
             let upgradeInfo = {
                 compilationID:compilationID,//编办ID
                 upgrade_time:new Date().getTime(),
-                isUpgrade:true,
-                remark: ''
+                isUpgrade: status !== 2,
+                remark: '',
+                deadline: deadline,
             };
 
             if (upgradeIndex === -1) {
@@ -143,6 +147,12 @@ class CLDController {
             let result = await userModel.updateUser(condition, {upgrade_list: upgrade_list});
 
             if (result) {
+                // 短信发送
+                if (smssend) {
+                    // 发送短信
+                    const Sms = new SMS();
+                    await Sms.sendProductMsg(userData.mobile, status, userData.real_name, compilationData.name, deadline);
+                }
                 response.json({error: 0, msg: 'success'});
             } else {
                 throw '更新失败';

+ 45 - 0
modules/users/models/sms.js

@@ -111,6 +111,51 @@ class SMS {
         }
     }
 
+    async sendProductMsg(mobile, status, name, product, deadline) {
+        try {
+            let templateId = 0;
+            switch (status) {
+                case 1: templateId = 746380;break;// 产品升级通知
+                case 2: templateId = 746381;break;// 产品降级通知
+                case 3: templateId = 746379;break;// 产品延期通知
+            }
+            const formData = {
+                smsUser: this.smsUser,
+                templateId: templateId,
+                msgType: 0,
+                phone: mobile,
+            };
+            formData.vars = '{"%name%": "' + name + '", "%product%": "' + product + '"' + (status !== 2 ? ', "%deadline%": "' + deadline + '"' : '') +'}';
+            const signature = await this.getSignature(this.sortDict(formData), this.smskey);
+            formData.signature = signature;
+
+            let postData = {
+                url: this.url,
+                form: formData,
+                encoding: 'utf8'
+            };
+
+            return new Promise(function (resolve, reject) {
+                try {
+                    // 请求接口
+                    Request.post(postData, function (err, postResponse, body) {
+                        if (err) {
+                            throw '请求错误';
+                        }
+                        if (postResponse.statusCode !== 200) {
+                            throw '短信发送失败!';
+                        }
+                        resolve(body);
+                    });
+                } catch (error) {
+                    reject([]);
+                }
+            });
+        } catch (error) {
+            console.log(error);
+        }
+    }
+
     md5(data) {
         var str = data;
         return crypto.createHash("md5").update(str).digest("hex");

+ 1 - 1
web/over_write/js/hunan_2020.js

@@ -239,7 +239,7 @@ if (typeof baseFigureTemplate !== 'undefined') {
         },
         // 养护工程费(不含设备费) 算法:取清单固定类别是“建筑安装工程费”的金额,扣除设备的金额(所有设备类型的人材机型定额)。
         YHGCFBHSB(tender) {
-            let baseFee = this[YHGCF](tender);
+            let baseFee = this['YHGCF'](tender);
             const fixedNode = projectObj.project.mainTree.roots.find(node => node.getFlag() === fixedFlag.CONSTRUCTION_INSTALL_FEE);
             const allSubNodes = [];
             projectObj.project.mainTree.getAllSubNode(fixedNode, allSubNodes);