作者 刘锟

update

... ... @@ -669,14 +669,14 @@ class ProjectUpdate extends Command
$gallery = [];
if (is_array($ve)) {
foreach ($ve as $ve_img) {
$gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve_img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
$gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve_img, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)];
}
} else {
$gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
$gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)];
}
$value = Arr::a2s($gallery);
} elseif ($extend['type'] == 4) {
$value = Arr::a2s([$this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url)]);
$value = Arr::a2s([$this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)]);
} else {
$value = $ve;
}
... ... @@ -942,7 +942,7 @@ class ProjectUpdate extends Command
}
//资源下载
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url)
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url, $same_name = 0)
{
if (!$url) {
return '';
... ... @@ -964,7 +964,7 @@ class ProjectUpdate extends Command
$path = '/' . $path;
}
$url_complete = ($scheme ?: 'https') . '://' . $domain . $path;
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete, '', '', $same_name);
if ($new_url) {
CollectSource::insert([
... ...
... ... @@ -72,17 +72,24 @@ class CosService
* @param $file_url
* @param $key
* @param $body_str
* @param int $same_name 是否保持名称一直
* @return string
* @author Akun
* @date 2023/09/21 9:39
*/
public static function uploadRemote($project_id,$image_type,$file_url,$key='',$body_str='')
public static function uploadRemote($project_id,$image_type,$file_url,$key='',$body_str='',$same_name=0)
{
if(!$key){
$url_arr = parse_url($file_url);
$ext = explode('.',$url_arr['path']);
$filename = uniqid().rand(10000,99999).'.'.end($ext);
if($same_name){
$path_arr = explode('/',$url_arr['path']);
$filename = end($path_arr);
}else{
$ext = explode('.',$url_arr['path']);
$filename = uniqid().rand(10000,99999).'.'.end($ext);
}
$uploads = config('upload.default_file');
$path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m');
... ...