作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !107
@@ -5,6 +5,7 @@ namespace App\Console\Commands\Update; @@ -5,6 +5,7 @@ namespace App\Console\Commands\Update;
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Http\Logic\Bside\Product\CategoryLogic; 6 use App\Http\Logic\Bside\Product\CategoryLogic;
7 use App\Models\Blog\Blog; 7 use App\Models\Blog\Blog;
  8 +use App\Models\Collect\CollectSource;
8 use App\Models\Collect\CollectTask; 9 use App\Models\Collect\CollectTask;
9 use App\Models\Com\UpdateLog; 10 use App\Models\Com\UpdateLog;
10 use App\Models\News\News; 11 use App\Models\News\News;
@@ -14,6 +15,7 @@ use App\Models\Product\Product; @@ -14,6 +15,7 @@ use App\Models\Product\Product;
14 use App\Models\RouteMap\RouteMap; 15 use App\Models\RouteMap\RouteMap;
15 use App\Models\Template\BCustomTemplate; 16 use App\Models\Template\BCustomTemplate;
16 use App\Models\WebSetting\WebSettingReceiving; 17 use App\Models\WebSetting\WebSettingReceiving;
  18 +use App\Services\CosService;
17 use App\Services\ProjectServer; 19 use App\Services\ProjectServer;
18 use Illuminate\Console\Command; 20 use Illuminate\Console\Command;
19 use Illuminate\Support\Facades\DB; 21 use Illuminate\Support\Facades\DB;
@@ -79,10 +81,22 @@ class ProjectUpdate extends Command @@ -79,10 +81,22 @@ class ProjectUpdate extends Command
79 $domain_arr = parse_url($api_url); 81 $domain_arr = parse_url($api_url);
80 //获取网站配置 82 //获取网站配置
81 $link_type = 0; 83 $link_type = 0;
  84 + $web_url_domain = $domain_arr['host'];
  85 + $home_url = $domain_arr['host'];
82 $url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text'; 86 $url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text';
83 $data_config = curl_c($url_web_config); 87 $data_config = curl_c($url_web_config);
84 if ($data_config) { 88 if ($data_config) {
85 - $link_type = $data_config['link_type']; 89 + $link_type = $data_config['link_type'] ?? 0;
  90 +
  91 + $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
  92 + if (isset($web_url_arr['host'])) {
  93 + $web_url_domain = $web_url_arr['host'];
  94 + }
  95 +
  96 + $home_url_arr = parse_url($data_config['home_url'] ?? '');
  97 + if (isset($home_url_arr['host'])) {
  98 + $home_url = $home_url_arr['host'];
  99 + }
86 } 100 }
87 //获取所有语种 101 //获取所有语种
88 $language_list = []; 102 $language_list = [];
@@ -234,7 +248,7 @@ class ProjectUpdate extends Command @@ -234,7 +248,7 @@ class ProjectUpdate extends Command
234 $gallery = []; 248 $gallery = [];
235 if ($item['images'] ?? []) { 249 if ($item['images'] ?? []) {
236 foreach ($item['images'] as $k_img => $img) { 250 foreach ($item['images'] as $k_img => $img) {
237 - $gallery[] = ['alt' => '这是一张产品图', 'url' => $img]; 251 + $gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
238 } 252 }
239 } 253 }
240 //分类 254 //分类
@@ -323,9 +337,7 @@ class ProjectUpdate extends Command @@ -323,9 +337,7 @@ class ProjectUpdate extends Command
323 } else { 337 } else {
324 $image = $item['images'] ?? ''; 338 $image = $item['images'] ?? '';
325 } 339 }
326 - if (strpos($image, '//') === 0) {  
327 - $image = 'https:' . $image;  
328 - } 340 +
329 $id = $model->addReturnId([ 341 $id = $model->addReturnId([
330 'project_id' => $project_id, 342 'project_id' => $project_id,
331 'name' => $item['ttile'], 343 'name' => $item['ttile'],
@@ -333,7 +345,7 @@ class ProjectUpdate extends Command @@ -333,7 +345,7 @@ class ProjectUpdate extends Command
333 'seo_keywords' => $item['keywords'] ?? '', 345 'seo_keywords' => $item['keywords'] ?? '',
334 'seo_description' => $item['description'] ?? '', 346 'seo_description' => $item['description'] ?? '',
335 'text' => $item['content'] ?? '', 347 'text' => $item['content'] ?? '',
336 - 'image' => $image, 348 + 'image' => $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url),
337 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE, 349 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE,
338 'is_upgrade' => 1, 350 'is_upgrade' => 1,
339 'url' => $route 351 'url' => $route
@@ -547,4 +559,44 @@ class ProjectUpdate extends Command @@ -547,4 +559,44 @@ class ProjectUpdate extends Command
547 } 559 }
548 } 560 }
549 } 561 }
  562 +
  563 + //资源下载
  564 + protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url)
  565 + {
  566 + if (!$url) {
  567 + return '';
  568 + }
  569 +
  570 + $arr = parse_url($url);
  571 + $scheme = $arr['scheme'] ?? '';
  572 + $host = $arr['host'] ?? '';
  573 + $path = $arr['path'] ?? '';
  574 +
  575 + if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) {
  576 +
  577 + $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
  578 + if (!$source) {
  579 + $url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
  580 + $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
  581 +
  582 + if ($new_url) {
  583 + CollectSource::insert([
  584 + 'project_id' => $project_id,
  585 + 'origin' => $url,
  586 + 'target' => $new_url,
  587 + 'created_at' => date('Y-m-d H:i:s'),
  588 + 'updated_at' => date('Y-m-d H:i:s'),
  589 + ]);
  590 +
  591 + return getImageUrl($new_url);
  592 + } else {
  593 + return $url;
  594 + }
  595 + } else {
  596 + return getImageUrl($source['target']);
  597 + }
  598 + } else {
  599 + return $url;
  600 + }
  601 + }
550 } 602 }