78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\common\command;
|
|
|
|
use app\adminapi\logic\qywx\CustomerLogic;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\input\Argument;
|
|
use think\console\input\Option;
|
|
use think\console\Output;
|
|
|
|
/**
|
|
* 企业微信客户同步命令
|
|
* 用法: php think qywx:sync_customer
|
|
*/
|
|
class QywxSyncCustomer extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
$this->setName('qywx:sync_customer')
|
|
->setDescription('同步企业微信客户到本地数据库')
|
|
->addArgument('action', Argument::OPTIONAL, '执行操作(sync/status)', 'sync');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$action = $input->getArgument('action') ?: 'sync';
|
|
|
|
switch ($action) {
|
|
case 'sync':
|
|
$this->syncCustomers($output);
|
|
break;
|
|
case 'status':
|
|
$this->showStatus($output);
|
|
break;
|
|
default:
|
|
$output->error('未知操作: ' . $action);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 同步客户
|
|
*/
|
|
private function syncCustomers(Output $output)
|
|
{
|
|
$output->info('开始同步企业微信客户...');
|
|
|
|
$result = CustomerLogic::syncCustomers();
|
|
|
|
if ($result === false) {
|
|
$output->error('同步失败: ' . CustomerLogic::getError());
|
|
return;
|
|
}
|
|
|
|
$output->info('同步完成!');
|
|
$output->info('总计同步: ' . ($result['sync_count'] ?? 0) . ' 个客户');
|
|
$output->info('新增: ' . ($result['new_count'] ?? 0));
|
|
$output->info('更新: ' . ($result['update_count'] ?? 0));
|
|
}
|
|
|
|
/**
|
|
* 显示同步状态
|
|
*/
|
|
private function showStatus(Output $output)
|
|
{
|
|
$stats = CustomerLogic::getStats();
|
|
|
|
$output->info('=== 企业微信客户同步状态 ===');
|
|
$output->info('客户总数: ' . $stats['total']);
|
|
$output->info('今日新增: ' . $stats['today']);
|
|
$output->info('同步状态: ' . $stats['syncStatusText']);
|
|
$output->info('最后同步: ' . $stats['lastSync']);
|
|
}
|
|
}
|