作者 lyh

gx

... ... @@ -150,7 +150,7 @@ class ImageController extends Controller
$imageModel = new ImageModel();
$image_hash = $imageModel->read(['hash'=>$hash]);
if($image_hash !== false){
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
}
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
... ...
... ... @@ -29,8 +29,6 @@ class ProductLogic extends BaseLogic
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
$data = parent::getList($map, $sort, $columns, $limit);
var_dump($data);
die();
foreach ($data['list'] as &$v){
$v = $this->formatData($v);
}
... ...
... ... @@ -4,7 +4,9 @@ namespace App\Models\Product;
use App\Helper\Arr;
use App\Models\Base;
use App\Models\File\Image;
use App\Models\RouteMap;
use App\Services\CosService;
use App\Services\Facades\Upload;
use Illuminate\Database\Eloquent\SoftDeletes;
... ... @@ -36,7 +38,32 @@ class Product extends Base
$value['url'] = Upload::url2path($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']);
... ...