CreatorVideoDayInitCommand.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Command;
  3. use App\Model\CreatorModel;
  4. use Carbon\Carbon;
  5. use Hyperf\Command\Command as HyperfCommand;
  6. use Psr\Container\ContainerInterface;
  7. use Hyperf\Command\Annotation\Command;
  8. #[Command]
  9. class CreatorVideoDayInitCommand extends HyperfCommand
  10. {
  11. /**
  12. * 执行的命令行
  13. *
  14. * @var string
  15. */
  16. protected $name = 'creator:video_day_init';
  17. /**
  18. * @var ContainerInterface
  19. */
  20. protected $container;
  21. public function __construct(ContainerInterface $container)
  22. {
  23. $this->container = $container;
  24. parent::__construct($this->name);
  25. }
  26. public function handle()
  27. {
  28. $chunkSize = 100;
  29. CreatorModel::query()->where('day_video', '>', 0)->orderBy('id', 'ASC')->chunk($chunkSize, function ($items) {
  30. foreach ($items as $item) {
  31. $item->day_video = 0;
  32. $item->save();
  33. }
  34. });
  35. $nowDate = Carbon::now()->toDateTimeString();
  36. logger('CreatorVideoDayInitCommand:完成每日清零创作者视频量');
  37. $this->comment(sprintf('[%s]完成每日清零创作者视频量', $nowDate));
  38. }
  39. }