作者 lyh
@@ -467,6 +467,9 @@ if (!function_exists('getImageUrl')) { @@ -467,6 +467,9 @@ if (!function_exists('getImageUrl')) {
467 if((strpos($path,'https://')!== false) || (strpos($path,'http://') !== false)){ 467 if((strpos($path,'https://')!== false) || (strpos($path,'http://') !== false)){
468 return $path; 468 return $path;
469 } 469 }
  470 + if(substr($path,0,2) == '//'){
  471 + return 'https:'.$path;
  472 + }
470 if($location == 1){ 473 if($location == 1){
471 $cos = config('filesystems.disks.cos'); 474 $cos = config('filesystems.disks.cos');
472 $cosCdn = $cos['cdn']; 475 $cosCdn = $cos['cdn'];
@@ -646,3 +649,43 @@ function redis_add($key,$val,$ttl=3600){ @@ -646,3 +649,43 @@ function redis_add($key,$val,$ttl=3600){
646 "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])", [$key, $val, $ttl], 1 649 "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])", [$key, $val, $ttl], 1
647 ); 650 );
648 } 651 }
  652 +
  653 +/**
  654 + * 判断远程地址是否需要下载
  655 + * @param $url
  656 + * @author Akun
  657 + * @date 2023/12/08 14:17
  658 + */
  659 +function check_remote_url_down($url){
  660 + if(!$url){
  661 + return false;
  662 + }
  663 +
  664 + if(substr($url,0,2) == '//'){
  665 + return false;
  666 + }
  667 +
  668 + $arr = parse_url($url);
  669 + $scheme = $arr['scheme'] ?? '';
  670 + $host = $arr['host'] ?? '';
  671 + $path = $arr['path'] ?? '';
  672 +
  673 + if($scheme && !in_array($scheme,['http','https'])){
  674 + return false;
  675 + }
  676 +
  677 + if(!$host){
  678 + return false;
  679 + }
  680 +
  681 + $host_arr = explode('.',$host);
  682 + if(strpos($host_arr[0],'cdn') !== false){
  683 + return false;
  684 + }
  685 +
  686 + if(strpos($path, '.') === false){
  687 + return false;
  688 + }
  689 +
  690 + return true;
  691 +}
@@ -265,7 +265,7 @@ class BlogLogic extends BaseLogic @@ -265,7 +265,7 @@ class BlogLogic extends BaseLogic
265 preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result); 265 preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result);
266 if($result[2]??[]){ 266 if($result[2]??[]){
267 foreach ($result[2] as $img){ 267 foreach ($result[2] as $img){
268 - $data[4] = str_replace($img,getImageUrl(CosService::uploadRemote($project_id,'image_news',$img)),$data[4]); 268 + check_remote_url_down($img) && $data[4] = str_replace($img,getImageUrl(CosService::uploadRemote($project_id,'image_news',$img)),$data[4]);
269 } 269 }
270 } 270 }
271 271
@@ -273,20 +273,25 @@ class BlogLogic extends BaseLogic @@ -273,20 +273,25 @@ class BlogLogic extends BaseLogic
273 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video); 273 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video);
274 if($result_video[2]??[]){ 274 if($result_video[2]??[]){
275 foreach ($result_video[2] as $video){ 275 foreach ($result_video[2] as $video){
276 - $data[4] = str_replace($video,getImageUrl(CosService::uploadRemote($project_id,'image_news',$video)),$data[4]); 276 + check_remote_url_down($video) && $data[4] = str_replace($video,getImageUrl(CosService::uploadRemote($project_id,'image_news',$video)),$data[4]);
277 } 277 }
278 } 278 }
279 279
280 $text = $data[4]; 280 $text = $data[4];
281 } 281 }
282 282
  283 + $img = '';
  284 + if($data[5]??''){
  285 + $img = check_remote_url_down($data[5]) ? CosService::uploadRemote($project_id, 'image_news', $data[5]) : $data[5];
  286 + }
  287 +
283 $id = $this->model->addReturnId( 288 $id = $this->model->addReturnId(
284 [ 289 [
285 'name' => $data[0], 290 'name' => $data[0],
286 'category_id' => $category_id, 291 'category_id' => $category_id,
287 'text' => $text, 292 'text' => $text,
288 'remark' => $data[3] ?? '', 293 'remark' => $data[3] ?? '',
289 - 'image' => (isset($data[5]) && $data[5]) ? CosService::uploadRemote($project_id, 'image_blog', $data[5]) : '', 294 + 'image' => $img,
290 'seo_title' => $data[6] ?? '', 295 'seo_title' => $data[6] ?? '',
291 'seo_keywords' => $data[7] ?? '', 296 'seo_keywords' => $data[7] ?? '',
292 'seo_description' => $data[8] ?? '', 297 'seo_description' => $data[8] ?? '',
@@ -94,7 +94,9 @@ class InquiryLogic extends BaseLogic @@ -94,7 +94,9 @@ class InquiryLogic extends BaseLogic
94 }) 94 })
95 ->select($fields)->orderBy('id', 'desc')->paginate($page_size, ['*'], 'page', $page); 95 ->select($fields)->orderBy('id', 'desc')->paginate($page_size, ['*'], 'page', $page);
96 $data = $lists->toArray(); 96 $data = $lists->toArray();
97 - 97 + foreach ($data['list'] as &$v){
  98 + $v = array_merge($v, $v['data']);
  99 + }
98 return $this->success($data); 100 return $this->success($data);
99 } 101 }
100 102
@@ -299,7 +299,7 @@ class NewsLogic extends BaseLogic @@ -299,7 +299,7 @@ class NewsLogic extends BaseLogic
299 preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result); 299 preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result);
300 if($result[2]??[]){ 300 if($result[2]??[]){
301 foreach ($result[2] as $img){ 301 foreach ($result[2] as $img){
302 - $data[4] = str_replace($img,getImageUrl(CosService::uploadRemote($project_id,'image_news',$img)),$data[4]); 302 + check_remote_url_down($img) && $data[4] = str_replace($img,getImageUrl(CosService::uploadRemote($project_id,'image_news',$img)),$data[4]);
303 } 303 }
304 } 304 }
305 305
@@ -307,20 +307,25 @@ class NewsLogic extends BaseLogic @@ -307,20 +307,25 @@ class NewsLogic extends BaseLogic
307 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video); 307 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video);
308 if($result_video[2]??[]){ 308 if($result_video[2]??[]){
309 foreach ($result_video[2] as $video){ 309 foreach ($result_video[2] as $video){
310 - $data[4] = str_replace($video,getImageUrl(CosService::uploadRemote($project_id,'image_news',$video)),$data[4]); 310 + check_remote_url_down($video) && $data[4] = str_replace($video,getImageUrl(CosService::uploadRemote($project_id,'image_news',$video)),$data[4]);
311 } 311 }
312 } 312 }
313 313
314 $text = $data[4]; 314 $text = $data[4];
315 } 315 }
316 316
  317 + $img = '';
  318 + if($data[5]??''){
  319 + $img = check_remote_url_down($data[5]) ? CosService::uploadRemote($project_id, 'image_news', $data[5]) : $data[5];
  320 + }
  321 +
317 $id = $this->model->addReturnId( 322 $id = $this->model->addReturnId(
318 [ 323 [
319 'name' => $data[0], 324 'name' => $data[0],
320 'category_id' => $category_id, 325 'category_id' => $category_id,
321 'text' => $text, 326 'text' => $text,
322 'remark' => $data[3] ?? '', 327 'remark' => $data[3] ?? '',
323 - 'image' => (isset($data[5]) && $data[5]) ? CosService::uploadRemote($project_id, 'image_news', $data[5]) : '', 328 + 'image' => $img,
324 'seo_title' => $data[6] ?? '', 329 'seo_title' => $data[6] ?? '',
325 'seo_keywords' => $data[7] ?? '', 330 'seo_keywords' => $data[7] ?? '',
326 'seo_description' => $data[8] ?? '', 331 'seo_description' => $data[8] ?? '',
@@ -620,7 +620,7 @@ class ProductLogic extends BaseLogic @@ -620,7 +620,7 @@ class ProductLogic extends BaseLogic
620 $img_arr = explode(',',$data[7]); 620 $img_arr = explode(',',$data[7]);
621 foreach ($img_arr as $v_img){ 621 foreach ($img_arr as $v_img){
622 if($v_img){ 622 if($v_img){
623 - $one_img = CosService::uploadRemote($project_id,'image_product',$v_img); 623 + $one_img = check_remote_url_down($v_img) ? CosService::uploadRemote($project_id,'image_product',$v_img) : $v_img;
624 if($one_img){ 624 if($one_img){
625 $one_gallery = [ 625 $one_gallery = [
626 'alt' => '这是一张产品图', 626 'alt' => '这是一张产品图',
@@ -643,7 +643,7 @@ class ProductLogic extends BaseLogic @@ -643,7 +643,7 @@ class ProductLogic extends BaseLogic
643 preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[5], $result_intro); 643 preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[5], $result_intro);
644 if($result_intro[2]??[]){ 644 if($result_intro[2]??[]){
645 foreach ($result_intro[2] as $vi_img){ 645 foreach ($result_intro[2] as $vi_img){
646 - $data[5] = str_replace($vi_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_img)),$data[5]); 646 + check_remote_url_down($vi_img) && $data[5] = str_replace($vi_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_img)),$data[5]);
647 } 647 }
648 } 648 }
649 649
@@ -651,7 +651,7 @@ class ProductLogic extends BaseLogic @@ -651,7 +651,7 @@ class ProductLogic extends BaseLogic
651 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[5], $result_intro_video); 651 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[5], $result_intro_video);
652 if($result_intro_video[2]??[]){ 652 if($result_intro_video[2]??[]){
653 foreach ($result_intro_video[2] as $vi_video){ 653 foreach ($result_intro_video[2] as $vi_video){
654 - $data[5] = str_replace($vi_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_video)),$data[5]); 654 + check_remote_url_down($vi_video) && $data[5] = str_replace($vi_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_video)),$data[5]);
655 } 655 }
656 } 656 }
657 657
@@ -664,7 +664,7 @@ class ProductLogic extends BaseLogic @@ -664,7 +664,7 @@ class ProductLogic extends BaseLogic
664 preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[6], $result_content); 664 preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[6], $result_content);
665 if($result_content[2]??[]){ 665 if($result_content[2]??[]){
666 foreach ($result_content[2] as $vc_img){ 666 foreach ($result_content[2] as $vc_img){
667 - $data[6] = str_replace($vc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_img)),$data[6]); 667 + check_remote_url_down($vc_img) && $data[6] = str_replace($vc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_img)),$data[6]);
668 } 668 }
669 } 669 }
670 670
@@ -672,7 +672,7 @@ class ProductLogic extends BaseLogic @@ -672,7 +672,7 @@ class ProductLogic extends BaseLogic
672 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[6], $result_content_video); 672 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[6], $result_content_video);
673 if($result_content_video[2]??[]){ 673 if($result_content_video[2]??[]){
674 foreach ($result_content_video[2] as $vc_video){ 674 foreach ($result_content_video[2] as $vc_video){
675 - $data[6] = str_replace($vc_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_video)),$data[6]); 675 + check_remote_url_down($vc_video) && $data[6] = str_replace($vc_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_video)),$data[6]);
676 } 676 }
677 } 677 }
678 678
@@ -698,7 +698,7 @@ class ProductLogic extends BaseLogic @@ -698,7 +698,7 @@ class ProductLogic extends BaseLogic
698 698
699 if($result_desc[2]??[]){ 699 if($result_desc[2]??[]){
700 foreach ($result_desc[2] as $vdesc_img){ 700 foreach ($result_desc[2] as $vdesc_img){
701 - $v_desc['text'] = str_replace($vdesc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vdesc_img)),$v_desc['text']); 701 + check_remote_url_down($vdesc_img) && $v_desc['text'] = str_replace($vdesc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vdesc_img)),$v_desc['text']);
702 } 702 }
703 } 703 }
704 704
@@ -706,7 +706,7 @@ class ProductLogic extends BaseLogic @@ -706,7 +706,7 @@ class ProductLogic extends BaseLogic
706 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $v_desc['text'], $result_desc_video); 706 preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $v_desc['text'], $result_desc_video);
707 if($result_desc_video[2]??[]){ 707 if($result_desc_video[2]??[]){
708 foreach ($result_desc_video[2] as $vdesc_video){ 708 foreach ($result_desc_video[2] as $vdesc_video){
709 - $v_desc['text'] = str_replace($vdesc_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vdesc_video)),$v_desc['text']); 709 + check_remote_url_down($vdesc_video) && $v_desc['text'] = str_replace($vdesc_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vdesc_video)),$v_desc['text']);
710 } 710 }
711 } 711 }
712 } 712 }