Эх сурвалжийг харах

修改接口:修改组件、删除组件的接口

15313670163 15 цаг өмнө
parent
commit
9454e7294d

+ 263 - 26
app/JsonRpc/PublicRpcService.php

@@ -1295,6 +1295,9 @@ class PublicRpcService implements PublicRpcServiceInterface
             ->get();
         return Result::success($result);
     }
+    /*
+    新增组件
+    */
     public function addComponent(array $data): array
     {
         unset($data['user_id']);
@@ -1305,61 +1308,140 @@ class PublicRpcService implements PublicRpcServiceInterface
         $component_id = Component::where('component_type',$data['component_type'])->first();
         if(!empty($component_id)){
             return Result::error('组件编号已存在!');
-
         }
         $component_place = SectorPlace::where('sector_type',$sector['place_type'])
         ->where('type_id',2)->where('sort_id',$data['sort_id'])->first();
-        // return Result::success($component_place);
-         // 组件分类:2:资讯-轮播组件;3:资讯-推荐类组件;4:资讯-热点类组件;5:广告类组件;
-        // 6:列表类组件;7:详情类组件;8:底部导航类组件;9:栏目资讯类组件;10:最新资讯类;11:导航栏类;',
+        // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐类组件;4:资讯-热点类组件;5:栏目资讯类;
+        // 6:广告类组件;7:列表类组件;8:详情类组件;9:底部导航类组件;10:最新资讯类组件;11:导航栏类;
         if(is_array($data['page_type']) && !empty($data['page_type'])){
             $page_type = array_values(array_map('intval',$data['page_type']));
             $data['page_type'] = json_encode($page_type,true);
         }
         $data['type_id'] = intval($data['type_id']);
         $add_arr = [
-            'template_id' => $data['template_id'],
-            'sector_id' => $data['sector_id'],
+            'template_id' => intval($data['template_id']),
+            'sector_id' => intval($data['sector_id']),
             'page_type' => $data['page_type'],
-            'component_type' => $data['component_type'],
+            'component_type' => intval($data['component_type']),
             'component_name' => $data['component_name'],
             'component_img' => $data['component_img'],
             'place_type' => $component_place['component_type'],
             'size_id' => $component_place['size_id'],
-            'type_id' => $data['type_id'],
-            'sort_id' => $data['sort_id'],
+            'type_id' => intval($data['type_id']),
+            'sort_id' => intval($data['sort_id']),
         ];
-        
         switch($data['type_id']){
             case 1:                         //1:资讯-头条组件;
             case 2:                         //2:资讯-轮播组件;
             case 3:                         //3:资讯-推荐类组件;
             case 4:                         //4:资讯-热点类组件;
             case 10:                        //10:最新资讯类;
-                $add_arr['level'] = $data['level'];
-                $add_arr['img_num'] = $data['img_num'];
-                $add_arr['text_num'] = $data['text_num'];
+                $add_arr['level'] = intval($data['level']);
+                $add_arr['img_num'] = intval($data['img_num']);
+                $add_arr['text_num'] = intval($data['text_num']);
+                $add_arr['child_imgnum'] = intval($data['img_num'] ?? null);
+                $add_arr['child_textnum'] = intval($data['text_num'] ?? null);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'level' => $add_arr['level'] ?? '',
+                    'imgSize' => $add_arr['img_num'] ?? '',
+                    'textSize' => $add_arr['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => $add_arr['child_imgnum'] ?? '',
+                        'textSize' => $add_arr['child_textnum'] ?? '',
+                    ]
+                ];
                 break;
-            case 5:
-                $add_arr['img_num'] = $data['img_num'];
-                $add_arr['text_num'] = $data['text_num'];
+            case 5:                         //5:栏目资讯类组件;
+                $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' => intval($data['level'] ?? ''),
+                    'imgSize' => $add_arr['img_num'] ?? '',
+                    'textSize' => $add_arr['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => $add_arr['child_imgnum'] ?? '',
+                        'textSize' => $add_arr['child_textnum'] ?? '',
+                    ]
+                ];
                 break;
-
             case 7:                      //7:列表类组件;
-                $add_arr['pageSize'] = $data['pageSize'];
+                $add_arr['pageSize'] = intval($data['pageSize']);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'pageType' => [
+                        'page' => 1,
+                        'pageSize' => $add_arr['pageSize'] ?? '',
+                    ]
+                ];
+                break;
+            case 8:                     //8:详情类组件;
+                $component_data['componentData'] = [
+                    'article_id' => '',
+                ];
+                break;
+            case 9:                     //9:底部导航类组件;
+                $component_data['componentData'] = [
+                    'fcat_id' => '',
+                ];
                 break;
             case 11:                     //11:导航栏类;
                 $add_arr['cate_place'] = 0;
-                $add_arr['pageSize'] = $data['pageSize'];
+                $add_arr['pageSize'] = intval($data['pageSize']);
+                $component_data['componentData'] = [
+                    'pid' => '',
+                    'placeid' => 1,
+                    'num' => $add_arr['pageSize'],
+                ];
                 break;
             default:
                 break;
-
         }
-       
-       
+        $component_head_code = [
+            'component_type' => $add_arr['component_type'],
+            'type_id' => $add_arr['type_id'],
+            'component_name' => $add_arr['component_name'],
+            'sort_id' => $add_arr['sort_id'],
+        ];
+        if(isset($data['listType']) && !empty($data['listType']) && is_array($data['listType'])){
+            $list_type['listType'] = $data['listType'];
+            $add_arr['component_column'] = json_encode($list_type,true);
+        }
+        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);
+        }
+
         return Result::success($add_arr);
-        // $result = Component::insertGetId($data);
+        Db::beginTransaction();
+        try{
+            $result = Component::insertGetId($add_arr);
+            if(empty($result)){
+                Db::rollBack();
+                return Result::error('添加失败!');
+            }
+            // $sector_num = Sector::where('sector_id',$add_arr['sector_id'])->first();
+            $component = Component::where('sector_id',$sector['sector_id'])->where('sort_id',$add_arr['sort_id'])->count();
+            if($component == 0){
+                $sector = Sector::where('sector_id',$sector['sector_id'])->update(['status',0]);
+                if(empty($sector)){
+                    Db::rollBack();
+                    return Result::error('通栏不存在!');
+                }
+            }
+            Db::commit();
+        }catch(\Exception $e){
+            Db::rollBack();
+            return Result::error($e->getMessage());
+        }
+        // $result = Component::insertGetId($add_arr);
         if ($result) {
             return Result::success($result);
         } else {
@@ -1368,13 +1450,168 @@ class PublicRpcService implements PublicRpcServiceInterface
     }
     public function delComponent(array $data): array
     {
-        $result = Component::where('id', $data['id'])->delete();
+
+        $component = Component::where('id', $data['id'])->first();
+        if(empty($component)){
+            return Result::error('组件不存在!');
+        }
+        // $sector_num = Sector::where('sector_id',$component['sector_id'])->first();
+        $component_num = Component::where('id','!=',$data['id'])->where('sector_id',$component['sector_id'])
+        ->where('sort_id',$component['sort_id'])->count();
+        Db::beginTransaction();
+        try{
+            $result = Component::where('id',$data['id'])->delete();
+            if(empty($result)){
+                Db::rollBack();
+                return Result::error('删除失败!');
+            }
+            if($component_num == 0){
+                $sector = Sector::where('sector_id',$component['sector_id'])->update(['status',0]);
+                if(empty($sector)){
+                    Db::rollBack();
+                    return Result::error('通栏不存在!');
+                }
+            }
+            Db::commit();
+        }catch(\Exception $e){
+            Db::rollBack();
+            return Result::error($e->getMessage());
+        }
         return Result::success($result);
     }
     public function updateComponent(array $data): array
     {
-        $result = Component::where('id', $data['id'])->update($data);
-        return Result::success($result);
+        unset($data['user_id']);
+        $sector = Sector::where('sector_id',$data['sector_id'])->first();
+        if(empty($sector)){
+            return Result::error('通栏不存在!');
+        }
+        $component_id = Component::function()->first();
+        if(!empty($component_id) || $component_id != null){
+            return Result::error('组件编号已存在!');
+        }
+        return Result::success($component_id);
+        $component_place = SectorPlace::where('sector_type',$sector['place_type'])
+        ->where('type_id',2)->where('sort_id',$data['sort_id'])->first();
+        // return Result::success($component_place);
+        // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐类组件;4:资讯-热点类组件;5:栏目资讯类;
+        // 6:广告类组件;7:列表类组件;8:详情类组件;9:底部导航类组件;10:最新资讯类组件;11:导航栏类;
+        if(is_array($data['page_type']) && !empty($data['page_type'])){
+            $page_type = array_values(array_map('intval',$data['page_type']));
+            $data['page_type'] = json_encode($page_type,true);
+        }
+        $data['type_id'] = intval($data['type_id']);
+        $add_arr = [
+            'template_id' => intval($data['template_id']),
+            'sector_id' => intval($data['sector_id']),
+            'page_type' => $data['page_type'],
+            'component_type' => intval($data['component_type']),
+            'component_name' => $data['component_name'],
+            'component_img' => $data['component_img'],
+            'place_type' => $component_place['component_type'],
+            'size_id' => $component_place['size_id'],
+            'type_id' => intval($data['type_id']),
+            'sort_id' => intval($data['sort_id']),
+        ];
+        
+        switch($data['type_id']){
+            case 1:                         //1:资讯-头条组件;
+            case 2:                         //2:资讯-轮播组件;
+            case 3:                         //3:资讯-推荐类组件;
+            case 4:                         //4:资讯-热点类组件;
+            case 10:                        //10:最新资讯类;
+                $add_arr['level'] = intval($data['level']);
+                $add_arr['img_num'] = intval($data['img_num']);
+                $add_arr['text_num'] = intval($data['text_num']);
+                $add_arr['child_imgnum'] = intval($data['img_num'] ?? null);
+                $add_arr['child_textnum'] = intval($data['text_num'] ?? null);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'level' => $add_arr['level'] ?? '',
+                    'imgSize' => $add_arr['img_num'] ?? '',
+                    'textSize' => $add_arr['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => $add_arr['child_imgnum'] ?? '',
+                        'textSize' => $add_arr['child_textnum'] ?? '',
+                    ]
+                ];
+                break;
+            case 5:                         //5:栏目资讯类组件;
+                $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' => intval($data['level'] ?? ''),
+                    'imgSize' => $add_arr['img_num'] ?? '',
+                    'textSize' => $add_arr['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => $add_arr['child_imgnum'] ?? '',
+                        'textSize' => $add_arr['child_textnum'] ?? '',
+                    ]
+                ];
+                break;
+
+            case 7:                      //7:列表类组件;
+                $add_arr['pageSize'] = intval($data['pageSize']);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'pageType' => [
+                        'page' => 1,
+                        'pageSize' => $add_arr['pageSize'] ?? '',
+                    ]
+                ];
+                break;
+            case 8:                     //8:详情类组件;
+                $component_data['componentData'] = [
+                    'article_id' => '',
+                ];
+                break;
+            case 9:                     //9:底部导航类组件;
+                $component_data['componentData'] = [
+                    'fcat_id' => '',
+                ];
+                break;
+            case 11:                     //11:导航栏类;
+                $add_arr['cate_place'] = 0;
+                $add_arr['pageSize'] = intval($data['pageSize']);
+                $component_data['componentData'] = [
+                    'pid' => '',
+                    'placeid' => 1,
+                    'num' => $add_arr['pageSize'],
+                ];
+                break;
+            default:
+                break;
+
+        }
+        $component_head_code = [
+            'component_type' => $add_arr['component_type'],
+            'type_id' => $add_arr['type_id'],
+            'component_name' => $add_arr['component_name'],
+            'sort_id' => $add_arr['sort_id'],
+        ];
+        if(isset($data['listType']) && !empty($data['listType']) && is_array($data['listType'])){
+            $list_type['listType'] = $data['listType'];
+            $add_arr['component_column'] = json_encode($list_type,true);
+        }
+        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);
+        }
+
+        return Result::success($add_arr);
+        // $result = Component::where('id',$data['id'])->update($add_arr);
+        if ($result) {
+            return Result::success($result);
+        } else {
+            return Result::error('添加失败');
+        }
     }
 
     public function getWebsiteTemplateInfo(array $data)