作者 lyh

gx

<?php
use App\Models\File\Image;
use App\Models\File\File;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use App\Utils\EncryptUtils;
... ... @@ -456,11 +457,11 @@ if (!function_exists('getImageUrl')) {
* @method :post
* @time :2023/7/20 16:46
*/
function getImageUrl($path,$location = 0,$storage_type = 0){
function getImageUrl($path,$storage_type = 0){
if(is_array($path)){
$url =[];
foreach ($path as $v){
$url[] = getImageUrl($v,$location,$storage_type);
$url[] = getImageUrl($v,$storage_type);
}
}else{
if(empty($path)){
... ... @@ -472,7 +473,12 @@ if (!function_exists('getImageUrl')) {
if(substr($path,0,2) == '//'){
return 'https:'.$path;
}
if($location == 0){
$imageModel = new Image();
$imageInfo = $imageModel->read(['path'=>$path],'is_cos');
if($imageInfo === false){
return '';
}
if($imageInfo['is_cos'] == 1){
$cos = config('filesystems.disks.cos');
$cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1'];
$url = $cosCdn.$path;
... ... @@ -494,11 +500,11 @@ if (!function_exists('getFileUrl')) {
* @method :post
* @time :2023/7/20 16:46
*/
function getFileUrl($path,$location = 0,$storage_type = 0){
function getFileUrl($path,$storage_type = 0){
if(is_array($path)){
$url =[];
foreach ($path as $v){
$url[] = getFileUrl($v,$location,$storage_type);
$url[] = getFileUrl($v,$storage_type);
}
}else{
if(empty($path)){
... ... @@ -510,7 +516,12 @@ if (!function_exists('getFileUrl')) {
if(substr($path,0,2) == '//'){
return 'https:'.$path;
}
if($location == 0){
$fileModel = new File();
$fileInfo = $fileModel->read(['path'=>$path],'is_cos');
if($fileInfo === false){
return '';
}
if($fileInfo['is_cos'] == 1){
$cos = config('filesystems.disks.cos');
$cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1'];
$url = $cosCdn.$path;
... ... @@ -568,7 +579,8 @@ if (!function_exists('str_replace_url')) {
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$cosCdn1 = $cos['cdn1'];
if($url && ((strpos($url,$cosCdn) !== false) || (strpos($url,$cosCdn1) !== false))){
$cosCdn2 = config('filesystems.disks.s3')['cdn'];
if($url && ((strpos($url,$cosCdn) !== false) || (strpos($url,$cosCdn1) !== false) || (strpos($url,$cosCdn2) !== false))){
// 外部URL无需解析
// 使用 parse_url 函数来解析 URL
$urlParts = parse_url($url);
... ...
... ... @@ -38,7 +38,7 @@ class BlogController extends BaseController
foreach ($lists['list'] as $k => $v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_BLOG,$v['id']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['image_link'] = getImageUrl($v['image'],$this->user['storage_type']);
$v['operator_name'] = $user->getName($v['operator_id']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_BLOG,BTemplate::IS_DETAIL,$template_id,$v['id']);
$lists['list'][$k] = $v;
... ...
... ... @@ -37,7 +37,7 @@ class CustomModuleContentController extends BaseController
$data = $this->getAllCategoryName();
foreach ($lists['list'] as $k=>$v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['image_link'] = getImageUrl($v['image'],$this->user['storage_type']);
$v['operator_name'] = (new User())->getName($v['operator_id']);
$lists['list'][$k] = $v;
}
... ...
... ... @@ -41,7 +41,7 @@ class NewsController extends BaseController
foreach ($lists['list'] as $k => $v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['url'] = $this->user['domain'].getRouteMap(RouteMap::SOURCE_NEWS,$v['id']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['image_link'] = getImageUrl($v['image'],$this->user['storage_type']);
$v['operator_name'] = $user->getName($v['operator_id']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_NEWS,BTemplate::IS_DETAIL,$template_id,$v['id']);
$lists['list'][$k] = $v;
... ...
... ... @@ -41,7 +41,7 @@ class CategoryController extends BaseController
foreach ($list as $k =>$v){
$v['url'] = $this->user['domain'] . $v['route'].'/';
$v['product_num'] = Category::getProductNum($v['id']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['image_link'] = getImageUrl($v['image'],$this->user['storage_type']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']);
$list[$k] = $v;
}
... ...
... ... @@ -78,25 +78,25 @@ class ProductController extends BaseController
public function getHandleFileImage($v){
//ToDo::处理图片及文件
if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
$v['thumb']['url'] = getImageUrl($v['thumb']['url'],$this->user['project_location'] ?? 0,$this->user['storage_type'] ?? 0);
$v['thumb']['url'] = getImageUrl($v['thumb']['url'],$this->user['storage_type'] ?? 0);
}
if(!empty($v['gallery'])){
foreach ($v['gallery'] as $gallery_k => $gallery_v){
$gallery_v['url'] = getImageUrl($gallery_v['url'],$this->user['project_location'] ?? 0,$this->user['storage_type'] ?? 0);
$gallery_v['url'] = getImageUrl($gallery_v['url'],$this->user['storage_type'] ?? 0);
$v['gallery'][$gallery_k] = $gallery_v;
}
}
if(!empty($v['icon'])){
foreach ($v['icon'] as $icon_k => $icon_v){
$icon_v = getImageUrl($icon_v,$this->user['project_location'] ?? 0,$this->user['storage_type'] ?? 0);
$icon_v = getImageUrl($icon_v,$this->user['storage_type'] ?? 0);
$v['icon'][$icon_k] = $icon_v;
}
}
if(!empty($v['video']) && !empty($v['video']['url'])){
$v['video']['url'] = getImageUrl($v['video']['url'],$this->user['project_location'] ?? 0,$this->user['storage_type'] ?? 0);
$v['video']['url'] = getImageUrl($v['video']['url'],$this->user['storage_type'] ?? 0);
}
if(!empty($v['files']) && !empty($v['files']['url'])){
$v['files']['url'] = getImageUrl($v['files']['url'],$this->user['project_location'] ?? 0,$this->user['storage_type'] ?? 0);
$v['files']['url'] = getImageUrl($v['files']['url'],$this->user['storage_type'] ?? 0);
}
return $this->success($v);
}
... ... @@ -330,7 +330,7 @@ class ProductController extends BaseController
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = (array)$v1;
$v1['url'] = getImageUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
$v1['url'] = getImageUrl($v1['url'],$this->user['storage_type']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
... ... @@ -339,9 +339,9 @@ class ProductController extends BaseController
foreach ($arr1 as $k1=>$v1){
$v1 = (array)$v1;
if(isset($v1['url'])){
$v1['url'] = getFileUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
$v1['url'] = getFileUrl($v1['url'],$this->user['storage_type']);
}else{
$v1 = getFileUrl($v1,$this->user['project_location'],$this->user['storage_type']);
$v1 = getFileUrl($v1,$this->user['storage_type']);
}
$arr1[$k1] = $v1;
}
... ...
... ... @@ -25,7 +25,7 @@ class WebSettingImageController extends BaseController
public function lists(WebSettingImage $webSettingImage){
$list = $webSettingImage->list([],'id',['id','image','type']);
foreach ($list as $k=>$v){
$v['image'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['image'] = getImageUrl($v['image'],$this->user['storage_type']);
$list[$k] = $v;
}
$this->response('success',Code::SUCCESS,$list);
... ...
... ... @@ -22,7 +22,7 @@ class BTemplateController extends BaseController
$lists = $BTemplateLogic->publicTemplateLists($this->map,$this->page,$this->row,$this->order);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => &$v){
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['image_link'] = getImageUrl($v['image'],$this->user['storage_type']);
$lists['list'][$k] = $v;
}
}
... ...
... ... @@ -336,7 +336,7 @@ class FileController
$fileModel = new File();
$lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at','name']);
foreach ($lists as $k => $v){
$v['file_link'] = getFileUrl($v['path'],$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0);
$v['file_link'] = getFileUrl($v['path'],$this->cache['storage_type'] ?? 0);
$lists[$k] = $v;
}
$this->response('success',Code::SUCCESS,$lists);
... ... @@ -352,7 +352,7 @@ class FileController
public function responseData($path, $name){
$data = [
'file'=>$path,
'file_link'=>getFileUrl($path,$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0),
'file_link'=>getFileUrl($path,$this->cache['storage_type'] ?? 0),
'name'=>$name,
'file_download'=>url('a/download_files?path='.$path)
];
... ...
... ... @@ -363,7 +363,7 @@ class ImageController extends Controller
$lists = $imageModel->lists($this->map,$this->page,$this->row);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v['image_link'] = getImageUrl($v['path'],$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0);
$v['image_link'] = getImageUrl($v['path'],$this->cache['storage_type'] ?? 0);
$lists['list'][$k] = $v;
}
}
... ... @@ -429,7 +429,7 @@ class ImageController extends Controller
public function responseData($path = '', $name = ''){
$data = [
'image'=>$path,
'image_link'=>getImageUrl($path,$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0),
'image_link'=>getImageUrl($path,$this->cache['storage_type'] ?? 0),
'name'=>$name,
'image_download'=>url('a/download_images?path='.$path)
];
... ...
... ... @@ -101,7 +101,7 @@ class BlogLogic extends BaseLogic
//获取标签名称
$blogLabelLogic = new BlogLabelLogic();
$info['label_name'] = $blogLabelLogic->getLabelName($info['label_id']);
$info['image_link'] = getImageUrl($info['image'],$this->user['project_location'],$this->user['storage_type']);
$info['image_link'] = getImageUrl($info['image'],$this->user['storage_type']);
return $this->success($info);
}
... ...
... ... @@ -39,7 +39,7 @@ class CustomModuleContentLogic extends BaseLogic
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
$info['image'] = getImageUrl($info['image'],$this->user['project_location'],$this->user['storage_type']);
$info['image'] = getImageUrl($info['image'],$this->user['storage_type']);
$info['extend'] = $this->getExtendInfo($info['module_id'],$info['id']);
return $this->success($info);
}
... ... @@ -86,14 +86,14 @@ class CustomModuleContentLogic extends BaseLogic
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = (array)$v1;
$v1['url'] = getImageUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
$v1['url'] = getImageUrl($v1['url'],$this->user['storage_type']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
}elseif($v['type'] == 4){
$arr1 = json_decode($info['values']);
foreach ($arr1 as $k1=>$v1){
$v1 = getFileUrl($v1,$this->user['project_location'],$this->user['storage_type']);
$v1 = getFileUrl($v1,$this->user['storage_type']);
$arr1[$k1] = $v1;
}
$v['values'] = $arr1;
... ...
... ... @@ -147,7 +147,7 @@ class NewsLogic extends BaseLogic
$this->fail('error');
}
$info['category_id'] = explode(',',trim($info['category_id'],','));
$info['image_link'] = getImageUrl($info['image'],$this->user['project_location'],$this->user['storage_type']);
$info['image_link'] = getImageUrl($info['image'],$this->user['storage_type']);
return $this->success($info);
}
... ...
... ... @@ -32,7 +32,7 @@ class CategoryLogic extends BaseLogic
foreach ($data as &$v){
$v['url'] = $this->user['domain'] . $v['route'] ;
$v['product_num'] = Category::getProductNum($v['id']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['image_link'] = getImageUrl($v['image'],$this->user['storage_type']);
}
if(!$map){
$data = Arr::listToTree($data);
... ...