Files
usedcar/app/command/SyncCommand.php
T
2025-05-14 13:19:23 +08:00

100 lines
3.1 KiB
PHP

<?php
namespace app\command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use support\Db;
use app\mzl\modules\translation\service\TranslationService;
class SyncCommand extends Command
{
protected static $defaultName = 'sync:data';
protected static $defaultDescription = '同步数据';
protected function execute(InputInterface $input, OutputInterface $output): int
{
// $this->energy();
return self::SUCCESS;
}
public function energy()
{
try {
$lis = Db::table('tb_energy')->get();
foreach ($lis as $key => $val) {
$getId = Db::table('hs_energy')->insertGetId([
'status' => 1,
'sort' => 0,
'created_at' => time(),
'updated_at' => time()
]);
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'energy',
$getId,
'zh',
['name'=>$val->name]
);
}
} catch (\Throwable $th) {
var_dump($th->getFile().'-'.$th->getLine().'-'.$th->getMessage());
}
}
public function types()
{
try {
$lis = Db::table('tb_types')->get();
foreach ($lis as $key => $val) {
$getId = Db::table('hs_types')->insertGetId([
'img' => '',
'status' => 1,
'sort' => 0,
'created_at' => time(),
'updated_at' => time()
]);
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'type',
$getId,
'zh',
['name'=>$val->name]
);
}
} catch (\Throwable $th) {
var_dump($th->getFile().'-'.$th->getLine().'-'.$th->getMessage());
}
}
public function brand()
{
try {
$lis = Db::table('tb_brand')->get();
foreach ($lis as $key => $val) {
$getId = Db::table('hs_brand')->insertGetId([
'status' => 1,
'sort' => 0,
'created_at' => time(),
'updated_at' => time()
]);
// 异步翻译并写入 hs_vehicle_data_translation 表
(new TranslationService())->queueTranslations(
'brand',
$getId,
'zh',
['name'=>$val->name]
);
}
} catch (\Throwable $th) {
var_dump($th->getFile().'-'.$th->getLine().'-'.$th->getMessage());
}
}
}