浏览代码

修改获取底部导航、获取底部导航列表

15313670163 2 月之前
父节点
当前提交
0578139f16
共有 1 个文件被更改,包括 14 次插入9 次删除
  1. 14 9
      app/JsonRpc/FooterService.php

+ 14 - 9
app/JsonRpc/FooterService.php

@@ -27,21 +27,25 @@ class FooterService implements FooterServiceInterface
         if(isset($data['name'])){
             array_push($where, ['footer_category.name','like','%'.$data['name'].'%']);
         }
-        $query = FooterCategory::when(!empty($where), function ($query) use ($where) {
+        $query = FooterCategory::query();
+        if (!empty($where)) {
             $query->where($where);
-        });
-        $rep = $query->leftJoin("website","website.id","footer_category.website_id")
-        ->select("footer_category.*","website.website_name","website.id as website_id")
-        ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("updated_at","desc")
-        ->get();
+        }
         $count = $query->count();
+        $rep = $query->leftJoin("website", "website.id", "footer_category.website_id")
+            ->select("footer_category.*", "website.website_name", "website.id as website_id")
+            ->offset(($data['page'] - 1) * $data['pageSize'])
+            ->limit($data['pageSize'])
+            ->orderByDesc("updated_at")
+            ->get();
+        
         // var_dump($where);
         $result  = [];
         $result = [
             'rows'=>$rep,
             'count'=>$count
         ];
-        if($count == 0){
+        if(empty($result)){
             return Result::error("没有查到相关数据!");
         }
         return Result::success($result);
@@ -203,6 +207,7 @@ class FooterService implements FooterServiceInterface
                 array_push($where, ['con_title','like','%'.$data['con_title'].'%']);
             }
         }
+        $count = FooterContent::where($where)->count();
         $rep = FooterContent::where($where)
         ->leftJoin('footer_category','footer_category.id','fcat_id')
         ->select('footer_content.*','footer_category.type')
@@ -210,8 +215,8 @@ class FooterService implements FooterServiceInterface
         ->offset(($data['page']-1)*$data['pageSize'])
         ->orderBy("updated_at","desc")
         ->get();
-        $count = FooterContent::where($where)->count();
-        if($count == 0){
+        
+        if(empty($rep)){
             return Result::error("没有查到相关数据!");
         }else{
             $result = [