二次改版

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

@@ -14,7 +14,22 @@ class ArticleController extends Controller
return redirect($article->url);
}
return view('articles.show', compact('article'));
$category = $article->categories()->first();
$parent = $category;
$topCate = $category->getTopCategory();
if ($category->childrens->isEmpty() && $category->parent) {
$parent = $category->parent;
}
$data = [
'article' => $article,
'category' => $category,
'parent' => $parent,
'topCate' => $topCate,
];
return view('articles.show', $data);
}
}

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);
}
}

View File

@@ -19,12 +19,13 @@ class Controller extends BaseController
{
//顶部分类
$categorys = Category::where('status', 1)
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW])
->where('top_show', 1)
->orderBy('order', 'asc')
->select('id', 'title')
->get();
$links = Link::get();
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_LINK])
->where('top_show', 1)
->orderBy('order', 'asc')
->select('id', 'title')
->get();
$links = Link::get();
View::share('all_categorys', $categorys);
View::share('links', $links);

View File

@@ -4,19 +4,134 @@ namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Article;
use App\Models\Category;
use App\Models\Link;
use Illuminate\Http\Request;
class IndexController extends Controller
{
/**
* Notes: 首页
*
* @Author: 玄尘
* @Date : 2020/6/1 9:11
*/
public function index()
{
return view('index.index');
$nyydtCate = Category::find(7);//能源院动态
$mtbdCate = Category::find(31);//媒体报道
$dzjsCate = Category::find(28);//党政建设
$xxydCate = Category::find(9);//学习园地
$notices = Article::query()
->ByCategory(6)
->bysort()
->take(2)
->get();//两个通知公告
$mtbdArticles = Article::query()
->byCategory(31)
->bysort()
->take(2)
->get();
$nyydtimg = Article::query()
->byCategory(7)
->whereNotNull('cover')
->bysort()
->take(2)
->get();
$nyydt = Article::query()
->whereNotIn('id', $nyydtimg->pluck('id'))
->byCategory(7)
->bysort()
->take(4)
->get();
$dzjsimg = Article::query()
->byCategory($dzjsCate->id)
->whereNotNull('cover')
->bysort()
->first();
$dzjsArticles = Article::query()
->where('id', '<>', $dzjsimg->id)
->byCategory($dzjsCate->id)
->bysort()
->take(6)
->get();
$xxydimg = Article::query()
->byCategory($xxydCate->id)
->whereNotNull('cover')
->bysort()
->first();
$xxydArticles = Article::query()
->where('id', '<>', $xxydimg->id)
->byCategory($xxydCate->id)
->bysort()
->take(6)
->get();
$advert = Advert::query()->where('category_id', 36)->first();
$categorys = Category::oldest('order')->find([20, 21, 24]);//成果
$categorys = $categorys->map(function ($info) {
$imgArticle = Article::query()
->byCategory($info->id)
->whereNotNull('cover')
->bysort()
->first();
$info->imgArticle = $imgArticle;
$info->articleLists = Article::query()
->where('id', '<>', $imgArticle->id)
->byCategory($info->id)
->bysort()
->take(4)
->get();
return $info;
});
$data = compact(
'categorys',
'xxydCate',
'mtbdCate',
'nyydtCate',
'dzjsCate',
'notices',
'mtbdArticles',
'xxydArticles',
'dzjsArticles',
'nyydt',
'dzjsimg',
'xxydimg',
'advert',
'nyydtimg'
);
return view('index.index', $data);
}
/**
* Notes: 搜索
*
* @Author: 玄尘
* @Date: 2022/6/29 10:14
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function search(Request $request)
{
$title = $request->title;
$articles = Article::query()->latest()->where('title', 'like', "%{$title}%")->paginate();
return view('index.search', compact('articles'));
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\Staff;
class StaffController extends Controller
{
public $category_id = 16;
public function index()
{
$category = Category::find($this->category_id);
$parent = $category;
$topCate = $category->getTopCategory();
if ($category->childrens->isEmpty() && $category->parent) {
$parent = $category->parent;
}
$staffs = Staff::query()->latest('order')->get();
$data = [
'staffs' => $staffs,
'category' => $category,
'parent' => $parent,
'topCate' => $topCate,
];
return view('staff.index', $data);
}
/**
* Notes: description
*
* @Author: 玄尘
* @Date : 2021/10/8 14:54
* @param \App\Models\Staff $staff
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show(Staff $staff)
{
$parent = $category = $staff->category;
if ($category->children->isEmpty() && $category->parent) {
$parent = $category->parent;
}
$topCate = $category->getTopCategory();
return view('staff.show', compact('staff', 'category', 'topCate', 'parent'));
}
}

View File

@@ -58,7 +58,7 @@ class TestController extends Controller
$info = Article::create($data);
$cate->article_id = $info->id;
$cate->type = Category::TYPE_SHOW;
$cate->type = Category::TYPE_LINK;
$cate->save();
$article[] = $info->id;
}