瀏覽代碼

变更短信结果和记录上一次变更信息

laiguoran 5 年之前
父節點
當前提交
e21b559484
共有 3 個文件被更改,包括 55 次插入27 次删除
  1. 9 8
      app/controller/change_controller.js
  2. 2 2
      app/lib/sms.js
  3. 44 17
      app/service/change.js

+ 9 - 8
app/controller/change_controller.js

@@ -418,13 +418,15 @@ module.exports = app => {
                             au.totalCost = 0;
                             if (au.uid === renderData.uid) {
                                 for (const [auindex, at] of auditTotalCost.entries()) {
-                                    if (at[index - 2] !== undefined) {
-                                        au.list_amount.push(at[index - 2]);
-                                        au.totalCost += parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, at[index - 2]), renderData.tpUnit));
-                                    } else if (at[index - 2] === undefined) {
-                                        au.list_amount.push(changeList[auindex].camount);
-                                        au.totalCost += parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, changeList[auindex].camount), renderData.tpUnit));
-                                    }
+                                    // if (at[index - 2] !== undefined) {
+                                    //     au.list_amount.push(at[index - 2]);
+                                    //     au.totalCost += parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, at[index - 2]), renderData.tpUnit));
+                                    // } else if (at[index - 2] === undefined) {
+                                    //     au.list_amount.push(changeList[auindex].camount);
+                                    //     au.totalCost += parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, changeList[auindex].camount), renderData.tpUnit));
+                                    // }
+                                    au.list_amount.push(changeList[auindex].spamount);
+                                    au.totalCost += parseFloat(ctx.helper.roundNum(ctx.helper.accMul(changeList[auindex].unit_price, changeList[auindex].spamount), renderData.tpUnit));
                                 }
                             } else {
                                 for (const [auindex, at] of auditTotalCost.entries()) {
@@ -440,7 +442,6 @@ module.exports = app => {
                 // 获取是否已存在调用变更令
                 const stageChangeNum = await ctx.service.stageChange.count({ cid: change.cid });
                 const stageChangeNum2 = await ctx.service.stageChange.count({ cid: change.cid, qty: null });
-                console.log(stageChangeNum2);
                 renderData.stageChangeNum = stageChangeNum - stageChangeNum2;
                 await this.layout('change/info.ejs', renderData, 'change/info_modal.ejs');
             } catch (err) {

+ 2 - 2
app/lib/sms.js

@@ -19,8 +19,8 @@ class SMS {
      */
     constructor(ctx) {
         this.ctx = ctx;
-        // this.url = 'https://sms.yunpian.com/v2/sms/batch_send.json';
-        this.url = 'http://sms.haotingyun.com/v2/sms/single_send.json';
+        this.url = 'https://sms.yunpian.com/v2/sms/batch_send.json';
+        // this.url = 'http://sms.haotingyun.com/v2/sms/single_send.json';
         this.url2 = 'http://sms.haotingyun.com/v2/sms/tpl_single_send.json';
         // this.url = 'http://101.132.42.40:7862/sms';
     }

+ 44 - 17
app/service/change.js

@@ -366,9 +366,10 @@ module.exports = app => {
                             camount: clInfo[6],
                             samount: '',
                             detail: clInfo[7],
+                            spamount: clInfo[6],
                         };
                         insertCL.push(clArray);
-                        total_price = this.ctx.helper.accAdd(total_price, this.ctx.helper.accMul(clArray.unit_price, clArray.camount));
+                        total_price = this.ctx.helper.accAdd(total_price, this.ctx.helper.accMul(clArray.unit_price, clArray.spamount));
                     }
                     await this.transaction.insert(this.ctx.service.changeAuditList.tableName, insertCL);
                 }
@@ -449,6 +450,7 @@ module.exports = app => {
                         const list_update = {
                             id: lid,
                             audit_amount: audit_amount.join(','),
+                            spamount: parseFloat(amount),
                         };
                         if (postData.audit_next_id === undefined) {
                             list_update.samount = amount;
@@ -461,18 +463,24 @@ module.exports = app => {
                     change_update.status = audit.flow.status.checked;
                     change_update.p_code = postData.p_code;
                     change_update.sin_time = Date.parse(new Date()) / 1000;
-                    change_update.total_price = total_price;
 
                     // 添加短信通知-审批通过提醒功能
-                    const smsUser = await this.ctx.service.projectAccount.getDataById(changeData.uid);
-                    if (smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
-                        const smsType = JSON.parse(smsUser.sms_type);
-                        if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                            const sms = new SMS(this.ctx);
-                            const content = '【纵横计量支付】' + changeData.code + '变更,审批通过。';
-                            sms.send(smsUser.auth_mobile, content);
+                    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 !== undefined && smsUser.sms_type !== '') {
+                            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);
+                    }
                 } else {
                     // 设置下一个审批人为审批状态
                     const nextAudit_update = {
@@ -494,6 +502,7 @@ module.exports = app => {
                         }
                     }
                 }
+                change_update.total_price = total_price;
                 const options = {
                     where: {
                         cid: postData.change_id,
@@ -592,12 +601,19 @@ module.exports = app => {
                     usort++;
                 }
                 await this.transaction.insert(this.ctx.service.changeAudit.tableName, insert_audit_array);
+                // 变更金额也退回
+                const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: changeInfo.cid } });
+                let total_price = 0;
+                for (const cl of changeList) {
+                    total_price += this.ctx.helper.accMul(cl.unit_price, cl.camount);
+                }
                 // 设置变更令退回
                 const change_update = {
                     w_code: postData.w_code,
                     status: audit.flow.status.back,
                     times: newTimes,
                     cin_time: Date.parse(new Date()) / 1000,
+                    total_price,
                 };
                 const options = {
                     where: {
@@ -609,16 +625,22 @@ module.exports = app => {
                 result = true;
 
                 // 添加短信通知-审批退回提醒功能
-                const smsUser = await this.ctx.service.projectAccount.getDataById(changeData.uid);
-                if (smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
-                    const smsType = JSON.parse(smsUser.sms_type);
-                    if (smsType[smsTypeConst.const.BG] !== undefined && smsType[smsTypeConst.const.BG].indexOf(smsTypeConst.judge.result.toString()) !== -1) {
-                        const sms = new SMS(this.ctx);
-                        const code = await sms.contentChange(changeData.code);
-                        const content = '【纵横计量支付】' + code + '变更,审批退回。';
-                        sms.send(smsUser.auth_mobile, content);
+                const mobile_array = [];
+                for (const user of insert_audit_array) {
+                    const smsUser = await this.ctx.service.projectAccount.getDataById(user.uid);
+                    if (smsUser.auth_mobile !== undefined && smsUser.sms_type !== '') {
+                        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);
+                }
             } catch (error) {
                 await this.transaction.rollback();
                 result = false;
@@ -698,13 +720,17 @@ module.exports = app => {
 
                 // 审批列表数据也要回退
                 const changeList = await this.ctx.service.changeAuditList.getAllDataByCondition({ where: { cid: changeInfo.cid } });
+                let total_price = 0;
                 for (const cl of changeList) {
                     const audit_amount = cl.audit_amount.split(',');
+                    const last_amount = audit_amount[audit_amount.length - 1];
                     audit_amount.splice(-1, 1);
                     const list_update = {
                         id: cl.id,
                         audit_amount: audit_amount.join(','),
+                        spamount: parseFloat(last_amount),
                     };
+                    total_price += this.ctx.helper.accMul(cl.unit_price, parseFloat(last_amount));
                     await this.transaction.update(this.ctx.service.changeAuditList.tableName, list_update);
                 }
 
@@ -713,6 +739,7 @@ module.exports = app => {
                     w_code: postData.w_code,
                     status: audit.flow.status.backnew,
                     cin_time: Date.parse(new Date()) / 1000,
+                    total_price,
                 };
                 const options = {
                     where: {