Jelajahi Sumber

Merge branch '20250814_randomweb_fr'

15313670163 4 bulan lalu
induk
melakukan
85082e824c
1 mengubah file dengan 41 tambahan dan 13 penghapusan
  1. 41 13
      app/JsonRpc/PublicRpcService.php

+ 41 - 13
app/JsonRpc/PublicRpcService.php

@@ -2934,8 +2934,31 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::error('此皮肤不存在!');
         }
         $rule = TemplateRule::first();
-        $index_rule = json_decode($rule['index_rule']);
-        $class_rule = json_decode($rule['class_rule']);
+        switch ($data['page']) {
+            case 1:
+                $index_rule = json_decode($rule['index_rule']);
+                break;
+            case 2:
+                $index_rule = json_decode($rule['class_rule']);
+                break;
+            case 3:
+                $index_rule = json_decode($rule['list_rule']);
+                break;
+            case 4:
+                $index_rule = json_decode($rule['article_rule']);
+                break;
+            case 5:
+                $index_rule = json_decode($rule['search_rule']);
+                break;
+            case 6:
+                $index_rule = json_decode($rule['aloneList_rule']);
+                break;
+            case 7:
+                $index_rule = json_decode($rule['aloneArticle_rule']);
+                break;
+            default:
+                break;
+        }
         // return Result::success($index_rule);
         $tempalte['index'] = $this->randomPage($data,$data['page'],$index_rule);
         // $tempalte['class'] = $this->randomPage($data,2,$class_rule);
@@ -2958,7 +2981,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(empty($sectors)){
             return Result::error('通栏不存在!');
         }
-
+        // return $sectors;
         // 获取每个类别的通栏数量
         $type_num = array_count_values(array_column($sectors,'sector_type'));
         // 此页面通栏的所有类别
@@ -2987,7 +3010,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         }
         // var_dump("sector_types",$all_sector_types);
         // var_dump("must_type",$must_type);
-        // return $type_num;
+        // return $is_must;
 
 
         // 非必须通栏的随机处理
@@ -3031,7 +3054,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         // var_dump("randomKeys",$randomKeys);
         // var_dump("random_sector",$random_sector);
         var_dump("rand_count",$rand_count);
-        // return $random_type;
+        // return $random_sector;
 
         // 必需通栏
         $must_type = array_intersect($all_sector_types,$must_type);
@@ -3059,7 +3082,7 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $rule_repeat[$key] = $value-1;
             }
         }
-        // var_dump("repeat_num",$repeat_num);
+        var_dump("repeat_num",$repeat_num);
         // return $sector_zuhe1;
 
         // 剩余通栏进行重复处理
@@ -3071,8 +3094,11 @@ class PublicRpcService implements PublicRpcServiceInterface
         $repaet_key = 0;
         $num = 0;
         $type = [];
+        // 防止无限循环,设置最大迭代次数
+        $max_iterations = 1000; 
+        $iteration_count = 0;
         // return $rule_repeat;
-        for($repaet_key; $repaet_key < $repeat_num;){
+        while($repaet_key < $repeat_num && $iteration_count < $max_iterations){
             $num++;
             foreach($repeat_type as $key => $value){
                 $type[$key] = $num;
@@ -3094,7 +3120,7 @@ class PublicRpcService implements PublicRpcServiceInterface
                     break;
                 }
             }
-            
+            $iteration_count++;
         }
         
         // var_dump("num", $num);
@@ -3135,7 +3161,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         $sector_id = array_column($sector,'id');
         $data['page'] = $page;
         $component[] = $this->randomComponent($sector_id,$data,$sector);
-
+        var_dump("sector_id",$sector_id);
         return ['sector_id'=>$sector_id,
         // 'sector'=>$sector,
         'component'=>$component,
@@ -3307,6 +3333,7 @@ class PublicRpcService implements PublicRpcServiceInterface
                     // $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'])) {
@@ -3321,20 +3348,21 @@ class PublicRpcService implements PublicRpcServiceInterface
                     }
                     // var_dump($images);
                     $Component['componentData'] = $components[$selectedComponentId]['componentData'];
-                    if($data['page'] == 1 && in_array($components[$selectedComponentId]['type_id'],[7,14,15])){
+                    if($data['page'] == 1 &&(isset($components[$selectedComponentId]['componentData']['type_id']) && in_array($components[$selectedComponentId]['type_id'],[7,14,15])) ){
                         $Component['componentData']['name'] = '请选择栏目';
                     }
-                    if($data['page'] == 2 && in_array($components[$selectedComponentId]['type_id'],[7,14,15])){
+                    if($data['page'] == 2 && (isset($components[$selectedComponentId]['componentData']['type_id']) && in_array($components[$selectedComponentId]['type_id'],[7,14,15]))){
                         $Component['componentData']['name'] = '自动生成';
                     }
-                    if($components[$selectedComponentId]['type_id'] == 11){
+                    if(isset($components[$selectedComponentId]['componentData']['type_id']) && $components[$selectedComponentId]['type_id'] == 11){
                        $template_data[$key]['ad'] = $components[$selectedComponentId]['componentData']['ad'];
                        $Component['componentData'] = [];
                     }
-                    if($components[$selectedComponentId]['type_id'] == 15){
+                    if(isset($components[$selectedComponentId]['componentData']['type_id']) && $components[$selectedComponentId]['type_id'] == 15){
                        $template_data[$key]['ad'] = $components[$selectedComponentId]['ad'];
                     //    $components[$selectedComponentId]['componentData'] = [];
                     }
+                    // var_dump('---------------------------',$components[$selectedComponentId]);
                     $sector_component[$sortId] = $Component;
                     //  $sector_component[$sortId] = $selectedComponentId;
                 }