作者 lyh

gx

@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 2
3 namespace App\Models; 3 namespace App\Models;
4 4
  5 +use App\Models\File\Image;
  6 +use App\Services\CosService;
5 use Illuminate\Database\Eloquent\Model; 7 use Illuminate\Database\Eloquent\Model;
6 class Base extends Model 8 class Base extends Model
7 { 9 {
@@ -209,5 +211,29 @@ class Base extends Model @@ -209,5 +211,29 @@ class Base extends Model
209 }); 211 });
210 return $query; 212 return $query;
211 } 213 }
212 - 214 + /**
  215 + * @remark :获取图片链接
  216 + * @name :getImageUrl
  217 + * @author :lyh
  218 + * @method :post
  219 + * @time :2023/7/20 16:46
  220 + */
  221 + public function getImageUrl($hash){
  222 + if(is_array($hash)){
  223 + $url = [];
  224 + foreach ($hash as $k => $v){
  225 + $url['images_link'][$k] = $this->getImageUrl($v);
  226 + }
  227 + }else{
  228 + $imageModel = new Image();
  229 + $info = $imageModel->read(['hash'=>$hash]);
  230 + if($info['is_cos'] == 1){
  231 + $cos = new CosService();
  232 + $url = $cos->getImageUrl($info['path']);
  233 + }else{
  234 + $url = url('b/image/'.$info['hash']);
  235 + }
  236 + }
  237 + return $url;
  238 + }
213 } 239 }
@@ -35,44 +35,19 @@ class Product extends Base @@ -35,44 +35,19 @@ class Product extends Base
35 } 35 }
36 36
37 public function setThumbAttribute($value){ 37 public function setThumbAttribute($value){
38 - $value['url'] = Upload::url2path($value['url']); 38 + $value['url'] = $this->getImageUrl($value['url']);
39 $this->attributes['thumb'] = Arr::a2s($value); 39 $this->attributes['thumb'] = Arr::a2s($value);
40 } 40 }
41 - /**  
42 - * @remark :获取图片链接  
43 - * @name :getImageUrl  
44 - * @author :lyh  
45 - * @method :post  
46 - * @time :2023/7/20 16:46  
47 - */  
48 - public function getImageUrl($hash){  
49 - if(is_array($hash)){  
50 - $url = [];  
51 - foreach ($hash as $k => $v){  
52 - $url['images_link'][$k] = $this->getImageUrl($v);  
53 - }  
54 - }else{  
55 - $imageModel = new Image();  
56 - $info = $imageModel->read(['hash'=>$hash]);  
57 - if($info['is_cos'] == 1){  
58 - $cos = new CosService();  
59 - $url = $cos->getImageUrl($info['path']);  
60 - }else{  
61 - $url = url('b/image/'.$info['hash']);  
62 - }  
63 - }  
64 41
65 - return $url;  
66 - }  
67 public function getThumbAttribute($value){ 42 public function getThumbAttribute($value){
68 $value = Arr::s2a($value); 43 $value = Arr::s2a($value);
69 - $value['url'] = Upload::path2url($value['url']); 44 + $value['url'] = $this->getImageUrl($value['url']);
70 return $value; 45 return $value;
71 } 46 }
72 47
73 public function setGalleryAttribute($value){ 48 public function setGalleryAttribute($value){
74 foreach ($value as &$v){ 49 foreach ($value as &$v){
75 - $v['url'] = Upload::url2path($v['url']); 50 + $v['url'] = $this->getImageUrl($value['url']);
76 } 51 }
77 $this->attributes['gallery'] = Arr::a2s($value); 52 $this->attributes['gallery'] = Arr::a2s($value);
78 } 53 }
@@ -80,7 +55,7 @@ class Product extends Base @@ -80,7 +55,7 @@ class Product extends Base
80 public function getGalleryAttribute($value){ 55 public function getGalleryAttribute($value){
81 $value = Arr::s2a($value); 56 $value = Arr::s2a($value);
82 foreach ($value as &$v){ 57 foreach ($value as &$v){
83 - $v['url'] = Upload::path2url($v['url']); 58 + $v['url'] = $this->getImageUrl($value['url']);
84 } 59 }
85 return $value; 60 return $value;
86 } 61 }