|
@@ -655,6 +655,7 @@ class NewsService implements NewsServiceInterface
|
|
public function getWebsiteArticlett(array $data): array
|
|
public function getWebsiteArticlett(array $data): array
|
|
{
|
|
{
|
|
$category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
|
|
$category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
|
|
|
|
+ $category = array_values(array_unique($category->toArray()));
|
|
$result = [];
|
|
$result = [];
|
|
if ($category) {
|
|
if ($category) {
|
|
$placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
$placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
@@ -673,14 +674,27 @@ class NewsService implements NewsServiceInterface
|
|
foreach ($keywordArray as $k => $v) {
|
|
foreach ($keywordArray as $k => $v) {
|
|
$whereL7[] = ['keyword', 'like', '%' . $v . '%'];
|
|
$whereL7[] = ['keyword', 'like', '%' . $v . '%'];
|
|
}
|
|
}
|
|
|
|
+ // 原始查询
|
|
$result = Article::where($whereL7)
|
|
$result = Article::where($whereL7)
|
|
->offset($placeid)
|
|
->offset($placeid)
|
|
->limit($data['pageSize'])
|
|
->limit($data['pageSize'])
|
|
->orderBy('updated_at', 'desc')
|
|
->orderBy('updated_at', 'desc')
|
|
- ->get();
|
|
|
|
- if (empty($result)) {
|
|
|
|
- return Result::success([]);
|
|
|
|
- }
|
|
|
|
|
|
+ ->get()
|
|
|
|
+ ->map(function ($article ) use ($data) {
|
|
|
|
+ $catid = $article->catid;
|
|
|
|
+ $pinyin = '';
|
|
|
|
+ $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
|
+ $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
|
|
+ if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
|
|
|
|
+ $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
|
+ $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
|
|
|
|
+ }
|
|
|
|
+ $article->pinyin = $pinyin;
|
|
|
|
+ return $article;
|
|
|
|
+ });
|
|
|
|
+ if (empty($result)) {
|
|
|
|
+ return Result::success([]);
|
|
|
|
+ }
|
|
return Result::success($result);
|
|
return Result::success($result);
|
|
} else {
|
|
} else {
|
|
return Result::error("参数错误level=7,id不能为空", 0);
|
|
return Result::error("参数错误level=7,id不能为空", 0);
|
|
@@ -691,6 +705,8 @@ class NewsService implements NewsServiceInterface
|
|
var_dump($where, 'where-----------------');
|
|
var_dump($where, 'where-----------------');
|
|
$result = Article::where($where)
|
|
$result = Article::where($where)
|
|
->whereIn("catid", $category)
|
|
->whereIn("catid", $category)
|
|
|
|
+ // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
|
|
|
|
+ // ->where('website_category.website_id', $data['website_id'])
|
|
->where(function ($query) use ($data) {
|
|
->where(function ($query) use ($data) {
|
|
$query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
$query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
->orWhereNull("ignore_ids");
|
|
->orWhereNull("ignore_ids");
|
|
@@ -702,17 +718,35 @@ class NewsService implements NewsServiceInterface
|
|
->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
|
|
->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
|
|
})
|
|
})
|
|
->when($data['level'] == 4, function ($query) {
|
|
->when($data['level'] == 4, function ($query) {
|
|
- $query->orderBy("updated_at", "desc");
|
|
|
|
|
|
+ $query->orderBy("article.updated_at", "desc");
|
|
})
|
|
})
|
|
->when(!empty($data['level']), function ($query) use ($data) {
|
|
->when(!empty($data['level']), function ($query) use ($data) {
|
|
if ($data['level'] != 4 && $data['level'] != 5) {
|
|
if ($data['level'] != 4 && $data['level'] != 5) {
|
|
$query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
$query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
- ->orderBy("updated_at", "desc");
|
|
|
|
|
|
+ ->orderBy("article.updated_at", "desc");
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+ ->select('article.*')
|
|
->offset($placeid)
|
|
->offset($placeid)
|
|
->limit($data['pageSize'])
|
|
->limit($data['pageSize'])
|
|
- ->get();
|
|
|
|
|
|
+ ->get()
|
|
|
|
+ ->map(function ($article ) use ($data) {
|
|
|
|
+ $catid = $article->catid;
|
|
|
|
+ $pinyin = '';
|
|
|
|
+ // $category = WebsiteCategory::whereIn('category_id', $catArrId)->where('website_category.website_id', $data['website_id'])->get()->all();
|
|
|
|
+ // if ($catArrId) {
|
|
|
|
+ // foreach ($catArrId as $categoryId) {
|
|
|
|
+ $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
|
+ $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
|
|
+ if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
|
|
|
|
+ $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
|
+ $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
|
|
|
|
+ }
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ $article->pinyin = $pinyin;
|
|
|
|
+ return $article;
|
|
|
|
+ });
|
|
if (empty($result)) {
|
|
if (empty($result)) {
|
|
return Result::error("暂无头条新闻", 0);
|
|
return Result::error("暂无头条新闻", 0);
|
|
}
|
|
}
|
|
@@ -1318,7 +1352,7 @@ class NewsService implements NewsServiceInterface
|
|
// return Result::error("暂无此栏目",0);
|
|
// return Result::error("暂无此栏目",0);
|
|
}else{
|
|
}else{
|
|
$parent_alias = $category->alias ?? '';
|
|
$parent_alias = $category->alias ?? '';
|
|
- $parent_pinyin = $category->aLIas_pinyin ?'/'.$category->aLIas_pinyin.'/' : null;
|
|
|
|
|
|
+ $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
// 查询图片新闻
|
|
// 查询图片新闻
|
|
$imgArticles = Article::where('catid', $parentCatId)
|
|
$imgArticles = Article::where('catid', $parentCatId)
|
|
->where('status', 1)
|
|
->where('status', 1)
|
|
@@ -1376,15 +1410,15 @@ class NewsService implements NewsServiceInterface
|
|
];
|
|
];
|
|
|
|
|
|
if (!empty($item['child']) && $item['child'] != "") {
|
|
if (!empty($item['child']) && $item['child'] != "") {
|
|
- $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin : '';
|
|
|
|
|
|
+ $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
|
|
$childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
|
|
$childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
|
|
- ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin_str])
|
|
|
|
|
|
+ ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
|
|
->get()->all();
|
|
->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)
|
|
$childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
|
|
- ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin])
|
|
|
|
|
|
+ ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
|
|
->first();
|
|
->first();
|
|
$child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
|
|
$child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
|
|
if(empty($childCategoryInfo)){
|
|
if(empty($childCategoryInfo)){
|
|
@@ -1473,7 +1507,7 @@ class NewsService implements NewsServiceInterface
|
|
];
|
|
];
|
|
// 查询栏目名称
|
|
// 查询栏目名称
|
|
$category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
|
|
$category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
|
|
- $pinyin = $category->aLIas_pinyin ? '/'.$category->aLIas_pinyin.'/' : null;
|
|
|
|
|
|
+ $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
if(empty($category)){
|
|
if(empty($category)){
|
|
$imgArticles = [];
|
|
$imgArticles = [];
|
|
$textArticles = [];
|
|
$textArticles = [];
|