Kaynağa Gözat

修改验证关键词、添加版式、修改版式、版式画布生成的接口;随机模板-获取规则、随机模板-随即通栏、随机模板-随机组件

FengR 2 ay önce
ebeveyn
işleme
0aa9e0d031
1 değiştirilmiş dosya ile 267 ekleme ve 370 silme
  1. 267 370
      app/JsonRpc/PublicRpcService.php

+ 267 - 370
app/JsonRpc/PublicRpcService.php

@@ -2467,9 +2467,13 @@ class PublicRpcService implements PublicRpcServiceInterface
                     return Result::error('组件版式编号已存在!');
                 }
                 $data['component_num'] = 0;
-                if(in_array($data['type'],[23,24])){
-                    $data['cat_num'] = 2;
-                }
+            }
+            if(in_array($data['type'],[23,24])){
+                $data['cat_num'] = 2;
+            }else if(in_array($data['type'],[7,14])){
+                $data['cat_num'] = 1;
+            }else{
+                $data['cat_num'] = 0;
             }
         }
         Db::beginTransaction();
@@ -2540,12 +2544,15 @@ class PublicRpcService implements PublicRpcServiceInterface
                 
             }
         }
-        
-        return ['map_json'=>$map ?? [],
-        'component'=>count($component),
-        'row_num'=>$row_num ?? 0,
-        'cat_num'=>$cat_num ?? 0,
-        'component_info'=>$component,];
+        $map_data = [
+            'map_json'=>$map ?? [],
+            'component'=>count($component),
+            'row_num'=>$row_num ?? 0,
+            'cat_num'=>$cat_num ?? 0,
+            'component_info'=>$component,
+            ];
+
+        return $map_data;
     }
     /**
      * 通栏版式管理-修改通栏版式
@@ -2609,6 +2616,13 @@ class PublicRpcService implements PublicRpcServiceInterface
             if (!empty($component)) {
                 return Result::error('组件版式编号或位置已存在!');
             }
+            if(in_array($data['type'],[23,24])){
+                $data['cat_num'] = 2;
+            }else if(in_array($data['type'],[7,14])){
+                $data['cat_num'] = 1;
+            }else{
+                $data['cat_num'] = 0;
+            }
             $result['component'] = SectorPlace::where('id', $data['id'])->update($data);
             $map = $this->changeSectorPlaceJson($data['sector_type']) ?? [];
             $data['cat_num'] = $map['cat_num'] ?? 0;
@@ -3112,25 +3126,25 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(isset($data['page']) && !empty($data['page'])){
             switch ($data['page']) {
                 case 1:
-                    $index_rule = json_decode($rule['index_rule']);
+                    $rule = json_decode($rule['index_rule']);
                     break;
                 case 2:
-                    $index_rule = json_decode($rule['class_rule']);
+                    $rule = json_decode($rule['class_rule']);
                     break;
                 case 3:
-                    $index_rule = json_decode($rule['list_rule']);
+                    $rule = json_decode($rule['list_rule']);
                     break;
                 case 4:
-                    $index_rule = json_decode($rule['info_rule']);
+                    $rule = json_decode($rule['info_rule']);
                     break;
                 case 5:
-                    $index_rule = json_decode($rule['search_rule']);
+                    $rule = json_decode($rule['search_rule']);
                     break;
                 case 6:
-                    $index_rule = json_decode($rule['footerlist_rule']);
+                    $rule = json_decode($rule['footerlist_rule']);
                     break;
                 case 7:
-                    $index_rule = json_decode($rule['footerinfo_rule']);
+                    $rule = json_decode($rule['footerinfo_rule']);
                     break;
                 default:
                     break;
@@ -3141,10 +3155,11 @@ class PublicRpcService implements PublicRpcServiceInterface
         if ($cate_num < 5) {
             return Result::error('此网站栏目过少,无法进行随机模板!');
         }
+        $cate_num = min($cate_num, 24);
         // return Result::success($data);
         // $tempalte['index'] = $this->randomWeb($data,$index_rule);
         if(isset($data['page']) && !empty($data['page'])){
-            $tempalte['index'] = $this->randomPage($data,$cate_num,$index_rule);
+            $tempalte['index'] = $this->randomPage($data,$cate_num,$rule);
         }else{ 
             $data['page'] = 1;
             $ruleIndex = json_decode($rule->index_rule);
@@ -3214,7 +3229,6 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $carry[$sectors[$idx]['sector_type']][] = $idx;
                 return $carry;
             },
-            []
         );
 
         // 对 all_sector_type 去重后,每个类型随机挑一个 sector 索引
@@ -3261,10 +3275,13 @@ class PublicRpcService implements PublicRpcServiceInterface
             return $must_sector;
         }
         // 必需通栏中的栏目数量
-        $must_cat_num = array_sum(array_column($must_sector,'cat_num'));
-        if($must_cat_num>$cate_num){
-            return '栏目数量过少,无法完成必需通栏随机!';
+        if($page == 1){
+            $must_cat_num = array_sum(array_column($must_sector,'cat_num'));
+            if($must_cat_num>$cate_num){
+                return '栏目数量过少,无法完成必需通栏随机!';
+            }
         }
+       
         // var_dump(['must_cat_num'=>$must_cat_num,'cate_num'=>$cate_num]);
         // 2.非必须通栏的随机处理
         $not_must_type = array_unique(array_diff($unique_sector_type, $must_type));
@@ -3305,10 +3322,12 @@ class PublicRpcService implements PublicRpcServiceInterface
             $random_sector = array_values(array_intersect_key($sectors, array_flip($randomKeys)));
             $rand_count = count($random_sector);
         }
-        $random_cat_num = array_sum(array_column($random_sector,'cat_num'));
-        $random_cat_num += $must_cat_num;
-        if($random_cat_num>$cate_num){
-            return '栏目数量过少,无法完成随机!';
+        if($page == 1){
+            $random_cat_num = array_sum(array_column($random_sector,'cat_num'));
+            $random_cat_num += $must_cat_num;
+            if($random_cat_num>$cate_num){
+                return '栏目数量过少,无法完成随机!';
+            }
         }
         // var_dump("randomKeys",$randomKeys);
         // var_dump("random_sector",$random_sector);
@@ -3316,6 +3335,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         // var_dump("random_cat_num", $random_cat_num);
         // return $random_sector;
         // var_dump("must_sector",$must_sector);
+        // var_dump("sector_num",$sector_num);
         // var_dump("must_count",$must_count);
         // return ['random_sector'=>$random_sector,'random_cat_num'=>$random_cat_num,'cate_num'=>$cate_num];
 
@@ -3344,127 +3364,147 @@ class PublicRpcService implements PublicRpcServiceInterface
             $repeat_type = array_intersect($rule_repaet_type, $unique_sector_type);
             // 获取可以随机重复的通栏
             $repaet_key = 0;
-            $num = 0;
             $type = [];
             // return $rule_repaet_type;
             // 防止无限循环,设置最大迭代次数
             $max_iterations = 10;
             $iteration_count = 0;
             // 剩余的栏目数量
-            $sector_cate_comnum = $cate_num - $random_cat_num;
-            if($sector_cate_comnum < 0){
-                return '栏目数量过少,无法完成随机!';
+            if($page == 1){
+                $sector_cate_comnum = $cate_num - $random_cat_num;
+                if($sector_cate_comnum < 0){
+                    return '栏目数量过少,无法完成随机!';
+                }
             }
-            // var_dump("sector_comnum", $sector_cate_comnum);
-            $com_num = 0;
+           
             // return [
-            //     'repeat_type'=>$repeat_type,
+            //     // 'repeat_type'=>$repeat_type,
+            //     // 'repeat_num'=>$repeat_num,
+            //     'must_count'=>$must_count,
+            //     'rand_count'=>$rand_count,
             //     'repeat_num'=>$repeat_num,
+            //     'sector_num'=>$sector_num,
+            //     'cate_num'=>$cate_num,
             //     'sector_comnum'=>$sector_cate_comnum,
-            //     'rule_repeat'=>$rule_repeat,
-            //     'unique_sector_type'=>$unique_sector_type,
-            //     'all_sector_type'=>$all_sector_type,
-            // ];
-            $repaet_cat_num = 0;
-            $sector_key = 0;
-            $repeat_onenum = [];
-            $repeat_type_sectornum = array_count_values( $all_sector_type);
-            $repeat_type_sectorkey = array_keys($repeat_type_sectornum);
+            //     'random_cat_num'=>$random_cat_num,
+            //     // 'rule_repeat'=>$rule_repeat,
+            //     // 'unique_sector_type'=>$unique_sector_type,
+            //     // 'all_sector_type'=>$all_sector_type,
+            //     // 'sector_zuhe1' =>$sector_zuhe1
+            // ];          
+            
+            // -----新添加的代码-----
+            $re_sector = array_intersect($all_sector_type,$repeat_type);
+            $re_sector_key = array_keys($re_sector);
+            $every_repeattype_num = array_count_values($re_sector);
+            // $re_sector_key = array_keys($re_sector,1);
+            $repaet_key = 0;
+            $re_type_keys = [];
+
+
+            $one_sector_key = array_search(1,$re_sector);
+            $two_sector_key = array_search(2,$re_sector);
+            $three_sector_key = array_search(3,$re_sector);
+            $all_cat_num = array_column($sectors,'cat_num');
+
+            // $rule_repeat['1'] = 1;
+            // return $rule_repeat;
+            // $three_sector_key = array_search(3,$re_sector);
+            // $min_one_sector = max(array_column('cat_num',$all_sector));
             // 随机重复通栏-----
+            // $rule_repeat['1'] = 1;
+                   //             // 找出 all_sector_type 中值为 1 的键
             while ($repaet_key <= $repeat_num-1 && $iteration_count < $max_iterations) {
-                if ($sector_cate_comnum - $repaet_cat_num > 0) {
-                    foreach ($repeat_type as $key => $value) {
-                        if(!isset($repeat_onenum[$value])){
-                            $repeat_onenum[$value] = 0;
-                        }
-                        $sector_key = $repaet_key;
-                        // 确保 $value 是数组且不为空,再使用 $value[0] 或 array_rand
-                        if(in_array($value,$all_sector_type) && in_array($value,$repeat_type_sectorkey) ){
-                            // $sector_key = $key+$num;
-                            // 可重复通栏,每一个可重复种类的通栏随机取1
-                            if($repeat_type_sectornum[$value] > 1){
-                                // 找出 all_sector_type 中值为 1 的键
-                                $keys_equal_one = array_keys($all_sector_type,$value);
-                                // 随机取一个键
-                                $random_key = $keys_equal_one[array_rand($keys_equal_one)];
-                                $repeat_sector_key[$sector_key] = $random_key;
-                            }else{
-                                $repeat_sector_key[$sector_key] = array_keys($all_sector_type,$value)[0];
-                            }
-                            $sector_cat_key = $repeat_sector_key[$sector_key];
-                            $repaet_cat_num += $sectors[$sector_cat_key]['cat_num'];
-                        //    var_dump(['--------------------' => $sector_cate_comnum - $repaet_cat_num <= 0,
-                        //     '************************' => $repaet_cat_num]);
-                            if($sector_cate_comnum - $repaet_cat_num <= 0){
-                                unset($repeat_sector_key[$sector_key]);
-                                // $repaet_key--;
-                                // $sector_key = $sector_key-$repaet_key;
-                                $repaet_cat_num = $repaet_cat_num-$sectors[$sector_cat_key]['cat_num'];
-                                // var_dump(['33333333333333333' => $sector_key]);
-                                continue;
-                            }else{
-                                $repeat_onenum[$value]++;
-                                
-                                $repaet_key++;
-                            }
-                            //  var_dump(['22222222222222222' => $sector_key]);
-                           
+                // 剩余通栏数量>0   若不是首页则继续;若是首页则需要判断剩余栏目数量是否>3
+                if ($repeat_num-$repaet_key > 0 && ($page != 1 || (isset($sector_cate_comnum) && $sector_cate_comnum > 3))) {
+                    foreach($repeat_type as $key => $value){
+                    $type_key = strval($value);
+                    if(!isset($re_type_keys[$value])){
+                        $re_type_keys[$value] = [];
+                    }
+                    // 剩余的通栏数量>0  并且 剩余的此类通栏数量>0
+                    if($repeat_num-$repaet_key > 0 && $rule_repeat[$type_key]- count($re_type_keys[$value]) > 0 && ($page != 1 || (isset($sector_cate_comnum) && $sector_cate_comnum > 3))){
+                        // var_dump("0000",array_keys($re_sector,$value));
+                        $one_sector_type = array_keys($re_sector,$value);
+                        // 若是此类通栏的数量>1  则随机取一个对应的键值
+                        if(count($one_sector_type) > 1){
+                            // 从 $one_sector_type 数组中随机取一个键名,并取其对应值
+                            $cat_key = $one_sector_type[array_rand($one_sector_type)];
                         }else{
-                            break;
+                            $cat_key = $one_sector_type[0];
                         }
-                        // if (is_array($value) && count($value) > 0) {
-                            // if (in_array($value, $repeat_type_sectorkey) && in_array($value, $repeat_type_sectorkey) && 
-                            // isset($rule_repeat[$value]) && $repeat_onenum[$value] <= $rule_repeat[$value]) {
-                            //     $repeat_onenum[$value] = $key;
-                            // }
-                            
-                        // }
+                        $repeat_sector_key[$repaet_key] = $cat_key;
+                        $repaet_key++;
+                        // var_dump("1115----------cat_key",$cat_key);
+                        if($page == 1){
+                            $sector_cate_comnum -= $all_cat_num[$cat_key];
+                        }
+                        if(!in_array($repaet_key,$re_type_keys[$value])){
+                            $re_type_keys[$value][] = $repaet_key;
+                            // var_dump("1117----------re_type_keys",$re_type_keys);
+                        }                           
+                    }else{
+                        break;
                     }
-                } else {
-                    break;
                 }
-                $num++;
-                $iteration_count++;
+            } else {
+                break;
             }
-            // $value = 1;
-            // return [
-            //     'repeat_num'=>$repeat_num,
-            //     'sector_cate_comnum'=>$sector_cate_comnum,
-            //     'repaet_cat_num'=>$repaet_cat_num,
-            //     'repeat_onenum'=>$repeat_onenum,
-            //     'repeat_sector_key'=>$repeat_sector_key,
-            //     // 'sector_cate_comnum'=>$sector_cate_comnum,
-            //     'sector_cat_key'=>$sector_cat_key,
-            //     // 'all_sector_type'=>$all_sector_type,
-            //     // 'sectors'=>$sectors,
-            // ];
-            // var_dump("num", $num);
-            // var_dump("repeat_sector_key", $repeat_sector_key);
-            // 随机的重复通栏键值转换成真正的通栏
-            $repeat_sector = [];
-            if (isset($repeat_sector_key) && !empty($repeat_sector_key) && is_array($repeat_sector_key)) {
+            $iteration_count++;
+        }
+        // var_dump("num", $num);
+        // var_dump("repeat_sector_key", $repeat_sector_key);
+        // 若是首页的通栏没有到10个,栏目还有剩余1~3个,则继续随机(已知当剩余栏目为4还会随机)
+        if($page == 1 && count($repeat_sector_key) < $repeat_num && $sector_cate_comnum > 0){
+            if($sector_cate_comnum == 1){
+                array_push($repeat_sector_key,$one_sector_key);
+            }else if($sector_cate_comnum == 2){
+                array_push($repeat_sector_key,$two_sector_key);
+            }else{
+                array_push($repeat_sector_key,$three_sector_key);
+            }
+        }
+        // 随机的重复通栏键值转换成真正的通栏
+        $repeat_sector = [];
+        if (isset($repeat_sector_key) && !empty($repeat_sector_key) && is_array($repeat_sector_key)) {
 
-                foreach ($repeat_sector_key as $key => $value) {
-                    if (isset($sectors[$value])) {
-                        $repeat_sector[$key] = $sectors[$value];
-                    }
+            foreach ($repeat_sector_key as $key => $value) {
+                if (isset($sectors[$value])) {
+                    $repeat_sector[$key] = $sectors[$value];
+                }else{
+                    continue;
                 }
             }
-            $repeat_count = count($repeat_sector);
-            var_dump("repeat_count", $repeat_count);
-            // return [
-            //     'sector_comnum'=>$sector_comnum,
-            //     'com_num'=>$com_num,
-            //     'repeat_count'=>$repeat_count,
-            //     'repeat_sector'=>$repeat_sector,
-            // ];
-            // // var_dump("repeat_sector", $repeat_sector);
-            //  return $repeat_sector;
-
-            $sector = array_merge($repeat_sector,$sector_zuhe1);
-        }else{
-            $sector = $sector_zuhe1;
         }
+        $repeat_count = count($repeat_sector);
+        var_dump("repeat_count", $repeat_count);
+        // return [
+        //     'not_repeat_num'=>$rand_count + $must_count,
+        //     // 'repeat_count'=>$repeat_count,
+        //     'repeat_num'=>$repeat_num,
+        //     'repeat_sector'=>$repeat_sector,
+        //     'repeat_type'=>$repeat_type,
+        //     '$repaet_key'=>$repaet_key,
+        //     'all_sector_type'=>$all_sector_type,
+        //     're_sector'=>$re_sector,
+        //     're_sector_key'=>$re_sector_key,
+        //     'resdfddd'=>$every_repeattype_num,
+        //     'repeat_sector_key'=>$repeat_sector_key,
+        //     // 'ddd'=>$ddd,
+        // //     'sector_num'=>$sector_num,
+        // //     'sector_zuhe1'=>count($sector_zuhe1),
+        // //     // 'repeat_sector'=>$repeat_sector,                                                
+        //     // 'cate_num'=>$cate_num,
+        //     // 'random_cat_num'=>$random_cat_num,
+        //     'rule_repeat' => $rule_repeat
+        // ];
+        // // var_dump("repeat_sector", $repeat_sector);
+        //  return $repeat_sector;
+
+        $sector = array_merge($repeat_sector,$sector_zuhe1);
+    }else{
+        $sector = $sector_zuhe1;
+    }
         // var_dump("sector_ids",$sector_ids);
         //  
         // 各类型通栏最大数量数量限制 = 规则最大数量-已经存在的通栏数量(目前的通栏不会有重复的,所以只是-1)
@@ -3536,7 +3576,8 @@ class PublicRpcService implements PublicRpcServiceInterface
         $component[] = $this->randomComponent($sector_id,$data,$sector);
         var_dump("sector_id",$sector_id);
         return [
-            // 'sector_id'=>$sector_id,
+            'sector_id'=>$sector_id,
+            'sector_count'=>count($sector),
             // 'sectors'=>$sectors,
             // 'sector_comnum'=>$sector_comnum,
             // 'com_num'=>$com_num,
@@ -3546,235 +3587,81 @@ class PublicRpcService implements PublicRpcServiceInterface
             // 'sector'=>$sector,
         ];
     }
-    public function randomComponent($sector_id,$data,$sector){
+     public function randomComponent($sector_id, $data, $sector)
+    {
         $rawResults = SectorComponent::whereIn('sector_component.sectorid', $sector_id)
             ->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'])
+            ->leftJoin('component_img', function ($join) use ($data) {
+                $join->on('component_img.component_id', '=', 'component.component_type')
+                     ->where('component_img.template_id', '=', $data['template_id'] ?? 0);
+            })
             ->select(
                 'component.*',
                 'component_img.img_name',
                 'component_img.img_id',
                 'component_img.img_url',
                 'sector_component.sort_id',
-                'sector_component.sectorid',
-                // 'sector.sector_type',
+                'sector_component.sectorid'
             )
             ->orderBy('sector_component.sort_id')
             ->orderBy('component.component_type')
-            ->get();
-        // 按sectorid和sort_id分组数据
-        $groupedResults = [];
-        $sort_ids = [];
-        $sector_ids = [];
-        $component_list = [];
-        $component_ids = [];
-        $img_ids = [];
-        $sort_key = 0;
+            ->get()->all();
         // return $rawResults;
-        // $groupedResults重构数组,将相同位置的组件合并,相同组件的样式合并(已经包括所有选择的组件及组件样式)
-        // $sort_component = array_column($rawResults,'sort_id');
-        foreach ($rawResults as $key => $item) {
-            $sectorId = $item->sectorid;
-            $sortId = $item->sort_id;
-            $sector_type = $item->sector_type;
-            $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;
-            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'] = [];
+        $img_key = 0;
+        $com_key = 0;
+        foreach( $rawResults as $key => $value){
+            $component_id = $value['component_type'];
+            $sort_id = $value['sort_id']-1;
+            $img_id = intval($value['img_id']);
+            $sector_id = $value['sectorid'];
+            $component_data = json_decode($value['component_data'] ?? '[]',true);
+            $component_column = json_decode($value['component_column'] ?? '[]',true);
+            $component_json['componentData'] = $component_data['componentData'] ?? [];
+            // 组件类型:1:头条;2:轮播图;3:推荐图;4:最新资讯;5:推荐资讯;6:热点资讯;7:栏目资讯类;
+            // 8:列表类;9:详情类;10:二级导航栏类;11:广告类;12:静态类;13:单页导航类;14:资讯广告混合类;
+            // 15:滚动图文类;16:搜索框类;17:单页列表类;18:单页详情类;19-24:选项卡3-7
+            if(!in_array($value['type_id'],[10,11,12,16,])){
+                $component_json['componentData']['listType'] = $component_column['listType'] ?? '';
             }
-            $componentData['componentData'] += $component_listtype;
-            $component_code = $componentData;
-            $component_list[$key] = $component_code;
-            // $component_list[$key]['listType'] = $component_listtype;
-            // }
-            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($groupedResults[$sectorId][$sort_id])) {
-            //     // $groupedResults[$sectorId][$sortId] = [];
-            //     $com_key = 0;
-            //         $groupedResults[$sectorId][$sort_id][$com_key] = [
-            //         'component_type' => $item->component_type,
-            //         'type_id' => $component_type,
-            //         'sort' => $sortId,
-            //         'width' => $item->component_width,
-            //         'height' => $item->component_height,
-            //         'images'  =>   [
-            //                     'img_name' => $item->img_name,
-            //                     'img_id' => $item->img_id,
-            //                     'img_url' => $item->img_url,
-            //                     'component_type' => $component_type,
-            //                 ]
-            //     ];                
-            //     // 检查 $sectorId 和 $sort_id 是否为合法的数组键类型(字符串或整数)
-
-            // }else{
-
-            //     if((isset($component_ids) && in_array($componentId,$component_ids))){
-            //         if(isset($img_arr)){
-            //             $img_arr++;
-            //         }else{
-            //             $img_arr = 0;
-            //             if(isset($com_key)){
-            //         $com_key++;
-            //     }
-            //         }
-            //         // $com_id_key = array_search($componentId,$component_ids);
-            //         $groupedResults[$sectorId][$sort_id][$com_key]['images'][$img_arr] = [
-            //             'img_name' => $item->img_name,
-            //             'img_id' => $item->img_id,
-            //             'img_url' => $item->img_url,
-            //             'component_type' => $component_type,
-            //         ];
-            //     }else{
-            //         $img_arr = 0;
-            //         $com_key = $com_key ?? 0;
-            //         $groupedResults[$sectorId][$sort_id][$com_key] = [
-            //             'component_type' => $item->component_type,
-            //             'type_id' => $component_type,
-            //             'sort' => $sortId,
-            //             'width' => $item->component_width,
-            //             'height' => $item->component_height,
-            //             'images' => 
-            //             [
-            //                 $img_arr =>
-            //                     [
-            //                         'img_name' => $item->img_name,
-            //                         'img_id' => $item->img_id,
-            //                         'img_url' => $item->img_url,
-            //                         'component_type' => $component_type,
-            //                     ]
-            //             ]
-            //         ];
-            //     }
-            // }
-            // $component = $groupedResults[$sectorId][$sort_id];
-            // if(count($component) > 1){
-            //     $com_key = 0;
-            // }
-            // if(!in_array($sectorId,$sector_ids)){
-            //     $sort_key = 0;
-            //     $sector_ids[$sectorId][$sort_key] = $sectorId;
-            // }else{
-            //     $sort_key++;
-            //     $sector_ids[$sectorId][$sort_key] = $sectorId;
-            // }
-            if (!isset($com_key) || !in_array($sectorId, $sector_ids) || !isset($sort_ids[$sectorId]) || !in_array($sortId, $sort_ids[$sectorId])) {
+            if(!isset($component_img[$component_id])){
+                $component_img[$component_id] = [];
                 $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)) {
+            }else{
                 $com_key++;
             }
-            if (in_array($componentId, $component_ids) && !in_array($imgId, $img_ids[$componentId])) {
-                $img_key++;
-            } else {
+            if(!isset($component_img[$component_id][$sort_id])){
+                $component_img[$component_id][$sort_id] = [];
                 $img_key = 0;
+            }else{
+                $img_key++;
             }
-            if (!in_array($componentId, $component_ids)) {
-                $groupedResults[$sectorId][$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][$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(!empty($img_id)){
+                $component_img[$component_id][$sort_id][$img_key] = 
+                    [
+                        'component_id' => $value['component_type'],
+                        'img_id' => $value['img_id'],
+                        'component_imgurl' => $value['img_url'],
                     ];
-                }
             }
-            $groupedResults[$sectorId][$sort_id][$com_key]['images'][$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][$sort_id+1][$com_key]['images'][$img_key] = [
-                    'img_name' => $item->img_name,
-                    'img_id' => $imgId,
-                    'img_url' => $item->img_url,
-                    'component_type' => $componentId,
-                ];
-            }
-            // $groupedResults[$sectorId]['sector_type'] = $sector_type;
-
-            // $component_type[$key] = $groupedResults[$sectorId][$sort_id]['component_type'];
-            // $sort_com = $groupedResults[$sectorId][$sort_id]['component_type'];
-            // if(count($sort_com) == 1){
-            //     $com_key = 0;
+            // else{
+            //     $component_img[$component_id][$sort_id][$img_key] = [];
             // }
-            // // 组件分类:1.头条资讯;2.轮播图资讯;3.推荐图;4.最新资讯;5.推荐资讯;6.热点资讯;7.栏目资讯;8.列表类;9.详情类;
-            // // 10.二级导航类;11.广告类;12.静态类;13.单页导航类;14.资讯广告混合类;15.滚动图文类;16.搜索框类;17.单页列表类;18.单页详情类;
-            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][(int)$sort_id][$com_key]['ad'] = $component_ad;
-                        $groupedResults[(int)$sectorId][(int)$sort_id][$com_key]['ad']['website_id'] = $data['website_id'];
-                    }
-                    if ($component_type != 11) {
-                        $groupedResults[(int)$sectorId][(int)$sort_id][$com_key]['componentData'] = $component_code['componentData'];
-                        if(in_array($component_type,[19,20,21,22,23,24])){
-                            $groupedResults[(int)$sectorId][(int)$sort_id+1][$com_key]['componentData'] = $component_code['componentData'];
-                        }
-                    }
-                } else {
-                    $groupedResults[(int)$sectorId][(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;
+            // $component_img = array_values($component_img[$component_id][$sort_id]);
+            $groupedResults[$sector_id][$sort_id] =
+                [
+                    'component_type' => $component_id,
+                    'sort' => $value['sort_id'],
+                    'type_id' => $value['type_id'],
+                    'componentData' => $component_json['componentData'],
+                    'images' => $component_img[$component_id][$sort_id]
+                ];
+            if(in_array($value['type_id'],[11,14,24])){
+                $groupedResults[$sector_id][$sort_id]['ad'] = json_decode($value['ad'],JSON_UNESCAPED_UNICODE);
             }
-            $sector_ids[$key] = $sectorId;
-            $sort_ids[$sectorId][$sort_id] = $sort_id;
-            // $img_ids[$componentId] = $imgId;
+            // [$img_id-1] = $value['img_id'];
         }
-        // return $sort_ids;
-
-        $result = [];
-        // return  $groupedResults;
+        // return ['groupedResults'=>$groupedResults,
+        //         'component_data'=>$component_data];
         $y_num = 0;
         foreach ($sector as $key => $value) {
             // array_push($value['sort_id'],$key);
@@ -3811,60 +3698,67 @@ class PublicRpcService implements PublicRpcServiceInterface
             if (isset($groupedResults[$sectorid]) && !empty($groupedResults[$sectorid]) && is_array($groupedResults[$sectorid])) {
                 $componet_key = 0;
                 foreach ($groupedResults[$sectorid] as $sortId => $components) {
-                    // 通栏某一位置的随机组件
-                    if (count($components) > 1) {
-                        $componentIds = count($components);
-                        $selectedComponentId = rand(0, $componentIds - 1);
-                    } else {
-                        $selectedComponentId = 0;
-                    }
-                    // var_dump($components[$selectedComponentId]);
-                    // $Component = $components[$selectedComponentId];
-                    $Component['component_type'] = $components[$selectedComponentId]['component_type'] ?? 0;
-                    $Component['sort'] = $components[$selectedComponentId]['sort'] ?? 1;
-                    $Component['type_id'] = $components[$selectedComponentId]['type_id'] ?? 0;
-                    // 通栏某一位置的随机组件样式图
-                    // 检查 $Component['images'] 是否存在且为数组
-                    if (isset($components[$selectedComponentId]['images']) && is_array($components[$selectedComponentId]['images'])) {
-                        $images = count($components[$selectedComponentId]['images']);
+                   var_dump('start-------------------------------------sortId',$sortId);
+            // //     //     // 通栏某一位置的随机组件
+                    // if (count($components) > 1) {
+                    //     $componentIds = count($components);
+                    //     $selectedComponentId = rand(0, $componentIds - 1);
+                    // } else {
+                    //     $selectedComponentId = 0;
+                    // }
+            //         // var_dump($components[$selectedComponentId]);
+                    // $Component = $components;
+                    $Component['component_type'] = $components['component_type'] ?? 0;
+                    $Component['sort'] = $components['sort'] ?? 1;
+                    $Component['type_id'] = $components['type_id'] ?? 0;
+            //         // 通栏某一位置的随机组件样式图
+            //         // 检查 $Component['images'] 是否存在且为数组
+                    if (isset($components['images']) && is_array($components['images'])) {
+                        var_dump('action1-------------------------------------sortId',$sortId);
+                        $images = count($components['images']);
                         $selectedImage = 0;
                         if ($images > 1) {
                             $selectedImage = rand(0, $images - 1);
                         }
-                        if (isset($components[$selectedComponentId]['images'][$selectedImage])) {
-                            $Component['component_style'] = is_object($components[$selectedComponentId]['images'][$selectedImage]) ? $components[$selectedComponentId]['images'][$selectedImage]->img_id : $components[$selectedComponentId]['images'][$selectedImage]['img_id'];
+                        if (isset($components['images'][$selectedImage])) {
+                            $Component['component_style'] = is_object($components['images'][$selectedImage]) ? $components['images'][$selectedImage]->img_id : $components['images'][$selectedImage]['img_id'];
+                            var_dump('action2-------------------------------------sortId',$sortId);
                         }
                     }
-                    $image_info[$key] = is_object($components[$selectedComponentId]['images'][$selectedImage]) ? $components[$selectedComponentId]['images'][$selectedImage] : $components[$selectedComponentId]['images'][$selectedImage];
-                    // var_dump($images);
-                    $Component['componentData'] = $components[$selectedComponentId]['componentData'] ?? [];
-                    if ($data['page'] == 1 && (isset($components[$selectedComponentId]['type_id']) && in_array($components[$selectedComponentId]['type_id'], [7, 14, 15]))) {
+                    var_dump('action3-------------------------------------sortId',$selectedImage);
+                    if(isset($components['images'][$selectedImage])){
+                        $image_info[$key] = is_object($components['images'][$selectedImage]) ? $components['images'][$selectedImage] : $components['images'][$selectedImage];
+                    }
+                    var_dump('action4-------------------------------------sortId',$sortId);       
+              // var_dump($images);
+                    $Component['componentData'] = $components['componentData'] ?? [];
+                    if ($data['page'] == 1 && (isset($components['type_id']) && in_array($components['type_id'], [7, 14, 15, 23, 24]))) {
                         $Component['componentData']['name'] = '请选择栏目';
                     }
-                    if ($data['page'] == 2 && (isset($components[$selectedComponentId]['type_id']) && in_array($components[$selectedComponentId]['type_id'], [7, 14, 15]))) {
+                    if ($data['page'] == 2 && (isset($components['type_id']) && in_array($components['type_id'], [7, 14, 15, 23, 24]))) {
                         $Component['componentData']['name'] = '自动生成';
                     }
-                    if (isset($components[$selectedComponentId]['type_id']) && $components[$selectedComponentId]['type_id'] == 11) {
-                        $ad = $components[$selectedComponentId]['ad'];
-                        // $ad['thumb'] = $image_info[$key]['img_url'];
+                    if (isset($components['type_id']) && $components['type_id'] == 11) {
+                        $ad = $components['ad'];
+                        $ad['thumb'] = $image_info[$key]['component_imgurl'] ?? '';
                         $template_data[$key]['ad'] = $ad;
                         $canvas_adinfo[$key] = $ad;
                         $canvas_data[$key]['content']['ad'] = $canvas_adinfo[$key];
                         //    // 确保 $ad 和 $canvas_adinfo[$key] 元素数量一致,直接组合
-                        // //    $canvas_data[$key]['ad'] = array_combine($ad, $canvas_adinfo[$key]);
+                        // $canvas_data[$key]['ad'] = array_combine($ad, $canvas_adinfo[$key]);
                         $Component['componentData'] = [];
                     }
-                    if (isset($components[$selectedComponentId]['type_id']) && $components[$selectedComponentId]['type_id'] == 14) {
-                        $ad = $components[$selectedComponentId]['ad'];
-                        $ad['thumb'] = $image_info[$key]['img_url'];
+                    if (isset($components['type_id']) && $components['type_id'] == 14) {
+                        $ad = $components['ad'];
+                        $ad['thumb'] = $image_info[$key]['component_imgurl'] ?? '';
                         $template_data[$key]['ad'] = $ad;
                         $canvas_adinfo[$key] = $ad;
                         $canvas_data[$key]['content']['ad'] = $canvas_adinfo[$key];
-                        // //    $canvas_data[$key]['ad'] = array_combine($ad, $canvas_adinfo[$key]);
+                        //    $canvas_data[$key]['ad'] = array_combine($ad, $canvas_adinfo[$key]);
 
                         //     // $Component['componentData'] = [];
                     }
-                    // var_dump('---------------------------',$components[$selectedComponentId]);
+            //         // var_dump('---------------------------',$components[$selectedComponentId]);
                     $sector_component[$componet_key] = $Component;
                     $componet_key++;
                 }
@@ -4359,24 +4253,27 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error('关键词不能为空!');
         }
         $keyword = json_decode($data['keyword'],true);
-        $keyword = array_map('trim', $keyword);
+        // return Result::success(is_array($keyword));
         // $keyword_list = array_column($keyword,'keyword');
-        if(count($keyword) != count(array_unique($keyword))){
-            return Result::error('关键词不能重复!');
+        if(is_array($keyword) && count($keyword) != 1){
+            $keyword = array_map('trim', $keyword);
+            if(count($keyword) != count(array_unique($keyword))){
+                return Result::error('关键词不能重复!');
+            }
+            if(($data['type'] == 'style' || $data['type'] == 'skin')){
+                $keyword = preg_replace('/,/', ', ', $keyword);
+            }
         }
         // return Result::success(json_encode($keyword,JSON_UNESCAPED_UNICODE));
         $keyword = json_encode($keyword, JSON_UNESCAPED_UNICODE);
-        
         if($data['type'] == 'style'){
             $template_class_keyword = TemplateClass::pluck('keyword')->toArray();
-            $keyword = preg_replace('/,/', ', ', $keyword);
             if(in_array($keyword,$template_class_keyword)){
                 return Result::error('此风格关键词已存在!');
             }
         }
         if($data['type'] == 'skin'){
             $template_keyword = Template::pluck('template_keyword')->toArray();
-            $keyword = preg_replace('/,/', ', ', $keyword);
             if(in_array($keyword,$template_keyword)){
                 return Result::error('此皮肤关键词已存在!');
             }