|
@@ -479,45 +479,55 @@ class NewsService implements NewsServiceInterface
|
|
|
{
|
|
|
// return Result::success($data);
|
|
|
$where[] = ['status', '=', 1];
|
|
|
+ $website_id = $data['website_id'];
|
|
|
if (isset($data['catid']) && !empty($data['catid'])) {
|
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
|
|
|
- array_push($where, ['catid', '=', $data['catid']]);
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
|
|
|
if (empty($category)) {
|
|
|
return Result::error("此网站暂无此栏目", 0);
|
|
|
}
|
|
|
+ array_push($where, ['catid', '=', $data['catid']]);
|
|
|
+
|
|
|
}
|
|
|
// return Result::success($where);
|
|
|
- $rep = Article::where($where)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->select(
|
|
|
- 'article.id',
|
|
|
- 'article.title',
|
|
|
- 'article.imgurl',
|
|
|
- 'article.author',
|
|
|
- 'article.updated_at',
|
|
|
- 'article.introduce',
|
|
|
- 'article.islink',
|
|
|
- 'article.linkurl',
|
|
|
- 'article.copyfrom',
|
|
|
- 'article.cat_arr_id',
|
|
|
- 'article.catid')
|
|
|
- ->orderBy("updated_at", "desc")
|
|
|
+ $query = Article::where($where)
|
|
|
+ ->leftJoinSub(function ($query) use ($website_id) {
|
|
|
+ $query->from('article_ignore')
|
|
|
+ ->where('website_id', $website_id);
|
|
|
+ }, 'article_ignore', function ($join) {
|
|
|
+ $join->on('article_ignore.article_id', '=', 'article.id');
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($website_id) {
|
|
|
+ $query->whereNull('article_ignore.article_id')
|
|
|
+ ->orWhere('article_ignore.website_id', '!=', $website_id);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'article.id',
|
|
|
+ 'article.title',
|
|
|
+ 'article.imgurl',
|
|
|
+ 'article.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.copyfrom',
|
|
|
+ 'article.cat_arr_id',
|
|
|
+ 'article.catid');
|
|
|
+ $count = $query->count();
|
|
|
+ $rep = $query->orderBy("updated_at", "desc")
|
|
|
->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
->limit($data['pageSize'])
|
|
|
- ->get();
|
|
|
- $web['website_id'] = $data['website_id'];
|
|
|
- $rep = $this->processArticles($rep,$web);
|
|
|
- $count = Article::where($where)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })->count();
|
|
|
-
|
|
|
+ ->get()->all();
|
|
|
+ $categorys = $this->processArticlePro($website_id);
|
|
|
+ $cat_1st_arr = $categorys['cat_1st_arr'];
|
|
|
+ $catiall = $categorys['catiall'];
|
|
|
+ // $web['website_id'] = $data['website_id'];
|
|
|
+ foreach ($rep as $k => $v) {
|
|
|
+ $rep[$k]->category_name = $catiall[$v->catid]['alias'];
|
|
|
+ $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
|
|
|
+ }
|
|
|
+ // $rep = $this->processArticles($rep,$web);
|
|
|
$data = [
|
|
|
- 'rows' => $rep->toArray(),
|
|
|
+ 'rows' => $rep,
|
|
|
'count' => $count,
|
|
|
];
|
|
|
|
|
@@ -830,12 +840,20 @@ class NewsService implements NewsServiceInterface
|
|
|
public function selectWebsiteArticle(array $data): array
|
|
|
{
|
|
|
$category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
|
|
|
+ $website_id = $data['website_id'];
|
|
|
+ $categorys = $this->processArticlePro($website_id);
|
|
|
+ $catiall = $categorys['catiall'];
|
|
|
$query = Article::where('status', 1)
|
|
|
->whereIn('catid', $category)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->where(function ($subQuery) use ($data) {
|
|
|
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
|
|
|
- })->orWhereNull("ignore_ids");
|
|
|
+ ->leftJoinSub(function ($query) use ($website_id) {
|
|
|
+ $query->from('article_ignore')
|
|
|
+ ->where('website_id', $website_id);
|
|
|
+ }, 'article_ignore', function ($join) {
|
|
|
+ $join->on('article_ignore.article_id', '=', 'article.id');
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($website_id) {
|
|
|
+ $query->whereNull('article_ignore.article_id')
|
|
|
+ ->orWhere('article_ignore.website_id', '!=', $website_id);
|
|
|
});
|
|
|
// return Result::success($all_articles);
|
|
|
if (isset($data['cityid']) && !empty($data['cityid'])) {
|
|
@@ -869,8 +887,11 @@ class NewsService implements NewsServiceInterface
|
|
|
->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
->limit($data['pageSize'])
|
|
|
->get();
|
|
|
- $web['website_id'] = $data['website_id'];
|
|
|
- $articles = $this->processArticles($articles,$web);
|
|
|
+
|
|
|
+ foreach ($articles as $k => $v) {
|
|
|
+ $articles[$k]->category_name = $catiall[$v->catid]['alias'];
|
|
|
+ $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
|
|
|
+ }
|
|
|
if (empty($articles)) {
|
|
|
return Result::error("没有符合条件的资讯数据");
|
|
|
}
|
|
@@ -1210,142 +1231,89 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
|
|
|
*/
|
|
|
public function getWebsiteArticles(array $data): array
|
|
|
{
|
|
|
- $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{
|
|
|
- $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
|
|
|
- $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
|
|
|
- // return Result::success($website);
|
|
|
- // 查询图片新闻
|
|
|
- // 合并查询条件
|
|
|
- $baseQuery = Article::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('website_category.website_id', $website['website_id'])
|
|
|
- ->where('article.status', 1)
|
|
|
- ->leftJoin('website_category', 'website_category.category_id', 'article.catid');
|
|
|
-
|
|
|
- // 查询文字新闻
|
|
|
- $textArticles = clone $baseQuery;
|
|
|
- $textArticles = $textArticles->whereIn('catid',$child_category)
|
|
|
- ->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", [$parent_alias])
|
|
|
- ->orderBy('article.updated_at', 'desc')
|
|
|
- ->limit($parentTextNum)
|
|
|
- ->get()
|
|
|
- ->all();
|
|
|
- if(empty($textArticles)){
|
|
|
- $textArticles = clone $baseQuery;
|
|
|
- $textArticles = $textArticles->where('catid',$parentCatId)
|
|
|
- ->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", [$parent_alias])
|
|
|
- ->orderBy('article.updated_at', 'desc')
|
|
|
- ->limit($parentTextNum)
|
|
|
- ->get()
|
|
|
- ->all();
|
|
|
- }
|
|
|
- // 查询图片新闻
|
|
|
- $imgArticles = clone $baseQuery;
|
|
|
- $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid',$child_category)
|
|
|
- ->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", [$parent_alias])
|
|
|
- ->orderBy('article.updated_at', 'desc')
|
|
|
- ->limit($parentImgNum)
|
|
|
- ->get()
|
|
|
- ->all();
|
|
|
- if(empty($imgArticles)){
|
|
|
- $imgArticles = clone $baseQuery;
|
|
|
- $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid',$parentCatId)
|
|
|
- ->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", [$parent_alias])
|
|
|
- ->orderBy('article.updated_at', 'desc')
|
|
|
- ->limit($parentImgNum)
|
|
|
- ->get()
|
|
|
- ->all();
|
|
|
+ $website_id = $data['website_id'];
|
|
|
+ $catids = json_decode($data['id'], true);
|
|
|
+ $parent_category = array_column($catids, 'parent');
|
|
|
+ if(!empty($parent_category) && is_array($parent_category)){
|
|
|
+ $categorys = $this->processArticlePro($website_id);
|
|
|
+ $catiall = $categorys['catiall'];
|
|
|
+ $cat_1st_arr = $categorys['cat_1st_arr'];
|
|
|
+ // return Result::success($categorys);
|
|
|
+ foreach($parent_category as $key => $value){
|
|
|
+ $arr = array_map('intval', explode(',', $value));
|
|
|
+ $parent_category = $arr[0] ?? 0;
|
|
|
+ $article_imgnum = $arr[1] ?? 0;
|
|
|
+ $article_textnum = $arr[2] ?? 0;
|
|
|
+ if($parent_category != 0){
|
|
|
+ $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
|
|
|
+ // return Result::success($category_arr);
|
|
|
+ if($article_imgnum != 0){
|
|
|
+ $img_article = Article::whereIn('catid', $category_arr)
|
|
|
+ ->where('status',1)
|
|
|
+ ->where('imgurl','!=', '')
|
|
|
+ ->leftJoinSub(function ($query) use ($website_id) {
|
|
|
+ $query->from('article_ignore')
|
|
|
+ ->where('website_id', $website_id);
|
|
|
+ }, 'article_ignore', function ($join) {
|
|
|
+ $join->on('article_ignore.article_id', '=', 'article.id');
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($website_id) {
|
|
|
+ $query->whereNull('article_ignore.article_id')
|
|
|
+ ->orWhere('article_ignore.website_id', '!=', $website_id);
|
|
|
+ })
|
|
|
+ ->select('id','title','imgurl','author','updated_at','introduce',
|
|
|
+ 'islink','linkurl','copyfrom','cat_arr_id','catid as category_id')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($article_imgnum)
|
|
|
+ ->get()->all();
|
|
|
+
|
|
|
+ foreach ($img_article as $k => $v) {
|
|
|
+ $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
|
|
|
+ // return Result::success($v);
|
|
|
+
|
|
|
+ $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $img_article = [];
|
|
|
+ }
|
|
|
+ if($article_textnum != 0){
|
|
|
+ $text_article = Article::whereIn('catid', $category_arr)
|
|
|
+ ->where('status',1)
|
|
|
+ ->leftJoinSub(function ($query) use ($website_id) {
|
|
|
+ $query->from('article_ignore')
|
|
|
+ ->where('website_id', $website_id);
|
|
|
+ }, 'article_ignore', function ($join) {
|
|
|
+ $join->on('article_ignore.article_id', '=', 'article.id');
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($website_id) {
|
|
|
+ $query->whereNull('article_ignore.article_id')
|
|
|
+ ->orWhere('article_ignore.website_id', '!=', $website_id);
|
|
|
+ })
|
|
|
+ ->select('id','title','author','updated_at','introduce','islink',
|
|
|
+ 'linkurl','copyfrom','cat_arr_id','catid as category_id')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($article_textnum)
|
|
|
+ ->get()->all();
|
|
|
+ foreach ($text_article as $k => $v) {
|
|
|
+ $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
|
|
|
+ $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
|
|
|
+ // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $text_article = [];
|
|
|
+ }
|
|
|
+ $catiall[$parent_category]['imgnum'] = $img_article ?? [];
|
|
|
+ $catiall[$parent_category]['textnum'] = $text_article ?? [];
|
|
|
+ $parent[$key] = $catiall[$parent_category];
|
|
|
+ }else{
|
|
|
+ $parent[$key] = [];
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- $resultItem = [
|
|
|
- 'alias' => $category ? $category->alias : null,
|
|
|
- 'category_id' => $parentCatId,
|
|
|
- 'pinyin' => $pinyin ? $pinyin : null,
|
|
|
- 'imgnum' => $imgArticles ?? [],
|
|
|
- 'textnum' => $textArticles ?? [],
|
|
|
-
|
|
|
- ];
|
|
|
-
|
|
|
+ }
|
|
|
|
|
|
- return $resultItem;
|
|
|
- }, $data);
|
|
|
- return Result::success($result);
|
|
|
+ return Result::success($parent);
|
|
|
|
|
|
}
|
|
|
|