作者 刘锟

update

@@ -669,14 +669,14 @@ class ProjectUpdate extends Command @@ -669,14 +669,14 @@ class ProjectUpdate extends Command
669 $gallery = []; 669 $gallery = [];
670 if (is_array($ve)) { 670 if (is_array($ve)) {
671 foreach ($ve as $ve_img) { 671 foreach ($ve as $ve_img) {
672 - $gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve_img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)]; 672 + $gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve_img, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)];
673 } 673 }
674 } else { 674 } else {
675 - $gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url)]; 675 + $gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)];
676 } 676 }
677 $value = Arr::a2s($gallery); 677 $value = Arr::a2s($gallery);
678 } elseif ($extend['type'] == 4) { 678 } elseif ($extend['type'] == 4) {
679 - $value = Arr::a2s([$this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url)]); 679 + $value = Arr::a2s([$this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)]);
680 } else { 680 } else {
681 $value = $ve; 681 $value = $ve;
682 } 682 }
@@ -942,7 +942,7 @@ class ProjectUpdate extends Command @@ -942,7 +942,7 @@ class ProjectUpdate extends Command
942 } 942 }
943 943
944 //资源下载 944 //资源下载
945 - protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url) 945 + protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url, $same_name = 0)
946 { 946 {
947 if (!$url) { 947 if (!$url) {
948 return ''; 948 return '';
@@ -964,7 +964,7 @@ class ProjectUpdate extends Command @@ -964,7 +964,7 @@ class ProjectUpdate extends Command
964 $path = '/' . $path; 964 $path = '/' . $path;
965 } 965 }
966 $url_complete = ($scheme ?: 'https') . '://' . $domain . $path; 966 $url_complete = ($scheme ?: 'https') . '://' . $domain . $path;
967 - $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete); 967 + $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete, '', '', $same_name);
968 968
969 if ($new_url) { 969 if ($new_url) {
970 CollectSource::insert([ 970 CollectSource::insert([
@@ -72,17 +72,24 @@ class CosService @@ -72,17 +72,24 @@ class CosService
72 * @param $file_url 72 * @param $file_url
73 * @param $key 73 * @param $key
74 * @param $body_str 74 * @param $body_str
  75 + * @param int $same_name 是否保持名称一直
75 * @return string 76 * @return string
76 * @author Akun 77 * @author Akun
77 * @date 2023/09/21 9:39 78 * @date 2023/09/21 9:39
78 */ 79 */
79 - public static function uploadRemote($project_id,$image_type,$file_url,$key='',$body_str='') 80 + public static function uploadRemote($project_id,$image_type,$file_url,$key='',$body_str='',$same_name=0)
80 { 81 {
81 if(!$key){ 82 if(!$key){
82 $url_arr = parse_url($file_url); 83 $url_arr = parse_url($file_url);
83 - $ext = explode('.',$url_arr['path']);  
84 84
85 - $filename = uniqid().rand(10000,99999).'.'.end($ext); 85 + if($same_name){
  86 + $path_arr = explode('/',$url_arr['path']);
  87 + $filename = end($path_arr);
  88 + }else{
  89 + $ext = explode('.',$url_arr['path']);
  90 +
  91 + $filename = uniqid().rand(10000,99999).'.'.end($ext);
  92 + }
86 93
87 $uploads = config('upload.default_file'); 94 $uploads = config('upload.default_file');
88 $path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m'); 95 $path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m');