Files
cunkebao_v3/Server/application/command/AccountListCommand.php

57 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2025-03-24 14:59:19 +08:00
<?php
2025-03-24 16:42:36 +08:00
namespace app\command;
2025-03-24 14:59:19 +08:00
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use think\Queue;
2025-03-24 16:42:36 +08:00
use app\job\AccountListJob;
2025-03-24 14:59:19 +08:00
2025-03-24 16:42:36 +08:00
class AccountListCommand extends Command
2025-03-24 14:59:19 +08:00
{
protected function configure()
{
2025-03-24 16:42:36 +08:00
$this->setName('account:list')
->setDescription('获取公司账号列表,并根据分页自动处理下一页');
2025-03-24 14:59:19 +08:00
}
protected function execute(Input $input, Output $output)
{
2025-03-24 16:42:36 +08:00
$output->writeln('开始处理公司账号列表任务...');
2025-03-24 14:59:19 +08:00
try {
// 初始页码
$pageIndex = 0;
$pageSize = 100; // 每页获取100条记录
// 将第一页任务添加到队列
$this->addToQueue($pageIndex, $pageSize);
2025-03-24 16:42:36 +08:00
$output->writeln('公司账号列表任务已添加到队列');
2025-03-24 14:59:19 +08:00
} catch (\Exception $e) {
2025-03-24 16:42:36 +08:00
Log::error('公司账号列表任务添加失败:' . $e->getMessage());
$output->writeln('公司账号列表任务添加失败:' . $e->getMessage());
2025-03-24 14:59:19 +08:00
return false;
}
return true;
}
/**
* 添加任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
*/
protected function addToQueue($pageIndex, $pageSize)
{
$data = [
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
];
2025-03-24 16:42:36 +08:00
// 添加到队列,设置任务名为 account_list
Queue::push(AccountListJob::class, $data, 'account_list');
2025-03-24 14:59:19 +08:00
}
}