作者 lyh

gx

@@ -9,6 +9,8 @@ use App\Exceptions\AsideGlobalException; @@ -9,6 +9,8 @@ use App\Exceptions\AsideGlobalException;
9 use App\Exceptions\BsideGlobalException; 9 use App\Exceptions\BsideGlobalException;
10 use App\Helper\Arr; 10 use App\Helper\Arr;
11 use App\Models\Devops\ServerInformationLog; 11 use App\Models\Devops\ServerInformationLog;
  12 +use App\Models\File\Image;
  13 +use App\Services\CosService;
12 use Illuminate\Database\Eloquent\Model; 14 use Illuminate\Database\Eloquent\Model;
13 use Illuminate\Support\Facades\Cache; 15 use Illuminate\Support\Facades\Cache;
14 use Illuminate\Support\Facades\DB; 16 use Illuminate\Support\Facades\DB;
@@ -380,7 +382,33 @@ class Logic @@ -380,7 +382,33 @@ class Logic
380 return $this->success($info); 382 return $this->success($info);
381 } 383 }
382 384
  385 + /**
  386 + * @remark :获取图片链接
  387 + * @name :getImageUrl
  388 + * @author :lyh
  389 + * @method :post
  390 + * @time :2023/7/20 16:46
  391 + */
  392 + public function getImageUrl($hash){
383 393
  394 + if(is_array($hash)){
  395 + $url = [];
  396 + foreach ($hash as $k => $v){
  397 + $url['images_link'][$k] = $this->getImageUrl($v);
  398 + }
  399 + }else{
  400 + $imageModel = new Image();
  401 + $info = $imageModel->read(['hash'=>$hash]);
  402 + if($info['is_cos'] == 1){
  403 + $cos = new CosService();
  404 + $url = $cos->getImageUrl($info['path']);
  405 + }else{
  406 + $url = url('b/image/'.$info['hash']);
  407 + }
  408 + }
  409 +
  410 + return $url;
  411 + }
384 412
385 /** 413 /**
386 * 获取实例 414 * 获取实例
@@ -38,7 +38,16 @@ class ProductRequest extends FormRequest @@ -38,7 +38,16 @@ class ProductRequest extends FormRequest
38 return [ 38 return [
39 'title' => 'required|max:200', 39 'title' => 'required|max:200',
40 'route' => 'required|max:200', 40 'route' => 'required|max:200',
41 - 'gallery' => 'required|array', 41 + 'gallery' => ['required', 'array', function ($attribute, $value, $fail) {
  42 + foreach ($value as $v) {
  43 + if (empty($v['url'])) {
  44 + $fail('图片链接不能为空');
  45 + }
  46 + if (!Str::contains($v['url'], env('UPLOAD_LOCAL_URL') ?: env('APP_URL'))) {
  47 + $fail('图片链接不正确');
  48 + }
  49 + }
  50 + }],
42 'attrs' => ['array', function ($attribute, $value, $fail) { 51 'attrs' => ['array', function ($attribute, $value, $fail) {
43 foreach ($value as $v) { 52 foreach ($value as $v) {
44 if (empty($v['key'])) { 53 if (empty($v['key'])) {