Explorar el Código

修复变更审批bug及定时器推送

ellisran hace 1 año
padre
commit
52c6737b81
Se han modificado 2 ficheros con 50 adiciones y 51 borrados
  1. 49 50
      app/schedule/shenpi_again.js
  2. 1 1
      app/service/change.js

+ 49 - 50
app/schedule/shenpi_again.js

@@ -38,56 +38,55 @@ class ShenpiAgain extends Subscription {
         const tenderInfoList = await ctx.service.tenderInfo.getAllDataByCondition({ columns: ['id', 'tid', 'deal_info'], where: { tid: tidList } });
         const updateData = [];
         const deleteData = [];
-        // for (const i of list) {
-        //     if (i.times > 10) continue;// 发超过10次就不发了吧
-        //     const uinfo = ctx.helper._.find(usersNoticeSetting, { id: i.uid });
-        //     const notice_again = uinfo.notice_again ? JSON.parse(uinfo.notice_again) : null;
-        //     if (!notice_again) continue;
-        //     const pinfo = ctx.helper._.find(projectsNoticeSetting, { id: i.pid });
-        //     const notice_setting = pinfo.notice_setting ? JSON.parse(pinfo.notice_setting) : ctx.helper._.cloneDeep(projectSettingConst.noticeSetting);
-        //     const interval = notice_setting.mode === 'fixed' ? notice_setting.fixed : (i.times === 0 ? notice_setting.activity.first : (i.times === 1 ? notice_setting.activity.second : notice_setting.activity.later));
-        //     const send_time = ctx.helper.calculateNextSendTime(i.last_time, interval, notice_setting.shield_times.start, notice_setting.shield_times.end);
-        //     console.log(new Date(), send_time);
-        //     if (new Date() > send_time) {
-        //         // 判断是否已经sp_type的sp_id已经完成审批或者是否存在,如果已经审批或不存在则需要删除
-        //         const spInfo = await ctx.service.noticeAgain.getSpResult(i.table_name, i.sp_id);
-        //         if (!spInfo) {
-        //             deleteData.push(i.id);
-        //             continue;
-        //         } else {
-        //             const status = spInfo.status || spInfo.audit_status;
-        //             if (status !== 2) {
-        //                 updateData.push({
-        //                     id: i.id,
-        //                     status: 2,
-        //                 });
-        //                 continue;
-        //             }
-        //         }
-        //         // 重发信息并记录到更新表里数据
-        //         const t = ctx.helper._.find(tenderList, { id: i.tid });
-        //         const tenderInfo = ctx.helper._.find(tenderInfoList, { tid: i.tid });
-        //         const newTenderInfo = {
-        //             deal_info: { buildName: '' },
-        //         };
-        //         if (tenderInfo) {
-        //             newTenderInfo.deal_info = JSON.parse(tenderInfo.deal_info);
-        //         }
-        //         const tender = {
-        //             data: t,
-        //             info: newTenderInfo,
-        //         };
-        //         console.log(tender);
-        //         // await ctx.helper.sendWechat(i.uid, i.sms_type, smsTypeConst.judge.approval.toString(), i.template, JSON.parse(i.wx_data), tender);
-        //         updateData.push({
-        //             id: i.id,
-        //             times: i.times + 1,
-        //             last_time: ctx.helper.dateTran(new Date(), 'YYYY-MM-DD HH:mm'),
-        //         });
-        //     }
-        // }
-        // if (updateData.length > 0) await ctx.service.noticeAgain.defaultUpdateRows(updateData);
-        // if (deleteData.length > 0) await ctx.service.noticeAgain.deleteById(deleteData);
+        for (const i of list) {
+            if (i.times > 10) continue;// 发超过10次就不发了吧
+            const uinfo = ctx.helper._.find(usersNoticeSetting, { id: i.uid });
+            const notice_again = uinfo.notice_again ? JSON.parse(uinfo.notice_again) : null;
+            if (!notice_again) continue;
+            const pinfo = ctx.helper._.find(projectsNoticeSetting, { id: i.pid });
+            const notice_setting = pinfo.notice_setting ? JSON.parse(pinfo.notice_setting) : ctx.helper._.cloneDeep(projectSettingConst.noticeSetting);
+            const interval = notice_setting.mode === 'fixed' ? notice_setting.fixed : (i.times === 0 ? notice_setting.activity.first : (i.times === 1 ? notice_setting.activity.second : notice_setting.activity.later));
+            const send_time = ctx.helper.calculateNextSendTime(i.last_time, interval, notice_setting.shield_times.start, notice_setting.shield_times.end);
+            console.log(new Date(), send_time);
+            if (new Date() > send_time) {
+                // 判断是否已经sp_type的sp_id已经完成审批或者是否存在,如果已经审批或不存在则需要删除
+                const spInfo = await ctx.service.noticeAgain.getSpResult(i.table_name, i.sp_id);
+                if (!spInfo) {
+                    deleteData.push(i.id);
+                    continue;
+                } else {
+                    const status = spInfo.status || spInfo.audit_status;
+                    if (status !== 2) {
+                        updateData.push({
+                            id: i.id,
+                            status: 2,
+                        });
+                        continue;
+                    }
+                }
+                // 重发信息并记录到更新表里数据
+                const t = ctx.helper._.find(tenderList, { id: i.tid });
+                const tenderInfo = ctx.helper._.find(tenderInfoList, { tid: i.tid });
+                const newTenderInfo = {
+                    deal_info: { buildName: '' },
+                };
+                if (tenderInfo) {
+                    newTenderInfo.deal_info = JSON.parse(tenderInfo.deal_info);
+                }
+                const tender = {
+                    data: t,
+                    info: newTenderInfo,
+                };
+                await ctx.helper.sendWechat(i.uid, i.sms_type, smsTypeConst.judge.approval.toString(), i.template, JSON.parse(i.wx_data), tender);
+                updateData.push({
+                    id: i.id,
+                    times: i.times + 1,
+                    last_time: ctx.helper.dateTran(new Date(), 'YYYY-MM-DD HH:mm'),
+                });
+            }
+        }
+        if (updateData.length > 0) await ctx.service.noticeAgain.defaultUpdateRows(updateData);
+        if (deleteData.length > 0) await ctx.service.noticeAgain.deleteById(deleteData);
     }
 }
 

+ 1 - 1
app/service/change.js

@@ -1293,7 +1293,7 @@ module.exports = app => {
                 // 重新发送配置
                 await this.ctx.service.noticeAgain.addNoticeAgain(this.transaction, smsTypeConst.const.BG, {
                     pid: this.ctx.session.sessionProject.id,
-                    tid: this.ctx.change.tid,
+                    tid: changeData.tid,
                     uid: lastauditInfo.uid,
                     sp_type: 'change',
                     sp_id: result_audit.insertId,