Просмотр исходного кода

新增接口:获取通栏组件及组件预览图;修改接口:新增皮肤;修改皮肤;(关键词去首尾空格)

FengR 2 месяцев назад
Родитель
Сommit
28b36e1507
2 измененных файлов с 202 добавлено и 2 удалено
  1. 200 2
      app/JsonRpc/PublicRpcService.php
  2. 2 0
      app/JsonRpc/PublicRpcServiceInterface.php

+ 200 - 2
app/JsonRpc/PublicRpcService.php

@@ -891,6 +891,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         if ($template) {
             return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
         }
+        $data['template_keyword'] = array_map('trim', $data['template_keyword']);
         $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
         $page_type = json_decode($data['page_type'], true);
         $data['page_type'] = json_encode(array_values(array_unique($page_type)));
@@ -957,6 +958,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         if ($template) {
             return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
         }
+        $data['template_keyword'] = array_map('trim', $data['template_keyword']);
         $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
         $page_type = json_decode($data['page_type'], true);
         $data['page_type'] = json_encode(array_values(array_unique($page_type)));
@@ -999,7 +1001,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         if (isset($data['template_name']) && !empty($data['template_name'])) {
             $where[] = ['template_name', 'like', '%' . $data['template_name'] . '%'];
         }
-        $result = Template::where($where)->get()->all();
+        $result = Template::where($where)->select('id','template_id','template_name','template_keyword','page_type','template_class_id')->get()->all();
         if (empty($result)) {
             return Result::error("暂无皮肤", 0);
         }
@@ -3931,5 +3933,201 @@ class PublicRpcService implements PublicRpcServiceInterface
         // ];
     //     return $component_img;
     // }
-    
+    /**
+     * 自助建站-获取所有通栏、组件、组件样式
+     */
+    public function getAllSectorComponentStyle(array $data): array
+    {
+        $sector_component_style = Sector::where('sector.template_id',$data['template_id'])
+            ->leftJoin('sector_component','sector.id','sector_component.sectorid')
+            ->leftJoin('component', 'component.component_type', 'sector_component.component_id')
+            ->leftJoin('component_img', 'component_img.component_id', 'component.component_type')
+            // ->leftJoin('sector', 'sector.id', 'sector_component.sectorid')
+            ->where('component_img.template_id', '=', $data['template_id'])
+            ->select(
+                'sector.sector_id',
+                'sector.sector_keyword',
+                'sector.component_num',
+                'sector.sector_width',
+                'sector.sector_height',
+                'sector.pic_height',
+                'component.component_type',
+                'component.component_keyword',
+                'component.component_data',
+                'component.component_column',
+                'component.ad',
+                'component.type_id',
+                // 'component.component_code',
+                'component_img.img_name',
+                'component_img.img_id',
+                'component_img.img_url',
+                'sector_component.sort_id',
+                'sector_component.sectorid',
+                // 'sector.sector_type',
+            )
+            ->orderBy('sector_component.sort_id')
+            ->orderBy('component.component_type')
+            ->get()->all();
+        $groupedResults = [];
+        $sort_ids = [];
+        $sector_ids = [];
+        $component_list = [];
+        $component_ids = [];
+        $img_ids = [];
+        // return Result::success($sector_component_style);
+       foreach ($sector_component_style as $key => $item) {
+            $sectorId = $item->sectorid;
+            $sortId = $item->sort_id;
+            $sector_type = $item->sector_type;
+            $component_num = $item->component_num;
+            $componentId = $item->component_type;
+            $component_data = $item->component_data;
+            $component_column = $item->component_column;
+            $component_type = $item->type_id;
+            $component_ad = $item->ad;
+            $imgId = $item->img_id;
+            $sector_height = $item->sector_height;
+            $pic_height = $item->pic_height;
+            $sectorName = $item->sector_id;
+            if (!isset($groupedResults[$sectorId])) {
+                $groupedResults[$sectorId] = [];
+            }
+            $componentData = !empty($component_data) && is_string($component_data) ? json_decode($component_data, true) : [];
+            $component_listtype = !empty($component_column) && is_string($component_column) ? json_decode($component_column, true) : [];
+            $component_code = !empty($component_code) && is_string($component_code) ? json_decode($component_code, true) : [];
+            $component_ad = !empty($component_ad) && is_string($component_ad) ? json_decode($component_ad, true) : [];
+            // 确保 $componentData['componentData'] 是数组,避免 array_push 传入 null
+            if (!isset($componentData['componentData']) || !is_array($componentData['componentData'])) {
+                $componentData['componentData'] = [];
+            }
+            $componentData['componentData'] += $component_listtype;
+            $component_code = $componentData;
+            $component_list[$key] = $component_code;
+            // $component_list[$key]['listType'] = $component_listtype;
+            // }
+            if(!in_array($sectorId,$sector_ids)){
+                $groupedResults[$sectorId] = [
+                    'sector_id' => $sectorName,
+                    'sector_keyword' => $item->sector_keyword,
+                    'component_num' => $component_num,
+                    'sector_width' => $item->sector_width,
+                    'sector_height' => $sector_height,
+                    'pic_height' => $pic_height,
+                ];
+            }
+            if(in_array($component_type,[19,20,21,22,23,24])){
+                $sortId = $sortId*2-1;
+                $sort_id = intval($sortId-1);
+            }else{
+                $sort_id = intval($sortId - 1);
+            }
+            if (!isset($com_key) || !in_array($sectorId, $sector_ids) || !isset($sort_ids[$sectorId]) || !in_array($sortId, $sort_ids[$sectorId])) {
+                $com_key = 0;
+                // if(!in_array($componentId,$component_ids)){
+                //     $img_key = 0;
+                // }
+                $img_key = 0;
+            } else if (in_array($sortId, $sort_ids[$sectorId]) && in_array($sectorId, $sector_ids) && !in_array($componentId, $component_ids)) {
+                $com_key++;
+            }
+            if (in_array($componentId, $component_ids) && !in_array($imgId, $img_ids[$componentId])) {
+                $img_key++;
+            } else {
+                $img_key = 0;
+            }
+            if (!in_array($componentId, $component_ids)) {
+                $groupedResults[$sectorId]['component_list'][$sort_id][$com_key] = [
+                    'component_type' => $item->component_type,
+                    'type_id' => $component_type,
+                    'sort' => $sortId,
+                    // 'width' => $item->component_width,
+                    // 'height' => $item->component_height,
+                ];
+                if(in_array($component_type,[19,20,21,22,23,24])){
+                    $groupedResults[$sectorId]['component_list'][$sort_id+1][$com_key] = [
+                        'component_type' => $item->component_type,
+                        'type_id' => $component_type,
+                        'sort' => $sortId+1,
+                        // 'width' => $item->component_width,
+                        // 'height' => $item->component_height,
+                    ];
+                }
+            }
+            if($component_type == 11){
+                 $groupedResults[$sectorId]['component_list'][$sort_id][$com_key]['component_style_data'][$img_key] = [
+                    'img_name' => $item->img_name,
+                    'img_id' => $imgId,
+                    'img_url' => $item->img_url,
+                    // 'component_type' => $componentId,
+                ];
+            }else{
+                $groupedResults[$sectorId]['component_list'][$sort_id][$com_key]['component_style_data'][$img_key] = [
+                    'img_name' => $item->img_name,
+                    'img_id' => $imgId,
+                    // 'img_url' => $item->img_url,
+                    // 'component_type' => $componentId,
+                ];
+            }
+            
+            if(in_array($component_type,[19,20,21,22,23,24])){
+                $groupedResults[$sectorId]['component_list'][$sort_id+1][$com_key]['component_style_data'][$img_key] = [
+                    'img_name' => $item->img_name,
+                    'img_id' => $imgId,
+                    // 'img_url' => $item->img_url,
+                    // 'component_type' => $componentId,
+                ];
+            }
+            
+             $com_key = 0;
+            // }
+            // // 组件分类:1.头条资讯;2.轮播图资讯;3.推荐图;4.最新资讯;5.推荐资讯;6.热点资讯;7.栏目资讯;8.列表类;9.详情类;
+            // // 10.二级导航类;11.广告类;12.静态类;13.单页导航类;14.资讯广告混合类;15.滚动图文类;16.搜索框类;17.单页列表类;18.单页详情类;
+            // 19:选项卡-推荐图类;20:选项卡-最新资讯类;21:选项卡-推荐资讯类;22:选项卡-热点资讯类;23:选项卡-栏目资讯类;24:选项卡-栏目广告混合类;
+            if (is_scalar($sectorId) && is_scalar($sort_id)) {
+                if (!in_array($component_type, [10, 12, 16])) {
+                    if ($component_type == 11 || $component_type == 14 || $component_type == 24) {
+                        $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id][$com_key]['ad'] = $component_ad;
+                        $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id][$com_key]['ad']['website_id'] = $data['website_id'];
+                    }
+                    if ($component_type != 11) {
+                        $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id][$com_key]['componentData'] = $component_code['componentData'];
+                        if(in_array($component_type,[19,20,21,22,23,24])){
+                            $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id+1][$com_key]['componentData'] = $component_code['componentData'];
+                        }
+                    }
+                } else {
+                    $groupedResults[(int)$sectorId]['component_list'][(int)$sort_id][$com_key]['componentData'] = [];
+                    // if(in_array($component_type,[19,20,21,22,23,24])){
+                    //     $groupedResults[(int)$sectorId][(int)$sort_id+1][$com_key]['componentData'] = [];   
+                    // }
+                }
+            } else {
+                // 处理非法键类型的情况,可根据实际需求修改错误处理逻辑
+                trigger_error('Illegal offset type for $sectorId or $sort_id', E_USER_WARNING);
+            }
+            // // 判断此组件是否存在数组中的依据(若是有重复的组件,一定是组件样式重复)
+            $component_ids[$key] = $componentId;
+            if (!isset($sort_ids[$sectorId])) {
+                $sort_ids[$sectorId] = [];
+            }
+            if (!in_array($sortId, $sort_ids[$sectorId])) {
+                $sort_ids[$sectorId][] = $sortId;
+            }
+            if (!isset($img_ids[$componentId])) {
+                $img_ids[$componentId] = [];
+            }
+            if (!in_array($imgId, $img_ids[$componentId])) {
+                $img_ids[$componentId][] = $imgId;
+            }
+            $sector_ids[$key] = $sectorId;
+            $sort_ids[$sectorId][$sort_id] = $sort_id;
+            // $img_ids[$componentId] = $imgId;
+        }
+        // return Result::success($groupedResults);
+        if (empty($groupedResults)) {
+            return Result::error('通栏组件样式不存在!');
+        }
+        $groupedResults = array_values($groupedResults);
+        return Result::success($groupedResults);
+    }
 }

+ 2 - 0
app/JsonRpc/PublicRpcServiceInterface.php

@@ -213,6 +213,8 @@ interface PublicRpcServiceInterface
     public function getSectorType(array $data): array;
     // 自助建站-随机模板
     public function randomWebTemplate(array $data): array;
+    //自助建站-获取某皮肤下的通栏、组件、组件预览图
+    public function getAllSectorComponentStyle(array $data): array;