Sfoglia il codice sorgente

Merge branch 'master' of http://git.bjzxtw.org.cn:3000/zxt/public_producer

LiuJ 4 mesi fa
parent
commit
3d6c784202
2 ha cambiato i file con 332 aggiunte e 161 eliminazioni
  1. 310 152
      app/JsonRpc/PublicRpcService.php
  2. 22 9
      app/JsonRpc/WebsiteService.php

+ 310 - 152
app/JsonRpc/PublicRpcService.php

@@ -1544,10 +1544,10 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $add_arr['img_num'] = intval($data['img_num']);
                 $add_arr['img_num'] = intval($data['img_num']);
                 $add_arr['text_num'] = intval($data['text_num']);
                 $add_arr['text_num'] = intval($data['text_num']);
                 $component_data['componentData'] = [
                 $component_data['componentData'] = [
-                    'category_id' => '',
+                    // 'category_id' => '',
                     'level' => $add_arr['level'],
                     'level' => $add_arr['level'],
                     'name' => '',
                     'name' => '',
-                    'category_arr' => [],
+                    // 'category_arr' => [],
                     'imgSize' => $data['img_num'] ?? '',
                     'imgSize' => $data['img_num'] ?? '',
                     'textSize' => $data['text_num'] ?? '',
                     'textSize' => $data['text_num'] ?? '',
                     'child' => [
                     'child' => [
@@ -1557,9 +1557,9 @@ class PublicRpcService implements PublicRpcServiceInterface
                     ]
                     ]
                 ]; 
                 ]; 
                 if($data['type_id'] == 4){
                 if($data['type_id'] == 4){
-                    $component_data['componentData']['name'] = '热点精选';
+                    $component_data['componentData']['name'] = '最新资讯';
                 }
                 }
-                if($data['type_id'] == 5){
+                if($data['type_id'] == 5 || $data['type_id'] == 6){
                     $component_data['componentData']['name'] = '热点精选';
                     $component_data['componentData']['name'] = '热点精选';
                 }
                 }
                 $add_arr['component_data'] = json_encode($component_data, true);
                 $add_arr['component_data'] = json_encode($component_data, true);
@@ -1817,9 +1817,9 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $add_arr['img_num'] = intval($data['img_num']);
                 $add_arr['img_num'] = intval($data['img_num']);
                 $add_arr['text_num'] = intval($data['text_num']);
                 $add_arr['text_num'] = intval($data['text_num']);
                 $component_data['componentData'] = [
                 $component_data['componentData'] = [
-                    'category_id' => '',
+                    // 'category_id' => '',
                     'level' => $add_arr['level'],
                     'level' => $add_arr['level'],
-                    'category_arr' => [],
+                    // 'category_arr' => [],
                     'name' => '',
                     'name' => '',
                     'imgSize' => $data['img_num'] ?? '',
                     'imgSize' => $data['img_num'] ?? '',
                     'textSize' => $data['text_num'] ?? '',
                     'textSize' => $data['text_num'] ?? '',
@@ -1832,7 +1832,7 @@ class PublicRpcService implements PublicRpcServiceInterface
                 if($data['type_id'] == 4){
                 if($data['type_id'] == 4){
                     $component_data['componentData']['name'] = '最新资讯';
                     $component_data['componentData']['name'] = '最新资讯';
                 }
                 }
-                if($data['type_id'] == 5){
+                if($data['type_id'] == 5 || $data['type_id'] == 6){
                     $component_data['componentData']['name'] = '热点精选';
                     $component_data['componentData']['name'] = '热点精选';
                 }
                 }
                 $add_arr['component_data'] = json_encode($component_data, true);
                 $add_arr['component_data'] = json_encode($component_data, true);
@@ -2945,16 +2945,16 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $index_rule = json_decode($rule['list_rule']);
                 $index_rule = json_decode($rule['list_rule']);
                 break;
                 break;
             case 4:
             case 4:
-                $index_rule = json_decode($rule['article_rule']);
+                $index_rule = json_decode($rule['info_rule']);
                 break;
                 break;
             case 5:
             case 5:
                 $index_rule = json_decode($rule['search_rule']);
                 $index_rule = json_decode($rule['search_rule']);
                 break;
                 break;
             case 6:
             case 6:
-                $index_rule = json_decode($rule['aloneList_rule']);
+                $index_rule = json_decode($rule['footerlist_rule']);
                 break;
                 break;
             case 7:
             case 7:
-                $index_rule = json_decode($rule['aloneArticle_rule']);
+                $index_rule = json_decode($rule['footerinfo_rule']);
                 break;
                 break;
             default:
             default:
                 break;
                 break;
@@ -3010,11 +3010,12 @@ class PublicRpcService implements PublicRpcServiceInterface
         }
         }
         // var_dump("sector_types",$all_sector_types);
         // var_dump("sector_types",$all_sector_types);
         // var_dump("must_type",$must_type);
         // var_dump("must_type",$must_type);
-        // return $is_must;
+        // return $must_type;
 
 
 
 
         // 非必须通栏的随机处理
         // 非必须通栏的随机处理
         $not_must_type = array_diff($all_sector_types,$must_type);
         $not_must_type = array_diff($all_sector_types,$must_type);
+        
         $total = count($not_must_type);
         $total = count($not_must_type);
         $randomCount = mt_rand(0, $total); // 可能为0(无元素)或任意数量,最多等于数组长度
         $randomCount = mt_rand(0, $total); // 可能为0(无元素)或任意数量,最多等于数组长度
         $and_type = $rule->and_type ?? [];
         $and_type = $rule->and_type ?? [];
@@ -3059,106 +3060,175 @@ class PublicRpcService implements PublicRpcServiceInterface
         // 必需通栏
         // 必需通栏
         $must_type = array_intersect($all_sector_types,$must_type);
         $must_type = array_intersect($all_sector_types,$must_type);
         // return $must_type;
         // return $must_type;
+// 此代码用于从 $sectors 数组中筛选出必需的通栏数据。
+// 1. array_keys($must_type) 获取 $must_type 数组的所有键名
+// 2. array_flip() 将这些键名作为值,生成一个新数组
+// 3. array_intersect_key() 比较 $sectors 和上述新数组的键名,返回键名相同的元素
+// 4. array_values() 重新索引返回的数组,使其键名从 0 开始连续递增
+// 最终得到的 $must_sector 数组包含了 $sectors 中对应 $must_type 键名的所有必需通栏数据
         $must_sector = array_values(array_intersect_key($sectors, array_flip(array_keys($must_type))));
         $must_sector = array_values(array_intersect_key($sectors, array_flip(array_keys($must_type))));
         $must_count = count($must_sector);
         $must_count = count($must_sector);
         // var_dump("must_sector",$must_sector);
         // var_dump("must_sector",$must_sector);
-        var_dump("must_count",$must_count);
+        // var_dump("must_count",$must_count);
         // return $must_sector;
         // return $must_sector;
-
-
-
-
         // 计算随机之后减去必需的通栏,查询重复通栏可用数量;(目前的这些通栏没有重复的同类别通栏)
         // 计算随机之后减去必需的通栏,查询重复通栏可用数量;(目前的这些通栏没有重复的同类别通栏)
         $repeat_num = $sector_num-$rand_count-$must_count;
         $repeat_num = $sector_num-$rand_count-$must_count;
         // 组合起来通栏
         // 组合起来通栏
         $sector_zuhe1 = array_merge($must_sector,$random_sector);
         $sector_zuhe1 = array_merge($must_sector,$random_sector);
-
-        // 各类型通栏最大数量数量限制 = 规则最大数量-已经存在的通栏数量(目前的通栏不会有重复的,所以只是-1)
-        $rule_repeat = (array)$rule->type_max;
-        $sector_zuhe1_type = array_count_values(array_column($sector_zuhe1,'sector_type'));
-        // $sector_arr = array_intersect_key($rule_repeat,$sector_zuhe1_type);
-        foreach($rule_repeat as $key => $value){
-            if(in_array($key,array_keys($sector_zuhe1_type))){
-                $rule_repeat[$key] = $value-1;
-            }
-        }
-        var_dump("repeat_num",$repeat_num);
-        // return $sector_zuhe1;
-
-        // 剩余通栏进行重复处理
-        // $rule_repeat = (array)$rule->type_max;
-        // 取到可以重复的通栏类别
-        $rule_repaet_type =  array_keys($rule_repeat);
-        $repeat_type = array_intersect_key($sector_types, array_flip($rule_repaet_type));
-        // 获取可以随机重复的通栏
-        $repaet_key = 0;
-        $num = 0;
-        $type = [];
-        // 防止无限循环,设置最大迭代次数
-        $max_iterations = 1000; 
-        $iteration_count = 0;
-        // return $rule_repeat;
-        while($repaet_key < $repeat_num && $iteration_count < $max_iterations){
-            $num++;
-            foreach($repeat_type as $key => $value){
-                $type[$key] = $num;
-                // $type代表每个类型的通栏数量,每个类型的通栏的数量应该≤规则限制的数量
-                if($repaet_key < $repeat_num  && $type[$key] <= $rule_repeat[$key]-1){
-                    // $max_repaert_num = $rule_repeat[$key];
-                    // if($max_repaert_num < $num ){
-                        // $arr_key = $num+$key;
-                        if (count($value) > 0) {
-                            // 若 可以随机的通栏类型存在多个通栏,随机取其一
-                            $repeat_sector_key[$repaet_key] = $value[array_rand($value)];
-                        } else {
-                            $repeat_sector_key[$repaet_key] = $value[0];
-                        }
-                        // $type[$repaet_key] = $repeat_sector_key[$repaet_key];
-                        $repaet_key++;
+        $sector_ids = array_column($sector_zuhe1, 'id');
+        if($repeat_num > 0){
+            $rule_repeat = (array)$rule->type_max;
+            $sector_zuhe1_type = array_count_values(array_column($sector_zuhe1,'sector_type'));
+            // $sector_arr = array_intersect_key($rule_repeat,$sector_zuhe1_type);
+            foreach($rule_repeat as $key => $value){
+                if(in_array($key,array_keys($sector_zuhe1_type))){
+                    $rule_repeat[$key] = $value-1;
+                }
+            }
+            var_dump("repeat_num",$repeat_num);
+            // return array_intersect($sector_zuhe1,$must_sector);
+            if(count(array_intersect($sector_zuhe1,$must_sector)) != count($must_sector)){
+                return '此页面缺少必要通栏!';
+            }
+            // 剩余通栏进行重复处理
+            // $rule_repeat = (array)$rule->type_max;
+            // 取到可以重复的通栏类别
+            $rule_repaet_type =  array_keys($rule_repeat);
+            $repeat_type = array_intersect_key($sector_types, array_flip($rule_repaet_type));
+            // 获取可以随机重复的通栏
+            $repaet_key = 0;
+            $num = 0;
+            $type = [];
+            // return $rule_repaet_type;
+            // 防止无限循环,设置最大迭代次数
+            $max_iterations = 20; 
+            $iteration_count = 0;
+            // return [
+            //     'repaet_key' => $repaet_key,
+            //     'repeat_num' => $repeat_num,
+            //     'rule_repeat' => $rule_repeat,
+            //     'repeat_type' => $repeat_type,
+            //     'must_type' => $must_type,
+            // ];
+            while($repaet_key < $repeat_num && $iteration_count < $max_iterations){
+                $num++;
+                foreach($repeat_type as $key => $value){
+                    if(!isset($type[$key])){
+                        $type[$key] = 0;
+                    }else{
+                        $type[$key]++;
+                    }
+                    // $type代表每个类型的通栏数量,每个类型的通栏的数量应该≤规则限制的数量
+                    if($repaet_key < $repeat_num  && $type[$key] <= $rule_repeat[$key]){
+                        // $max_repaert_num = $rule_repeat[$key];
+                        // if($max_repaert_num < $num ){
+                        //     // $arr_key = $num+$key;
+                            if (count($value) > 1) {
+                                // 若 可以随机的通栏类型存在多个通栏,随机取其一
+                                $repeat_sector_key[$repaet_key] = $value[array_rand($value)];
+                            } else {
+                                $repeat_sector_key[$repaet_key] = $value[0];
+                            }
+                            $type[$repaet_key] = $repeat_sector_key[$repaet_key];
+                            $repaet_key++;
+                        // }
+                    }
+                    // else{
+                    //     break;
                     // }
                     // }
-                }else{
-                    break;
+                }
+                // var_dump("num",  $type[$key]);
+                // var_dump("repeat_sector_key", $repeat_sector_key);
+                $iteration_count++;
+            }
+            // return $repeat_sector_key;
+            // 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)){
+
+                foreach ($repeat_sector_key as $key => $value) {
+                    if (isset($sectors[$value])) {
+                        $repeat_sector[$key] = $sectors[$value];
+                    }
                 }
                 }
             }
             }
-            $iteration_count++;
-        }
+            $repeat_count = count($repeat_sector);
+            var_dump("repeat_count",$repeat_count);
+            // var_dump("repeat_sector", $repeat_sector);
+            //  return ($data['page'] == '2' || $data['page'] == 2);
+            
+            $sector = array_merge($repeat_sector,$sector_zuhe1);
+        }else{
+            $sector = $sector_zuhe1;
+        }
+        // var_dump("sector_ids",$sector_ids);
+        // return [
+        //     'random_sector'=>$random_sector,
+        //     'must_sector'=>$must_sector,
+        //     'sector_ids'=>$sector_ids,
+        // ];
+        // 各类型通栏最大数量数量限制 = 规则最大数量-已经存在的通栏数量(目前的通栏不会有重复的,所以只是-1)
         
         
-        // var_dump("num", $num);
-        // var_dump("repeat_sector_key", $repeat_sector_key);
-        // 随机的重复通栏键值转换成真正的通栏
-        $repeat_sector = [];
-        foreach ($repeat_sector_key as $key => $value) {
-            if (isset($sectors[$value])) {
-                $repeat_sector[$key] = $sectors[$value];
-            }
-        }
-        $repeat_count = count($repeat_sector);
-        var_dump("repeat_count",$repeat_count);
-        // var_dump("repeat_sector", $repeat_sector);
-
-
-        $sector = array_merge($repeat_sector,$sector_zuhe1);
+        // var_dump("sector",$sector);
         // 处理头条及轮播图在随机通栏中的特殊位置特殊处理
         // 处理头条及轮播图在随机通栏中的特殊位置特殊处理
         $sector_specal_sort = array_column($sector,'sector_type');
         $sector_specal_sort = array_column($sector,'sector_type');
-        if(in_array(6,$sector_specal_sort) || in_array(7,$sector_specal_sort)){
+        if(in_array(6,$sector_specal_sort) || in_array(7,$sector_specal_sort) || in_array(5,$sector_specal_sort)){
+            
             $toutiao_key = array_search(6,$sector_specal_sort) ?? null;
             $toutiao_key = array_search(6,$sector_specal_sort) ?? null;
             $pic_key = array_search(7,$sector_specal_sort) ?? null;
             $pic_key = array_search(7,$sector_specal_sort) ?? null;
+            $cat_key = array_search(5,$sector_specal_sort) ?? null;
             $toutiao = $sector[$toutiao_key];
             $toutiao = $sector[$toutiao_key];
             $pic =  $sector[$pic_key];
             $pic =  $sector[$pic_key];
-            $soty_1 = $sector[0];
+            $cat =  $sector[$cat_key];
+            $sort_1 = $sector[0];
             $sort_2 = $sector[1];
             $sort_2 = $sector[1];
-            if(!empty($toutiao_key)){
-                $sector[0] = $toutiao;
-                $sector[$toutiao_key] = $soty_1;
-                $sector[1] = $pic;
-                $sector[$pic_key] = $sort_2;
-            }else{
-                 $sector[0] = $pic;
-                $sector[$pic_key] = $sort_2;
+            $sort_3 = $sector[2];
+            
+        // return $sector_specal_sort;
+        //  return [
+        //     'sector_ids' => array_column($sector_zuhe1,'id'),
+        //     // 'repeat_sector' => $repeat_sector,
+        //     'sector_id' => array_column($sector,'id'),
+        //     'array_intersect' => count(array_intersect($sector,$must_sector)),
+        //     'old' => [ $toutiao_key,$pic_key,$cat_key],
+        //     'new' => [  $sort_1,$sort_2,$sort_3]
+        // ];
+            if($data['page'] == 1 || $data['page'] == '1'){
+                if($toutiao_key){
+                    $sector[0] = $toutiao;
+                    $sector[$toutiao_key] = $sort_1;
+                    $sector[1] = $pic;
+                    $sector[$pic_key] = $sort_2;
+                }
+                if($cat_key){
+                     $sector[0] = $pic;
+                    $sector[$pic_key] = $sort_1;
+                }
+            }
+            if($data['page'] == '2' || $data['page'] == 2 || in_array(5,$sector_specal_sort)){
+                $sector[0] = $cat;
+                $sector[$cat_key] = $sort_1;
+                if($toutiao_key && $pic_key){
+                    $sector[1] = $toutiao;
+                    $sector[$toutiao_key] = $sort_2;
+                    $sector[2] = $pic;
+                    $sector[$pic_key] = $sort_3;
+                }
+                if($pic_key){
+                     $sector[1] = $pic;
+                    $sector[$pic_key] = $sort_2;
+                }
             }
             }
+            
 
 
         }
         }
         $sector_id = array_column($sector,'id');
         $sector_id = array_column($sector,'id');
+       
+        // if(count(array_intersect($sector,$must_sector)) != count($must_sector)){
+        //     return '此页面缺少必要通栏!';
+        // }
         $data['page'] = $page;
         $data['page'] = $page;
         $component[] = $this->randomComponent($sector_id,$data,$sector);
         $component[] = $this->randomComponent($sector_id,$data,$sector);
         var_dump("sector_id",$sector_id);
         var_dump("sector_id",$sector_id);
@@ -3169,8 +3239,6 @@ class PublicRpcService implements PublicRpcServiceInterface
     ];
     ];
     }
     }
     public function randomComponent($sector_id,$data,$sector){
     public function randomComponent($sector_id,$data,$sector){
-        // return $sector;
-        // 获取原始查询结果
         $rawResults = SectorComponent::whereIn('sector_component.sectorid', $sector_id)
         $rawResults = SectorComponent::whereIn('sector_component.sectorid', $sector_id)
             ->leftJoin('component','component.component_type','sector_component.component_id')
             ->leftJoin('component','component.component_type','sector_component.component_id')
             ->leftJoin('component_img','component_img.component_id','component.component_type')
             ->leftJoin('component_img','component_img.component_id','component.component_type')
@@ -3182,10 +3250,15 @@ class PublicRpcService implements PublicRpcServiceInterface
             ->get();
             ->get();
         // 按sectorid和sort_id分组数据
         // 按sectorid和sort_id分组数据
         $groupedResults = [];
         $groupedResults = [];
-        $arr = 0;
+        $sort_ids = [];
+        $sector_ids = [];
         $component_list = [];
         $component_list = [];
+        $component_ids = [];
+        $img_ids = [];
+        $sort_key = 0;
         // return $rawResults;
         // return $rawResults;
         // $groupedResults重构数组,将相同位置的组件合并,相同组件的样式合并(已经包括所有选择的组件及组件样式)
         // $groupedResults重构数组,将相同位置的组件合并,相同组件的样式合并(已经包括所有选择的组件及组件样式)
+        // $sort_component = array_column($rawResults,'sort_id');
         foreach ($rawResults as $key => $item) {
         foreach ($rawResults as $key => $item) {
             $sectorId = $item->sectorid;
             $sectorId = $item->sectorid;
             $sortId = $item->sort_id;
             $sortId = $item->sort_id;
@@ -3194,6 +3267,7 @@ class PublicRpcService implements PublicRpcServiceInterface
             $component_column = $item->component_column;
             $component_column = $item->component_column;
             $component_type = $item->type_id;
             $component_type = $item->type_id;
             $component_ad = $item->ad;
             $component_ad = $item->ad;
+            $imgId = $item->img_id;
             if (!isset($groupedResults[$sectorId])) {
             if (!isset($groupedResults[$sectorId])) {
                 $groupedResults[$sectorId] = [];
                 $groupedResults[$sectorId] = [];
             }
             }
@@ -3206,69 +3280,123 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $componentData['componentData'] = [];
                 $componentData['componentData'] = [];
             }
             }
             $componentData['componentData'] += $component_listtype;
             $componentData['componentData'] += $component_listtype;
-                $component_code = $componentData;
-                $component_list[$key] = $component_code;
+            $component_code = $componentData;
+            $component_list[$key] = $component_code;
                 // $component_list[$key]['listType'] = $component_listtype;
                 // $component_list[$key]['listType'] = $component_listtype;
             // }
             // }
             $sort_id = intval($sortId-1);
             $sort_id = intval($sortId-1);
-            if(!isset($groupedResults[$sectorId][$sort_id])) {
-                // $groupedResults[$sectorId][$sortId] = [];
+            // 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])){
                 $com_key = 0;
                 $com_key = 0;
-                    $groupedResults[$sectorId][$sort_id][$com_key] = [
+                // 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][$sort_id][$com_key] = [
                     'component_type' => $item->component_type,
                     'component_type' => $item->component_type,
                     'type_id' => $component_type,
                     'type_id' => $component_type,
                     'sort' => $sortId,
                     'sort' => $sortId,
-                    'images'  =>   [
-                                'img_name' => $item->img_name,
-                                'img_id' => $item->img_id,
-                                'img_url' => $item->img_url,
-                            ]
-                ];                
-                // 检查 $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,
-                    ];
-                }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,
-                        'images' => 
-                        [
-                            $img_arr =>
-                                [
-                                    'img_name' => $item->img_name,
-                                    'img_id' => $item->img_id,
-                                    'img_url' => $item->img_url,
-                                ]
-                        ]
-                    ];
-                }
+                    'width' => $item->component_width,
+                    'height' => $item->component_height,
+                ];
             }
             }
-            // 组件分类:1.头条资讯;2.轮播图资讯;3.推荐图;4.最新资讯;5.推荐资讯;6.热点资讯;7.栏目资讯;8.列表类;9.详情类;
-            // 10.二级导航类;11.广告类;12.静态类;13.单页导航类;14.资讯广告混合类;15.滚动图文类;16.搜索框类;17.单页列表类;18.单页详情类;
+            $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,
+            ];
+            // $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;
+            // }
+            // // 组件分类: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 (is_scalar($sectorId) && is_scalar($sort_id)) {
                 if(!in_array($component_type,[10,12,16])){
                 if(!in_array($component_type,[10,12,16])){
-                    if($component_type == 15){
+                    if($component_type == 11 || $component_type == 14){
                         $groupedResults[(int)$sectorId][(int)$sort_id][$com_key]['ad'] = $component_ad;
                         $groupedResults[(int)$sectorId][(int)$sort_id][$com_key]['ad'] = $component_ad;
-                    }else{
+                        $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'];
                         $groupedResults[(int)$sectorId][(int)$sort_id][$com_key]['componentData'] = $component_code['componentData'];
                     }
                     }
                 }else{
                 }else{
@@ -3278,8 +3406,22 @@ class PublicRpcService implements PublicRpcServiceInterface
                 // 处理非法键类型的情况,可根据实际需求修改错误处理逻辑
                 // 处理非法键类型的情况,可根据实际需求修改错误处理逻辑
                 trigger_error('Illegal offset type for $sectorId or $sort_id', E_USER_WARNING);
                 trigger_error('Illegal offset type for $sectorId or $sort_id', E_USER_WARNING);
             }
             }
-            // 判断此组件是否存在数组中的依据(若是有重复的组件,一定是组件样式重复)
-            $component_ids[$sort_id] = $componentId;
+            // // 判断此组件是否存在数组中的依据(若是有重复的组件,一定是组件样式重复)
+            $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;
+            // $img_ids[$componentId] = $imgId;
         }
         }
 
 
         // return $groupedResults;
         // return $groupedResults;
@@ -3303,7 +3445,7 @@ class PublicRpcService implements PublicRpcServiceInterface
             }else{
             }else{
                 $date = substr($date, 0, 9); // 截取前9位
                 $date = substr($date, 0, 9); // 截取前9位
             }
             }
-            $random_num = intval($date) . rand(1000, 9999); // 拼接4位随机数,组成13位随机数
+            $random_num = intval(intval($date) . rand(1000, 9999)); // 拼接4位随机数,组成13位随机数
             $y_num = $y_num + $value['pic_height'];
             $y_num = $y_num + $value['pic_height'];
             $sector_width = $value['sector_width']/100;
             $sector_width = $value['sector_width']/100;
             $canvas_data[$key] = [
             $canvas_data[$key] = [
@@ -3346,8 +3488,10 @@ class PublicRpcService implements PublicRpcServiceInterface
                             $Component['component_style'] = is_object($components[$selectedComponentId]['images'][$selectedImage]) ? $components[$selectedComponentId]['images'][$selectedImage]->img_id : $components[$selectedComponentId]['images'][$selectedImage]['img_id'];
                             $Component['component_style'] = is_object($components[$selectedComponentId]['images'][$selectedImage]) ? $components[$selectedComponentId]['images'][$selectedImage]->img_id : $components[$selectedComponentId]['images'][$selectedImage]['img_id'];
                         }
                         }
                     }
                     }
+                    $image_info[$key] = is_object($components[$selectedComponentId]['images'][$selectedImage]) ? $components[$selectedComponentId]['images'][$selectedImage] : $components[$selectedComponentId]['images'][$selectedImage];
+
                     // var_dump($images);
                     // var_dump($images);
-                    $Component['componentData'] = $components[$selectedComponentId]['componentData'];
+                    $Component['componentData'] = $components[$selectedComponentId]['componentData'] ?? [];
                     if($data['page'] == 1 &&(isset($components[$selectedComponentId]['type_id']) && in_array($components[$selectedComponentId]['type_id'],[7,14,15])) ){
                     if($data['page'] == 1 &&(isset($components[$selectedComponentId]['type_id']) && in_array($components[$selectedComponentId]['type_id'],[7,14,15])) ){
                         $Component['componentData']['name'] = '请选择栏目';
                         $Component['componentData']['name'] = '请选择栏目';
                     }
                     }
@@ -3355,26 +3499,40 @@ class PublicRpcService implements PublicRpcServiceInterface
                         $Component['componentData']['name'] = '自动生成';
                         $Component['componentData']['name'] = '自动生成';
                     }
                     }
                     if(isset($components[$selectedComponentId]['type_id']) && $components[$selectedComponentId]['type_id'] == 11){
                     if(isset($components[$selectedComponentId]['type_id']) && $components[$selectedComponentId]['type_id'] == 11){
-                       $template_data[$key]['ad'] = $components[$selectedComponentId]['componentData']['ad'];
+                        $ad = $components[$selectedComponentId]['ad'];
+                        $ad['thumb'] = $image_info[$key]['img_url'];
+                        $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]);
                        $Component['componentData'] = [];
                        $Component['componentData'] = [];
                     }
                     }
-                    if(isset($components[$selectedComponentId]['type_id']) && $components[$selectedComponentId]['type_id'] == 15){
-                       $template_data[$key]['ad'] = $components[$selectedComponentId]['ad'];
-                    //    $components[$selectedComponentId]['componentData'] = [];
+                    if(isset($components[$selectedComponentId]['type_id']) && $components[$selectedComponentId]['type_id'] == 14){
+                        $ad = $components[$selectedComponentId]['ad'];
+                        // $ad['thumb'] = $image_info[$key]['img_url'];
+                        $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]);
+
+                    //     // $Component['componentData'] = [];
                     }
                     }
                     // var_dump('---------------------------',$components[$selectedComponentId]);
                     // var_dump('---------------------------',$components[$selectedComponentId]);
                     $sector_component[$sortId] = $Component;
                     $sector_component[$sortId] = $Component;
+                    // $canvas_component[$sortId] = $Component;
                     //  $sector_component[$sortId] = $selectedComponentId;
                     //  $sector_component[$sortId] = $selectedComponentId;
                 }
                 }
                 // var_dump("image",$image);
                 // var_dump("image",$image);
             }
             }
             $template_data[$key]['componentList'] = $sector_component;
             $template_data[$key]['componentList'] = $sector_component;
             $canvas_data[$key]['content']['componentList'] = $sector_component;
             $canvas_data[$key]['content']['componentList'] = $sector_component;
+            // $canvas_data[$key]['ad'] = $key;
             $canvas_data[$key]['dataSort'] = $key;
             $canvas_data[$key]['dataSort'] = $key;
             $canvas_data[$key]['moved'] = false;
             $canvas_data[$key]['moved'] = false;
             // $page['template'][$key][$sector_key]['componentData'] = $result[$sectorId];
             // $page['template'][$key][$sector_key]['componentData'] = $result[$sectorId];
         }
         }
-        
+        // return $canvas_data;
         return [
         return [
             'template_data' => $template_data,
             'template_data' => $template_data,
             'canvas_data' => $canvas_data,
             'canvas_data' => $canvas_data,

+ 22 - 9
app/JsonRpc/WebsiteService.php

@@ -716,6 +716,12 @@ class WebsiteService implements WebsiteServiceInterface
         $website_id = [
         $website_id = [
             'website_id' => $data['website_id'],
             'website_id' => $data['website_id'],
         ];
         ];
+        $website_column_arr = Website::where('id',$data['website_id'])->value('website_column_arr_id');
+        if(empty($website_column_arr)){
+            return Result::error("未查询到此网站所属网系!",0);
+        }
+        $website_column_arr = json_decode($website_column_arr, true);
+        // return Result::success(!in_array(3,$website_column_arr) && $data['pid'] == 0);
         // 初始化 $pid 数组
         // 初始化 $pid 数组
         // $pid = [];
         // $pid = [];
         // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
         // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
@@ -727,7 +733,12 @@ class WebsiteService implements WebsiteServiceInterface
         $pid = array_values(array_unique($pid->toArray()));
         $pid = array_values(array_unique($pid->toArray()));
         // 构建查询语句
         // 构建查询语句
         $query = WebsiteCategory::where($website_id)
         $query = WebsiteCategory::where($website_id)
-            ->where('pid', $data['pid'])
+            ->when(!in_array(3,$website_column_arr) && $data['pid'] == 0, function ($query) use ($website_column_arr) {
+                $query->where('is_show', 1);
+            })
+            ->when(in_array(3,$website_column_arr) ||  $data['pid'] != 0, function ($query) use ($data) {
+                $query->where('pid', $data['pid']);
+            })
             ->offset($data['placeid'])
             ->offset($data['placeid'])
             ->limit($data['num'])
             ->limit($data['num'])
             ->orderBy('sort')
             ->orderBy('sort')
@@ -2787,14 +2798,16 @@ class WebsiteService implements WebsiteServiceInterface
         if (empty($website)) {
         if (empty($website)) {
             return Result::error("暂无该网站", 0);
             return Result::error("暂无该网站", 0);
         }
         }
-        if (isset($data['pinyin']) && !empty($data['pinyin'])) {
-            $result = WebsiteCategory::where('website_category.website_id', $data['website_id'])
-                ->where('website_category.aLIas_pinyin', $data['pinyin'])
-                ->leftJoin('website_category as pc', function ($join) use ($data) {
-                    $join->on('pc.pid', '=', 'website_category.category_id')
-                        ->where('pc.website_id', '=', $data['website_id']);
-                })
-                ->select('website_category.category_id', 'website_category.type', 'website_category.alias', DB::raw('CASE WHEN pc.category_id IS NOT NULL THEN 1 ELSE 0 END as children_count'))
+        if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
+            $result = WebsiteCategory::where('website_id',$data['website_id'])
+            ->where('aLIas_pinyin',$data['pinyin'])
+            // $result = WebsiteCategory::where('category_id', $category_id)
+                // ->where('website_category.path', $data['pinyin'])
+                // ->leftJoin('website_category as pc', function ($join) use ($data) {
+                //     $join->on('pc.pid', '=', 'website_category.category_id')
+                //         ->where('pc.website_id', '=', $data['website_id']);
+                // })
+                ->select('website_category.category_id','website_category.type', 'website_category.alias',)
                 ->first();
                 ->first();
         }
         }
         if (isset($data['foot_pinyin']) && !empty($data['foot_pinyin'])) {
         if (isset($data['foot_pinyin']) && !empty($data['foot_pinyin'])) {