Browse Source

生成彩虹豆、收取彩虹豆

wzq 5 years ago
parent
commit
37d50edcb6

+ 70 - 0
app/Console/Commands/PostCollectBean.php

@@ -0,0 +1,70 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/7/2
+ * Time: 15:58
+ */
+namespace App\Console\Commands;
+
+
+use App\Models\PostData;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class PostCollectBean extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:collect_bean';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '内容领取彩虹豆';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(PostData $postData)
+    {
+        parent::__construct();
+        $this->postData = $postData;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始更新内容领取彩虹豆");
+
+        $key = 'post_collect_bean';
+        $ids = Redis::ZRANGE($key, 0 , -1, 'WITHSCORES');
+        foreach($ids as $postId => $val){
+            try{
+                $value = Redis::ZSCORE($key, $postId);
+                Redis::ZREM ($key, $postId);
+                $this->postData->where('post_id', $postId)->increment('collect_bean', $value);
+                Log::debug('更新内容领取彩虹豆成功'.$postId.'-'.$value);
+            }catch (\Exception $exception){
+                Log::error('更新内容领取彩虹豆失败'.$postId.'-'.$val.$exception->getMessage());
+            }
+            usleep(10000);
+        }
+
+
+        $this->line("更新内容领取彩虹豆结束");
+
+    }
+}

+ 70 - 0
app/Console/Commands/PostCreateBean.php

@@ -0,0 +1,70 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/7/2
+ * Time: 14:49
+ */
+namespace App\Console\Commands;
+
+
+use App\Models\PostData;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class PostCreateBean extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:create_bean';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '内容生成彩虹豆';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(PostData $postData)
+    {
+        parent::__construct();
+        $this->postData = $postData;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始更新内容生成彩虹豆");
+
+        $key = 'post_create_bean';
+        $ids = Redis::ZRANGE($key, 0 , -1, 'WITHSCORES');
+        foreach($ids as $postId => $val){
+            try{
+                $value = Redis::ZSCORE($key, $postId);
+                Redis::ZREM ($key, $postId);
+                $this->postData->where('post_id', $postId)->increment('create_bean', $value);
+                Log::debug('更新内容生成彩虹豆成功'.$postId.'-'.$value);
+            }catch (\Exception $exception){
+                Log::error('更新内容生成彩虹豆失败'.$postId.'-'.$val.$exception->getMessage());
+            }
+            usleep(10000);
+        }
+
+
+        $this->line("更新内容生成彩虹豆结束");
+
+    }
+}

+ 12 - 0
app/Console/Kernel.php

@@ -5,6 +5,8 @@ namespace App\Console;
 use App\Console\Commands\Apollo;
 use App\Console\Commands\CommunityMemberStatistics;
 use App\Console\Commands\Downloads;
+use App\Console\Commands\PostCollectBean;
+use App\Console\Commands\PostCreateBean;
 use App\Console\Commands\PostStatistics;
 use App\Console\Commands\PostYesterday;
 use App\Console\Commands\VirusAdd;
@@ -24,6 +26,8 @@ class Kernel extends ConsoleKernel
         Downloads::class,
         VirusAdd::class,
         PostStatistics::class,
+        PostCreateBean::class,
+        PostCollectBean::class,
         CommunityMemberStatistics::class
     ];
 
@@ -51,5 +55,13 @@ class Kernel extends ConsoleKernel
         $schedule->command('member:statistics')
             ->dailyAt('00:05')
             ->withoutOverlapping()->appendOutputTo($path);
+        //内容生成彩虹豆
+        $schedule->command('post:create_bean')
+            ->everyFiveMinutes()
+            ->withoutOverlapping()->appendOutputTo($path);
+        //内容收取彩虹豆
+        $schedule->command('post:collect_bean')
+            ->everyFiveMinutes()
+            ->withoutOverlapping()->appendOutputTo($path);
     }
 }