Quellcode durchsuchen

自动发送钉钉提醒

kevin_zhangl vor 3 Jahren
Ursprung
Commit
60f4551edd

+ 2 - 0
common/components/SwooleAsyncTimer.php

@@ -67,6 +67,8 @@ class SwooleAsyncTimer extends SwooleAsyncTimerComponent implements SocketInterf
             Queue::instance()->initRedis();
             // 初始化备份历史奖金数据表
 //            TaskFunc::initAutoBakBalance();
+            // 初始化自动发送钉钉推送消息
+            TaskFunc::initAutoSendDingTalk();
         }
     }
 

+ 1 - 1
common/helpers/DingTalk.php

@@ -21,7 +21,7 @@ class DingTalk
         $data = curl_exec($ch);
         curl_close($ch);
 
-        return $data;
+        return json_decode($data, true);
     }
 
     public static function sendNotice($message)

+ 21 - 0
common/libs/taskQueue/TaskFunc.php

@@ -6,6 +6,7 @@ namespace common\libs\taskQueue;
 
 use common\helpers\Cache;
 use common\helpers\Date;
+use common\helpers\DingTalk;
 use common\models\forms\HistoryBonusForm;
 use common\models\TaskQueue;
 use SebastianBergmann\CodeCoverage\Report\PHP;
@@ -42,4 +43,24 @@ class TaskFunc
     public static function testTaskQueue(){
         print_r('执行到测试任务'.PHP_EOL);
     }
+
+    /**
+     * 初始化自动发送钉钉提醒任务
+     */
+    public static function initAutoSendDingTalk() {
+        // 查看数据库中是否存在未开始的任务,如果没有就添加一个新任务
+        if(!TaskQueue::find()->where('TYPE=:TYPE AND CONTENT=:CONTENT AND STARTED_AT>:STARTED_AT', [':TYPE'=>Queue::TYPE_FUNC, ':CONTENT'=>TaskFunc::class.'::autoSendDingTalkTable', ':STARTED_AT'=>Date::nowTime()])->asArray()->exists()){
+            // 获取站点配置中的备份时间
+            $config = Cache::getSystemConfig();
+            $sendDingTalkTime = (int)$config['sendDingTalkTime']['VALUE'];
+            Queue::instance()->addTask(Queue::TYPE_FUNC, TaskFunc::class.'::autoSendDingTalkTable', [], Queue::LOOP_TYPE_DAY, $sendDingTalkTime . ':00', 0);
+        }
+    }
+
+    /**
+     * 自动送钉钉提醒
+     */
+    public static function autoSendDingTalkTable() {
+        DingTalk::sendNotice('(NG)提醒:自动发送...');
+    }
 }