|
...
|
...
|
@@ -8,9 +8,12 @@ use App\Models\Devops\ServerConfig; |
|
|
|
use App\Models\Devops\ServersIp;
|
|
|
|
use App\Models\Domain\DomainCreateTask;
|
|
|
|
use App\Models\Domain\DomainInfo;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\Keyword;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\Project\DeployBuild;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\Template\BCustomTemplate;
|
|
|
|
use App\Models\WebSetting\WebLanguage;
|
|
|
|
use App\Services\BatchExportService;
|
|
|
|
use App\Services\ProjectServer;
|
|
...
|
...
|
@@ -35,7 +38,120 @@ class Temp extends Command |
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$this->check_server_main_site();
|
|
|
|
$this->importTdk();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function importTdk()
|
|
|
|
{
|
|
|
|
$project_id = 2379;
|
|
|
|
$source = 'page';
|
|
|
|
$file_url = 'https://ecdn6.globalso.com/upload/p/2379/image_other/2025-04/products.csv';
|
|
|
|
|
|
|
|
//判断文件编码格式是否正确
|
|
|
|
$is_gbk = 0;
|
|
|
|
$file_code_type = $this->get_code_type($file_url);
|
|
|
|
if ($file_code_type === false) {
|
|
|
|
$this->output('文件编码格式错误');
|
|
|
|
return true;
|
|
|
|
} elseif ($file_code_type === 'GBK') {
|
|
|
|
$is_gbk = 1;
|
|
|
|
setlocale(LC_ALL, 'zh_CN');
|
|
|
|
}
|
|
|
|
|
|
|
|
//读取文件内容
|
|
|
|
//读取csv文件
|
|
|
|
$line_of_text = [];
|
|
|
|
try {
|
|
|
|
$opts = [
|
|
|
|
'http' => [
|
|
|
|
'method' => 'GET',
|
|
|
|
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
|
|
|
|
],
|
|
|
|
'ssl' => [
|
|
|
|
'verify_peer' => false,
|
|
|
|
'verify_peer_name' => false
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$file_handle = fopen($file_url, 'r', null, stream_context_create($opts));
|
|
|
|
while (!feof($file_handle)) {
|
|
|
|
$line_of_text[] = fgetcsv($file_handle, 0, ',');
|
|
|
|
}
|
|
|
|
fclose($file_handle);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->output($e->getMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$success_count = 0; //成功导入条数
|
|
|
|
if (count($line_of_text) > 1) {
|
|
|
|
//设置数据库
|
|
|
|
$project = ProjectServer::useProject($project_id);
|
|
|
|
if ($project) {
|
|
|
|
foreach ($line_of_text as $k => $v) {
|
|
|
|
if ($k > 0 && isset($v[0]) && $v[0]) {
|
|
|
|
|
|
|
|
if ($is_gbk) {
|
|
|
|
foreach ($v as $kk => $vv) {
|
|
|
|
$v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$url = $v[0];
|
|
|
|
$title = $v[1];
|
|
|
|
$desc = $v[2];
|
|
|
|
$keyword = $v[3];
|
|
|
|
|
|
|
|
$route = trim(str_replace('https://www.docareco.com/', '', $url), '/');
|
|
|
|
if ($route) {
|
|
|
|
if ($source == 'page') {
|
|
|
|
$model = new BCustomTemplate();
|
|
|
|
$model->edit([
|
|
|
|
'title' => $title,
|
|
|
|
'keywords' => $keyword,
|
|
|
|
'description' => $desc
|
|
|
|
], ['url' => $route]);
|
|
|
|
} elseif ($source == 'product_category') {
|
|
|
|
$model = new Category();
|
|
|
|
$model->edit([
|
|
|
|
'seo_title' => $title,
|
|
|
|
'seo_keywords' => $keyword,
|
|
|
|
'seo_des' => $desc
|
|
|
|
], ['route' => $route]);
|
|
|
|
} elseif ($source == 'product') {
|
|
|
|
$model = new Product();
|
|
|
|
$model->edit(['seo_mate' => Arr::a2s([
|
|
|
|
'title' => $title,
|
|
|
|
'keyword' => $keyword,
|
|
|
|
'description' => $desc
|
|
|
|
])], ['route' => $route]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$success_count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//关闭数据库
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->output('导入tdk成功执行' . $success_count . '条');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//判断编码格式
|
|
|
|
protected function get_code_type($file)
|
|
|
|
{
|
|
|
|
$list = array('GBK', 'UTF-8');
|
|
|
|
$str = curl_c($file, false);
|
|
|
|
foreach ($list as $item) {
|
|
|
|
$tmp = mb_convert_encoding($str, $item, $item);
|
|
|
|
if (md5($tmp) == md5($str)) {
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|