作者 lyh

gx

... ... @@ -9,6 +9,8 @@ use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Models\Devops\ServerInformationLog;
use App\Models\File\Image;
use App\Services\CosService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
... ... @@ -380,7 +382,33 @@ class Logic
return $this->success($info);
}
/**
* @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;
}
/**
* 获取实例
... ...
... ... @@ -38,7 +38,16 @@ class ProductRequest extends FormRequest
return [
'title' => 'required|max:200',
'route' => 'required|max:200',
'gallery' => 'required|array',
'gallery' => ['required', 'array', function ($attribute, $value, $fail) {
foreach ($value as $v) {
if (empty($v['url'])) {
$fail('图片链接不能为空');
}
if (!Str::contains($v['url'], env('UPLOAD_LOCAL_URL') ?: env('APP_URL'))) {
$fail('图片链接不正确');
}
}
}],
'attrs' => ['array', function ($attribute, $value, $fail) {
foreach ($value as $v) {
if (empty($v['key'])) {
... ...