Переглянути джерело

Merge branch '20250522_diywebfr'

15313670163 3 днів тому
батько
коміт
27b883b028
1 змінених файлів з 107 додано та 120 видалено
  1. 107 120
      app/JsonRpc/PublicRpcService.php

+ 107 - 120
app/JsonRpc/PublicRpcService.php

@@ -39,6 +39,9 @@ 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
 {
@@ -1244,43 +1247,25 @@ class PublicRpcService implements PublicRpcServiceInterface
     public function getComponentList(array $data): array
     {
         $where = [];
-        if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
-            $where['template_class.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['sector_id']) && !empty($data['sector_id'])) {
-            $where['component.sector_id'] = $data['sector_id'];
-        };
         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');
+            array_push($where, ['size.width', 'like', '%' . $data['width'] . '%']);
+            array_push($where, ['size.height', 'like', '%' . $data['height'] . '%']);
         } else if (isset($data['width']) && !empty($data['width'])) {
-            $size_id = Size::where('width', 'like', '%' . $data['width'] . '%')->pluck('id');
+            array_push($where, ['size.width', 'like', '%' . $data['width'] . '%']);
         } else if (isset($data['height']) && !empty($data['height'])) {
-            $size_id = Size::where('height', 'like', '%' . $data['height'] . '%')->pluck('id');
+            array_push($where, ['size.height', 'like', '%' . $data['height'] . '%']);
         } else {
-            $size_id = [];
-        }
-        if(isset($data['page_type']) && !empty($data['page_type'])){
-             array_push($where, ['component.page_type', 'like', '%' . $data['page_type'] . '%']);
         }
         if(isset($data['type_id']) && !empty($data['type_id'])){
             $where['component.type_id'] = $data['type_id'];
         }
-        $result = Component::when(!empty($size_id), function ($query) use ($size_id) {
-            $query->whereIn('component.size_id', $size_id);
-        })
-            ->where($where)
-            ->leftJoin('template', 'template.template_id', '=', 'component.template_id')
-            ->leftJoin('template_class', 'template.template_class_id', '=', 'template_class.class_id') // 添加与 template_class 的关联
-            ->leftJoin('sector', 'sector.sector_id', '=', 'component.sector_id')
-            ->leftJoin('size','size.id','=','component.size_id')
+        $result = Component::where($where)
             ->leftJoin('component_type','component_type.id','=','component.type_id')
-            ->select( 'component.*', 'sector.sector_id','sector.sector_name','template.template_id',
-            'template.template_name','template_class.class_id', 'template_class.name as class_name',
-            'size.width','size.height','component_type.com_typename')
-            ->orderBy('sector.updated_at', 'desc')
+            ->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('暂无数据');
@@ -1292,13 +1277,8 @@ class PublicRpcService implements PublicRpcServiceInterface
         $where = ['component.id'=>$data['id']];
 
         $result = Component::where($where)
-            // ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 去掉这一行
-            ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
-            ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
-            ->leftJoin('size','size.id','=','component.size_id')
             ->leftJoin('component_type','component_type.id','=','component.type_id')
-            ->select( 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*',
-            'size.width','size.height','component_type.com_typename')
+            ->select(  'component.*','component_type.com_typename')
             ->get();
         if(empty($result)){
             return Result::error('暂无数据');
@@ -1312,33 +1292,27 @@ class PublicRpcService implements PublicRpcServiceInterface
     public function addComponent(array $data): array
     {
         unset($data['user_id']);
-        $sector = Sector::where('sector_id',$data['sector_id'])->first();
-        if(empty($sector)){
-            return Result::error('通栏不存在!');
-        }
         $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();
-        // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐类组件;4:资讯-热点类组件;5:栏目资讯类;
-        // 6:广告类组件;7:列表类组件;8:详情类组件;9:底部导航类组件;10:最新资讯类组件;11:导航栏类;
+        // 组件分类: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']),
-            'sector_id' => intval($data['sector_id']),
             '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'],
+            'component_width' => $data['component_width'],
+            'component_height' => $data['component_height'],
             'type_id' => intval($data['type_id']),
-            'sort_id' => intval($data['sort_id']),
+            'component_keyword' => $data['component_keyword'],
         ];
         switch($data['type_id']){
         //    组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
         //    7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
+        // 14:广告资讯混合类;
             case 1:                         //1:资讯-头条组件;
                  $add_arr['level'] = 1;
             case 2:                         //2:资讯-轮播组件;
@@ -1351,7 +1325,14 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $add_arr['level'] = 5;
             case 6:                        //6:资讯-热点类组件;
                 $add_arr['level'] = 6;
-            case 7:                        //7:资讯-栏目类组件;
+            case 14:
+                $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'];
+             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);
@@ -1397,6 +1378,15 @@ class PublicRpcService implements PublicRpcServiceInterface
                     'num' => $add_arr['pageSize'],
                 ];
                 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'];
+                break;
+
             default:
                 break;
         }
@@ -1404,7 +1394,6 @@ class PublicRpcService implements PublicRpcServiceInterface
             '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'];
@@ -1416,30 +1405,27 @@ class PublicRpcService implements PublicRpcServiceInterface
         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);
-        Db::beginTransaction();
-        try{
-            $result = Component::insertGetId($add_arr);
-            if(empty($result)){ 
-                Db::rollBack();
-                return Result::error('添加失败!');
-            }
-            $component = Component::where('sector_id',$sector['sector_id'])->distinct('sort_id')->count('sort_id');
-            // return Result::success($component == $sector['component_num']);
-            if($component == $sector['component_num'] && $sector['status'] == 0){
-                $sector_status = Sector::where('sector_id',$sector['sector_id'])->update(['status'=>1]);
-                if(empty($sector_status)){
-                    Db::rollBack();
-                    return Result::error('通栏状态不存在!');
-                }
-            }
-            Db::commit();
-            return Result::success($result);
-        }catch(\Exception $e){
-            Db::rollBack();
-            return Result::error($e->getMessage());
+            
+        $result = Component::insertGetId($add_arr);
+        if(empty($result)){ 
+            return Result::error('添加失败!');
         }
+        return Result::success($result);
     }
     public function delComponent(array $data): array
     {
@@ -1448,28 +1434,9 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(empty($component)){
             return Result::error('组件不存在!');
         }
-        // $sector_num = Sector::where('sector_id',$component['sector_id'])->first();
-        Db::beginTransaction();
-        try{
-            $result = Component::where('id',$data['id'])->delete();
-            if(empty($result)){
-                Db::rollBack();
-                return Result::error('删除失败!');
-            }
-            $component_num = Component::where('id','!=',$data['id'])->where('sector_id',$component['sector_id'])
-            ->where('sort_id',$component['sort_id'])->count();
-            $sector_status = Sector::where('sector_id',$component['sector_id'])->first();
-            if($component_num == 0 && $sector_status['status'] == 1){
-                $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());
+        $result = Component::where('id',$data['id'])->delete();
+        if(empty($result)){
+            return Result::error('删除失败!');
         }
         return Result::success($result);
     }
@@ -1478,36 +1445,24 @@ class PublicRpcService implements PublicRpcServiceInterface
         unset($data['user_id']);
         $id = $data['id'];
         unset($data['id']);
-        $sector = Sector::where('sector_id',$data['sector_id'])->first();
-        if(empty($sector)){
-            return Result::error('通栏不存在!');
-        }
         $component_id = Component::where('id','!=',$id)->where('component_type',$data['component_type'])->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);
-        }
+        //    组件分类: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']),
-            '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'],
+            'component_width' => $data['component_width'],
+            'component_height' => $data['component_height'],
             'type_id' => intval($data['type_id']),
-            'sort_id' => intval($data['sort_id']),
+            'component_keyword' => $data['component_keyword'],
         ];
         
         switch($data['type_id']){
@@ -1523,6 +1478,13 @@ class PublicRpcService implements PublicRpcServiceInterface
                 $add_arr['level'] = 5;
             case 6:                        //6:资讯-热点类组件;
                 $add_arr['level'] = 6;
+            case 14:
+                $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'];
             case 7:                        //7:资讯-栏目类组件;
                 $add_arr['img_num'] = intval($data['img_num']);
                 $add_arr['text_num'] = intval($data['text_num']);
@@ -1560,6 +1522,14 @@ class PublicRpcService implements PublicRpcServiceInterface
                     'fcat_id' => '',
                 ];
                 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'];
+                break;
             case 13:                     //13:底部导航类;
                 $add_arr['cate_place'] = 0;
                 $add_arr['pageSize'] = intval($data['pageSize']);
@@ -1576,7 +1546,6 @@ class PublicRpcService implements PublicRpcServiceInterface
             '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'];
@@ -1588,14 +1557,26 @@ class PublicRpcService implements PublicRpcServiceInterface
         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',$id)->update($add_arr);
-        if ($result) {
-            return Result::success($result);
-        } else {
-            return Result::error('添加失败');
+        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();
+            return Result::error('修改失败!');
         }
+        return Result::success($result);
     }
 
     public function getWebsiteTemplateInfo(array $data)
@@ -2129,21 +2110,27 @@ class PublicRpcService implements PublicRpcServiceInterface
         $article = Article::first()->toArray();
         $category = WebsiteCategory::first()->toArray();
         $footer_category = FooterCategory::first()->toArray();
-        $type_arr = [1,2,3,4,5,7,8,10];
+        $ad = AdPlace::leftJoin('ad_size','ad_place.ad_size_id','=','ad_size.id')
+        ->select('ad_place.*','ad_size.width','ad_size.height')
+        ->first()->toArray();
+        $type_arr = [1,2,3,4,5,7,8,9];
         // 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:导航栏类;
+            // 组件分类: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'] == 9){
+            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'] == 11){
-                $component_type[$key]['all_code'] = array_keys($category);
 
+            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);