Преглед на файлове

组件管理-获取组件类型

15313670163 преди 3 дни
родител
ревизия
1777cc097b
променени са 1 файла, в които са добавени 22 реда и са изтрити 23 реда
  1. 22 23
      app/JsonRpc/PublicRpcService.php

+ 22 - 23
app/JsonRpc/PublicRpcService.php

@@ -2106,7 +2106,10 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(isset($data['id']) && !empty($data['id'])){
             $where['id'] = $data['id'];
         }
-        $component_type = ComponentType::where($where)->get()->all();
+        $component_type = ComponentType::where($where)->first();
+        if(empty($component_type)){
+            return Result::error('组件类型不存在!');
+        }
         $article = Article::first()->toArray();
         $category = WebsiteCategory::first()->toArray();
         $footer_category = FooterCategory::first()->toArray();
@@ -2114,33 +2117,29 @@ class PublicRpcService implements PublicRpcServiceInterface
         ->select('ad_place.*','ad_size.width','ad_size.height')
         ->first()->toArray();
         $type_arr = [1,2,3,4,5,6,7,8,9,14];
-        // return Result::success(in_array(intval($value['id']),$type_arr));
-        foreach($component_type as $key => $value){
-            // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
-            // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
-            if(in_array(intval($value['id']),$type_arr)){
-                $component_type[$key]['all_code'] = array_keys($article);
-            }
-            if($value['id'] == 13){
-                $component_type[$key]['all_code'] = array_keys($footer_category);
-
-            } if($value['id'] == 11){
-                $component_type[$key]['all_code'] = array_keys($ad);
-
-            }
-
-            if($value['id'] == 10){
-                $component_type[$key]['all_code'] = array_keys($category);
-            }
-            if($value['com_code']){
-                $component_type[$key]['com_code'] = json_decode($value['com_code'],true);
+        // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
+        // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
+        $default_code = json_decode($component_type['com_code'] ?? '',true);
+        $article_code = array_keys($article);
+        if(in_array($component_type['id'], $type_arr) && !empty($default_code)){
+            $merged['info'] = array_values(array_unique(array_merge($default_code['listType'], $article_code)));
+            $merged['count'] = count($merged['info']);
+            // 遍历 $default_code 和 $article 合并键值
+            foreach ($merged['info'] as $key => $value) {
+                $key = $value;
+                if (in_array($value,$article_code)) {
+                    $merged['info'][$key] = true;
+                } else {
+                    $merged['info'][$key] = false;
+                }
             }
-            // $component_type[$key]['com_code'] = json_decode($value['com_code'],true);
+            // $component_type['merged_info'] = $merged;
         }
+         $merged['count'] = count($merged['info']);
         if(empty($category)){
             return Result::error('组件类型不存在!');
         }
-        return Result::success($component_type);
+        return Result::success($merged);
     }
     /**
      * 组件管理-获取所有组件