UpdatePostInfo.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/8/13
  6. * Time: 10:59
  7. */
  8. namespace App\Console\Commands;
  9. use App\Models\Post;
  10. use Illuminate\Console\Command;
  11. use Illuminate\Support\Facades\Redis;
  12. class UpdatePostInfo extends Command
  13. {
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'post:update_info';
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = '更新内容信息';
  26. /**
  27. * Create a new command instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct(Post $post)
  32. {
  33. parent::__construct();
  34. $this->post = $post;
  35. }
  36. /**
  37. * Execute the console command.
  38. *
  39. * @return mixed
  40. */
  41. public function handle()
  42. {
  43. $this->line("开始更新内容信息");
  44. $bar = $this->output->createProgressBar($this->post->count());
  45. $this->post->chunk(100, function($posts) use ($bar){
  46. foreach($posts as $post){
  47. $bar->advance();
  48. if(!$post->data) continue;
  49. Redis::HSET('post_info_'.$post->id,
  50. 'id', $post->id,
  51. 'uid', $post->uid,
  52. 'type', $post->type,
  53. 'img', $post->img,
  54. 'imgs', json_encode(array_column($post->imgs->toArray(), 'img')),
  55. 'video', $post->video,
  56. 'topic_ids', $post->topic_ids,
  57. 'title', $post->title,
  58. 'content', $post->content,
  59. 'location', $post->location,
  60. 'pv', $post->data->pv,
  61. 'dislike_count', $post->data->dislike_count,
  62. 'praise_count', $post->data->praise_count,
  63. 'share_count', $post->data->share_count,
  64. 'comment_count', $post->data->comment_count,
  65. 'collect_count', $post->data->collect_count,
  66. 'available_bean', $post->data->available_bean,
  67. 'will_collect_bean', $post->data->will_collect_bean,
  68. 'create_bean', $post->data->create_bean,
  69. 'collect_bean', $post->data->collect_bean);
  70. }
  71. usleep(100000);
  72. });
  73. $bar->finish();
  74. $this->line("\n更新内容信息结束");
  75. }
  76. }