|
...
|
...
|
@@ -5,6 +5,7 @@ namespace App\Console\Commands\Test; |
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Http\Logic\Bside\Product\CategoryLogic;
|
|
|
|
use App\Models\Com\Notify;
|
|
|
|
use App\Models\CustomModule\CustomModuleContent;
|
|
|
|
use App\Models\Devops\ServerConfig;
|
|
|
|
use App\Models\Devops\ServersIp;
|
|
|
|
use App\Models\Domain\DomainCreateTask;
|
|
...
|
...
|
@@ -16,6 +17,7 @@ use App\Models\Product\Product; |
|
|
|
use App\Models\Project\DeployBuild;
|
|
|
|
use App\Models\Project\DeployOptimize;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Models\Template\BCustomTemplate;
|
|
|
|
use App\Models\WebSetting\WebLanguage;
|
|
|
|
use App\Services\BatchExportService;
|
|
...
|
...
|
@@ -41,7 +43,197 @@ class Temp extends Command |
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$this->specialImport();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 3531项目导入扩展模块内容
|
|
|
|
* @return bool
|
|
|
|
* @author Akun
|
|
|
|
* @date 2025/06/05 10:47
|
|
|
|
*/
|
|
|
|
public function specialImport()
|
|
|
|
{
|
|
|
|
$file_url = 'https://ecdn6.globalso.com/upload/p/3531/file/2025-06/news.csv';
|
|
|
|
$domain = 'www.hybio.com.cn';
|
|
|
|
$project_id = 3531;
|
|
|
|
$is_gbk = 0;
|
|
|
|
$file_code_type = $this->get_code_type($file_url);
|
|
|
|
if ($file_code_type === false) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', import fail, error: 文件编码格式错误' . PHP_EOL;
|
|
|
|
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('import fail, error: ' . $e->getMessage());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$total_count = 0; //总条数
|
|
|
|
$success_count = 0; //成功导入条数
|
|
|
|
$repeat_count = 0; //过滤已存在条数
|
|
|
|
$fail_count = 0;//导入失败条数
|
|
|
|
$fail_line = [];//失败行数
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$v[0] = $this->special2str($v[0]);
|
|
|
|
|
|
|
|
$total_count += 1;
|
|
|
|
try {
|
|
|
|
if ($this->importModule($project_id, $domain, $v)) {
|
|
|
|
$success_count += 1;
|
|
|
|
} else {
|
|
|
|
$repeat_count += 1;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$fail_count += 1;
|
|
|
|
$fail_line[] = $k + 1;
|
|
|
|
$this->output('title: ' . $v[0] . ', import fail, error: ' . $e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//关闭数据库
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->output('import end, total count: ' . $total_count . ', success count: ' . $success_count . ', repeat_count count: ' . $repeat_count . ', fail_count count: ' . $fail_count);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function importModule($project_id, $domain, $data)
|
|
|
|
{
|
|
|
|
$model = new CustomModuleContent();
|
|
|
|
$module = $model->read(['name' => $data[0]]);
|
|
|
|
if (!$module) {
|
|
|
|
|
|
|
|
$content = '';
|
|
|
|
if ($data[4] ?? '') {
|
|
|
|
//处理内容中的图片
|
|
|
|
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result);
|
|
|
|
if ($result[2] ?? []) {
|
|
|
|
foreach ($result[2] as $img) {
|
|
|
|
$new_img = check_remote_url_down($img, $project_id, $domain, 1);
|
|
|
|
$new_img && $data[4] = str_replace($img, $new_img, $data[4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//处理内容中的视频
|
|
|
|
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video);
|
|
|
|
if ($result_video[2] ?? []) {
|
|
|
|
foreach ($result_video[2] as $video) {
|
|
|
|
$new_video = check_remote_url_down($video, $project_id, $domain, 1);
|
|
|
|
$new_video && $data[4] = str_replace($video, $new_video, $data[4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = $data[4];
|
|
|
|
}
|
|
|
|
|
|
|
|
$seo_title = '';
|
|
|
|
if ($data[6] ?? '') {
|
|
|
|
$seo_title = substr(strip_tags($data[6]), 0, 70);
|
|
|
|
}
|
|
|
|
|
|
|
|
$seo_keywords = '';
|
|
|
|
if ($data[7] ?? '') {
|
|
|
|
$seo_keywords = substr(strip_tags(str_replace('^v6sp$', ',', $data[7])), 0, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
$seo_description = '';
|
|
|
|
if ($data[8] ?? '') {
|
|
|
|
$seo_description = substr(strip_tags($data[8]), 0, 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
$release_at = date('Y-m-d H:i:s');
|
|
|
|
if ($data[9] ?? '') {
|
|
|
|
$release_at = date('Y-m-d H:i:s', strtotime($data[9]));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$id = $model->addReturnId(
|
|
|
|
[
|
|
|
|
'name' => $data[0],
|
|
|
|
'category_id' => ',1,',
|
|
|
|
'module_id' => 2,
|
|
|
|
'content' => $content,
|
|
|
|
'seo_title' => $seo_title,
|
|
|
|
'seo_keywords' => $seo_keywords,
|
|
|
|
'seo_description' => $seo_description,
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'operator_id' => 8143,
|
|
|
|
'status' => 0,
|
|
|
|
'route' => '',
|
|
|
|
'release_at' => $release_at
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$route = RouteMap::setRoute($data[0], RouteMap::SOURCE_MODULE, $id, $project_id);
|
|
|
|
|
|
|
|
$model->edit(['route' => $route], ['id' => $id]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//特殊字符转换
|
|
|
|
protected function special2str($str)
|
|
|
|
{
|
|
|
|
if (strpos($str, ';') === false) {
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
$list = [
|
|
|
|
'<' => '<',
|
|
|
|
'>' => '>',
|
|
|
|
'&' => '&',
|
|
|
|
'´' => "'",
|
|
|
|
'"' => '"',
|
|
|
|
' ' => ' ',
|
|
|
|
''' => "'"
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($list as $k => $v) {
|
|
|
|
$str = str_replace($k, $v, $str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|