初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command\live;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use app\common\library\live\message\Manager;
|
||||
|
||||
/**
|
||||
* 清理已删除课程对应的阿里云互动消息群组
|
||||
*
|
||||
* 用法:
|
||||
* php think live:cleanup-group 执行清理
|
||||
* php think live:cleanup-group --dry-run 仅预览,不实际删除
|
||||
* php think live:cleanup-group --batch-size=100 指定批次大小
|
||||
*
|
||||
* 建议通过系统 crontab 每天执行一次:
|
||||
* 0 3 * * * cd /path/to/project && php think live:cleanup-group >> /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']
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user