Browse Source

机器人修改,10秒发完五句话

lizhen_gitee 3 years ago
parent
commit
8963a1b2a5
1 changed files with 15 additions and 4 deletions
  1. 15 4
      application/index/controller/Plantask.php

+ 15 - 4
application/index/controller/Plantask.php

@@ -27,11 +27,11 @@ class Plantask extends Controller
         $map = [
             'gh_id'  => ['gt',0],
         ];
-        $ghuser = Db::name('user')->where($map)->orderRaw('rand()')->value('id');
+        $ghuser = Db::name('user')->where($map)->orderRaw('rand()')->limit(5)->column('id');
         //dump($ghuser);
 
         //随机取出一句话
-        $oneword = Db::name('plantask_accost')->orderRaw('rand()')->value('title');
+        $oneword = Db::name('plantask_accost')->orderRaw('rand()')->limit(5)->column('title');
         //dump($oneword);
 
         //发送出去
@@ -42,9 +42,14 @@ class Plantask extends Controller
         if($times === false){
             $times = 0;
         }
+
         if($times < 5){
-            $this->sendMessageToUser($ghuser,$oneuser,$oneword);
-            $cache->set('plantask_first_word_'.$oneuser, $times + 1);
+            for($i = 0;$i < 5;$i++){
+                $ghuser_one  = isset($ghuser[$i])  ? $ghuser[$i]  : $ghuser[array_rand($ghuser)];
+                $oneword_one = isset($oneword[$i]) ? $oneword[$i] : $oneword[array_rand($oneword)];
+                $this->sendMessageToUser($ghuser_one,$oneuser,$oneword_one);
+            }
+            $cache->set('plantask_first_word_'.$oneuser, 5);
         }
 
     }
@@ -109,6 +114,12 @@ class Plantask extends Controller
         }
     }
 
+    //清空redis
+    public function clear_redis(){
+        $val = input('uid');
+        $cache = Cache::connect(['type'=>'Redis']);
+        $cache->rm('plantask_first_word_'.$val);
+    }
 
 
     /**