| 1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- declare(strict_types=1);
- namespace App\Command;
- use App\Model\Mongo\VideoLikeModel;
- use App\Model\VideoModel;
- use Hyperf\Command\Command as HyperfCommand;
- use Hyperf\Command\Annotation\Command;
- /**
- * @Command
- */
- class VideoLikeCommand extends HyperfCommand
- {
- /**
- * 执行的命令行
- *
- * @var string
- */
- protected $name = 'analyze:video_like';
- public function handle()
- {
- VideoModel::query()->where('status', 1)->orderBy('id', 'ASC')->chunk(1000, function ($items) {
- foreach ($items as $item) {
- $item->like = make(VideoLikeModel::class)->db()
- ->countDocuments(['vid' => $item->id]);
- $item->save();
- }
- $this->info('分片1000,数据点赞数同步');
- });
- }
- }
|