12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?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\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("开始更新内容信息");
- $bar = $this->output->createProgressBar($this->post->withTrashed()->count());
- $this->post->withTrashed()->chunk(100, function($posts) use ($bar){
- foreach($posts as $post){
- $bar->advance();
- if(!$post->data) continue;
- 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,
- 'created_at', $post->created_at);
- }
- usleep(100000);
- });
- $bar->finish();
- $this->line("\n更新内容信息结束");
- }
- }
|