|
@@ -1316,19 +1316,31 @@ class NewsService implements NewsServiceInterface
|
|
$imgArticles = [];
|
|
$imgArticles = [];
|
|
$textArticles = [];
|
|
$textArticles = [];
|
|
// return Result::error("暂无此栏目",0);
|
|
// return Result::error("暂无此栏目",0);
|
|
- } else {
|
|
|
|
|
|
+ }else{
|
|
|
|
+ $parent_alias = $category->alias ?? '';
|
|
|
|
+ $parent_pinyin = $category->aLIas_pinyin ?'/'.$category->aLIas_pinyin.'/' : null;
|
|
// 查询图片新闻
|
|
// 查询图片新闻
|
|
$imgArticles = Article::where('catid', $parentCatId)
|
|
$imgArticles = Article::where('catid', $parentCatId)
|
|
- ->where('status', 1)
|
|
|
|
- ->where(function ($query) use ($website) {
|
|
|
|
- $query->where(function ($subQuery) use ($website) {
|
|
|
|
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
|
|
- })->orWhereNull("ignore_ids");
|
|
|
|
- })
|
|
|
|
- ->where('imgurl', '!=', '')
|
|
|
|
- ->orderBy('updated_at', 'desc')
|
|
|
|
- ->limit($parentImgNum)
|
|
|
|
- ->get()->all();
|
|
|
|
|
|
+ ->where('status', 1)
|
|
|
|
+ ->where(function ($query) use ($website) {
|
|
|
|
+ $query->where(function ($subQuery) use ($website) {
|
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
|
|
|
|
+ })->orWhereNull("ignore_ids");
|
|
|
|
+ })
|
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
|
+ ->select(
|
|
|
|
+ 'article.id',
|
|
|
|
+ 'article.title',
|
|
|
|
+ 'article.imgurl',
|
|
|
|
+ 'article.author',
|
|
|
|
+ 'article.updated_at',
|
|
|
|
+ 'article.introduce',
|
|
|
|
+ 'article.islink',
|
|
|
|
+ 'article.linkurl',
|
|
|
|
+ 'article.copyfrom')
|
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
|
+ ->limit($parentImgNum)
|
|
|
|
+ ->get()->all();
|
|
|
|
|
|
// 查询文字新闻
|
|
// 查询文字新闻
|
|
$textArticles = Article::where('catid', $parentCatId)
|
|
$textArticles = Article::where('catid', $parentCatId)
|
|
@@ -1338,28 +1350,40 @@ class NewsService implements NewsServiceInterface
|
|
$subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
$subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
})->orWhereNull("ignore_ids");
|
|
})->orWhereNull("ignore_ids");
|
|
})
|
|
})
|
|
|
|
+ ->select(
|
|
|
|
+ 'article.id',
|
|
|
|
+ 'article.title',
|
|
|
|
+ 'article.author',
|
|
|
|
+ 'article.updated_at',
|
|
|
|
+ 'article.introduce',
|
|
|
|
+ 'article.islink',
|
|
|
|
+ 'article.linkurl',
|
|
|
|
+ 'article.copyfrom')
|
|
->orderBy('updated_at', 'desc')
|
|
->orderBy('updated_at', 'desc')
|
|
->limit($parentTextNum)
|
|
->limit($parentTextNum)
|
|
->get()->all();
|
|
->get()->all();
|
|
}
|
|
}
|
|
$resultItem = [
|
|
$resultItem = [
|
|
- 'alias' => $category ? $category->alias : null,
|
|
|
|
|
|
+ 'alias' => $parent_alias,
|
|
'category_id' => $parentCatId,
|
|
'category_id' => $parentCatId,
|
|
- 'pinyin' => $category->aLIas_pinyin ?? '',
|
|
|
|
|
|
+ 'pinyin' => $parent_pinyin,
|
|
'imgnum' => $imgArticles,
|
|
'imgnum' => $imgArticles,
|
|
'textnum' => $textArticles,
|
|
'textnum' => $textArticles,
|
|
|
|
|
|
];
|
|
];
|
|
|
|
|
|
if (!empty($item['child']) && $item['child'] != "") {
|
|
if (!empty($item['child']) && $item['child'] != "") {
|
|
- // 查询第一个pid等于parent中第一个参数的category来获取child的category_id
|
|
|
|
- $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)->select('category_id', 'alias', 'aLIas_pinyin')->get()->all();
|
|
|
|
|
|
+ $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin : '';
|
|
|
|
+ $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
|
|
|
|
+ ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin_str])
|
|
|
|
+ ->get()->all();
|
|
if ($childCategory) {
|
|
if ($childCategory) {
|
|
list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
|
|
list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
|
|
// 查询子栏目名称
|
|
// 查询子栏目名称
|
|
- $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
|
|
|
|
- // $childAllCartegory = WebsiteCategory::where('pid', $childCatId)->where($website)->first(['category_id']);
|
|
|
|
- if (empty($childCategoryInfo)) {
|
|
|
|
|
|
+ $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
|
|
|
|
+ ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin])
|
|
|
|
+ ->first();
|
|
|
|
+ if(empty($childCategoryInfo)){
|
|
$childImgArticles = [];
|
|
$childImgArticles = [];
|
|
$childTextArticles = [];
|
|
$childTextArticles = [];
|
|
} else {
|
|
} else {
|
|
@@ -1371,6 +1395,16 @@ class NewsService implements NewsServiceInterface
|
|
$subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
$subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
})->orWhereNull("ignore_ids");
|
|
})->orWhereNull("ignore_ids");
|
|
})
|
|
})
|
|
|
|
+ ->select(
|
|
|
|
+ 'article.id',
|
|
|
|
+ 'article.title',
|
|
|
|
+ 'article.imgurl',
|
|
|
|
+ 'article.author',
|
|
|
|
+ 'article.updated_at',
|
|
|
|
+ 'article.introduce',
|
|
|
|
+ 'article.islink',
|
|
|
|
+ 'article.linkurl',
|
|
|
|
+ 'article.copyfrom')
|
|
->where('imgurl', '!=', '')
|
|
->where('imgurl', '!=', '')
|
|
->orderBy('updated_at', 'desc')
|
|
->orderBy('updated_at', 'desc')
|
|
->limit($childImgNum)
|
|
->limit($childImgNum)
|
|
@@ -1383,6 +1417,15 @@ class NewsService implements NewsServiceInterface
|
|
$subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
$subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
})->orWhereNull("ignore_ids");
|
|
})->orWhereNull("ignore_ids");
|
|
})
|
|
})
|
|
|
|
+ ->select(
|
|
|
|
+ 'article.id',
|
|
|
|
+ 'article.title',
|
|
|
|
+ 'article.author',
|
|
|
|
+ 'article.updated_at',
|
|
|
|
+ 'article.introduce',
|
|
|
|
+ 'article.islink',
|
|
|
|
+ 'article.linkurl',
|
|
|
|
+ 'article.copyfrom')
|
|
->orderBy('updated_at', 'desc')
|
|
->orderBy('updated_at', 'desc')
|
|
->limit($childTextNum)
|
|
->limit($childTextNum)
|
|
->get()->all();
|
|
->get()->all();
|
|
@@ -1413,60 +1456,94 @@ class NewsService implements NewsServiceInterface
|
|
*/
|
|
*/
|
|
public function getWebsiteArticles(array $data): array
|
|
public function getWebsiteArticles(array $data): array
|
|
{
|
|
{
|
|
- // 修正传入的字符串,将单引号替换为双引号
|
|
|
|
- $input['id'] = $data['id'];
|
|
|
|
- $input['website_id'] = $data['website_id'];
|
|
|
|
- // 将 JSON 字符串转换为 PHP 数组
|
|
|
|
- $data = json_decode($input['id'], true);
|
|
|
|
- // 使用 array_map 处理每个元素
|
|
|
|
- $result = array_map(function ($item) use ($input) {
|
|
|
|
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
|
|
|
|
- $website = [
|
|
|
|
- 'website_id' => $input['website_id'],
|
|
|
|
- ];
|
|
|
|
- // 查询栏目名称
|
|
|
|
- $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
|
|
|
|
- if (empty($category)) {
|
|
|
|
- $imgArticles = [];
|
|
|
|
- $textArticles = [];
|
|
|
|
- // return Result::error("暂无此栏目",0);
|
|
|
|
- } else {
|
|
|
|
- // 查询图片新闻
|
|
|
|
- $imgArticles = Article::where('status', 1)
|
|
|
|
- ->where(function ($query) use ($website) {
|
|
|
|
|
|
+ $input['id'] = $data['id'];
|
|
|
|
+ $input['website_id'] = $data['website_id'];
|
|
|
|
+ $data = json_decode($input['id'], true);
|
|
|
|
+ // 使用 array_map 处理每个元素
|
|
|
|
+ $result = array_map(function ($item) use ($input) {
|
|
|
|
+ list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
|
|
|
|
+ $website = [
|
|
|
|
+ 'website_id' => $input['website_id']
|
|
|
|
+ ];
|
|
|
|
+ // 查询栏目名称
|
|
|
|
+ $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
|
|
|
|
+ $pinyin = $category->aLIas_pinyin ? '/'.$category->aLIas_pinyin.'/' : null;
|
|
|
|
+ if(empty($category)){
|
|
|
|
+ $imgArticles = [];
|
|
|
|
+ $textArticles = [];
|
|
|
|
+ // return Result::error("暂无此栏目",0);
|
|
|
|
+ }else{
|
|
|
|
+ // return Result::success($website);
|
|
|
|
+ // 查询图片新闻
|
|
|
|
+ // 合并查询条件
|
|
|
|
+ $baseQuery = Article::where(function ($query) use ($website) {
|
|
$query->where(function ($subQuery) use ($website) {
|
|
$query->where(function ($subQuery) use ($website) {
|
|
$subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
$subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
})->orWhereNull("ignore_ids");
|
|
})->orWhereNull("ignore_ids");
|
|
})
|
|
})
|
|
- ->where('imgurl', '!=', '')
|
|
|
|
->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
|
|
->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
|
|
->leftJoin('website_category', 'website_category.category_id', 'article.catid')
|
|
->leftJoin('website_category', 'website_category.category_id', 'article.catid')
|
|
- ->select('article.*', 'website_category.category_id', 'website_category.alias', 'website_category.aLIas_pinyin')
|
|
|
|
- ->orderBy('updated_at', 'desc')
|
|
|
|
- ->limit($parentImgNum)
|
|
|
|
- ->get()->all();
|
|
|
|
- // 查询文字新闻
|
|
|
|
- $textArticles = Article::where('status', 1)
|
|
|
|
- ->where(function ($query) use ($website) {
|
|
|
|
- $query->where(function ($subQuery) use ($website) {
|
|
|
|
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
|
|
|
|
- })->orWhereNull("ignore_ids");
|
|
|
|
- })
|
|
|
|
- ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
|
|
|
|
- ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
|
|
|
|
- ->select('article.*', 'website_category.category_id', 'website_category.alias', 'website_category.aLIas_pinyin')
|
|
|
|
- ->orderBy('updated_at', 'desc')
|
|
|
|
|
|
+ ->where('website_category.website_id', $website['website_id'])
|
|
|
|
+ ->where('article.status', 1);
|
|
|
|
+
|
|
|
|
+ // 查询文字新闻
|
|
|
|
+ $textArticles = clone $baseQuery;
|
|
|
|
+ $textArticles = $textArticles
|
|
|
|
+ ->select(
|
|
|
|
+ 'article.id',
|
|
|
|
+ 'article.title',
|
|
|
|
+ // 'article.imgurl',
|
|
|
|
+ 'article.author',
|
|
|
|
+ 'article.updated_at',
|
|
|
|
+ 'article.introduce',
|
|
|
|
+ 'article.islink',
|
|
|
|
+ 'article.linkurl',
|
|
|
|
+ 'article.copyfrom',
|
|
|
|
+ 'website_category.category_id',
|
|
|
|
+ 'website_category.alias',
|
|
|
|
+ 'website_category.aLIas_pinyin'
|
|
|
|
+ )
|
|
|
|
+ ->selectRaw("CONCAT(?, aLIas_pinyin, '/') as aLIas_pinyin", [$pinyin])
|
|
|
|
+ ->orderBy('article.updated_at', 'desc')
|
|
->limit($parentTextNum)
|
|
->limit($parentTextNum)
|
|
- ->get()->all();
|
|
|
|
|
|
+ ->get()
|
|
|
|
+ ->all();
|
|
|
|
+ // 查询图片新闻
|
|
|
|
+ $imgArticles = clone $baseQuery;
|
|
|
|
+ $imgArticles = $imgArticles
|
|
|
|
+ ->select(
|
|
|
|
+ 'article.id',
|
|
|
|
+ 'article.title',
|
|
|
|
+ 'article.imgurl',
|
|
|
|
+ 'article.author',
|
|
|
|
+ 'article.updated_at',
|
|
|
|
+ 'article.introduce',
|
|
|
|
+ 'article.islink',
|
|
|
|
+ 'article.linkurl',
|
|
|
|
+ 'article.copyfrom',
|
|
|
|
+ 'website_category.category_id',
|
|
|
|
+ 'website_category.alias',
|
|
|
|
+ 'website_category.aLIas_pinyin'
|
|
|
|
+ )
|
|
|
|
+ ->selectRaw("CONCAT(?, aLIas_pinyin, '/') as aLIas_pinyin", [$pinyin])
|
|
|
|
+ ->orderBy('article.updated_at', 'desc')
|
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
|
+ ->limit($parentImgNum)
|
|
|
|
+ ->get()
|
|
|
|
+ ->all();
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
- $resultItem = [
|
|
|
|
- 'alias' => $category ? $category->alias : null,
|
|
|
|
- 'category_id' => $parentCatId,
|
|
|
|
- 'pinyin' => $category->aLIas_pinyin ?? '',
|
|
|
|
- 'imgnum' => $imgArticles,
|
|
|
|
- 'textnum' => $textArticles,
|
|
|
|
|
|
+
|
|
|
|
+ $resultItem = [
|
|
|
|
+ 'alias' => $category ? $category->alias : null,
|
|
|
|
+ 'category_id' => $parentCatId,
|
|
|
|
+ 'pinyin' => $pinyin ? $pinyin : null,
|
|
|
|
+ 'imgnum' => $imgArticles ?? [],
|
|
|
|
+ 'textnum' => $textArticles ?? [],
|
|
|
|
+
|
|
|
|
+ ];
|
|
|
|
|
|
- ];
|
|
|
|
|
|
|
|
return $resultItem;
|
|
return $resultItem;
|
|
}, $data);
|
|
}, $data);
|