作者 lyh

gx

... ... @@ -456,7 +456,7 @@ if (!function_exists('getImageUrl')) {
* @method :post
* @time :2023/7/20 16:46
*/
function getImageUrl($path,$location = 1){
function getImageUrl($path,$location = 1,$storage_type = 0){
if(is_array($path)){
$url =[];
foreach ($path as $v){
... ... @@ -473,7 +473,7 @@ if (!function_exists('getImageUrl')) {
return 'https:'.$path;
}
if($location == 1){
$cos = config('filesystems.disks.cos');
$cos = ($storage_type == 0) ? config('filesystems.disks.cos') : config('filesystems.disks.cos1');
$cosCdn = $cos['cdn'];
$url = $cosCdn.$path;
}else{
... ... @@ -483,6 +483,7 @@ if (!function_exists('getImageUrl')) {
return $url;
}
}
if (!function_exists('getFileUrl')) {
/**
* @remark :获取文件链接
... ... @@ -491,7 +492,7 @@ if (!function_exists('getFileUrl')) {
* @method :post
* @time :2023/7/20 16:46
*/
function getFileUrl($path,$location = 1){
function getFileUrl($path,$location = 1,$storage_type = 0){
if(is_array($path)){
$url =[];
foreach ($path as $v){
... ... @@ -508,7 +509,7 @@ if (!function_exists('getFileUrl')) {
return 'https:'.$path;
}
if($location == 1){
$cos = config('filesystems.disks.cos');
$cos = ($storage_type == 0) ? config('filesystems.disks.cos') : config('filesystems.disks.cos1');
$cosCdn = $cos['cdn'];
$url = $cosCdn.$path;
}else{
... ...
... ... @@ -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']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']);
$list[$k] = $v;
}
... ...
... ... @@ -60,7 +60,7 @@ class ProductController extends BaseController
$v['keyword_id_text'] = $this->keywordName($v['keyword_id'],$key_data);
$v['created_uid_text'] = $userModel->getName($v['created_uid']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id']);
$v['url'] = $this->user['domain'].$v['route'].'/';
$v = $this->getHandleFileImage($v,$cate_data,$key_data,$template_id);
$lists['list'][$k] = $v;
}
}
... ... @@ -68,7 +68,41 @@ class ProductController extends BaseController
}
/**
* @remark :处理列表返回参数
* @remark :获取时处理图片和文件
* @name :getHandleFileImage
* @author :lyh
* @method :post
* @time :2024/1/23 17:43
*/
public function getHandleFileImage($v){
$v['url'] = $this->user['domain'].$v['route'].'/';
//ToDo::处理图片及文件
if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
$v['thumb']['url'] = getImageUrl($v['thumb']['url'],$this->user['project_location'],$this->user['storage_type']);
}
if(!empty($v['gallery'])){
foreach ($v['gallery'] as $gallery_k => $gallery_v){
$gallery_v['url'] = getImageUrl($gallery_v['url'],$this->user['project_location'],$this->user['storage_type']);
$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'],$this->user['storage_type']);
$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'],$this->user['storage_type']);
}
if(!empty($v['files']) && !empty($v['files']['url'])){
$v['files']['url'] = getImageUrl($v['files']['url'],$this->user['project_location'],$this->user['storage_type']);
}
return $this->success($v);
}
/**
* @remark :搜索参数处理
* @name :handleReturnParam
* @author :lyh
* @method :post
... ... @@ -243,6 +277,8 @@ class ProductController extends BaseController
}else{
$v['status_text'] = '';
}
//ToDo::处理图片及文件
$v = $this->getHandleFileImage($v);
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id'] ?? 0);
$v['url'] = $this->user['domain'].$v['route'];
... ... @@ -251,6 +287,7 @@ class ProductController extends BaseController
return $v;
}
/**
* @remark :获取扩展字段详情
* @name :getExtendInfo
... ... @@ -293,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']);
$v1['url'] = getImageUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
... ... @@ -302,9 +339,9 @@ class ProductController extends BaseController
foreach ($arr1 as $k1=>$v1){
$v1 = (array)$v1;
if(isset($v1['url'])){
$v1['url'] = getFileUrl($v1['url']);
$v1['url'] = getFileUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
}else{
$v1 = getFileUrl($v1);
$v1 = getFileUrl($v1,$this->user['project_location'],$this->user['storage_type']);
}
$arr1[$k1] = $v1;
}
... ...
... ... @@ -102,51 +102,9 @@ class Product extends Base
3=>'热销产品'
];
/**
* 产品列表
* @param $map
* @param $page
* @param $row
* @param string $order
* @param string[] $fields
* @param string $sort
* @return array
* @author zbj
* @date 2023/10/17
*/
public function product_lists($map, $page, $row, $order = 'id', $fields = ['*'], $sort = 'desc'): array
{
$category_id = $map['category_id'] ?? 0;
$query = $this->where(function ($query) use ($category_id) {
if ($category_id) {
$category_ids = Category::getChildIdsArr($category_id);
$query->whereIn('id', function ($subQuery) use ($category_ids) {
$subQuery->select('product_id')
->from('gl_product_category_related')
->whereIn('cate_id', $category_ids)
->groupBy('product_id');
});
}
});
unset($map['category_id']);
$query = $this->formatQuery($map, $query);
$query = $this->sortOrder($query,$order,$sort);
$lists = $query->select($fields)->paginate($row, ['*'], 'page', $page);
if (empty($lists)) {
return [];
}
$lists = $lists->toArray();
return $lists;
}
public function getThumbAttribute($value){
if(!empty($value)){
$value = json_decode($value,true);
if(!empty($value['url'])){
$value['url'] = getImageUrl($value['url']);
}
}
return $value;
}
... ... @@ -155,12 +113,6 @@ class Product extends Base
public function getGalleryAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
foreach ($value as $k => $v){
if(!empty($v['url'])){
$v['url'] = getImageUrl($v['url']);
}
$value[$k] = $v;
}
}
return $value;
}
... ... @@ -175,9 +127,6 @@ class Product extends Base
public function getFilesAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
if(!empty($value['url'])){
$value['url'] = getImageUrl($value['url']);
}
}
return $value;
}
... ... @@ -192,10 +141,6 @@ class Product extends Base
public function getVideoAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
$value = Arr::s2a($value);
if(!empty($value['url'])){
$value['url'] = getImageUrl($value['url']);
}
}
return $value;
}
... ... @@ -210,10 +155,6 @@ class Product extends Base
public function getIconAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
foreach ($value as $k => $v){
$v = getImageUrl($v);
$value[$k] = $v;
}
}
return $value;
}
... ...