二次改版

This commit is contained in:
2022-06-29 17:03:47 +08:00
parent 2288b76e4e
commit 619e493b0e
168 changed files with 4676 additions and 1759 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Article;
use App\Models\Category;
use App\Models\Leader;
class CategoryController extends Controller
{
@@ -15,36 +16,115 @@ class CategoryController extends Controller
* @param Category $category [description]
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View [type] [description]
*/
public function index(Category $category)
public function show(Category $category)
{
if ($category->type == Category::TYPE_SHOW && $category->article_id) {
return redirect("articles/".$category->article_id);
} else {
// $articles = $category->relations(Category::TYPE_ARTICLE)
// ->where('status', 1)
// ->latest('sort')
// ->latest()
// ->paginate();
//跳转地址
if ($category->type == Category::TYPE_LINK && $category->uri) {
return redirect()->away($category->uri);
}
$topCate = $category->getTopCategory();
$template = 'list';
if ($category->template) {
$template = $category->template;
}
$parent = $category;
if ($category->children->isEmpty() && $category->parent) {
$parent = $category->parent;
}
$articles = Article::ByCategory($category->getAllChildrenId())
->where('status', 1)
->Bysort()
->paginate();
$data = [
'articles' => $articles,
'category' => $category,
'parent' => $parent,
'topCate' => $topCate,
];
if ($category->id == 2) {
$article = Article::query()->ByCategory(2)->Bysort()->first();
$data = array_merge($data, [
'article' => $article,
]);
}
if ($category->id == 18) {
$cgCate = Category::find(24);
$hjCate = Category::find(20);
$zlCate = Category::find(21);
$cgArticles = Article::query()->ByCategory($cgCate->id)->Bysort()->take(3)->get();
$hjArticles = Article::query()->ByCategory($hjCate->id)->Bysort()->take(3)->get();
$zlArticles = Article::query()->ByCategory($zlCate->id)->Bysort()->take(6)->get();
$data = array_merge($data, [
'cgCate' => $cgCate,
'hjCate' => $hjCate,
'zlCate' => $zlCate,
'cgArticles' => $cgArticles,
'hjArticles' => $hjArticles,
'zlArticles' => $zlArticles,
]);
}
if ($category->id == 3) {
$articles = Article::ByCategory($category->getAllChildrenId())
->where('status', 1)
->latest()
->latest('created_at')
->paginate();
->Bysort()
->get();
$parent = $category;
if ($category->childrens->isEmpty() && $category->parent) {
$parent = $category->parent;
}
$advert = Advert::where('category_id', 73)->first();
if ($category->id == 4) {
return view('category.list', compact('articles', 'category', 'parent', 'advert'));
}
return view('category.show', compact('articles', 'category', 'parent', 'advert'));
$data = array_merge($data, [
'articles' => $articles,
]);
}
if ($category->id == 5) {
$tzCate = Category::find(6);
$nyydtCate = Category::find(7);
$mtbdCate = Category::find(31);
$tzArticles = Article::query()->ByCategory($tzCate->id)->Bysort()->take(4)->get();
$nyydtArticles = Article::query()->ByCategory($nyydtCate->id)->Bysort()->take(3)->get();
$mtbdArticles = Article::query()->ByCategory($mtbdCate->id)->Bysort()->take(3)->get();
$data = array_merge($data, [
'tzCate' => $tzCate,
'nyydtCate' => $nyydtCate,
'mtbdCate' => $mtbdCate,
'tzArticles' => $tzArticles,
'nyydtArticles' => $nyydtArticles,
'mtbdArticles' => $mtbdArticles,
]);
}
if ($category->id == 11) {
$yjCate = Category::find(12);
$zdCate = Category::find(16);
$ljCate = Category::find(29);
$yjArticles = Article::query()->ByCategory($yjCate->id)->Bysort()->take(3)->get();
$ljLeaders = Leader::query()->where('category_id', $ljCate->id)->Bysort()->take(3)->get();
$data = array_merge($data, [
'yjCate' => $yjCate,
'zdCate' => $zdCate,
'ljCate' => $ljCate,
'yjArticles' => $yjArticles,
'ljLeaders' => $ljLeaders,
]);
}
if ($category->id == 32) {
$nghjxhArticle = Article::query()->ByCategory($category->id)->Bysort()->first();
$data = array_merge($data, [
'nghjxhArticle' => $nghjxhArticle,
]);
}
return view('category.'.$template, $data);
}
}