15313670163 1 هفته پیش
والد
کامیت
91b9e7992f
1فایلهای تغییر یافته به همراه45 افزوده شده و 146 حذف شده
  1. 45 146
      app/JsonRpc/FooterService.php

+ 45 - 146
app/JsonRpc/FooterService.php

@@ -12,22 +12,17 @@ use Hyperf\DbConnection\Db;
 use PhpParser\Node\Expr\Clone_;
 use Overtrue\Pinyin\Pinyin;
 
-use function Hyperf\Support\retry;
-use function PHPSTORM_META\type;
-use function PHPUnit\Framework\assertIsNotInt;
-use function PHPUnit\Framework\isNull;
-
 #[RpcService(name: "FooterService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class FooterService implements FooterServiceInterface
 {
     /**
-     * 获取底部导航列表
+     * 获取底部导航
      * @param array $data
      * @return array
      */
     public function getFooterCategory(array $data): array
     {
-        $where = ['pid' => 0];
+        $where = [];
         if(isset($data['website_name'])){
             array_push($where, ['website.website_name','like','%'.$data['website_name'].'%']);
         }
@@ -72,45 +67,18 @@ class FooterService implements FooterServiceInterface
             if(empty($webid)){
                 return Result::error("该网站不存在!");
             }
-            $isChild = 0;
-            if(isset($data['is_child']) && !empty($data['is_child']) && $data['is_child'] == 1){
-                $child = [
-                    'name' => $data['child_name'],
-                    'website_id' => $data['website_id'],
-                    'type' => 0,
-                ];
-                $isChild = $data['is_child'];
-                unset($data['child_name']);
-                unset($data['is_child']);
-            }
-            // return Result::success($data);
             Db::beginTransaction();
             try{
                 // 同一网站下的底部导航名称不能重复
                 $name = FooterCategory::where('website_id',$data['website_id'])->where('name',$data['name'])->first();
                 if(!empty($name)){
-                    Db::rollBack();
                     return Result::error("该底部导航名称已存在!");
                 }
                 $pinyin = new Pinyin();
-                $data['name_pinyin'] = $pinyin->permalink($data['name'], '') ;
-                $result = [];
-                $result['parent'] = FooterCategory::insertGetId($data); 
-                if($isChild == 1){
-                    $child['pid'] = $result['parent'];
-                    $child['name_pinyin'] = $pinyin->permalink($child['name'], '');
-                    // 暂时用不到   若是一个栏目对应多个子级栏目  则需要判断子级栏目名称是否重复
-                    // $child_name = FooterCategory::where('website_id',$data['website_id'])->where('pid',$child['pid'])->first();
-                    // if(!empty($child_name)){
-                    //     Db::rollBack();
-                    //     return Result::error("该子级栏目名称已存在!"); 
-                    // }
-                    $result['child'] = FooterCategory::insertGetId($child);
-                    if(empty($result['child'])){
-                        Db::rollBack();
-                        return Result::error("子级栏目添加失败!");
-                    }
-                }
+                $result = FooterCategory::insertGetId($data); 
+                $name_pinyin['name_pinyin'] = $pinyin->permalink($data['name'], '') ;
+                // return Result::success($name_pinyin);
+                $result = FooterCategory::where('id', $result)->update($name_pinyin);
                 Db::commit();
             } catch(\Throwable $ex){
                 Db::rollBack();
@@ -118,7 +86,11 @@ class FooterService implements FooterServiceInterface
                 return Result::error("添加失败!",$errorMessage);
             }
         }
+        if(empty($result)){
+            return Result::error("添加失败!");
+        }else{
             return Result::success($result);
+        }
     }
      /**
       * 修改底部导航
@@ -132,20 +104,17 @@ class FooterService implements FooterServiceInterface
             return Result::error("该底部导航不存在!");
         }
         if(empty($data['website_id'])){
+            $web = Website::select('website_name','id')->get();
             $footer_category = FooterCategory::where('footer_category.id',$data['id'])
             ->leftJoin("website","website.id","footer_category.website_id")
             ->select("footer_category.*","website.website_name","website.id as website_id")
             ->first();
-            $child = FooterCategory::where('pid',$footer_category['id'])->first(); 
-            if(!empty($child)){
-                $footer_category['child_name'] = $child['name'];
-                $footer_category['child_id'] = $child['id'];
-                $footer_category['is_child'] = 1;
-            }else{
-                $footer_category['is_child'] = 0;
+            if(isset($data['name'])){
+                $footer_category['name'] = $data['name'];
             }
             $result = [
                 'rows'=>$footer_category,
+                'web'=>$web
             ];
         }else{
             $all_categories = FooterCategory::where('website_id',$data['website_id'])->where('id','!=',$data['id'])->pluck('name')->toArray();
@@ -158,69 +127,9 @@ class FooterService implements FooterServiceInterface
                 return Result::error("该网站不存在!");
             }
             $pinyin = new Pinyin();
-            $child_data = [];
-            $result = [];
-            Db::beginTransaction();
-            try{
-                if(isset($data['is_child']) && $data['is_child']!=''){
-                    $child = FooterCategory::where('pid',$data['id'])->first();
-                    if($data['is_child'] == 1){
-                        if(empty($data['child_name'])){
-                            Db::rollBack();
-                            return Result::error("请输入子级栏目名称!");
-                            var_dump($data['child_name']);
-                        }
-                        if(empty($child)){
-                            $child_data = [
-                                'name' => $data['child_name'],
-                                'name_pinyin' => $pinyin->permalink($data['child_name'], ''),
-                                'website_id' => $data['website_id'],
-                                'type' => 0,
-                                'pid' => $data['id'],
-                            ];
-                            $result['addchild'] = FooterCategory::insertGetId($child_data); 
-                            if(empty($result['addchild'])){
-                                Db::rollBack();
-                                return Result::error("子级栏目添加失败!");
-                            }
-                        }else{
-                            $child_data = [
-                                'name' => $data['child_name'],
-                                'name_pinyin' => $pinyin->permalink($data['child_name'], ''),
-                            ];
-                            $result['upchild'] = FooterCategory::where('pid',$data['id'])->update($child_data);
-                            if(empty($result['upchild'])){
-                                Db::rollBack();
-                                return Result::error("子级栏目修改失败!"); 
-                            }
-                        }
-                    }else{
-                        if(!empty($child)){
-                            $result['del_child_content'] = FooterContent::where('fcat_id',$child['id'])->delete();
-                             $result['delchild'] = FooterCategory::where('pid',$data['id'])->delete();
-                             if(empty($result['delchild'])) {
-                                Db::rollBack();
-                                return Result::error("子级栏目删除失败!");
-                            }
-                        }
-                    }
-                    unset($data['child_name']);
-                    unset($data['is_child']);
-                    $data['name_pinyin'] = $pinyin->permalink($data['name'], '');
-                    $result['rows'] = FooterCategory::where('id', $data['id'])->update($data);
-                    if(empty($result['rows'])){
-                        Db::rollBack();
-                        return Result::error("栏目修改失败!");
-                    }
-                    Db::commit();
-                }else{
-                    return Result::error("请选择是否添加子级栏目!");
-                }
-            } catch(\Throwable $ex){
-                Db::rollBack();
-                var_dump($ex->getMessage());
-                return Result::error("修改失败!",0); 
-            }           
+            $data['name_pinyin'] = $pinyin->permalink($data['name'], '');
+
+            $result = FooterCategory::where('id', $data['id'])->update($data);
         }
         if (empty($result)) {
             return Result::error("修改失败!");
@@ -243,15 +152,12 @@ class FooterService implements FooterServiceInterface
                 Db::rollBack();
                 return Result::error("该底部导航不存在!");
             }else{
-                
                 $result['footer_category'] = FooterCategory::where('id', $data['id'])->delete();
                 $result['footer_content'] = FooterContent::where('fcat_id', $data['id'])->delete();
-                $child = FooterCategory::where('pid', $data['id'])->first();
-                if(!empty($child)){
-                    $result['child'] = FooterCategory::where('pid', $data['id'])->delete();
-                    $result['child_content'] = FooterContent::where('fcat_id', $child['id'])->delete();
-                }
                 Db::commit();
+                // $result = FooterCategory::where('footer_category.id',$data['id'])
+                // ->leftJoin("footer_content","footer_content.fcat_id","footer_category.id")
+                // ->delete();
             }
             
         } catch(\Throwable $ex){
@@ -270,22 +176,21 @@ class FooterService implements FooterServiceInterface
     {
         // 底部导航类型    0:内容型;1:列表型;
         // var_dump($data);
+       
         $cat = FooterCategory::where('id', $data['fcat_id'])->first();
-        // return Result::success($cat);
         if (!$cat) {
             return Result::error("该底部导航不存在!");
         }
-        if($cat['type'] != $data['type_id']){
+        if($cat['type'] != $data['type']){
             return Result::error("请输入正确的底部导航类型!");
         }
-        // 内容型底部导航只能有一条内容
         if($cat['type'] == 0){
             $content = FooterContent::where('fcat_id', $data['fcat_id'])->first();
             if(!empty($content)){
                 return Result::error("该底部导航已添加内容!");
             }
         }else{
-        // 列表型底部导航\列表标头型底部导航列表标题不能重复
+            // return Result::success($data);
             if(!isset($data['list_title']) || empty($data['list_title'])){
                 return Result::error("请输入底部导航列表标题!");
             }
@@ -294,6 +199,7 @@ class FooterService implements FooterServiceInterface
                 return Result::error("该列表标题已存在!");
             }
         }
+        unset($data['type']);
         $result = FooterContent::insertGetId($data);
         if(empty($result)){
             return Result::error("添加失败!");
@@ -310,39 +216,31 @@ class FooterService implements FooterServiceInterface
     {
 
         $where = [];
-        $fcat_id = [];
-        $footer_category = FooterCategory::where('id', $data['fcat_id'])->first();
-        if(empty($footer_category)){
-            return Result::error("该底部导航不存在!"); 
-        }
-        $footer_category = $footer_category->toArray();
-        $fcat_id = $footer_category['id'];
-        if($footer_category['type'] == 1){
+        array_push($where, ['fcat_id',$data['fcat_id']]);
+        $type = FooterCategory::where('id', $data['fcat_id'])->value('type');
+        if($type == 1){
             if(isset($data['list_title'])){
                 array_push($where, ['list_title','like','%'.$data['list_title'].'%']);
             }
             if(isset($data['con_title'])){
                 array_push($where, ['con_title','like','%'.$data['con_title'].'%']);
             }
-            $child = FooterCategory::where('pid', $data['fcat_id'])->first();
-            if($child){
-                $fcat_id = [$footer_category['id'], $child->id];
-            }
         }
-        $count = FooterContent::whereIn('fcat_id', (array)$fcat_id)->where($where)->count();
-        $rep = FooterContent::whereIn('fcat_id', (array)$fcat_id)->where($where)
-            ->leftJoin('footer_category', 'footer_category.id', '=', 'footer_content.fcat_id')
-            ->select('footer_content.*', 'footer_category.type', 'footer_category.name as fcat_name')
-            ->limit($data['pageSize'])
-            ->offset(($data['page'] - 1) * $data['pageSize'])
-            ->orderBy("updated_at", "desc")
-            ->get();
+        $count = FooterContent::where($where)->count();
+        $rep = FooterContent::where($where)
+        ->leftJoin('footer_category','footer_category.id','fcat_id')
+        ->select('footer_content.*','footer_category.type')
+        ->limit($data['pageSize'])
+        ->offset(($data['page']-1)*$data['pageSize'])
+        ->orderBy("updated_at","desc")
+        ->get();
+        
         if(empty($rep)){
             return Result::error("没有查到相关数据!");
         }else{
             $result = [
-                'rows' => $rep,
-                'count' => $count
+                'rows'=>$rep,
+                'count'=>$count
             ];
             return Result::success($result);
         }
@@ -357,12 +255,13 @@ class FooterService implements FooterServiceInterface
     {      
         $result = FooterContent::where('footer_content.id', $data['id'])
         ->leftJoin('footer_category','footer_category.id','fcat_id')
-        ->select('footer_content.*','footer_category.type','footer_category.pid','footer_category.name as fcat_name')
+        ->select('footer_content.*','footer_category.type')
         ->first();   
         if(empty($result)){
             return Result::error("请输入正确的底部导航内容id!");
+        }else{
+            return Result::success($result);
         }
-        return Result::success($result);
     }
     /**
      * 编辑底部导航(列表)内容
@@ -378,19 +277,19 @@ class FooterService implements FooterServiceInterface
         if(!$content){
             return Result::error("该底部导航内容不存在!");
         }
-        if($content['type'] != $data['type_id']){
+        if($content['type'] != $data['type']){
             return Result::error("请输入正确的底部导航类型!");
         }
-        if($content['type_id'] == 1){
+        if($content['type'] == 1){
             if(!isset($data['list_title']) || empty($data['list_title'])){
                 return Result::error("请输入底部导航列表标题!");
             }
-            $list_title = FooterContent::where('fcat_id', $data['fcat_id'])->where('list_title',$data['list_title'])->first();
+            $list_title = FooterContent::where('fcat_id', $content['fcat_id'])->where('list_title',$data['list_title'])->first();
             if(!empty($list_title)){
                 return Result::error("该列表标题已存在!");
             }
         }
-        unset($data['type_id']);            
+        unset($data['type']);            
         $result = FooterContent::where('id', $data['id'])->update($data);   
         if(empty($result)){
             return Result::error("修改失败!");