VideoLikeCommand.php 814 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Command;
  4. use App\Model\Mongo\VideoLikeModel;
  5. use App\Model\VideoModel;
  6. use Hyperf\Command\Command as HyperfCommand;
  7. use Hyperf\Command\Annotation\Command;
  8. /**
  9. * @Command
  10. */
  11. class VideoLikeCommand extends HyperfCommand
  12. {
  13. /**
  14. * 执行的命令行
  15. *
  16. * @var string
  17. */
  18. protected $name = 'analyze:video_like';
  19. public function handle()
  20. {
  21. VideoModel::query()->where('status', 1)->orderBy('id', 'ASC')->chunk(1000, function ($items) {
  22. foreach ($items as $item) {
  23. $item->like = make(VideoLikeModel::class)->db()
  24. ->countDocuments(['vid' => $item->id]);
  25. $item->save();
  26. }
  27. $this->info('分片1000,数据点赞数同步');
  28. });
  29. }
  30. }