浏览代码

修改搜索新闻列表

15313670163 1 月之前
父节点
当前提交
6925085bf2
共有 2 个文件被更改,包括 44 次插入0 次删除
  1. 39 0
      app/JsonRpc/NewsService.php
  2. 5 0
      app/JsonRpc/NewsServiceInterface.php

+ 39 - 0
app/JsonRpc/NewsService.php

@@ -701,4 +701,43 @@ class NewsService implements NewsServiceInterface
         }
         }
         return Result::success($result);
         return Result::success($result);
     }
     }
+
+     /**
+     * 前端-搜索新闻列表
+     * @param array $data
+     * @return array
+     */
+    public function selectWebsiteArticle(array $data): array
+    {
+        $where = [];
+        // 初始化查询构造器
+        $query = Article::where('status', 1);
+
+        // 检查是否存在 cityid 参数
+        if (isset($data['cityid']) && !empty($data['cityid'])) {
+            $query->whereRaw("JSON_CONTAINS(city_arr_id, '".intval($data['cityid'])."')");
+        }
+
+        // 检查是否存在 department_id 参数
+        if (isset($data['department_id']) && $data['department_id'] !== null) {
+            // 修正此处的 $data['cityid'] 为 $data['department_id']
+            $query->whereRaw("JSON_CONTAINS(department_arr_id, '".intval($data['department_id'])."')");
+        }
+        // 计算总数
+        $count = $query->count();
+        // 分页查询
+        $articles = $query->orderBy("updated_at", "desc")
+            ->limit($data['pageSize'])
+            ->offset(($data['page'] - 1) * $data['pageSize'])
+            ->get()->all();
+        // 处理结果
+        if ($articles->isEmpty()) {
+            return Result::error("没有符合条件的资讯数据");
+        }
+        $data = [
+            'rows' => $articles->toArray(),
+            'count' => $count
+        ];
+        return Result::success($data);
+    }
 }
 }

+ 5 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -122,4 +122,9 @@ interface NewsServiceInterface
      * @return array
      * @return array
      */
      */
     public function getSurveyInfo(array $data):array;
     public function getSurveyInfo(array $data):array;
+     /**
+     * @param array $data
+     * @return array
+     */
+    public function selectWebsiteArticle(array $data):array;
 }
 }