|
@@ -288,8 +288,8 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
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 = [];
|
|
|
if ($category) {
|
|
|
$placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
@@ -297,13 +297,50 @@ class NewsService implements NewsServiceInterface
|
|
|
'status' => 1,
|
|
|
];
|
|
|
var_dump($data, 'data-----------------');
|
|
|
-
|
|
|
+ // level=7 根据文章key来匹配文章
|
|
|
+ if (isset($data['level']) && $data['level'] == 7) {
|
|
|
+ // 根据文章id获取key
|
|
|
+ // $data['id'] = 50142;
|
|
|
+ if (isset($data['id']) && !empty($data['id'])) {
|
|
|
+ $keyword = Article::where('id', $data['id'])->value('keyword');
|
|
|
+ $keywordArray = explode(',', $keyword);
|
|
|
+ $whereL7 = [];
|
|
|
+ foreach ($keywordArray as $k => $v) {
|
|
|
+ $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
|
|
|
+ }
|
|
|
+ // 原始查询
|
|
|
+ $result = Article::where($whereL7)
|
|
|
+ ->offset($placeid)
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->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);
|
|
|
+ } else {
|
|
|
+ return Result::error("参数错误level=7,id不能为空", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
//如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
|
|
|
// 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
|
|
|
var_dump($where, 'where-----------------');
|
|
|
-
|
|
|
$result = Article::where($where)
|
|
|
->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) {
|
|
|
$query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
->orWhereNull("ignore_ids");
|
|
@@ -315,17 +352,35 @@ class NewsService implements NewsServiceInterface
|
|
|
->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
|
|
|
})
|
|
|
->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) {
|
|
|
if ($data['level'] != 4 && $data['level'] != 5) {
|
|
|
$query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
|
- ->orderBy("updated_at", "desc");
|
|
|
+ ->orderBy("article.updated_at", "desc");
|
|
|
}
|
|
|
})
|
|
|
+ ->select('article.*')
|
|
|
->offset($placeid)
|
|
|
->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)) {
|
|
|
return Result::error("暂无头条新闻", 0);
|
|
|
}
|
|
@@ -915,7 +970,7 @@ class NewsService implements NewsServiceInterface
|
|
|
// return Result::error("暂无此栏目",0);
|
|
|
}else{
|
|
|
$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)
|
|
|
->where('status', 1)
|
|
@@ -973,15 +1028,15 @@ class NewsService implements NewsServiceInterface
|
|
|
];
|
|
|
|
|
|
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)
|
|
|
- ->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();
|
|
|
if ($childCategory) {
|
|
|
list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
|
|
|
// 查询子栏目名称
|
|
|
$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();
|
|
|
$child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
|
|
|
if(empty($childCategoryInfo)){
|
|
@@ -1071,7 +1126,7 @@ class NewsService implements NewsServiceInterface
|
|
|
];
|
|
|
// 查询栏目名称
|
|
|
$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)){
|
|
|
$imgArticles = [];
|
|
|
$textArticles = [];
|