二次改版
This commit is contained in:
@@ -22,7 +22,7 @@ class IndexController extends AdminController
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('title', '文章标题');
|
||||
$filter->equal('categories.id', '所属分类')->select(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_LINK]);
|
||||
}, '所有分类'));
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ class IndexController extends AdminController
|
||||
return $this->categories()->pluck('title');
|
||||
})->label();
|
||||
$grid->column('title', '文章标题');
|
||||
$grid->column('sort', '序号');
|
||||
$grid->column('sort', '序号')->editable();
|
||||
$states = [
|
||||
'on' => ['value' => 1, 'text' => '打开', 'color' => 'primary'],
|
||||
'off' => ['value' => 0, 'text' => '关闭', 'color' => 'default'],
|
||||
@@ -51,8 +51,9 @@ class IndexController extends AdminController
|
||||
$form = new Form(new Article);
|
||||
|
||||
$form->text('title', '文章标题')->rules('min:2');
|
||||
$form->text('origin', '来源');
|
||||
$form->belongsToMany('categories', CategorySelectAble::class, __('关联分类'));
|
||||
$form->textarea('description', '内容简介')->rules('max:350');
|
||||
$form->textarea('description', '内容简介');
|
||||
|
||||
$form->list('subjoin', '附加')
|
||||
->help('只有领导班子需要添加');
|
||||
@@ -62,6 +63,11 @@ class IndexController extends AdminController
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->multipleImage('pictures', '多图')
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->ueditor('content', '文章内容')->rules('required', ['required' => '详情不能为空']);
|
||||
$form->number('sort', '序号')
|
||||
->default(0)->rules('required', ['required' => '序号必须填写'])
|
||||
|
||||
@@ -19,6 +19,7 @@ class IndexController extends AdminController
|
||||
|
||||
/**
|
||||
* Index interface.
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
public function grid()
|
||||
@@ -34,23 +35,23 @@ class IndexController extends AdminController
|
||||
}, '一级分类'));
|
||||
$form->text('title', '分类名称')->rules('required');
|
||||
$form->select('type', '分类类型')
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (WidgetsForm $form) {
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
return Article::whereHas('categories', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
->options(Category::TYPES)
|
||||
->when(Category::TYPE_LINK, function (WidgetsForm $form) {
|
||||
$form->text('uri', '跳转地址');
|
||||
})
|
||||
->required();
|
||||
$form->textarea('description', '分类简介')
|
||||
->rules('nullable');
|
||||
->rules('nullable');
|
||||
$form->image('cover', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->image('label', '标签')
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->select('template', '模板')->options(config('settings.templates'));
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(0);
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->action(admin_url('categories'));
|
||||
@@ -74,9 +75,13 @@ class IndexController extends AdminController
|
||||
} else {
|
||||
$payload = "<i class='fa fa-eye text-gray'></i> ";
|
||||
}
|
||||
|
||||
$template = $branch['template'] ?? 'list';
|
||||
|
||||
$payload .= " [ID:{$branch['id']}] - ";
|
||||
$payload .= " <strong>{$branch['title']}</strong> ";
|
||||
$payload .= " <small>{$branch['type']}</small> ";
|
||||
$payload .= "【 {$template} 】";
|
||||
$payload .= " <small style='color:#999'>{$branch['description']}</small>";
|
||||
|
||||
return $payload;
|
||||
@@ -86,9 +91,10 @@ class IndexController extends AdminController
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
protected function form(): Form
|
||||
{
|
||||
$form = new Form(new Category);
|
||||
|
||||
@@ -97,23 +103,20 @@ class IndexController extends AdminController
|
||||
}, '一级分类'));
|
||||
$form->text('title', '分类名称')->rules('required');
|
||||
$form->select('type', '分类类型')
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (Form $form) {
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
return Article::whereHas('categories', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required()
|
||||
->rules('required');
|
||||
->options(Category::TYPES)
|
||||
->when(Category::TYPE_LINK, function (Form $form) {
|
||||
$form->text('uri', '跳转地址');
|
||||
})
|
||||
->required()
|
||||
->rules('required');
|
||||
$form->textarea('description', '分类简介')->rows(4)->rules('nullable');
|
||||
$form->image('cover', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->number('order', '排序')->default(0)->help('正序优先');
|
||||
$form->select('template', '模板')->options(config('settings.templates'));
|
||||
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(0);
|
||||
@@ -121,13 +124,13 @@ class IndexController extends AdminController
|
||||
$form->saving(function (Form $form) {
|
||||
|
||||
if (request()->has('title')) {
|
||||
if (request()->type == Category::TYPE_SHOW && empty(request()->article_id)) {
|
||||
// $error = new MessageBag([
|
||||
// 'title' => '错误',
|
||||
// 'message' => '文章类型是文章详情的时候需要选择关联文章',
|
||||
// ]);
|
||||
//
|
||||
// return back()->withInput()->with(compact('error'));
|
||||
if (request()->type == Category::TYPE_LINK && empty(request()->uri)) {
|
||||
$error = new MessageBag([
|
||||
'title' => '错误',
|
||||
'message' => '外链类型必须添加外链地址',
|
||||
]);
|
||||
|
||||
return back()->withInput()->with(compact('error'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
73
app/Admin/Controllers/Leader/IndexController.php
Normal file
73
app/Admin/Controllers/Leader/IndexController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Leader;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Leader;
|
||||
use App\Models\Staff;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '人才梯队';
|
||||
|
||||
public function grid(): Grid
|
||||
{
|
||||
$grid = new Grid(new Leader());
|
||||
|
||||
$grid->model()->with('category')->oldest('sort');
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->column(1 / 3, function (Grid\Filter $filter) {
|
||||
$filter->like('name', '姓名');
|
||||
});
|
||||
$filter->column(1 / 3, function (Grid\Filter $filter) {
|
||||
$filter->like('category.title', '所属分类');
|
||||
});
|
||||
$filter->column(1 / 3, function (Grid\Filter $filter) {
|
||||
$filter->equal('status', '状态')->select(Leader::STATUS);
|
||||
});
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('title', '标题');
|
||||
$grid->column('cover', '封面')->image('', 60, 60);
|
||||
$grid->column('category.title', '所属分类');
|
||||
$grid->column('sort', '排序')->editable();
|
||||
$grid->column('status', '状态')->bool();
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
public function form(): Form
|
||||
{
|
||||
$form = new Form(new Leader());
|
||||
|
||||
$form->text('title', '标题')->required();
|
||||
|
||||
$form->select('category_id', '所属分类')
|
||||
->options(function () {
|
||||
return Category::where('type', Category::TYPE_LEADER)->pluck('title', 'id');
|
||||
})
|
||||
->required();
|
||||
|
||||
$form->image('cover', '封面')
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->text('head', '带头人')->required();
|
||||
$form->text('reserve', '后备带头人')->required();
|
||||
$form->textarea('description', '简介');
|
||||
$form->ueditor('content', '详情')->required();
|
||||
$form->number('sort', '封面')->default(0);
|
||||
$form->switch('status', '状态')->default(1);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
78
app/Admin/Controllers/Staff/IndexController.php
Normal file
78
app/Admin/Controllers/Staff/IndexController.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Staff;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Staff;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '领导管理';
|
||||
|
||||
public function grid(): Grid
|
||||
{
|
||||
$grid = new Grid(new Staff());
|
||||
|
||||
$grid->model()->with('category')->oldest('order');
|
||||
|
||||
$grid->filter(function (Grid\Filter $filter) {
|
||||
$filter->column(1 / 3, function (Grid\Filter $filter) {
|
||||
$filter->like('name', '姓名');
|
||||
});
|
||||
$filter->column(1 / 3, function (Grid\Filter $filter) {
|
||||
$filter->like('category.title', '所属分类');
|
||||
});
|
||||
$filter->column(1 / 3, function (Grid\Filter $filter) {
|
||||
$filter->equal('status', '状态')->select(Staff::STATUS);
|
||||
});
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('name', '姓名');
|
||||
$grid->column('cover', '头像')->image('', 60, 60);
|
||||
$grid->column('category.title', '所属分类');
|
||||
$grid->column('order', '排序')->editable();
|
||||
$grid->column('status', '状态')->bool();
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
public function form(): Form
|
||||
{
|
||||
$form = new Form(new Staff());
|
||||
|
||||
$form->text('name', '姓名')
|
||||
->rules([
|
||||
'required',
|
||||
'max:4',
|
||||
], [
|
||||
'max' => '姓名最大长度不能超过 :max 个字符',
|
||||
])
|
||||
->required();
|
||||
$form->select('category_id', '所属分类')
|
||||
->options(function () {
|
||||
return Category::where('type', Category::TYPE_PERSON)->pluck('title', 'id');
|
||||
})
|
||||
->required();
|
||||
|
||||
$form->image('cover', '头像')
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->text('job', '职位')->required();
|
||||
$form->textarea('duty', '分工');
|
||||
|
||||
$form->ueditor('content', '简历')->required();
|
||||
$form->number('order','封面')->default(0);
|
||||
$form->switch('status', '状态')->default(1);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
11
app/Admin/Routes/leader.php
Normal file
11
app/Admin/Routes/leader.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace').'\\Leader',
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->resource('leader', 'IndexController');
|
||||
});
|
||||
12
app/Admin/Routes/staff.php
Normal file
12
app/Admin/Routes/staff.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace').'\\Staff',
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->resource('staff', 'IndexController');
|
||||
|
||||
});
|
||||
@@ -35,7 +35,7 @@ class CategorySelectAble extends Selectable
|
||||
$filter->equal('parent.id', '所属分类')
|
||||
->select(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)
|
||||
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_LINK]);
|
||||
}, '所有分类'));
|
||||
$filter->equal('type', '类型')->select(Category::TYPES);
|
||||
});
|
||||
|
||||
@@ -8,14 +8,16 @@ Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace'),
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
'as' => config('admin.route.prefix') . '.',
|
||||
'as' => config('admin.route.prefix').'.',
|
||||
], function (Router $router) {
|
||||
|
||||
$router->get('/', 'HomeController@index')->name('home');
|
||||
|
||||
});
|
||||
|
||||
require __DIR__ . '/Routes/article.php';
|
||||
require __DIR__ . '/Routes/category.php';
|
||||
require __DIR__ . '/Routes/link.php';
|
||||
require __DIR__ . '/Routes/advert.php';
|
||||
require __DIR__.'/Routes/article.php';
|
||||
require __DIR__.'/Routes/category.php';
|
||||
require __DIR__.'/Routes/link.php';
|
||||
require __DIR__.'/Routes/advert.php';
|
||||
require __DIR__.'/Routes/staff.php';
|
||||
require __DIR__.'/Routes/leader.php';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
58
app/Http/Controllers/StaffController.php
Normal file
58
app/Http/Controllers/StaffController.php
Normal 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'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,11 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use App\Models\Traits\OrderByIdDesc;
|
||||
use App\Scopes\SortScope;
|
||||
use App\Models\Traits\HasCovers;
|
||||
|
||||
class Advert extends Model
|
||||
{
|
||||
|
||||
use HasOneCover,
|
||||
use HasCovers,
|
||||
BelongsToCategory;
|
||||
}
|
||||
|
||||
@@ -2,21 +2,23 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use App\Models\Traits\HasCovers;
|
||||
use App\Models\Traits\HasSort;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
use HasOneCover;
|
||||
use HasCovers,HasSort;
|
||||
|
||||
/**
|
||||
* 应进行类型转换的属性
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'subjoin' => 'array',
|
||||
'subjoin' => 'array',
|
||||
'pictures' => 'array',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
@@ -26,6 +28,7 @@ class Article extends Model
|
||||
|
||||
/**
|
||||
* Notes: 关联分类
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2021/4/2 9:11
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
@@ -33,11 +36,12 @@ class Article extends Model
|
||||
public function categories(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Category::class)
|
||||
->using(ArticleCategory::class);
|
||||
->using(ArticleCategory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: description
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2021/4/2 9:17
|
||||
* @param $query
|
||||
@@ -46,7 +50,7 @@ class Article extends Model
|
||||
*/
|
||||
public function scopeByCategory($query, $ids)
|
||||
{
|
||||
if (!is_array($ids)) {
|
||||
if (! is_array($ids)) {
|
||||
$ids = [$ids];
|
||||
}
|
||||
|
||||
@@ -55,4 +59,16 @@ class Article extends Model
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getDateD()
|
||||
{
|
||||
return $this->created_at->format('d');
|
||||
}
|
||||
|
||||
public function getDateYM()
|
||||
{
|
||||
return $this->created_at->format('Y-m');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\HasCovers;
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
@@ -9,33 +10,50 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
class Category extends Model
|
||||
{
|
||||
|
||||
use AdminBuilder, ModelTree;
|
||||
use AdminBuilder, ModelTree, HasCovers;
|
||||
|
||||
public const TYPE_SHOW = 'show';
|
||||
public const TYPE_ARTICLE = 'article';
|
||||
public const TYPE_ADVERT = 'advert';
|
||||
const TYPE_LINK = 'link';
|
||||
const TYPE_ARTICLE = 'article';
|
||||
const TYPE_ADVERT = 'advert';
|
||||
const TYPE_PERSON = 'person';
|
||||
const TYPE_LEADER = 'leader';
|
||||
|
||||
public const TYPES = [
|
||||
const TYPES = [
|
||||
self::TYPE_ARTICLE => '文章列表',
|
||||
self::TYPE_SHOW => '文章详情',
|
||||
self::TYPE_LINK => '外链',
|
||||
self::TYPE_ADVERT => '图片',
|
||||
self::TYPE_PERSON => '领导',
|
||||
self::TYPE_LEADER => '人才梯队',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
/**
|
||||
* Notes: 跳转链接
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2022/4/28 13:53
|
||||
* @return string
|
||||
*/
|
||||
public function getLinkAttribute(): string
|
||||
{
|
||||
return route('category.show', $this);
|
||||
switch ($this->type) {
|
||||
case self::TYPE_LEADER:
|
||||
return route('leader.index');
|
||||
case self::TYPE_PERSON:
|
||||
return route('staff.index');
|
||||
default:
|
||||
return route('category.show', $this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的数据
|
||||
* @return [type] [description]
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\BelongsToMany|\Illuminate\Database\Eloquent\Relations\HasMany|null [type] [description]
|
||||
*/
|
||||
public function relations()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case self::TYPE_SHOW:
|
||||
return $this->belongsTo(Article::class);
|
||||
break;
|
||||
case self::TYPE_ARTICLE:
|
||||
return $this->belongsToMany(Article::class);
|
||||
break;
|
||||
@@ -61,7 +79,7 @@ class Category extends Model
|
||||
{
|
||||
return $this->belongsTo(Article::class);
|
||||
}
|
||||
|
||||
|
||||
public function articles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Article::class);
|
||||
@@ -69,6 +87,7 @@ class Category extends Model
|
||||
|
||||
/**
|
||||
* Notes: 获取当前分类及子分类ID
|
||||
*
|
||||
* @Author: <C.Jason>
|
||||
* @Date : 2020/4/6 3:12 下午
|
||||
* @return array
|
||||
@@ -81,16 +100,25 @@ class Category extends Model
|
||||
return $ids;
|
||||
}
|
||||
|
||||
//查找顶级分类
|
||||
public function getTop()
|
||||
/**
|
||||
* Notes: 获取顶级分类
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2022/4/28 13:52
|
||||
* @param $category_id
|
||||
* @return void
|
||||
*/
|
||||
public function getTopCategory()
|
||||
{
|
||||
$parent = $this;
|
||||
$category = $this;
|
||||
|
||||
while ($parent->parent_id != 0) {
|
||||
$parent = $parent->parent;
|
||||
while ($category) {
|
||||
if ($category->parent) {
|
||||
$category = $category->parent;
|
||||
} else {
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
|
||||
return $parent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
28
app/Models/Leader.php
Normal file
28
app/Models/Leader.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasCovers;
|
||||
use App\Models\Traits\HasSort;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Leader extends Model
|
||||
{
|
||||
use BelongsToCategory,
|
||||
HasCovers,
|
||||
HasSort;
|
||||
|
||||
const STATUS_FALSE = 0;
|
||||
const STATUS_TRUE = 1;
|
||||
|
||||
const STATUS = [
|
||||
self::STATUS_FALSE => '关闭',
|
||||
self::STATUS_TRUE => '开启',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('leader.show', $this);
|
||||
}
|
||||
}
|
||||
25
app/Models/Staff.php
Normal file
25
app/Models/Staff.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasCovers;
|
||||
|
||||
class Staff extends Model
|
||||
{
|
||||
use BelongsToCategory, HasCovers;
|
||||
|
||||
|
||||
const STATUS_FALSE = 0;
|
||||
const STATUS_TRUE = 1;
|
||||
|
||||
const STATUS = [
|
||||
self::STATUS_FALSE => '关闭',
|
||||
self::STATUS_TRUE => '开启',
|
||||
];
|
||||
|
||||
public function getLinkAttribute(): string
|
||||
{
|
||||
return route('staff.show', $this);
|
||||
}
|
||||
}
|
||||
89
app/Models/Traits/HasCovers.php
Normal file
89
app/Models/Traits/HasCovers.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use function collect;
|
||||
|
||||
trait HasCovers
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes : 获取封面图片字段(单图)
|
||||
*
|
||||
* @Date : 2021/3/16 4:34 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
public function getCoverField(): string
|
||||
{
|
||||
return $this->cover_field ?? 'cover';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 获取图片字段(多图)
|
||||
*
|
||||
* @Date : 2021/3/16 4:35 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
public function getPicturesField(): string
|
||||
{
|
||||
return $this->pictures_field ?? 'pictures';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 解析单图地址
|
||||
*
|
||||
* @Date : 2021/3/16 4:54 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
public function getCoverUrlAttribute(): string
|
||||
{
|
||||
$cover = $this->getAttribute($this->getCoverField());
|
||||
|
||||
return $this->parseImageUrl($cover);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 解析多图地址
|
||||
*
|
||||
* @Date : 2021/3/16 4:54 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return array
|
||||
*/
|
||||
public function getPicturesUrlAttribute(): array
|
||||
{
|
||||
$pictures = $this->getAttribute($this->getPicturesField());
|
||||
|
||||
if (empty($pictures)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($pictures)->map(function ($picture) {
|
||||
return $this->parseImageUrl($picture);
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 解析图片文件的实际展示地址
|
||||
*
|
||||
* @Date : 2021/3/16 4:53 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string|null $image
|
||||
* @return string
|
||||
*/
|
||||
protected function parseImageUrl(?string $image): string
|
||||
{
|
||||
if (empty($image)) {
|
||||
return '';
|
||||
} elseif (Str::startsWith($image, 'http')) {
|
||||
return $image;
|
||||
} else {
|
||||
return Storage::url($image);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,8 +9,9 @@ trait HasOneCover
|
||||
|
||||
/**
|
||||
* 拼接图片全地址
|
||||
* @author 玄尘 2020-03-05
|
||||
*
|
||||
* @return string
|
||||
* @author 玄尘 2020-03-05
|
||||
*/
|
||||
public function getCoverPathAttribute(): ?string
|
||||
{
|
||||
@@ -21,4 +22,20 @@ trait HasOneCover
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取标签
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2022/6/28 15:25
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLabelPathAttribute(): ?string
|
||||
{
|
||||
if ($this->label) {
|
||||
return Storage::url($this->label);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
26
app/Models/Traits/HasSort.php
Normal file
26
app/Models/Traits/HasSort.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use function collect;
|
||||
|
||||
trait HasSort
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 排序
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2022/6/28 14:49
|
||||
* @param $query
|
||||
* @param $ids
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeBySort($query)
|
||||
{
|
||||
return $query->latest('sort')->latest();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user