|
@@ -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("更新内容领取彩虹豆结束");
|
|
|
+
|
|
|
+ }
|
|
|
+}
|