|
@@ -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);
|
|
|
|
+ }
|
|
}
|
|
}
|