瀏覽代碼

修改接口:添加、修改组件;

15313670163 2 天之前
父節點
當前提交
1e27bd173f
共有 1 個文件被更改,包括 162 次插入137 次删除
  1. 162 137
      app/JsonRpc/PublicRpcService.php

+ 162 - 137
app/JsonRpc/PublicRpcService.php

@@ -1312,20 +1312,23 @@ class PublicRpcService implements PublicRpcServiceInterface
             'component_height' => $data['component_height'],
             'type_id' => intval($data['type_id']),
             'component_keyword' => $data['component_keyword'],
-            'component_column' => $component_type['com_code'],
         ];
+        $component_head_code = [
+            'component_type' => $add_arr['component_type'],
+            'type_id' => $add_arr['type_id'],
+            'component_name' => $add_arr['component_name'],
+        ];
+        $add_arr['component_code'] = json_encode($component_head_code,true);
         switch($data['type_id']){
             case 1:                         //1:资讯-头条组件;
             case 2:                         //2:资讯-轮播组件;
             case 3:                         //3:资讯-推荐图类组件;
             case 4:                         //4:资讯-最新类组件;
-            case 5:                        //5:资讯-推荐类组件;
-            case 6:                        //6:资讯-热点类组件;
+            case 5:                         //5:资讯-推荐类组件;
+            case 6:                         //6:资讯-热点类组件;
                 $add_arr['level'] = $data['type_id'];
                 $add_arr['img_num'] = intval($data['img_num']);
                 $add_arr['text_num'] = intval($data['text_num']);
-                $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
-                $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
                 $component_data['componentData'] = [
                     'category_id' => '',
                     'level' => $add_arr['level'],
@@ -1333,33 +1336,12 @@ class PublicRpcService implements PublicRpcServiceInterface
                     'textSize' => $data['text_num'] ?? '',
                     'child' => [
                         'id' => '',
-                        'imgSize' => $data['child_imgnum'] ?? '',
-                        'textSize' => $data['child_textnum'] ?? '',
+                        'imgSize' => '',
+                        'textSize' => ''
                     ]
-                ];
-                break;
-            case 14:
-                $add_arr['ad_width'] = intval($data['ad_width']);
-                $add_arr['ad_height'] = intval($data['ad_height']);
-                $add_arr['component_width'] = intval($data['component_width']);
-                $add_arr['component_height'] = intval($data['component_height']);
-                $add_arr['ad_type'] = intval($data['ad_type']);
-                $add_arr['ad_img'] = $data['ad_img'];
-                $add_arr['img_num'] = intval($data['img_num']);
-                $add_arr['text_num'] = intval($data['text_num']);
-                $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
-                $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
-                $component_data['componentData'] = [
-                    'category_id' => '',
-                    'level' => '',
-                    'imgSize' => $data['img_num'] ?? '',
-                    'textSize' => $data['text_num'] ?? '',
-                    'child' => [
-                        'id' => '',
-                        'imgSize' => $data['child_imgnum'] ?? '',
-                        'textSize' => $data['child_textnum'] ?? '',
-                    ]
-                ];
+                ]; 
+                $add_arr['component_data'] = json_encode($component_data, true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 7:                        //7:资讯-栏目类组件;
                 $add_arr['img_num'] = intval($data['img_num']);
@@ -1377,6 +1359,8 @@ class PublicRpcService implements PublicRpcServiceInterface
                         'textSize' => $add_arr['child_textnum'] ?? '',
                     ]
                 ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 8:                      //8:列表类组件;
                 $add_arr['pageSize'] = intval($data['pageSize']);
@@ -1387,16 +1371,26 @@ class PublicRpcService implements PublicRpcServiceInterface
                         'pageSize' => $add_arr['pageSize'] ?? '',
                     ]
                 ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 9:                     //9:详情类组件;
                 $component_data['componentData'] = [
                     'article_id' => '',
                 ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 10:                     //10:二级导航类组件;
+                $add_arr['cate_place'] = 1;
+                $add_arr['num'] = intval($data['num']);
                 $component_data['componentData'] = [
-                    'fcat_id' => '',
+                    'pid' => '',
+                    'placeid' => 1,
+                    'num' => $add_arr['num'],
                 ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 11:                     //11:广告类;
                 $add_arr['ad_width'] = intval($data['ad_width']);
@@ -1405,50 +1399,68 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $add_arr['component_height'] = intval($data['ad_height']);
                 $add_arr['ad_type'] = intval($data['ad_type']);
                 $add_arr['ad_img'] = $data['ad_img'];
+                $ad = [
+                    'width' => $add_arr['ad_width'],
+                    'height' => $add_arr['ad_height'],
+                    'name' => '',
+                    'price' => '',
+                    'introduce' => '',
+                    'website_id' => '',
+                    'thumb' => $add_arr['ad_img'],
+                    'typeid' => $add_arr['ad_type'],
+                    'ad_tag' => '',
+                ];
+                $add_arr['ad'] = json_encode($ad,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
-            case 12:                     //12:静态资源类;
-                $component_data['componentData'] = [];
-                break; 
             case 13:                     //13:底部导航类;
-                $add_arr['cate_place'] = 0;
-                $add_arr['pageSize'] = intval($data['pageSize']);
                 $component_data['componentData'] = [
-                    'pid' => '',
-                    'placeid' => 1,
-                    'num' => $add_arr['pageSize'],
+                    'fcat_id' => '',
+                ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
+                break;
+            case 14:
+                $add_arr['ad_width'] = intval($data['ad_width']);
+                $add_arr['ad_height'] = intval($data['ad_height']);
+                $add_arr['component_width'] = intval($data['component_width']);
+                $add_arr['component_height'] = intval($data['component_height']);
+                $add_arr['ad_type'] = intval($data['ad_type']);
+                $add_arr['ad_img'] = $data['ad_img'];
+                $add_arr['img_num'] = intval($data['img_num']);
+                $add_arr['text_num'] = intval($data['text_num']);
+                $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
+                $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'level' => '',
+                    'imgSize' => $data['img_num'] ?? '',
+                    'textSize' => $data['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => $data['child_imgnum'] ?? '',
+                        'textSize' => $data['child_textnum'] ?? '',
+                    ]
                 ];
+                $ad = [
+                    'width' => $add_arr['ad_width'],
+                    'height' => $add_arr['ad_height'],
+                    'name' => '',
+                    'price' => '',
+                    'introduce' => '',
+                    'website_id' => '',
+                    'thumb' => $add_arr['ad_img'],
+                    'typeid' => $add_arr['ad_type'],
+                    'ad_tag' => '',
+                ];
+                $add_arr['ad'] = json_encode($ad,true);
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             default:
                 break;
         }
-        $component_head_code = [
-            'component_type' => $add_arr['component_type'],
-            'type_id' => $add_arr['type_id'],
-            'component_name' => $add_arr['component_name'],
-        ];
-        $add_arr['component_column'] = $component_type['com_code'] ?? '';
-        if(isset($component_head_code) && !empty($component_head_code) && is_array($component_head_code)){
-            $add_arr['component_code'] = json_encode($component_head_code,true);
-        }
-        if(isset($component_data) && !empty($component_data) && is_array($component_data)){
-            $add_arr['component_data'] = json_encode($component_data,true);
-        }
-        if($data['type_id'] == 11 || $data['type_id'] == 14){
-            $ad = [
-                'width' => $add_arr['ad_width'],
-                'height' => $add_arr['ad_height'],
-                'name' => '',
-                'price' => '',
-                'introduce' => '',
-                'website_id' => '',
-                'thumb' => $add_arr['ad_img'],
-                'typeid' => $add_arr['ad_type'],
-                'ad_tag' => '',
-            ];
-            $add_arr['ad'] = json_encode($ad);
-        }
-        // return Result::success($add_arr);
-            
+        // return Result::success($add_arr['component_data']);
         $result = Component::insertGetId($add_arr);
         if(empty($result)){ 
             return Result::error('添加失败!');
@@ -1481,7 +1493,7 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(empty($component_type)){
             return Result::error('组件分类不存在!');
         }
-        // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
+       // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
         // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
         $data['type_id'] = intval($data['type_id']);
         $add_arr = [
@@ -1493,20 +1505,23 @@ class PublicRpcService implements PublicRpcServiceInterface
             'component_height' => $data['component_height'],
             'type_id' => intval($data['type_id']),
             'component_keyword' => $data['component_keyword'],
-            'component_column' => $component_type['com_code'],
-        ];        
+        ];
+        $component_head_code = [
+            'component_type' => $add_arr['component_type'],
+            'type_id' => $add_arr['type_id'],
+            'component_name' => $add_arr['component_name'],
+        ];
+        $add_arr['component_code'] = json_encode($component_head_code,true);
         switch($data['type_id']){
             case 1:                         //1:资讯-头条组件;
             case 2:                         //2:资讯-轮播组件;
             case 3:                         //3:资讯-推荐图类组件;
             case 4:                         //4:资讯-最新类组件;
-            case 5:                        //5:资讯-推荐类组件;
-            case 6:                        //6:资讯-热点类组件;
+            case 5:                         //5:资讯-推荐类组件;
+            case 6:                         //6:资讯-热点类组件;
                 $add_arr['level'] = $data['type_id'];
                 $add_arr['img_num'] = intval($data['img_num']);
                 $add_arr['text_num'] = intval($data['text_num']);
-                $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
-                $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
                 $component_data['componentData'] = [
                     'category_id' => '',
                     'level' => $add_arr['level'],
@@ -1514,33 +1529,12 @@ class PublicRpcService implements PublicRpcServiceInterface
                     'textSize' => $data['text_num'] ?? '',
                     'child' => [
                         'id' => '',
-                        'imgSize' => $data['child_imgnum'] ?? '',
-                        'textSize' => $data['child_textnum'] ?? '',
+                        'imgSize' => '',
+                        'textSize' => ''
                     ]
-                ];
-                break;
-            case 14:
-                $add_arr['ad_width'] = intval($data['ad_width']);
-                $add_arr['ad_height'] = intval($data['ad_height']);
-                $add_arr['component_width'] = intval($data['component_height']);
-                $add_arr['component_height'] = intval($data['component_height']);
-                $add_arr['ad_type'] = intval($data['ad_type']);
-                $add_arr['ad_img'] = $data['ad_img'];
-                $add_arr['img_num'] = intval($data['img_num']);
-                $add_arr['text_num'] = intval($data['text_num']);
-                $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
-                $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
-                $component_data['componentData'] = [
-                    'category_id' => '',
-                    'level' => '',
-                    'imgSize' => $data['img_num'] ?? '',
-                    'textSize' => $data['text_num'] ?? '',
-                    'child' => [
-                        'id' => '',
-                        'imgSize' => $data['child_imgnum'] ?? '',
-                        'textSize' => $data['child_textnum'] ?? '',
-                    ]
-                ];
+                ]; 
+                $add_arr['component_data'] = json_encode($component_data, true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 7:                        //7:资讯-栏目类组件;
                 $add_arr['img_num'] = intval($data['img_num']);
@@ -1549,7 +1543,7 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
                 $component_data['componentData'] = [
                     'category_id' => '',
-                    'level' => $add_arr['level'] ?? '',
+                    'level' => '',
                     'imgSize' => $add_arr['img_num'] ?? '',
                     'textSize' => $add_arr['text_num'] ?? '',
                     'child' => [
@@ -1558,6 +1552,8 @@ class PublicRpcService implements PublicRpcServiceInterface
                         'textSize' => $add_arr['child_textnum'] ?? '',
                     ]
                 ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 8:                      //8:列表类组件;
                 $add_arr['pageSize'] = intval($data['pageSize']);
@@ -1568,16 +1564,26 @@ class PublicRpcService implements PublicRpcServiceInterface
                         'pageSize' => $add_arr['pageSize'] ?? '',
                     ]
                 ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 9:                     //9:详情类组件;
                 $component_data['componentData'] = [
                     'article_id' => '',
                 ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 10:                     //10:二级导航类组件;
+                $add_arr['cate_place'] = 1;
+                $add_arr['num'] = intval($data['num']);
                 $component_data['componentData'] = [
-                    'fcat_id' => '',
+                    'pid' => '',
+                    'placeid' => 1,
+                    'num' => $add_arr['num'],
                 ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             case 11:                     //11:广告类;
                 $add_arr['ad_width'] = intval($data['ad_width']);
@@ -1586,48 +1592,67 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $add_arr['component_height'] = intval($data['ad_height']);
                 $add_arr['ad_type'] = intval($data['ad_type']);
                 $add_arr['ad_img'] = $data['ad_img'];
+                $ad = [
+                    'width' => $add_arr['ad_width'],
+                    'height' => $add_arr['ad_height'],
+                    'name' => '',
+                    'price' => '',
+                    'introduce' => '',
+                    'website_id' => '',
+                    'thumb' => $add_arr['ad_img'],
+                    'typeid' => $add_arr['ad_type'],
+                    'ad_tag' => '',
+                ];
+                $add_arr['ad'] = json_encode($ad,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
-            case 12:                     //12:静态资源类;
-                $component_data['componentData'] = [];
-                break; 
             case 13:                     //13:底部导航类;
-                $add_arr['cate_place'] = 0;
-                $add_arr['pageSize'] = intval($data['pageSize']);
                 $component_data['componentData'] = [
-                    'pid' => '',
-                    'placeid' => 1,
-                    'num' => $add_arr['pageSize'],
+                    'fcat_id' => '',
+                ];
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
+                break;
+            case 14:
+                $add_arr['ad_width'] = intval($data['ad_width']);
+                $add_arr['ad_height'] = intval($data['ad_height']);
+                $add_arr['component_width'] = intval($data['component_width']);
+                $add_arr['component_height'] = intval($data['component_height']);
+                $add_arr['ad_type'] = intval($data['ad_type']);
+                $add_arr['ad_img'] = $data['ad_img'];
+                $add_arr['img_num'] = intval($data['img_num']);
+                $add_arr['text_num'] = intval($data['text_num']);
+                $add_arr['child_imgnum'] = intval($data['child_imgnum'] ?? null);
+                $add_arr['child_textnum'] = intval($data['child_textnum'] ?? null);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'level' => '',
+                    'imgSize' => $data['img_num'] ?? '',
+                    'textSize' => $data['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => $data['child_imgnum'] ?? '',
+                        'textSize' => $data['child_textnum'] ?? '',
+                    ]
+                ];
+                $ad = [
+                    'width' => $add_arr['ad_width'],
+                    'height' => $add_arr['ad_height'],
+                    'name' => '',
+                    'price' => '',
+                    'introduce' => '',
+                    'website_id' => '',
+                    'thumb' => $add_arr['ad_img'],
+                    'typeid' => $add_arr['ad_type'],
+                    'ad_tag' => '',
                 ];
+                $add_arr['ad'] = json_encode($ad,true);
+                $add_arr['component_data'] = json_encode($component_data,true);
+                $add_arr['component_column'] = $component_type['com_code'] ?? '';
                 break;
             default:
                 break;
         }
-        $component_head_code = [
-            'component_type' => $add_arr['component_type'],
-            'type_id' => $add_arr['type_id'],
-            'component_name' => $add_arr['component_name'],
-        ];
-        $add_arr['component_column'] = $component_type['com_code'] ?? '';
-        if(isset($component_head_code) && !empty($component_head_code) && is_array($component_head_code)){
-            $add_arr['component_code'] = json_encode($component_head_code,true);
-        }
-        if(isset($component_data) && !empty($component_data) && is_array($component_data)){
-            $add_arr['component_data'] = json_encode($component_data,true);
-        }
-        if($data['type_id'] == 11 || $data['type_id'] == 14){
-            $ad = [
-                'width' => $add_arr['ad_width'],
-                'height' => $add_arr['ad_height'],
-                'name' => '',
-                'price' => '',
-                'introduce' => '',
-                'website_id' => '',
-                'thumb' => $add_arr['ad_img'],
-                'typeid' => $add_arr['ad_type'],
-                'ad_tag' => '',
-            ];
-            $add_arr['ad'] = json_encode($ad);
-        }
         $result =  Component::where('id',$id)->update($add_arr);
         if(empty($result)){ 
             Db::rollBack();