38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\command;
|
|
|
|
use app\common\service\qywx\MediaChannelService;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
|
|
class QywxScanMediaChannel extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->setName('qywx:scan-media-channel')
|
|
->addOption('batch', 'b', \think\console\input\Option::VALUE_OPTIONAL, '每批扫描客户数', 200)
|
|
->setDescription('扫描企微客户 follow_users 并记录渠道标签源');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$batchSize = max(1, (int) $input->getOption('batch'));
|
|
$output->writeln('开始扫描企微客户渠道标签...');
|
|
|
|
$result = MediaChannelService::scanFromContacts($batchSize);
|
|
|
|
$output->writeln(sprintf(
|
|
'扫描完成:客户 %d,发现渠道标签 %d,写入/更新 %d。',
|
|
(int) ($result['scanned_contacts'] ?? 0),
|
|
(int) ($result['discovered_tags'] ?? 0),
|
|
(int) ($result['inserted_or_updated'] ?? 0)
|
|
));
|
|
|
|
return 0;
|
|
}
|
|
}
|