作者 lyh
... ... @@ -5,6 +5,7 @@ namespace App\Console\Commands\Update;
use App\Helper\Arr;
use App\Http\Logic\Bside\Product\CategoryLogic;
use App\Models\Blog\Blog;
use App\Models\Collect\CollectSource;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\News\News;
... ... @@ -14,6 +15,7 @@ use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Models\WebSetting\WebSettingReceiving;
use App\Services\CosService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
... ... @@ -79,10 +81,22 @@ class ProjectUpdate extends Command
$domain_arr = parse_url($api_url);
//获取网站配置
$link_type = 0;
$web_url_domain = $domain_arr['host'];
$home_url = $domain_arr['host'];
$url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text';
$data_config = curl_c($url_web_config);
if ($data_config) {
$link_type = $data_config['link_type'];
$link_type = $data_config['link_type'] ?? 0;
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
if (isset($web_url_arr['host'])) {
$web_url_domain = $web_url_arr['host'];
}
$home_url_arr = parse_url($data_config['home_url'] ?? '');
if (isset($home_url_arr['host'])) {
$home_url = $home_url_arr['host'];
}
}
//获取所有语种
$language_list = [];
... ... @@ -234,7 +248,7 @@ class ProjectUpdate extends Command
$gallery = [];
if ($item['images'] ?? []) {
foreach ($item['images'] as $k_img => $img) {
$gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
$gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
}
}
//分类
... ... @@ -323,9 +337,7 @@ class ProjectUpdate extends Command
} else {
$image = $item['images'] ?? '';
}
if (strpos($image, '//') === 0) {
$image = 'https:' . $image;
}
$id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['ttile'],
... ... @@ -333,7 +345,7 @@ class ProjectUpdate extends Command
'seo_keywords' => $item['keywords'] ?? '',
'seo_description' => $item['description'] ?? '',
'text' => $item['content'] ?? '',
'image' => $image,
'image' => $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url),
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE,
'is_upgrade' => 1,
'url' => $route
... ... @@ -424,7 +436,7 @@ class ProjectUpdate extends Command
return $task_id;
}
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
$task_list = UpdateLog::where('project_id', 528)->where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
if ($task_list->count() == 0) {
return false;
}
... ... @@ -547,4 +559,45 @@ class ProjectUpdate extends Command
}
}
}
//资源下载
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url)
{
if (!$url) {
return '';
}
$arr = parse_url($url);
$scheme = $arr['scheme'] ?? '';
$host = $arr['host'] ?? '';
$path = $arr['path'] ?? '';
$url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) {
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
if (!$source) {
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
if ($new_url) {
CollectSource::insert([
'project_id' => $project_id,
'origin' => $url,
'target' => $new_url,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
return getImageUrl($new_url);
} else {
return $url_complete;
}
} else {
return getImageUrl($source['target']);
}
} else {
return $url_complete;
}
}
}
... ...