|
@@ -7,6 +7,7 @@ function loadListByChannelName($maxCount, $name) {
|
|
|
// 1. 从pr_cms_channel表中通过name查询channel_id
|
|
// 1. 从pr_cms_channel表中通过name查询channel_id
|
|
|
$channel = Db::table('pr_cms_channel')
|
|
$channel = Db::table('pr_cms_channel')
|
|
|
->where('name', $name)
|
|
->where('name', $name)
|
|
|
|
|
+ ->where('status', 'normal')
|
|
|
->first(['id']);
|
|
->first(['id']);
|
|
|
|
|
|
|
|
// 如果没有找到对应的频道,返回空数组
|
|
// 如果没有找到对应的频道,返回空数组
|
|
@@ -19,6 +20,7 @@ function loadListByChannelName($maxCount, $name) {
|
|
|
// 2. 在pr_cms_archives中通过channel_id按createtime倒序查询指定数量的最新文章
|
|
// 2. 在pr_cms_archives中通过channel_id按createtime倒序查询指定数量的最新文章
|
|
|
$articles = Db::table('pr_cms_archives')
|
|
$articles = Db::table('pr_cms_archives')
|
|
|
->where('channel_id', $channelId)
|
|
->where('channel_id', $channelId)
|
|
|
|
|
+ ->where('status', 'normal')
|
|
|
->order('createtime DESC')
|
|
->order('createtime DESC')
|
|
|
->limit(0, $maxCount)
|
|
->limit(0, $maxCount)
|
|
|
->get();
|
|
->get();
|
|
@@ -34,6 +36,7 @@ function loadListByChannelNameAndPage($maxCount, $name, $page, $searchKeyword =
|
|
|
// 1. 从pr_cms_channel表中通过name查询channel_id
|
|
// 1. 从pr_cms_channel表中通过name查询channel_id
|
|
|
$channel = Db::table('pr_cms_channel')
|
|
$channel = Db::table('pr_cms_channel')
|
|
|
->where('name', $name)
|
|
->where('name', $name)
|
|
|
|
|
+ ->where('status', 'normal')
|
|
|
->first(['id']);
|
|
->first(['id']);
|
|
|
|
|
|
|
|
// 如果没有找到对应的频道,返回包含空列表和0总页数的数组
|
|
// 如果没有找到对应的频道,返回包含空列表和0总页数的数组
|
|
@@ -45,7 +48,49 @@ function loadListByChannelNameAndPage($maxCount, $name, $page, $searchKeyword =
|
|
|
|
|
|
|
|
// 2. 查询符合条件的文章总数量
|
|
// 2. 查询符合条件的文章总数量
|
|
|
$totalCountQuery = Db::table('pr_cms_archives')
|
|
$totalCountQuery = Db::table('pr_cms_archives')
|
|
|
- ->where('channel_id', $channelId);
|
|
|
|
|
|
|
+ ->where('channel_id', $channelId)
|
|
|
|
|
+ ->where('status', 'normal');
|
|
|
|
|
+
|
|
|
|
|
+ // 如果提供了搜索关键字,添加对title字段的模糊搜索
|
|
|
|
|
+ if (!empty($searchKeyword)) {
|
|
|
|
|
+ $totalCountQuery->where('title', 'like', '%' . $searchKeyword . '%');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $totalCount = $totalCountQuery->count();
|
|
|
|
|
+
|
|
|
|
|
+ // 计算总页数
|
|
|
|
|
+ $totalPages = $totalCount > 0 ? ceil($totalCount / $maxCount) : 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 查询当前页的文章列表
|
|
|
|
|
+ $articlesQuery = Db::table('pr_cms_archives')
|
|
|
|
|
+ ->where('channel_id', $channelId)
|
|
|
|
|
+ ->where('status', 'normal');
|
|
|
|
|
+
|
|
|
|
|
+ // 如果提供了搜索关键字,添加对title字段的模糊搜索
|
|
|
|
|
+ if (!empty($searchKeyword)) {
|
|
|
|
|
+ $articlesQuery->where('title', 'like', '%' . $searchKeyword . '%');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $articles = $articlesQuery
|
|
|
|
|
+ ->order('createtime DESC')
|
|
|
|
|
+ ->limit(($page - 1) * $maxCount, $maxCount)
|
|
|
|
|
+ ->get();
|
|
|
|
|
+
|
|
|
|
|
+ // 返回包含文章列表和总页数的数组
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'list' => $articles ?? [],
|
|
|
|
|
+ 'totalPages' => $totalPages
|
|
|
|
|
+ ];
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ // 发生异常时返回包含空列表和0总页数的数组
|
|
|
|
|
+ return ['list' => [], 'totalPages' => 0];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+function loadListPage($maxCount, $page, $searchKeyword = '') {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 2. 查询符合条件的文章总数量
|
|
|
|
|
+ $totalCountQuery = Db::table('pr_cms_archives')
|
|
|
|
|
+ ->where('status', 'normal');
|
|
|
|
|
|
|
|
// 如果提供了搜索关键字,添加对title字段的模糊搜索
|
|
// 如果提供了搜索关键字,添加对title字段的模糊搜索
|
|
|
if (!empty($searchKeyword)) {
|
|
if (!empty($searchKeyword)) {
|
|
@@ -59,7 +104,7 @@ function loadListByChannelNameAndPage($maxCount, $name, $page, $searchKeyword =
|
|
|
|
|
|
|
|
// 3. 查询当前页的文章列表
|
|
// 3. 查询当前页的文章列表
|
|
|
$articlesQuery = Db::table('pr_cms_archives')
|
|
$articlesQuery = Db::table('pr_cms_archives')
|
|
|
- ->where('channel_id', $channelId);
|
|
|
|
|
|
|
+ ->where('status', 'normal');
|
|
|
|
|
|
|
|
// 如果提供了搜索关键字,添加对title字段的模糊搜索
|
|
// 如果提供了搜索关键字,添加对title字段的模糊搜索
|
|
|
if (!empty($searchKeyword)) {
|
|
if (!empty($searchKeyword)) {
|
|
@@ -86,6 +131,7 @@ function loadChildChannelByChannelName($name) {
|
|
|
// 1. 从pr_cms_channel表中通过name查询channel_id
|
|
// 1. 从pr_cms_channel表中通过name查询channel_id
|
|
|
$channel = Db::table('pr_cms_channel')
|
|
$channel = Db::table('pr_cms_channel')
|
|
|
->where('name', $name)
|
|
->where('name', $name)
|
|
|
|
|
+ ->where('status', 'normal')
|
|
|
->first(['id']);
|
|
->first(['id']);
|
|
|
|
|
|
|
|
// 如果没有找到对应的频道,返回空数组
|
|
// 如果没有找到对应的频道,返回空数组
|
|
@@ -98,6 +144,7 @@ function loadChildChannelByChannelName($name) {
|
|
|
// 2. 在pr_cms_channel中通过parent_id查询子频道
|
|
// 2. 在pr_cms_channel中通过parent_id查询子频道
|
|
|
$childChannels = Db::table('pr_cms_channel')
|
|
$childChannels = Db::table('pr_cms_channel')
|
|
|
->where('parent_id', $channelId)
|
|
->where('parent_id', $channelId)
|
|
|
|
|
+ ->where('status', 'normal')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
return $childChannels ?? [];
|
|
return $childChannels ?? [];
|
|
@@ -111,6 +158,7 @@ function getContentById($id) {
|
|
|
// 1. 从pr_cms_archives表中获取基础信息
|
|
// 1. 从pr_cms_archives表中获取基础信息
|
|
|
$archive = Db::table('pr_cms_archives')
|
|
$archive = Db::table('pr_cms_archives')
|
|
|
->where('id', $id)
|
|
->where('id', $id)
|
|
|
|
|
+ ->where('status', 'normal')
|
|
|
->first();
|
|
->first();
|
|
|
|
|
|
|
|
// 如果没有找到对应的归档信息,返回null
|
|
// 如果没有找到对应的归档信息,返回null
|