浏览代码

处理内容信息

wzq 5 年之前
父节点
当前提交
200365b13d
共有 2 个文件被更改,包括 88 次插入0 次删除
  1. 86 0
      app/Console/Commands/UpdatePostInfo.php
  2. 2 0
      app/Console/Kernel.php

+ 86 - 0
app/Console/Commands/UpdatePostInfo.php

@@ -0,0 +1,86 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/8/13
+ * Time: 10:59
+ */
+namespace App\Console\Commands;
+
+
+use App\Models\Post;
+use Illuminate\Console\Command;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class UpdatePostInfo extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:update_info';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '更新内容信息';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(Post $post)
+    {
+        parent::__construct();
+        $this->post = $post;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始更新内容信息");
+
+        $this->post->chunk(100, function($posts){
+            foreach($posts as $post){
+                if(!$post->data) continue;
+//                echo $post->data->pv;exit;
+                Redis::HSET('post_info_'.$post->id,
+                    'id', $post->id,
+                    'uid', $post->uid,
+                    'type', $post->type,
+                    'img', $post->img,
+                    'imgs', json_encode(array_column($post->imgs->toArray(), 'img')),
+                    'video', $post->video,
+                    'topic_ids', $post->topic_ids,
+                    'title', $post->title,
+                    'content', $post->content,
+                    'location', $post->location,
+                    'pv', $post->data->pv,
+                    'dislike_count', $post->data->dislike_count,
+                    'praise_count', $post->data->praise_count,
+                    'share_count', $post->data->share_count,
+                    'comment_count', $post->data->comment_count,
+                    'collect_count', $post->data->collect_count,
+                    'available_bean', $post->data->available_bean,
+                    'will_collect_bean', $post->data->will_collect_bean,
+                    'create_bean', $post->data->create_bean,
+                    'collect_bean', $post->data->collect_bean,
+                    'weight', $post->data->weight);
+            }
+            usleep(100000);
+        });
+        $this->line("更新内容信息结束");
+
+    }
+}

+ 2 - 0
app/Console/Kernel.php

@@ -10,6 +10,7 @@ use App\Console\Commands\PostCollectBean;
 use App\Console\Commands\PostCreateBean;
 use App\Console\Commands\PostStatistics;
 use App\Console\Commands\PostYesterday;
+use App\Console\Commands\UpdatePostInfo;
 use App\Console\Commands\VirusAdd;
 use Illuminate\Console\Scheduling\Schedule;
 use Laravel\Lumen\Console\Kernel as ConsoleKernel;
@@ -29,6 +30,7 @@ class Kernel extends ConsoleKernel
         PostStatistics::class,
         PostCreateBean::class,
         PostCollectBean::class,
+        UpdatePostInfo::class,
         CommunityMemberStatistics::class,
         MusicImport::class
     ];