> /var/log/live-group-cleanup.log 2>&1 */ class CleanupMessageGroup extends Command { protected function configure() { $this->setName('live:cleanup-group') ->setDescription('清理已删除课程对应的阿里云互动消息群组'); } protected function execute(Input $input, Output $output) { $dryRun = $input->hasOption('dry-run'); $batchSize = 50; // 解析 --batch-size $options = $input->getOptions(); if (isset($options['batch-size']) && (int)$options['batch-size'] > 0) { $batchSize = (int)$options['batch-size']; } $output->writeln($dryRun ? '[DRY-RUN] 预览模式,不实际删除' : '开始清理阿里云互动消息群组...'); $output->writeln('批次大小: ' . $batchSize); $result = Manager::cleanupOrphanGroups($batchSize, $dryRun); if (isset($result['msg'])) { $output->writeln($result['msg']); return; } if (empty($result['items'])) { $output->writeln('没有需要清理的群组'); return; } foreach ($result['items'] as $item) { $label = $dryRun ? 'PREVIEW' : strtoupper($item['action']); $line = sprintf('[%s] room_id=%s course_id=%s group_id=%s', $label, $item['room_id'], $item['course_id'], $item['group_id']); if (isset($item['error'])) { $line .= ' error=' . $item['error']; } $output->writeln($line); } $output->writeln(sprintf( '完成:删除 %d,失败 %d,跳过 %d', $result['deleted'], $result['failed'], $result['skipped'] )); } }