作者 lyh

gx

@@ -456,7 +456,7 @@ if (!function_exists('getImageUrl')) { @@ -456,7 +456,7 @@ if (!function_exists('getImageUrl')) {
456 * @method :post 456 * @method :post
457 * @time :2023/7/20 16:46 457 * @time :2023/7/20 16:46
458 */ 458 */
459 - function getImageUrl($path,$location = 1){ 459 + function getImageUrl($path,$location = 1,$storage_type = 0){
460 if(is_array($path)){ 460 if(is_array($path)){
461 $url =[]; 461 $url =[];
462 foreach ($path as $v){ 462 foreach ($path as $v){
@@ -473,7 +473,7 @@ if (!function_exists('getImageUrl')) { @@ -473,7 +473,7 @@ if (!function_exists('getImageUrl')) {
473 return 'https:'.$path; 473 return 'https:'.$path;
474 } 474 }
475 if($location == 1){ 475 if($location == 1){
476 - $cos = config('filesystems.disks.cos'); 476 + $cos = ($storage_type == 0) ? config('filesystems.disks.cos') : config('filesystems.disks.cos1');
477 $cosCdn = $cos['cdn']; 477 $cosCdn = $cos['cdn'];
478 $url = $cosCdn.$path; 478 $url = $cosCdn.$path;
479 }else{ 479 }else{
@@ -483,6 +483,7 @@ if (!function_exists('getImageUrl')) { @@ -483,6 +483,7 @@ if (!function_exists('getImageUrl')) {
483 return $url; 483 return $url;
484 } 484 }
485 } 485 }
  486 +
486 if (!function_exists('getFileUrl')) { 487 if (!function_exists('getFileUrl')) {
487 /** 488 /**
488 * @remark :获取文件链接 489 * @remark :获取文件链接
@@ -491,7 +492,7 @@ if (!function_exists('getFileUrl')) { @@ -491,7 +492,7 @@ if (!function_exists('getFileUrl')) {
491 * @method :post 492 * @method :post
492 * @time :2023/7/20 16:46 493 * @time :2023/7/20 16:46
493 */ 494 */
494 - function getFileUrl($path,$location = 1){ 495 + function getFileUrl($path,$location = 1,$storage_type = 0){
495 if(is_array($path)){ 496 if(is_array($path)){
496 $url =[]; 497 $url =[];
497 foreach ($path as $v){ 498 foreach ($path as $v){
@@ -508,7 +509,7 @@ if (!function_exists('getFileUrl')) { @@ -508,7 +509,7 @@ if (!function_exists('getFileUrl')) {
508 return 'https:'.$path; 509 return 'https:'.$path;
509 } 510 }
510 if($location == 1){ 511 if($location == 1){
511 - $cos = config('filesystems.disks.cos'); 512 + $cos = ($storage_type == 0) ? config('filesystems.disks.cos') : config('filesystems.disks.cos1');
512 $cosCdn = $cos['cdn']; 513 $cosCdn = $cos['cdn'];
513 $url = $cosCdn.$path; 514 $url = $cosCdn.$path;
514 }else{ 515 }else{
@@ -41,7 +41,7 @@ class CategoryController extends BaseController @@ -41,7 +41,7 @@ class CategoryController extends BaseController
41 foreach ($list as $k =>$v){ 41 foreach ($list as $k =>$v){
42 $v['url'] = $this->user['domain'] . $v['route'].'/'; 42 $v['url'] = $this->user['domain'] . $v['route'].'/';
43 $v['product_num'] = Category::getProductNum($v['id']); 43 $v['product_num'] = Category::getProductNum($v['id']);
44 - $v['image_link'] = getImageUrl($v['image']); 44 + $v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
45 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']); 45 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']);
46 $list[$k] = $v; 46 $list[$k] = $v;
47 } 47 }
@@ -60,7 +60,7 @@ class ProductController extends BaseController @@ -60,7 +60,7 @@ class ProductController extends BaseController
60 $v['keyword_id_text'] = $this->keywordName($v['keyword_id'],$key_data); 60 $v['keyword_id_text'] = $this->keywordName($v['keyword_id'],$key_data);
61 $v['created_uid_text'] = $userModel->getName($v['created_uid']); 61 $v['created_uid_text'] = $userModel->getName($v['created_uid']);
62 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id']); 62 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id']);
63 - $v['url'] = $this->user['domain'].$v['route'].'/'; 63 + $v = $this->getHandleFileImage($v,$cate_data,$key_data,$template_id);
64 $lists['list'][$k] = $v; 64 $lists['list'][$k] = $v;
65 } 65 }
66 } 66 }
@@ -68,7 +68,41 @@ class ProductController extends BaseController @@ -68,7 +68,41 @@ class ProductController extends BaseController
68 } 68 }
69 69
70 /** 70 /**
71 - * @remark :处理列表返回参数 71 + * @remark :获取时处理图片和文件
  72 + * @name :getHandleFileImage
  73 + * @author :lyh
  74 + * @method :post
  75 + * @time :2024/1/23 17:43
  76 + */
  77 + public function getHandleFileImage($v){
  78 + $v['url'] = $this->user['domain'].$v['route'].'/';
  79 + //ToDo::处理图片及文件
  80 + if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
  81 + $v['thumb']['url'] = getImageUrl($v['thumb']['url'],$this->user['project_location'],$this->user['storage_type']);
  82 + }
  83 + if(!empty($v['gallery'])){
  84 + foreach ($v['gallery'] as $gallery_k => $gallery_v){
  85 + $gallery_v['url'] = getImageUrl($gallery_v['url'],$this->user['project_location'],$this->user['storage_type']);
  86 + $v['gallery'][$gallery_k] = $gallery_v;
  87 + }
  88 + }
  89 + if(!empty($v['icon'])){
  90 + foreach ($v['icon'] as $icon_k => $icon_v){
  91 + $icon_v = getImageUrl($icon_v,$this->user['project_location'],$this->user['storage_type']);
  92 + $v['icon'][$icon_k] = $icon_v;
  93 + }
  94 + }
  95 + if(!empty($v['video']) && !empty($v['video']['url'])){
  96 + $v['video']['url'] = getImageUrl($v['video']['url'],$this->user['project_location'],$this->user['storage_type']);
  97 + }
  98 + if(!empty($v['files']) && !empty($v['files']['url'])){
  99 + $v['files']['url'] = getImageUrl($v['files']['url'],$this->user['project_location'],$this->user['storage_type']);
  100 + }
  101 + return $this->success($v);
  102 + }
  103 +
  104 + /**
  105 + * @remark :搜索参数处理
72 * @name :handleReturnParam 106 * @name :handleReturnParam
73 * @author :lyh 107 * @author :lyh
74 * @method :post 108 * @method :post
@@ -243,6 +277,8 @@ class ProductController extends BaseController @@ -243,6 +277,8 @@ class ProductController extends BaseController
243 }else{ 277 }else{
244 $v['status_text'] = ''; 278 $v['status_text'] = '';
245 } 279 }
  280 + //ToDo::处理图片及文件
  281 + $v = $this->getHandleFileImage($v);
246 $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL); 282 $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);
247 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id'] ?? 0); 283 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id'] ?? 0);
248 $v['url'] = $this->user['domain'].$v['route']; 284 $v['url'] = $this->user['domain'].$v['route'];
@@ -251,6 +287,7 @@ class ProductController extends BaseController @@ -251,6 +287,7 @@ class ProductController extends BaseController
251 return $v; 287 return $v;
252 } 288 }
253 289
  290 +
254 /** 291 /**
255 * @remark :获取扩展字段详情 292 * @remark :获取扩展字段详情
256 * @name :getExtendInfo 293 * @name :getExtendInfo
@@ -293,7 +330,7 @@ class ProductController extends BaseController @@ -293,7 +330,7 @@ class ProductController extends BaseController
293 $arr = json_decode($info['values']); 330 $arr = json_decode($info['values']);
294 foreach ($arr as $k1=>$v1){ 331 foreach ($arr as $k1=>$v1){
295 $v1 = (array)$v1; 332 $v1 = (array)$v1;
296 - $v1['url'] = getImageUrl($v1['url']); 333 + $v1['url'] = getImageUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
297 $arr[$k1] = $v1; 334 $arr[$k1] = $v1;
298 } 335 }
299 $v['values'] = $arr; 336 $v['values'] = $arr;
@@ -302,9 +339,9 @@ class ProductController extends BaseController @@ -302,9 +339,9 @@ class ProductController extends BaseController
302 foreach ($arr1 as $k1=>$v1){ 339 foreach ($arr1 as $k1=>$v1){
303 $v1 = (array)$v1; 340 $v1 = (array)$v1;
304 if(isset($v1['url'])){ 341 if(isset($v1['url'])){
305 - $v1['url'] = getFileUrl($v1['url']); 342 + $v1['url'] = getFileUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
306 }else{ 343 }else{
307 - $v1 = getFileUrl($v1); 344 + $v1 = getFileUrl($v1,$this->user['project_location'],$this->user['storage_type']);
308 } 345 }
309 $arr1[$k1] = $v1; 346 $arr1[$k1] = $v1;
310 } 347 }
@@ -102,51 +102,9 @@ class Product extends Base @@ -102,51 +102,9 @@ class Product extends Base
102 3=>'热销产品' 102 3=>'热销产品'
103 ]; 103 ];
104 104
105 -  
106 - /**  
107 - * 产品列表  
108 - * @param $map  
109 - * @param $page  
110 - * @param $row  
111 - * @param string $order  
112 - * @param string[] $fields  
113 - * @param string $sort  
114 - * @return array  
115 - * @author zbj  
116 - * @date 2023/10/17  
117 - */  
118 - public function product_lists($map, $page, $row, $order = 'id', $fields = ['*'], $sort = 'desc'): array  
119 - {  
120 - $category_id = $map['category_id'] ?? 0;  
121 - $query = $this->where(function ($query) use ($category_id) {  
122 - if ($category_id) {  
123 - $category_ids = Category::getChildIdsArr($category_id);  
124 - $query->whereIn('id', function ($subQuery) use ($category_ids) {  
125 - $subQuery->select('product_id')  
126 - ->from('gl_product_category_related')  
127 - ->whereIn('cate_id', $category_ids)  
128 - ->groupBy('product_id');  
129 - });  
130 - }  
131 - });  
132 - unset($map['category_id']);  
133 - $query = $this->formatQuery($map, $query);  
134 - $query = $this->sortOrder($query,$order,$sort);  
135 - $lists = $query->select($fields)->paginate($row, ['*'], 'page', $page);  
136 - if (empty($lists)) {  
137 - return [];  
138 - }  
139 - $lists = $lists->toArray();  
140 - return $lists;  
141 - }  
142 -  
143 -  
144 public function getThumbAttribute($value){ 105 public function getThumbAttribute($value){
145 if(!empty($value)){ 106 if(!empty($value)){
146 $value = json_decode($value,true); 107 $value = json_decode($value,true);
147 - if(!empty($value['url'])){  
148 - $value['url'] = getImageUrl($value['url']);  
149 - }  
150 } 108 }
151 return $value; 109 return $value;
152 } 110 }
@@ -155,12 +113,6 @@ class Product extends Base @@ -155,12 +113,6 @@ class Product extends Base
155 public function getGalleryAttribute($value){ 113 public function getGalleryAttribute($value){
156 if(!empty($value)){ 114 if(!empty($value)){
157 $value = Arr::s2a($value); 115 $value = Arr::s2a($value);
158 - foreach ($value as $k => $v){  
159 - if(!empty($v['url'])){  
160 - $v['url'] = getImageUrl($v['url']);  
161 - }  
162 - $value[$k] = $v;  
163 - }  
164 } 116 }
165 return $value; 117 return $value;
166 } 118 }
@@ -175,9 +127,6 @@ class Product extends Base @@ -175,9 +127,6 @@ class Product extends Base
175 public function getFilesAttribute($value){ 127 public function getFilesAttribute($value){
176 if(!empty($value)){ 128 if(!empty($value)){
177 $value = Arr::s2a($value); 129 $value = Arr::s2a($value);
178 - if(!empty($value['url'])){  
179 - $value['url'] = getImageUrl($value['url']);  
180 - }  
181 } 130 }
182 return $value; 131 return $value;
183 } 132 }
@@ -192,10 +141,6 @@ class Product extends Base @@ -192,10 +141,6 @@ class Product extends Base
192 public function getVideoAttribute($value){ 141 public function getVideoAttribute($value){
193 if(!empty($value)){ 142 if(!empty($value)){
194 $value = Arr::s2a($value); 143 $value = Arr::s2a($value);
195 - $value = Arr::s2a($value);  
196 - if(!empty($value['url'])){  
197 - $value['url'] = getImageUrl($value['url']);  
198 - }  
199 } 144 }
200 return $value; 145 return $value;
201 } 146 }
@@ -210,10 +155,6 @@ class Product extends Base @@ -210,10 +155,6 @@ class Product extends Base
210 public function getIconAttribute($value){ 155 public function getIconAttribute($value){
211 if(!empty($value)){ 156 if(!empty($value)){
212 $value = Arr::s2a($value); 157 $value = Arr::s2a($value);
213 - foreach ($value as $k => $v){  
214 - $v = getImageUrl($v);  
215 - $value[$k] = $v;  
216 - }  
217 } 158 }
218 return $value; 159 return $value;
219 } 160 }