作者 lyh

gx

@@ -150,7 +150,7 @@ class ImageController extends Controller @@ -150,7 +150,7 @@ class ImageController extends Controller
150 $imageModel = new ImageModel(); 150 $imageModel = new ImageModel();
151 $image_hash = $imageModel->read(['hash'=>$hash]); 151 $image_hash = $imageModel->read(['hash'=>$hash]);
152 if($image_hash !== false){ 152 if($image_hash !== false){
153 - return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); 153 + return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
154 } 154 }
155 $url = $this->config['root'].$this->path; 155 $url = $this->config['root'].$this->path;
156 $fileName = uniqid().rand(10000,99999).'.'.$image_type; 156 $fileName = uniqid().rand(10000,99999).'.'.$image_type;
@@ -29,8 +29,6 @@ class ProductLogic extends BaseLogic @@ -29,8 +29,6 @@ class ProductLogic extends BaseLogic
29 public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20) 29 public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
30 { 30 {
31 $data = parent::getList($map, $sort, $columns, $limit); 31 $data = parent::getList($map, $sort, $columns, $limit);
32 - var_dump($data);  
33 - die();  
34 foreach ($data['list'] as &$v){ 32 foreach ($data['list'] as &$v){
35 $v = $this->formatData($v); 33 $v = $this->formatData($v);
36 } 34 }
@@ -4,7 +4,9 @@ namespace App\Models\Product; @@ -4,7 +4,9 @@ namespace App\Models\Product;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Models\Base; 6 use App\Models\Base;
  7 +use App\Models\File\Image;
7 use App\Models\RouteMap; 8 use App\Models\RouteMap;
  9 +use App\Services\CosService;
8 use App\Services\Facades\Upload; 10 use App\Services\Facades\Upload;
9 use Illuminate\Database\Eloquent\SoftDeletes; 11 use Illuminate\Database\Eloquent\SoftDeletes;
10 12
@@ -36,7 +38,32 @@ class Product extends Base @@ -36,7 +38,32 @@ class Product extends Base
36 $value['url'] = Upload::url2path($value['url']); 38 $value['url'] = Upload::url2path($value['url']);
37 $this->attributes['thumb'] = Arr::a2s($value); 39 $this->attributes['thumb'] = Arr::a2s($value);
38 } 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 + }
39 64
  65 + return $url;
  66 + }
40 public function getThumbAttribute($value){ 67 public function getThumbAttribute($value){
41 $value = Arr::s2a($value); 68 $value = Arr::s2a($value);
42 $value['url'] = Upload::path2url($value['url']); 69 $value['url'] = Upload::path2url($value['url']);