| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Command;
- use App\Model\CreatorModel;
- use Carbon\Carbon;
- use Hyperf\Command\Command as HyperfCommand;
- use Psr\Container\ContainerInterface;
- use Hyperf\Command\Annotation\Command;
- #[Command]
- class CreatorVideoDayInitCommand extends HyperfCommand
- {
- /**
- * 执行的命令行
- *
- * @var string
- */
- protected $name = 'creator:video_day_init';
- /**
- * @var ContainerInterface
- */
- protected $container;
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
- parent::__construct($this->name);
- }
- public function handle()
- {
- $chunkSize = 100;
- CreatorModel::query()->where('day_video', '>', 0)->orderBy('id', 'ASC')->chunk($chunkSize, function ($items) {
- foreach ($items as $item) {
- $item->day_video = 0;
- $item->save();
- }
- });
- $nowDate = Carbon::now()->toDateTimeString();
- logger('CreatorVideoDayInitCommand:完成每日清零创作者视频量');
- $this->comment(sprintf('[%s]完成每日清零创作者视频量', $nowDate));
- }
- }
|