78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
||
|
||
namespace app\command;
|
||
|
||
use app\model\Vehicle;
|
||
use Symfony\Component\Console\Command\Command;
|
||
use Symfony\Component\Console\Input\InputInterface;
|
||
use Symfony\Component\Console\Output\OutputInterface;
|
||
use app\util\Xunfei;
|
||
use support\Db;
|
||
use app\model\Location;
|
||
|
||
class TransCommand extends Command
|
||
{
|
||
protected static $defaultName = 'trans';
|
||
protected static $defaultDescription = '翻译';
|
||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||
{
|
||
// $list = Vehicle::all()->toArray();
|
||
|
||
// $fields = ['classify', 'brand', 'model', 'status', 'purchase_location', 'procedure_location', 'fbo_destination'];
|
||
|
||
// foreach ($list as $key => &$item) {
|
||
// foreach ($item as $k => &$v) {
|
||
// if (in_array($k, $fields)) {
|
||
// $xunfei = new Xunfei();
|
||
// $rst_dst = $xunfei->fanyi($v, 'cn', 'ar');
|
||
// if ($rst_dst) {
|
||
// $list[$key][$k] = $rst_dst["trans_result"]["dst"];
|
||
// }
|
||
// }
|
||
// }
|
||
// unset($v);
|
||
|
||
// $id = $item['id'];
|
||
// unset($item['id']);
|
||
// unset($item['created_at']);
|
||
// unset($item['updated_at']);
|
||
// Db::table('vehicles_ar')->where('id', $id)->update($item);
|
||
|
||
// $output->write("{$id}: 翻译 - 已处理 \n");
|
||
// }
|
||
// unset($item);
|
||
|
||
|
||
|
||
|
||
$list = Location::all()->toArray();
|
||
|
||
$fields = ['name', 'address', 'area'];
|
||
|
||
foreach ($list as $key => &$item) {
|
||
foreach ($item as $k => &$v) {
|
||
if (in_array($k, $fields)) {
|
||
$xunfei = new Xunfei();
|
||
$rst_dst = $xunfei->fanyi($v, 'cn', 'ru');
|
||
if ($rst_dst) {
|
||
$list[$key][$k] = $rst_dst["trans_result"]["dst"];
|
||
}
|
||
}
|
||
}
|
||
unset($v);
|
||
|
||
$id = $item['id'];
|
||
unset($item['id']);
|
||
unset($item['created_at']);
|
||
unset($item['updated_at']);
|
||
Db::table('locations_ru')->where('id', $id)->update($item);
|
||
|
||
$output->write("{$id}: 翻译 - 已处理 \n");
|
||
}
|
||
unset($item);
|
||
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
} |