Просмотр исходного кода

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

LiuJ 6 месяцев назад
Родитель
Сommit
6217c3d811

+ 770 - 54
app/JsonRpc/PublicRpcService.php

@@ -36,6 +36,12 @@ use App\Constants\ErrorCode;
 use GuzzleHttp\Client;
 use GuzzleHttp\Exception\GuzzleException;
 use App\Model\SectorPlace;
+use App\Model\ComponentType;
+use App\Model\Article;
+use App\Model\WebsiteCategory;
+use App\Model\AdPlace;
+use App\Model\WebsiteImg;
+
 #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class PublicRpcService implements PublicRpcServiceInterface
 {
@@ -1008,15 +1014,20 @@ class PublicRpcService implements PublicRpcServiceInterface
         } else {
             $size_id = [];
         }
+        if(isset($data['page_type']) && !empty($data['page_type'])){
+             array_push($where, ['sector.page_type', 'like', '%' . $data['page_type'] . '%']);
+        }
         $result = Sector::when(!empty($size_id), function ($query) use ($size_id) {
-                $query->whereIn('size_id', $size_id);
+                $query->whereIn('sector.size_id', $size_id);
             })
             ->leftJoin('size', 'size.id', '=', 'sector.size_id')
             ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
             ->leftJoin('template_class', 'template_class.class_id', '=', 'template.template_class_id') 
+            ->leftJoin('sector_place', 'sector_place.sector_type', '=', 'sector.place_type')
             ->where($where)
-            ->select('sector.*', 'size.width','size.height','template_class.name as class_name','template.template_name')
-            
+            ->where('sector_place.type_id', 1)
+            ->select('sector.*', 'size.width', 'size.height', 'template_class.name as class_name', 'template_class.class_id', 'template.template_name',
+                     'sector_place.name as place_name', 'sector_place.sector_img as place_img')
             ->orderBy('sector.id', 'desc')
             ->paginate($data['page_size'], ['*'], 'page', $data['page']);
         if(empty($result)){
@@ -1157,6 +1168,16 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(!empty($sector_id)){
             return Result::error('通栏编号已存在!');
         }
+        $data['status'] = 0;
+        // 通栏分类:1:资讯类:2:通栏广告类;3:混合类;4:头条类;5:轮播图类;
+        $sector_code = [
+            'sectorName' => $data['sector_name'],
+            'sectorId' => $data['sector_id'],
+            'sectorType' => $data['sector_type'],
+            'sectorPlace' => $data['place_type'],
+        ];
+        // return Result::success($sector_code);
+         $data['sector_code'] = json_encode($sector_code);
         $result = Sector::insertGetId($data);
         if (empty($result)) {
             return Result::error('添加失败');
@@ -1199,6 +1220,14 @@ class PublicRpcService implements PublicRpcServiceInterface
                 return Result::error('通栏编号已存在!');
             }
         }
+        $sector_code = [
+            'sectorName' => strval($data['sector_name']),
+            'sectorId' => intval($data['sector_id']),
+            'sectorType' => intval($data['sector_type']),
+            'sectorPlace' => intval($data['place_type']),
+        ];
+        // return Result::success($sector_code);
+        $data['sector_code'] = json_encode($sector_code);
         // 对传入的 page_type 数组进行去重、转换为整数并重新索引
         $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
         $data['page_type'] = json_encode($data['page_type']);
@@ -1217,58 +1246,438 @@ class PublicRpcService implements PublicRpcServiceInterface
     }
     public function getComponentList(array $data): array
     {
-        var_dump($data, '---------');
         $where = [];
-        // $where[] = ['sector.id', '=', $data['id']];
-        if (!empty($data['template_class_id'])) {
-            $where['template_class.id'] = $data['template_class_id'];
+        if (isset($data['component_name']) && !empty($data['component_name'])) {
+            array_push($where, ['component.component_name', 'like', '%' . $data['component_name'] . '%']);
+        }
+        if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])) {
+            array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
+            array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
+        } else if (isset($data['width']) && !empty($data['width'])) {
+            array_push($where, ['component.component_width', 'like', '%' . $data['width'] . '%']);
+        } else if (isset($data['height']) && !empty($data['height'])) {
+            array_push($where, ['component.component_height', 'like', '%' . $data['height'] . '%']);
+        } else {
         }
-        if (!empty($data['component_name'])) {
-            $where['component.component_name'] = $data['component_name'];
+        if(isset($data['type_id']) && !empty($data['type_id'])){
+            $where['component.type_id'] = $data['type_id'];
         }
-        if (!empty($data['sector_id'])) {
-            $where['sector.id'] = $data['sector_id'];
-        };
-
         $result = Component::where($where)
-            ->leftJoin('template', 'template.id', '=', 'component.template_id')
-            ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
-            ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
-            ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'template_class.id as template_class_id', 'sector.sector_name as sector_name', 'component.*', 'sector.id as sector_id') // 修改这一行)
-            ->orderBy('sector.updated_at', 'desc')
-            ->orderBy('sector.created_at', 'desc')
+            ->leftJoin('component_type','component_type.id','=','component.type_id')
+            ->select( 'component.*', 'component_type.com_typename')
+            ->orderBy('component.updated_at', 'desc')
             ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
+        if(empty($result)){
+            return Result::error('暂无数据');
+        }
         return Result::success($result);
     }
     public function getComponentInfo(array $data): array
     {
-        $where = [];
+        $where = ['component.id'=>$data['id']];
+
         $result = Component::where($where)
-            ->leftJoin('template', 'template.id', '=', 'component.template_id')
-            ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
-            ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
-            ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
+            ->leftJoin('component_type','component_type.id','=','component.type_id')
+            ->select(  'component.*','component_type.com_typename')
             ->get();
+        if(empty($result)){
+            return Result::error('暂无数据');
+        }
+
         return Result::success($result);
     }
+    /*
+    新增组件
+    */
     public function addComponent(array $data): array
     {
         unset($data['user_id']);
-        $result = Component::insertGetId($data);
-        if ($result) {
-            return Result::success($result);
-        } else {
-            return Result::error('添加失败');
+        $component_id = Component::where('component_type',$data['component_type'])->first();
+        if(!empty($component_id)){
+            return Result::error('组件编号已存在!');
+        }
+        $component_type = ComponentType::where('id',$data['type_id'])->first();
+        if(empty($component_type)){
+            return Result::error('组件分类不存在!');
+        }
+        // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
+        // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
+        $data['type_id'] = intval($data['type_id']);
+        $add_arr = [
+            // 'template_id' => intval($data['template_id']),
+            'component_type' => intval($data['component_type']),
+            'component_name' => $data['component_name'],
+            'component_img' => $data['component_img'],
+            'component_width' => $data['component_width'],
+            'component_height' => $data['component_height'],
+            'type_id' => intval($data['type_id']),
+            'component_keyword' => $data['component_keyword'],
+        ];
+        $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:资讯-热点类组件;
+                $add_arr['level'] = $data['type_id'];
+                $add_arr['img_num'] = intval($data['img_num']);
+                $add_arr['text_num'] = intval($data['text_num']);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'level' => $add_arr['level'],
+                    'imgSize' => $data['img_num'] ?? '',
+                    'textSize' => $data['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => '',
+                        'textSize' => ''
+                    ]
+                ]; 
+                $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']);
+                $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' => $add_arr['img_num'] ?? '',
+                    'textSize' => $add_arr['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => $add_arr['child_imgnum'] ?? '',
+                        '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']);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'pageType' => [
+                        'page' => 1,
+                        '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'] = [
+                    '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']);
+                $add_arr['ad_height'] = intval($data['ad_height']);
+                $add_arr['component_width'] = intval($data['ad_width']);
+                $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 13:                     //13:底部导航类;
+                $component_data['componentData'] = [
+                    '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;
+        }
+        // return Result::success($add_arr['component_data']);
+        $result = Component::insertGetId($add_arr);
+        if(empty($result)){ 
+            return Result::error('添加失败!');
         }
+        return Result::success($result);
     }
     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('组件不存在!');
+        }
+        $result = Component::where('id',$data['id'])->delete();
+        if(empty($result)){
+            return Result::error('删除失败!');
+        }
         return Result::success($result);
     }
     public function updateComponent(array $data): array
     {
-        $result = Component::where('id', $data['id'])->update($data);
+        unset($data['user_id']);
+        $id = $data['id'];
+        unset($data['id']);
+        $component_id = Component::where('id','!=',$id)->where('component_type',$data['component_type'])->first();
+        if(!empty($component_id) || $component_id != null){
+            return Result::error('组件编号已存在!');
+        }
+        $component_type = ComponentType::where('id',$data['type_id'])->first();
+        if(empty($component_type)){
+            return Result::error('组件分类不存在!');
+        }
+       // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
+        // 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
+        $data['type_id'] = intval($data['type_id']);
+        $add_arr = [
+            // 'template_id' => intval($data['template_id']),
+            'component_type' => intval($data['component_type']),
+            'component_name' => $data['component_name'],
+            'component_img' => $data['component_img'],
+            'component_width' => $data['component_width'],
+            'component_height' => $data['component_height'],
+            'type_id' => intval($data['type_id']),
+            'component_keyword' => $data['component_keyword'],
+        ];
+        $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:资讯-热点类组件;
+                $add_arr['level'] = $data['type_id'];
+                $add_arr['img_num'] = intval($data['img_num']);
+                $add_arr['text_num'] = intval($data['text_num']);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'level' => $add_arr['level'],
+                    'imgSize' => $data['img_num'] ?? '',
+                    'textSize' => $data['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => '',
+                        'textSize' => ''
+                    ]
+                ]; 
+                $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']);
+                $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' => $add_arr['img_num'] ?? '',
+                    'textSize' => $add_arr['text_num'] ?? '',
+                    'child' => [
+                        'id' => '',
+                        'imgSize' => $add_arr['child_imgnum'] ?? '',
+                        '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']);
+                $component_data['componentData'] = [
+                    'category_id' => '',
+                    'pageType' => [
+                        'page' => 1,
+                        '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'] = [
+                    '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']);
+                $add_arr['ad_height'] = intval($data['ad_height']);
+                $add_arr['component_width'] = intval($data['ad_width']);
+                $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 13:                     //13:底部导航类;
+                $component_data['componentData'] = [
+                    '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;
+        }
+        $cll_column = [
+            'img_num' => null,
+            'text_num' => null,
+            'child_imgnum' => null,
+            'child_textnum' => null,
+            'category_id' => null,
+            'child_id' => null,
+            'num' => null,
+            'level' => null,
+            'fcatid' => null,
+            'article_id' => null,
+            'cate_place' => null,
+            'pageSize' => null,
+            'ad_img' => null,
+            'ad_width' => null,
+            'ad_height' => null,
+            'ad' => '',
+            'ad_type' => null,
+        ];
+        $add_arr = array_merge($cll_column,$add_arr);
+        $result =  Component::where('id',$id)->update($add_arr);
+        if(empty($result)){ 
+            Db::rollBack();
+            return Result::error('修改失败!');
+        }
         return Result::success($result);
     }
 
@@ -1524,33 +1933,340 @@ class PublicRpcService implements PublicRpcServiceInterface
         }
         return Result::success($template);
     }
+
+    /**
+     * 通栏版式管理-获取通栏版式列表
+     */ 
+    public function getSectorPlaceList(array $data): array
+    {
+        $where['sector_place.type_id'] = $data['type_id'];
+        if(isset($data['component_num']) && !empty($data['component_num'])){
+            $where['sector_place.component_num'] = $data['component_num'];
+        }
+        if(isset($data['sector_type']) && !empty($data['sector_type'])){
+            $where['sector_place.sector_type'] = $data['sector_type'];
+        }
+        // if(isset($data['component_type']) && !empty($data['component_type'])){
+        //     $where['sector_place.component_type'] = $data['component_type'];
+        // }
+        if(isset($data['name']) && !empty($data['name'])){
+            array_push($where,['sector_place.name', 'like', '%'.$data['name'].'%']);
+        } 
+        if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
+            $size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->pluck('id');
+        } else if( isset($data['width']) && !empty($data['width'])){
+            $size_id = Size::where('width','like','%' .$data['width'].'%')->pluck('id');
+        }else if( isset($data['height']) && !empty($data['height'])){
+            $size_id = Size::where('height','like','%' .$data['height'].'%')->pluck('id');
+        }else{
+            $size_id = [];
+        }
+        $sector_place = SectorPlace::where($where)
+            ->when(!empty($size_id), function ($query) use ($size_id) {
+                $query->whereIn('sector_place.size_id', $size_id);
+            })
+            ->leftJoin('size','sector_place.size_id','=','size.id')
+            ->select('sector_place.*','size.width','size.height');
+        $result['count'] = $sector_place->count();
+        $result['row'] =$sector_place->paginate($data['page_size'], ['*'], 'page', $data['page']);
+        if(empty($result['count'])){
+            return Result::error("暂无相关版式数据!");
+        }
+        return Result::success($result);
+    }
+    /**
+     * 通栏版式管理-添加通栏版式
+     */ 
+    public function addSectorPlace(array $data): array
+    {
+        // 1:通栏;2:组件;
+        if($data['type_id'] == 1){
+            $sector_place = SectorPlace::where('sector_type', $data['type'])->first(); 
+            if(!empty($sector_place)){
+                return Result::error('通栏版式类别编号已存在!');
+            }
+            $data = [
+                'name' => $data['name'],
+                'component_num' => $data['component_num'], 
+                'size_id' => $data['size_id'],
+                'sort_id' => 0,
+                'sector_img' => $data['sector_img'],
+                'sector_type' => $data['type'],
+                'type_id' => $data['type_id'],
+                'status' => 0,
+            ];
+        }else{
+            $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first(); 
+            if(empty($sector_type)){
+                return Result::error('通栏版式类别不存在!');
+            }
+            // $com_query = SectorPlace::where('type_id',2);
+            // ->query(function($query) use ($data){
+            //     $query->where('component_type', $data['type'])
+            //         ->Subquery(function($subQuery) use ($data) {
+            //             $subQuery->where('sector_type', $data['sector_type'])
+            //                      ->where('sort_id', $data['sort']);
+            //         });
+            // })                                                               //若是组件版式编号或者组件版式位置重复用此语句筛选
+            // ->where('sector_type',$data['sector_type'])                      //若是组件版式编号在同一个通栏版式下不重复就行,则启用此语句
+            $component =  SectorPlace::where('type_id',2)->where('component_type',$data['type'])->first();
+            if(!empty($component)){
+                return Result::error('组件版式类别编号已存在!');
+            }
+            // $com_query = clone $com_query;
+            $com_num =  SectorPlace::where('type_id',2)->where('sector_type',$data['sector_type'])->count('sort_id');
+            // return Result::success($com_num);
+            if($sector_type['component_num'] = $com_num){
+                $sector = SectorPlace::where('sector_type',$data['sector_type'])->where('type_id',1)->update(['status'=>1]);
+                if(empty($sector)){
+                    return Result::error('通栏版式状态修改失败!');
+                }
+            }
+            $data = [
+                'name' => $data['name'],
+                'component_num' => 0, 
+                'size_id' => $data['size_id'],
+                'sort_id' => $data['sort_id'],
+                'sector_img' => $data['sector_img'],
+                'component_type' => $data['type'],
+                'type_id' => $data['type_id'],
+                'sector_type' => $data['sector_type'],
+            ];
+        }
+        
+        $result = SectorPlace::insertGetId($data);
+        if(empty($result)){
+            return Result::error('添加失败!');
+        }
+        return Result::success('添加成功!',$result);
+    }
+    /**
+     * 通栏版式管理-修改通栏版式
+     */ 
+    public function upSectorPlace(array $data): array
+    {
+        $id = $data['id'];
+       // 1:通栏;2:组件;
+        if($data['type_id'] == 1){
+            $sector_place = SectorPlace::where('id','!=',$id)->where('sector_type', $data['type'])->where('type_id',1)->first(); 
+            if(!empty($sector_place)){
+                return Result::error('通栏版式类别编号已存在!');
+            }
+            $data = [
+                'name' => $data['name'],
+                'component_num' => $data['component_num'], 
+                'size_id' => $data['size_id'],
+                'sort_id' => 0,
+                'sector_img' => $data['sector_img'],
+                'sector_type' => $data['type'],
+                'type_id' => $data['type_id'],
+            ];
+        }else{
+            $sector_type = SectorPlace::where('sector_type', $data['sector_type'])->where('type_id',1)->first(); 
+            if(empty($sector_type)){
+                return Result::error('通栏版式类别不存在!');
+            }
+            $component = SectorPlace::where('id','!=',$id) 
+            ->where('component_type', $data['type'])
+            ->where('type_id',2)
+            ->first();
+            if(!empty($component)){
+                return Result::error('组件版式类别编号已存在!');
+            }
+            $data = [
+                'name' => $data['name'],
+                'component_num' => 0, 
+                'size_id' => $data['size_id'],
+                'sort_id' => $data['sort_id'],
+                'sector_img' => $data['sector_img'],
+                'component_type' => $data['type'],
+                'type_id' => $data['type_id'],
+                'sector_type' => $data['sector_type'],
+            ];
+        }
+        
+        $result = SectorPlace::where('id',$id)->update($data);
+        if(empty($result)){
+            return Result::error('修改失败!');
+        }
+        return Result::success('修改成功!',$result);
+    }
     /**
-     * 自助建站-通栏管理-获取通栏位置
+     * 通栏版式管理-删除通栏版式
+     */ 
+    public function delSectorPlace(array $data): array
+    {
+        $sector_place = SectorPlace::where('id',$data['id'])->first();
+        if(empty($sector_place)){
+            return Result::error('通栏版式不存在!');
+        }
+        if($sector_place['type_id'] == 1){
+            $sector = Sector::where('place_type', $sector_place['sector_type'])->first();
+            $component = SectorPlace::where('sector_type', $sector_place['sector_type'])
+            ->where('type_id',2)
+            ->first(); 
+            if(!empty($sector) || !empty($component)){
+                return Result::error('通栏版式分类已应用,暂不可删除!');
+            }
+        }else{
+            $sector = Component::where('place_type', $sector_place['component_type'])->first();
+            if(!empty($sector)){
+                return Result::error('组件版式分类已应用,暂不可删除!');
+            }
+            $component_num = SectorPlace::where('sector_type', $sector_place['sector_type'])
+            ->where('type_id',1)->update(['status'=> 0]);
+            if(empty($component_num)){
+                return Result::error('通栏版式状态修改失败!');
+            }
+        }
+       $result = SectorPlace::where('id',$data['id'])->delete();
+        if(empty($result)){
+            return Result::error('删除失败!');
+        }
+        return Result::success('删除成功!');
+    }
+    /**
+     * 自助建站-通栏版式管理-获取通栏版式详情
      */
-    public function getSectorPlace(array $data): array
-    {
-        if(isset($data['sector_num']) && !empty($data['sector_num'])){
-            $where['t.sector_num'] = $data['sector_num'];
-            $template = DB::table(DB::raw('(
-                SELECT 
-                    sp.*, 
-                    s.width, 
-                    s.height,
-                    ROW_NUMBER() OVER (PARTITION BY sp.type ORDER BY sp.id DESC) as rn
-                FROM sector_place sp
-                LEFT JOIN size s ON sp.size_id = s.id
-            ) as t'))
-            ->where('rn', 1)
-            ->where($where)
-            ->select('t.*')
-            ->get();
+    public function getSectorPlaceInfo(array $data): array
+    {
+        $result = SectorPlace::where('sector_place.id',$data['id'])
+        ->leftJoin('size','sector_place.size_id','=','size.id') 
+        ->select('sector_place.*','size.width','size.height')
+        ->first();
+        if(empty($result)){
+            return Result::error('通栏版式不存在!');
         }
-        if(isset($data['type']) && !empty($data['type'])){
-            $template = SectorPlace::where('type', $data['type'])->get()->all();
+        return Result::success($result);
+    }
+    /**
+     * 自助建站-通栏版式管理-获取通栏版式列表
+     */
+    public function getSectorPlaceSort(array $data): array
+    {
+        $sector = SectorPlace::where('sector_type',$data['sector_type'])->first();
+        if(empty($sector)){
+            return Result::error('通栏版式不存在!');
+        }
+        $component = SectorPlace::where('type_id',2)->where('sector_type',$sector['sector_type'])->pluck('sort_id')->toArray();
+        if(count($component) < $sector['component_num']){
+            // 根据 $sector['component_num'] 的值生成对应元素数量的数组
+            if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
+                $num = intval($sector['component_num']);
+                if ($num > 0 && $num <= 10) {
+// 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
+                    $sector_arr = range(1, $num);
+                } else {
+                    $sector_arr = [];
+                }
+            } else {
+                $sector_arr = [];
+            }
+            // 获取 $sector_arr 中不在 $component 里的元素
+            $sort = array_diff($sector_arr, $component);
+            // return Result::success($sort);
+        }
+        if(!empty($sort)){
+            $sort = array_values(array_map(function($value) {
+                return ['id' => $value];
+            }, $sort));
+        }else{
+            return Result::error("组件版式数量已达上限!");
         }
-        if(empty($template)){
-            return Result::error('未查询到通栏位置相关模版!');
+        return Result::success($sort);
+    }
+    /**
+     * 获取所有通栏版式
+     */ 
+    public function getAllSectorPlace(array $data): array
+    {
+        $where['type_id'] = $data['type_id'];
+        if($data['type_id'] == 1){
+            $where['status'] = 1;
+        }
+        if(isset($data['sector_type']) && !empty($data['sector_type'])){
+            $where['sector_type'] = $data['sector_type'];
+        }
+        if(isset($data['component_num']) && !empty($data['component_num'])){
+            $where['component_num'] = $data['component_num'];
+        }
+       $sector_place = SectorPlace::where($where)
+       ->leftJoin('size','sector_place.size_id','=','size.id') 
+       ->select('sector_place.*','size.width','size.height')
+       ->get()->all();
+       if(empty($sector_place)){
+            return Result::error('通栏版式不存在!');
+       }
+       return Result::success($sector_place);
+    }
+    /**
+     * 组件管理-获取组件类型
+     */
+    public function getComponentType(array $data): array
+    {
+        $where = [];
+        if(isset($data['id']) && !empty($data['id'])){
+            $where['id'] = $data['id'];
         }
-        return Result::success($template);
+        $component_type = ComponentType::where($where)->get()->all();
+        if(empty($component_type)){
+            return Result::error('组件类型不存在!');
+        }
+        if(count($component_type) == 1){
+            $all_code = json_decode($component_type[0]['com_code'] ?? '',true);
+            $component_type[0]['all_code'] = $all_code['listType'] ?? [];
+            $result = $component_type[0];
+        }else{
+            $result = $component_type;
+        }
+       
+        if(empty($component_type)){
+            return Result::error('组件类型不存在!');
+        }
+        return Result::success($component_type);
+    }
+    /**
+     * 组件管理-获取所有组件
+     */
+    public function getAllComponent(array $data): array
+    {
+        $where = [];
+        if(isset($data['sector_id']) && !empty($data['sector_id'])){
+            $where['component.sector_id'] = $data['sector_id'];
+        }
+        if(isset($data['sort_id']) && !empty($data['sort_id'])){
+            $where['component.sort_id'] = $data['sort_id'];
+        }
+        $component = Component::where($where)->leftJoin('size','component.size_id','=','size.id')
+        ->select('component.*','size.width','size.height')
+        ->get()->all();
+        if(empty($component)){
+            return Result::error('组件不存在!');
+        }
+        return Result::success($component);
+    }
+    /**
+     * 自助建站-流程管理-获取所有通栏
+     */
+    public function getAllSector(array $data): array
+    {
+        $where = [];
+         if(isset($data['template_id']) && !empty($data['template_id'])){
+            $where['template_id'] = $data['template_id'];
+        }
+        if(isset($data['page_type']) && !empty($data['page_type'])){
+            array_push($where,['page_type', 'like', '%'.$data['page_type'].'%']);
+        }
+        if(isset($data['status']) && !empty($data['status'])){
+            array_push($where,['status','!=',0]);
+        }
+        $sector = Sector::where($where)
+        ->leftJoin('size','sector.size_id','=','size.id')
+        ->select('sector.*','size.width','size.height')
+        ->get()->all();
+        if(empty($sector)){
+            return Result::error('通栏不存在!');
+        }
+        return Result::success($sector);
     }
 }

+ 18 - 1
app/JsonRpc/PublicRpcServiceInterface.php

@@ -184,5 +184,22 @@ interface PublicRpcServiceInterface
     public function getAllTemplate(array $data): array;
     public function getWebsiteTemplate(array $data): array;
     public function getAllSize(array $data): array;
-    public function getSectorPlace(array $data): array;
+
+    // 通栏版式管理-获取通栏版式列表
+    public function getSectorPlaceList(array $data): array;
+    public function addSectorPlace(array $data): array;
+    public function upSectorPlace(array $data): array;
+    public function delSectorPlace(array $data): array;
+    public function getSectorPlaceInfo(array $data): array;
+    // 通栏版式管理-通栏版式位置
+    public function getSectorPlaceSort(array $data): array;
+    //-所有通栏版式
+    public function getAllSectorPlace(array $data): array;
+    //组件管理-获取组件类型
+    public function getComponentType(array $data): array;
+    //自助建站-流程管理-获取所有通栏
+    public function getAllSector(array $data): array;
+    //组件管理-获取所有组件
+    public function getAllComponent(array $data): array;
+
 }

+ 54 - 44
app/JsonRpc/WebsiteService.php

@@ -664,43 +664,45 @@ class WebsiteService implements WebsiteServiceInterface
      * @return array
      */
 
-    public function getWebsiteModelCategory(array $data): array
-    {
-        // return Result::success($data);
-        $website_id = [
-            'website_id' => $data['website_id'],
-        ];
-        // 初始化 $pid 数组
-        // $pid = [];
-        // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
-        $pidQuery = WebsiteCategory::where($website_id)
-            ->where('pid', '!=', 0)
-            ->orderBy('sort')
-            ->select('pid', 'category_id', 'alias', 'aLIas_pinyin');
-        $pid = $pidQuery->pluck('pid');
-        $pid = array_values(array_unique($pid->toArray()));
-        // 构建查询语句
-        $query = WebsiteCategory::where($website_id)
-            ->where('pid', $data['pid'])
-            ->offset($data['placeid'])
-            ->limit($data['num'])
-            ->orderBy('sort');
-        // 如果 $pid 数组不为空,添加 CASE WHEN 条件
-        if (!empty($pid)) {
-            $placeholders = implode(',', array_fill(0, count($pid), '?'));
-            $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
-        } else {
-            // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
-            $query->select('website_category.*', DB::raw('0 as children_count'));
-        }
-
-        // 执行查询
-        $placeid = $data['placeid'] - 1;
-        $result = $query->offset($placeid)->limit($data['num'])->get();
-
-        if (!empty($result)) {
-            $pidResults = $pidQuery->get();
-            if (isset($data['type']) && $data['type'] == 1) {
+     public function getWebsiteModelCategory(array $data): array
+     {
+         // return Result::success($data);
+         $website_id = [
+             'website_id' => $data['website_id'],
+         ];
+         // 初始化 $pid 数组
+         // $pid = [];
+         // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
+         $pidQuery = WebsiteCategory::where($website_id)
+             ->where('pid', '!=', 0)
+             ->orderBy('sort')
+             ->select('pid', 'category_id', 'alias','aLIas_pinyin');
+         $pid = $pidQuery->pluck('pid');
+         $pid = array_values(array_unique($pid->toArray()));
+         // 构建查询语句
+         $query = WebsiteCategory::where($website_id)
+             ->where('pid', $data['pid'])
+             ->offset($data['placeid'])
+             ->limit($data['num'])
+             ->orderBy('sort')
+             ->orderBy('updated_at','desc')
+             ;
+         // 如果 $pid 数组不为空,添加 CASE WHEN 条件
+         if (!empty($pid)) {
+             $placeholders = implode(',', array_fill(0, count($pid), '?'));
+             $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
+         } else {
+             // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
+             $query->select('website_category.*', DB::raw('0 as children_count'));
+         }
+ 
+         // 执行查询
+         $placeid = $data['placeid'] - 1;
+         $result = $query->offset($placeid)->limit($data['num'])->get();
+ 
+         if (!empty($result)) {
+             $pidResults = $pidQuery->get();
+             if(isset($data['type']) && $data['type'] == 1){
                 $result = $result->map(function ($item) use ($pidResults) {
                     $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
                         if (!empty($child)) {
@@ -1549,6 +1551,7 @@ class WebsiteService implements WebsiteServiceInterface
             //            ->select("website_category.*", "department.name as department_name", "district.name as city_name")
             //            ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
             ->orderBy("sort", "asc")
+            ->orderBy("updated_at","desc")
             ->get();
 
         //        $count = WebsiteCategory::where($where)
@@ -1880,8 +1883,13 @@ class WebsiteService implements WebsiteServiceInterface
         //查询所有网站模板信息
         $query = Website::where('website.status', 1)
             ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
-            ->leftJoin("template", "template.id", "website_template_info.template_id")
-            ->leftJoin("template_class", "template_class.id", "template.template_class_id")
+            ->leftJoin("template", "template.template_id", "website_template_info.template_id")
+            ->leftJoin("template_class", "template_class.class_id", "template.template_class_id")
+            ->leftJoin('website_column', 'website_column.id', 'website.website_column_id')
+            ->leftJoin('website_column as parent_column', function ($join) {
+                $join->on('website_column.pid', '=', 'parent_column.id')
+                    ->where('website_column.pid', 2);
+            })
             ->select(
                 "website_template_info.id",
                 "template_class.name",
@@ -1892,6 +1900,8 @@ class WebsiteService implements WebsiteServiceInterface
                 "website_template_info.created_at",
                 "website_template_info.updated_at",
                 "website_template_info.page_type",
+                'website_column.column_name',
+                'parent_column.column_name as parent_column_name',
                 DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
                 "template.template_name"
             );
@@ -1947,14 +1957,14 @@ class WebsiteService implements WebsiteServiceInterface
         if (empty($foot_type)) {
             return Result::error("请先关联底部导航池!", 0);
         }
-        if (!in_array(1, $foot_type)) {
-            $missingTypes[] = "列表型底部导航";
-        }
-        if (!in_array(0, $foot_type)) {
+        // if (!in_array(1, $foot_type) ) {
+        //     $missingTypes[] = "列表型底部导航";
+        // }
+        if (!in_array(0, $foot_type) ) {
             $missingTypes[] = "内容型底部导航";
         }
         if (!empty($missingTypes)) {
-            $errorMessage = "请先添加" . implode(" 和 ", $missingTypes) . "!";
+            $errorMessage = "请先添加" . $missingTypes . "!";
             return Result::error($errorMessage, 0);
         }
         $result['foot_type'] = $foot_type;

+ 27 - 0
app/Model/ComponentType.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class  ComponentType extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'component_type';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 27 - 0
app/Model/LevelUser.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class LevelUser extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'level_user';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}