作者 lyh

gx

... ... @@ -2,6 +2,8 @@
namespace App\Models;
use App\Models\File\Image;
use App\Services\CosService;
use Illuminate\Database\Eloquent\Model;
class Base extends Model
{
... ... @@ -209,5 +211,29 @@ class Base extends Model
});
return $query;
}
/**
* @remark :获取图片链接
* @name :getImageUrl
* @author :lyh
* @method :post
* @time :2023/7/20 16:46
*/
public function getImageUrl($hash){
if(is_array($hash)){
$url = [];
foreach ($hash as $k => $v){
$url['images_link'][$k] = $this->getImageUrl($v);
}
}else{
$imageModel = new Image();
$info = $imageModel->read(['hash'=>$hash]);
if($info['is_cos'] == 1){
$cos = new CosService();
$url = $cos->getImageUrl($info['path']);
}else{
$url = url('b/image/'.$info['hash']);
}
}
return $url;
}
}
... ...
... ... @@ -35,44 +35,19 @@ class Product extends Base
}
public function setThumbAttribute($value){
$value['url'] = Upload::url2path($value['url']);
$value['url'] = $this->getImageUrl($value['url']);
$this->attributes['thumb'] = Arr::a2s($value);
}
/**
* @remark :获取图片链接
* @name :getImageUrl
* @author :lyh
* @method :post
* @time :2023/7/20 16:46
*/
public function getImageUrl($hash){
if(is_array($hash)){
$url = [];
foreach ($hash as $k => $v){
$url['images_link'][$k] = $this->getImageUrl($v);
}
}else{
$imageModel = new Image();
$info = $imageModel->read(['hash'=>$hash]);
if($info['is_cos'] == 1){
$cos = new CosService();
$url = $cos->getImageUrl($info['path']);
}else{
$url = url('b/image/'.$info['hash']);
}
}
return $url;
}
public function getThumbAttribute($value){
$value = Arr::s2a($value);
$value['url'] = Upload::path2url($value['url']);
$value['url'] = $this->getImageUrl($value['url']);
return $value;
}
public function setGalleryAttribute($value){
foreach ($value as &$v){
$v['url'] = Upload::url2path($v['url']);
$v['url'] = $this->getImageUrl($value['url']);
}
$this->attributes['gallery'] = Arr::a2s($value);
}
... ... @@ -80,7 +55,7 @@ class Product extends Base
public function getGalleryAttribute($value){
$value = Arr::s2a($value);
foreach ($value as &$v){
$v['url'] = Upload::path2url($v['url']);
$v['url'] = $this->getImageUrl($value['url']);
}
return $value;
}
... ...