|
@@ -1448,18 +1448,210 @@ class NewsService implements NewsServiceInterface
|
|
|
->get();
|
|
|
}
|
|
|
|
|
|
- // $category = $category->get();
|
|
|
-
|
|
|
- if (empty($category)) {
|
|
|
- return Result::error("查询失败", 0);
|
|
|
+ // $category = $category->get();
|
|
|
+
|
|
|
+ if(empty($category)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($category);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 模块新闻加强plus版
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteAllArticle(array $data): array
|
|
|
+ {
|
|
|
+ $time1 = microtime(true);
|
|
|
+ $wetbsite_id = $data['website_id'] ?? 2;
|
|
|
+ $data = json_decode($data['id'], true);
|
|
|
+
|
|
|
+ $categorys = $this->processArticlePro($wetbsite_id);
|
|
|
+ $cat_1st_arr = $categorys['cat_1st_arr'];
|
|
|
+ $catiall = $categorys['catiall'];
|
|
|
+ $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
|
|
|
+ $parent_category = array_column($data, 'parent');
|
|
|
+ $parent_cat = [];
|
|
|
+ $child_category = array_column($data,'child');
|
|
|
+ if(!empty($parent_category)){
|
|
|
+ foreach($parent_category as $key => $value){
|
|
|
+ $arr = array_map('intval', explode(',', $value));
|
|
|
+ $parent_cat[$key] = $arr[0] ?? 0;
|
|
|
+ $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 ($wetbsite_id) {
|
|
|
+ $query->from('article_ignore')
|
|
|
+ ->where('website_id', $wetbsite_id);
|
|
|
+ }, 'article_ignore', function ($join) {
|
|
|
+ $join->on('article_ignore.article_id', '=', 'article.id');
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($wetbsite_id) {
|
|
|
+ $query->whereNull('article_ignore.article_id')
|
|
|
+ ->orWhere('article_ignore.website_id', '!=', $wetbsite_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')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($article_imgnum)
|
|
|
+ ->get()->all();
|
|
|
+ foreach ($img_article as $k => $v) {
|
|
|
+ $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
|
|
|
+ $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
|
|
|
+
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $img_article = [];
|
|
|
+ }
|
|
|
+ if($article_textnum != 0){
|
|
|
+ $text_article = Article::whereIn('catid', $category_arr)
|
|
|
+ ->where('status',1)
|
|
|
+ ->leftJoinSub(function ($query) use ($wetbsite_id) {
|
|
|
+ $query->from('article_ignore')
|
|
|
+ ->where('website_id', $wetbsite_id);
|
|
|
+ }, 'article_ignore', function ($join) {
|
|
|
+ $join->on('article_ignore.article_id', '=', 'article.id');
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($wetbsite_id) {
|
|
|
+ $query->whereNull('article_ignore.article_id')
|
|
|
+ ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
|
|
|
+ })
|
|
|
+ ->select('id','title','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($article_textnum)
|
|
|
+ ->get()->all();
|
|
|
+ foreach ($text_article as $k => $v) {
|
|
|
+ $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
|
|
|
+ $text_article[$k]->pinyin = $catiall[$v->catid]['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] = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- return Result::success($category);
|
|
|
- }
|
|
|
- /**
|
|
|
- * 模块新闻加强版
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
+ if(!empty($child_category)){
|
|
|
+ foreach($child_category as $key => $value){
|
|
|
+ $arr = array_map('intval', explode(',', $value));
|
|
|
+ $parent_category = $parent_cat[$key];
|
|
|
+ $child_category = $arr[0] ?? 0;
|
|
|
+ $article_imgnum = $arr[1] ?? 0;
|
|
|
+ $article_textnum = $arr[2] ?? 0;
|
|
|
+
|
|
|
+ if($child_category != 0){
|
|
|
+ $all_childcat = $cat_1st_arr[$parent_category];
|
|
|
+ $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
|
|
|
+ // 从 $websiteInfoIndexed 中获取对应的数据
|
|
|
+ $info = $websiteInfoIndexed[$v];
|
|
|
+ // 返回一个包含所需信息的数组
|
|
|
+ return [
|
|
|
+ 'alias' => $info->alias,
|
|
|
+ 'category_id' => $info->category_id,
|
|
|
+ 'aLIas_pinyin' => $info->aLIas_pinyin,
|
|
|
+ 'pid' => $info->pid,
|
|
|
+ 'type' => $info->type,
|
|
|
+ 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
|
|
|
+ 'pinyin' => $info->pinyin,
|
|
|
+ ];
|
|
|
+ }, $all_childcat);
|
|
|
+ if($article_imgnum != 0){
|
|
|
+ $img_article = Article::where('catid', $child_category)
|
|
|
+ ->where('status',1)
|
|
|
+ ->where('imgurl','!=', '')
|
|
|
+ ->leftJoinSub(function ($query) use ($wetbsite_id) {
|
|
|
+ $query->from('article_ignore')
|
|
|
+ ->where('website_id', $wetbsite_id);
|
|
|
+ }, 'article_ignore', function ($join) {
|
|
|
+ $join->on('article_ignore.article_id', '=', 'article.id');
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($wetbsite_id) {
|
|
|
+ $query->whereNull('article_ignore.article_id')
|
|
|
+ ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
|
|
|
+ })
|
|
|
+ ->select('id','title','imgurl','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($article_imgnum)
|
|
|
+ ->get()->all();
|
|
|
+ foreach ($img_article as $k => $v) {
|
|
|
+ // var_dump($v);
|
|
|
+ // var_dump($k);
|
|
|
+ $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
|
|
|
+ $img_article[$k]->alias = $catiall[$v->catid]['alias'];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $img_article = [];
|
|
|
+ }
|
|
|
+ if($article_textnum != 0){
|
|
|
+ $text_article = Article::where('catid', $child_category)
|
|
|
+ ->where('status',1)
|
|
|
+ ->leftJoinSub(function ($query) use ($wetbsite_id) {
|
|
|
+ $query->from('article_ignore')
|
|
|
+ ->where('website_id', $wetbsite_id);
|
|
|
+ }, 'article_ignore', function ($join) {
|
|
|
+ $join->on('article_ignore.article_id', '=', 'article.id');
|
|
|
+ })
|
|
|
+ ->where(function ($query) use ($wetbsite_id) {
|
|
|
+ $query->whereNull('article_ignore.article_id')
|
|
|
+ ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
|
|
|
+ })
|
|
|
+ ->select('id','title','author','updated_at','introduce','islink','linkurl','copyfrom','cat_arr_id','catid')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($article_textnum)
|
|
|
+ ->get()->all();
|
|
|
+ foreach ($text_article as $k => $v) {
|
|
|
+ // var_dump($v);
|
|
|
+ // var_dump($k);
|
|
|
+ $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
|
|
|
+ // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
|
|
|
+ $text_article[$k]->alias = $catiall[$v->catid]['alias'];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $text_article = [];
|
|
|
+ }
|
|
|
+ $catiall[$child_category]['all_childcat'] = $processedChildCat;
|
|
|
+ $catiall[$child_category]['imgnum'] = $img_article;
|
|
|
+ $catiall[$child_category]['textnum'] = $text_article;
|
|
|
+ $child[$key] = $catiall[$child_category];
|
|
|
+ // var_dump($pids);
|
|
|
+ }else{
|
|
|
+ $child[$key] = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach($parent as $key => $value){
|
|
|
+ $result[$key] = $value;
|
|
|
+ if(!empty($child[$key])){
|
|
|
+ // var_dump($child[$key]);
|
|
|
+
|
|
|
+ $result[$key]['child'] = $child[$key];
|
|
|
+ // $value[$key]['child'] = $child[$key];
|
|
|
+ }else{
|
|
|
+ $result[$key]['child'] = [
|
|
|
+ "alias" => null,
|
|
|
+ "category_id" => null,
|
|
|
+ "type" => null,
|
|
|
+ "pinyin" => null,
|
|
|
+ "all_childcat" => [],
|
|
|
+ "imgnum" => [],
|
|
|
+ "textnum" => []
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* 辅助方法:获取文章列表
|
|
@@ -1980,20 +2172,12 @@ class NewsService implements NewsServiceInterface
|
|
|
//一级所有子级的记录
|
|
|
$cat_1st_arr = [];
|
|
|
foreach ($categorys as $key => $value) {
|
|
|
- if($value->pid != 0 && !in_array($value->category_id,$categoryPIds)){
|
|
|
- $cat_1st_arr[$value->pid][] = $value->category_id;
|
|
|
- }
|
|
|
- // unset($cat_1st_arr[0]);
|
|
|
- // //算出路由拼音
|
|
|
$category_arr_id = json_decode($value->category_arr_id);
|
|
|
$pinyin_str = '';
|
|
|
// 算出一级 并且算出子级
|
|
|
- if ($value->pid == 0) {
|
|
|
+ if ($value->pid != 0) {
|
|
|
$cat_1st_arr[$value->pid][] = $value->category_id;
|
|
|
- } else {
|
|
|
- $cat_1st_arr[$value->category_id][] = [];
|
|
|
- // $cat_1st_arr[$value->pid][] = $value->category_id;
|
|
|
- }
|
|
|
+ }
|
|
|
foreach ($category_arr_id as $k => $v) {
|
|
|
$pinyin_str .= $cat_arr[$v] . '/';
|
|
|
}
|
|
@@ -2002,7 +2186,6 @@ class NewsService implements NewsServiceInterface
|
|
|
$catiall[$value->category_id]['category_id'] = $value->category_id;
|
|
|
$catiall[$value->category_id]['type'] = $value->type;
|
|
|
$catiall[$value->category_id]['pinyin'] = $pinyin_str;
|
|
|
- // $cat_id = $value->category_id;
|
|
|
$websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
|
|
|
}
|
|
|
return [
|