初步完成
This commit is contained in:
@@ -24,7 +24,7 @@ class IndexController extends AdminController
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('title', '图片名称');
|
||||
$filter->like('category.id', '分类名称')->select(Category::selectOptions(function ($model) {
|
||||
$filter->equal('category.id', '分类名称')->select(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->where('type', Category::TYPE_ADVERT);
|
||||
}, '所有分类'));
|
||||
});
|
||||
@@ -51,29 +51,29 @@ class IndexController extends AdminController
|
||||
|
||||
$form->text('title', '图片名称')->required();
|
||||
$form->select('category_id', '所属分类')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->where('type', Category::TYPE_ADVERT);
|
||||
}, '选择分类'))
|
||||
->rules('required|min:1', [
|
||||
'required' => '必须选择所属分类',
|
||||
'min' => '必须选择所属分类',
|
||||
]);
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->where('type', Category::TYPE_ADVERT);
|
||||
}, '选择分类'))
|
||||
->rules('required|min:1', [
|
||||
'required' => '必须选择所属分类',
|
||||
'min' => '必须选择所属分类',
|
||||
]);
|
||||
$form->image('cover', '封面图片')
|
||||
->rules(function ($form) {
|
||||
if ($form->model()->cover != []) {
|
||||
return 'nullable|image';
|
||||
} else {
|
||||
return 'required';
|
||||
}
|
||||
})
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->rules(function ($form) {
|
||||
if ($form->model()->cover != []) {
|
||||
return 'nullable|image';
|
||||
} else {
|
||||
return 'required';
|
||||
}
|
||||
})
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->text('url', '链接地址');
|
||||
$form->number('sort', '排序')
|
||||
->default(1)
|
||||
->required()
|
||||
->help('数字越大越靠前');
|
||||
->default(1)
|
||||
->required()
|
||||
->help('数字越大越靠前');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class ArticleController extends AdminController
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '内容管理';
|
||||
|
||||
public function grid()
|
||||
@@ -19,7 +20,7 @@ class ArticleController extends AdminController
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('title', '文章标题');
|
||||
$filter->like('category.id', '所属分类')->select(Category::selectOptions(function ($model) {
|
||||
$filter->equal('category.id', '所属分类')->select(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
}, '所有分类'));
|
||||
});
|
||||
@@ -32,6 +33,10 @@ class ArticleController extends AdminController
|
||||
$grid->column('category.title', '所属分类');
|
||||
$grid->column('title', '文章标题');
|
||||
$grid->column('sort', '序号');
|
||||
$grid->status('状态')->switch([
|
||||
'on' => ['value' => 1, 'text' => '正常', 'color' => 'primary'],
|
||||
'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
|
||||
]);
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
@@ -43,21 +48,30 @@ class ArticleController extends AdminController
|
||||
|
||||
$form->text('title', '文章标题')->rules('min:2');
|
||||
$form->select('category_id', '所属分类')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
}, '选择分类'))
|
||||
->rules('required|min:1', [
|
||||
'required' => '必须选择所属分类',
|
||||
'min' => '必须选择所属分类',
|
||||
]);
|
||||
$form->text('keywords', '关键词')->rules('nullable');
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
|
||||
}, '选择分类'))
|
||||
->when('in', [3, 29], function (Form $form) {
|
||||
$form->text('working', '工龄');
|
||||
$form->text('job', '岗位');
|
||||
})
|
||||
->when('in', [56], function (Form $form) {
|
||||
$form->text('url', '跳转地址');
|
||||
})
|
||||
->rules('required|min:1', [
|
||||
'required' => '必须选择所属分类',
|
||||
'min' => '必须选择所属分类',
|
||||
]);
|
||||
// $form->text('keywords', '关键词')->rules('nullable');
|
||||
$form->textarea('description', '内容简介')->rules('max:350');
|
||||
$form->image('cover', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->ueditor('content', '文章内容')->rules('required', ['required' => '详情不能为空']);
|
||||
$form->number('sort', '序号')->default(0)->rules('required', ['required' => '序号必须填写'])->help('倒序优先');
|
||||
$form->switch('status', '状态')->default(1);
|
||||
|
||||
return $form;
|
||||
}
|
||||
83
app/Admin/Controllers/Article/PatentController.php
Normal file
83
app/Admin/Controllers/Article/PatentController.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Article;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Patent;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class PatentController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '专利论文';
|
||||
|
||||
public function grid()
|
||||
{
|
||||
$grid = new Grid(new Patent);
|
||||
$grid->model()->orderBy('id', 'desc');
|
||||
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('title', '专利/论文题目');
|
||||
$filter->equal('category_id', '所属分类')
|
||||
->select(Category::where('type', Category::TYPE_PATENT)->pluck('title', 'id'));
|
||||
$filter->equal('type', '类别')
|
||||
->select(Patent::TYPES);
|
||||
});
|
||||
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('number', '专利号');
|
||||
$filter->like('nickname', '第一发明人/论文作者');
|
||||
});
|
||||
|
||||
$filter->disableIdFilter();
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('type', '类别')->using(Patent::TYPES)->label();
|
||||
$grid->column('title', '专利/论文题目');
|
||||
$grid->column('number', '专利号');
|
||||
$grid->column('category.title', '所属分类');
|
||||
$grid->column('nickname', '第一发明人/论文作者');
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
$form = new Form(new Patent);
|
||||
|
||||
$form->text('title', '题目')->required();
|
||||
$form->select('type', '类别')
|
||||
->options(Patent::TYPES)
|
||||
->when('patent', function (Form $form) {
|
||||
$form->select('category_id', '专利类别')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->whereIn('type', [Category::TYPE_PATENT]);
|
||||
}, '专利类别'));
|
||||
$form->text('number', '专利号');
|
||||
|
||||
})
|
||||
->when('paper', function (Form $form) {
|
||||
$form->text('publication', '刊物名称');
|
||||
})
|
||||
->required();
|
||||
|
||||
$form->text('nickname', '第一发明人/论文作者')->required();
|
||||
|
||||
$form->image('cover', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->ueditor('content', '详情')->rules('required', ['required' => '详情不能为空']);
|
||||
$form->number('sort', '序号')->default(0)->required()->help('倒序优先');
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Article;
|
||||
|
||||
use App\Models\ArticlePicture;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class PictureController extends AdminController
|
||||
{
|
||||
protected $title = '随手拍';
|
||||
|
||||
public function grid()
|
||||
{
|
||||
$grid = new Grid(new ArticlePicture);
|
||||
$grid->model()->orderBy('id', 'desc');
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('title', '文章标题');
|
||||
});
|
||||
|
||||
$filter->disableIdFilter();
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('cover')->display(function () {
|
||||
return $this->one_picture_path;
|
||||
})->image('', 100);
|
||||
$grid->column('category.title', '所属分类');
|
||||
$grid->column('title', '文章标题');
|
||||
$grid->column('sort', '序号');
|
||||
$grid->column('created_at', '创建时间');
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
$form = new Form(new ArticlePicture);
|
||||
|
||||
$form->text('title', '文章标题')->rules('min:2');
|
||||
$form->hidden('category_id')->value(6);
|
||||
$form->multipleImage('pictures', '封面')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->number('sort', '序号')->default(0)->rules('required', ['required' => '序号必须填写'])->help('倒序优先');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,32 +31,31 @@ class IndexController extends AdminController
|
||||
$form = new WidgetsForm();
|
||||
|
||||
$form->select('parent_id', '上级分类')
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, '一级分类'))
|
||||
;
|
||||
->options(Category::selectOptions(function ($model) {
|
||||
return $model->where('status', 1);
|
||||
}, '一级分类'));
|
||||
$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('category', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (WidgetsForm $form) {
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
return Article::whereHas('category', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
$form->textarea('description', '分类简介')
|
||||
->rules('nullable');
|
||||
->rules('nullable');
|
||||
$form->text('keywords', '关键词')->rules('nullable');
|
||||
|
||||
$form->image('cover', 'Logo')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->number('order', '排序')->default(0);
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(1);
|
||||
$form->switch('top_show', '顶部导航显示')->states()->default(0);
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
$form->action(admin_url('categories'));
|
||||
|
||||
@@ -102,22 +101,22 @@ 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('category', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
->options(Category::TYPES)
|
||||
->when('show', function (Form $form) {
|
||||
$form->select('article_id', '关联文章')
|
||||
->options(function ($option, $info) {
|
||||
return Article::whereHas('category', function ($q) {
|
||||
$q->where('type', 'show');
|
||||
})->pluck('title', 'id');
|
||||
})->help('当分类类型是文章详情的时候需要选择关联文章');
|
||||
})
|
||||
->required();
|
||||
$form->textarea('description', '分类简介')->rows(4)->rules('nullable');
|
||||
$form->text('keywords', '关键词')->rules('nullable');
|
||||
$form->image('cover', 'Logo')
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
$form->number('order', '排序')->default(0)->help('正序优先');
|
||||
|
||||
$form->switch('status', '显示')->states()->default(1);
|
||||
@@ -126,14 +125,14 @@ 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_SHOW && empty(request()->article_id)) {
|
||||
// $error = new MessageBag([
|
||||
// 'title' => '错误',
|
||||
// 'message' => '文章类型是文章详情的时候需要选择关联文章',
|
||||
// ]);
|
||||
//
|
||||
// return back()->withInput()->with(compact('error'));
|
||||
// }
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -7,6 +7,6 @@ Route::group([
|
||||
'namespace' => config('admin.route.namespace') . '\\Article',
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->resource('articles', 'ArticleController');
|
||||
$router->resource('pictures', 'PictureController');
|
||||
$router->resource('articles', 'IndexController');
|
||||
$router->resource('patents', 'PatentController');
|
||||
});
|
||||
|
||||
96
app/Helpers/function.php
Normal file
96
app/Helpers/function.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Article;
|
||||
use App\Models\Patent;
|
||||
|
||||
function getOneCategory($categoryId, $return = '')
|
||||
{
|
||||
$category = Category::find($categoryId);
|
||||
if ($category) {
|
||||
if ($return) {
|
||||
return $category->{$return};
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
return new Category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取文章分类详情
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/10 13:21
|
||||
* @param $categoryId
|
||||
* @param string $result
|
||||
* @return \App\Models\Article
|
||||
*/
|
||||
function getOneArticleBYCate($categoryId, $result = '')
|
||||
{
|
||||
$info = Article::where('category_id', $categoryId)->latest('sort')->latest()->first();
|
||||
|
||||
if ($info) {
|
||||
if ($result) {
|
||||
return $info->{$result};
|
||||
}
|
||||
|
||||
return $info;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
return new Article;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取分类下的文章
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/9/10 10:05
|
||||
* @param $categoryId
|
||||
* @param $take
|
||||
* @return \App\Models\Article
|
||||
*/
|
||||
function getArticlesBYCate($categoryId, $take)
|
||||
{
|
||||
$articles = Article::where('category_id', $categoryId)
|
||||
->where('status', 1)
|
||||
->latest('sort')
|
||||
->latest()
|
||||
->take($take)
|
||||
->get();
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
//获取子分类
|
||||
function getCateChild($categoryId)
|
||||
{
|
||||
return Category::where('status', 1)
|
||||
->where('parent_id', $categoryId)
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
//获取顶级分类
|
||||
function getTopCate($categoryId)
|
||||
{
|
||||
$parent = Category::find($categoryId);
|
||||
|
||||
while ($parent->parent_id != 0) {
|
||||
$parent = $parent->parent;
|
||||
}
|
||||
|
||||
return $parent;
|
||||
}
|
||||
|
||||
//获取专利和论文
|
||||
function getPatent($take, $type = '')
|
||||
{
|
||||
return Patent::where('status', 1)
|
||||
->when($type, function ($q) use ($type) {
|
||||
$q->where('type', $type);
|
||||
})
|
||||
->get();
|
||||
|
||||
}
|
||||
@@ -3,43 +3,49 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePicture;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
|
||||
//文章列表
|
||||
public function index(Category $category)
|
||||
{
|
||||
$articles = Article::where('category_id', $category->id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(5);
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(5);
|
||||
|
||||
return view('articles.index', compact('articles', 'category'));
|
||||
}
|
||||
|
||||
//显示详情
|
||||
public function show(Article $article)
|
||||
{
|
||||
if ($article->url) {
|
||||
return redirect($article->url);
|
||||
}
|
||||
|
||||
$category = $article->category;
|
||||
return view('articles.show', compact('article', 'category'));
|
||||
|
||||
$next = Article::where('id', '>', $article->id)->where('status', 1)->first();
|
||||
$parent = getTopCate($category->id);
|
||||
|
||||
return view('articles.show', compact('article', 'category', 'next', 'parent'));
|
||||
}
|
||||
|
||||
public function category(Category $category)
|
||||
//搜索
|
||||
public function search(Request $request)
|
||||
{
|
||||
$article = Article::where('category_id', $category->id)->first();
|
||||
$title = $request->title;
|
||||
$articles = Article::where('status', 1)
|
||||
->when($title, function ($q) use ($title) {
|
||||
$q->where('title', 'like', "%{$title}%");
|
||||
})
|
||||
->paginate();
|
||||
|
||||
return view('articles.search', compact('articles'));
|
||||
|
||||
return view('articles.show', compact('article'));
|
||||
}
|
||||
|
||||
public function picture(Category $category)
|
||||
{
|
||||
$articles = ArticlePicture::where('category_id', $category->id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(12);
|
||||
return view('articles.picture', compact('articles', 'category'));
|
||||
}
|
||||
|
||||
public function picshow(ArticlePicture $article)
|
||||
{
|
||||
return view('articles.picshow', compact('article'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,38 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 分类下的文章
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/1 9:19
|
||||
* @param \App\Models\Category $category
|
||||
*/
|
||||
public function articles(Category $category)
|
||||
//显示分类
|
||||
public function show(Category $category)
|
||||
{
|
||||
if ($category->type == Category::TYPE_SHOW) {
|
||||
if ($category->relations) {
|
||||
return route('article.show', $category->relations);
|
||||
}
|
||||
}
|
||||
$parent = getTopCate($category->id);
|
||||
|
||||
$template = array_flip(config('haai.category'));
|
||||
if (isset($template[$category->id])) {
|
||||
return view('category.' . $template[$category->id], compact('category', 'parent'));
|
||||
}
|
||||
|
||||
return redirect(route('category.list', $category));
|
||||
|
||||
}
|
||||
|
||||
//显示文章列表
|
||||
public function list(Category $category)
|
||||
{
|
||||
$articles = Article::where('category_id', $category->id)->where('status', 1)->paginate();
|
||||
$parent = getTopCate($category->id);
|
||||
|
||||
return view('category.list', compact('category', 'parent', 'articles'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePicture;
|
||||
use App\Models\Patent;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
@@ -16,22 +18,32 @@ class IndexController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$ssp = ArticlePicture::orderBy('sort', 'desc')->take(3)->get(); //随手拍
|
||||
$all_articles = Article::orderBy('sort', 'desc')
|
||||
->whereNotIn('category_id', [20, 21, 22])
|
||||
->take(7)
|
||||
->get(); //最新资讯
|
||||
$danwei = Article::where('category_id', 15)->latest()->first(); //单位概况
|
||||
$ysbj = Article::where('category_id', 12)->latest()->take(3)->get(); //养生保健
|
||||
$dcyfx = Article::where('category_id', 10)->latest()->take(7)->get(); //调研与分析
|
||||
$yyjcyj = Article::where('category_id', 9)->latest()->take(7)->get(); //应用基础研究
|
||||
$jsyt = Article::where('category_id', 11)->latest()->take(7)->get(); //技术研讨
|
||||
$kyyyy = Article::where('category_id', 12)->latest()->take(7)->get(); //科研与应用
|
||||
$qkys = Article::where('category_id', 9)->latest()->take(7)->get(); //全科医学
|
||||
$center_advert = Advert::where('category_id', 18)->first();
|
||||
$qikan_advert = Advert::where('category_id', 19)->take(4)->orderBy('sort', 'desc')->get();
|
||||
// $ssp = ArticlePicture::orderBy('sort', 'desc')->take(3)->get(); //随手拍
|
||||
// $all_articles = Article::orderBy('sort', 'desc')
|
||||
// ->whereNotIn('category_id', [20, 21, 22])
|
||||
// ->take(7)
|
||||
// ->get(); //最新资讯
|
||||
// $danwei = Article::where('category_id', 15)->latest()->first(); //单位概况
|
||||
// $ysbj = Article::where('category_id', 12)->latest()->take(3)->get(); //养生保健
|
||||
// $dcyfx = Article::where('category_id', 10)->latest()->take(7)->get(); //调研与分析
|
||||
// $yyjcyj = Article::where('category_id', 9)->latest()->take(7)->get(); //应用基础研究
|
||||
// $jsyt = Article::where('category_id', 11)->latest()->take(7)->get(); //技术研讨
|
||||
// $kyyyy = Article::where('category_id', 12)->latest()->take(7)->get(); //科研与应用
|
||||
// $qkys = Article::where('category_id', 9)->latest()->take(7)->get(); //全科医学
|
||||
// $center_advert = Advert::where('category_id', 18)->first();
|
||||
// $qikan_advert = Advert::where('category_id', 19)->take(4)->orderBy('sort', 'desc')->get();
|
||||
|
||||
return view('index.index', compact('ssp', 'all_articles', 'danwei', 'ysbj', 'dcyfx', 'yyjcyj', 'jsyt', 'kyyyy', 'qkys', 'center_advert', 'qikan_advert'));
|
||||
$data = [
|
||||
'ysxw' => Article::where('category_id', 15)->latest('sort')->latest()->take(8)->get(),
|
||||
'kjcg' => Article::where('category_id', 20)->latest('sort')->latest()->take(8)->get(),
|
||||
'lwzl' => Patent::latest('sort')->latest()->take(11)->get(),
|
||||
'center_advert' => Advert::latest('sort')->latest()->where('category_id', 23)->take(3)->get(),
|
||||
'ysxw_right_advert' => Advert::latest('sort')->latest()->where('category_id', 24)->first(),
|
||||
'kjcg_right_advert' => Advert::latest('sort')->latest()->where('category_id', 25)->take(2)->get(),
|
||||
'lwzl_right_advert' => Advert::latest('sort')->latest()->where('category_id', 27)->take(2)->get(),
|
||||
];
|
||||
|
||||
return view('index.index', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
34
app/Http/Controllers/PatentController.php
Normal file
34
app/Http/Controllers/PatentController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Patent;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PatentController extends Controller
|
||||
{
|
||||
|
||||
//显示论文详情
|
||||
public function show(Patent $patent)
|
||||
{
|
||||
$next = Patent::where('id', '>', $patent->id)->where('status', 1)->first();
|
||||
|
||||
return view('patents.show', compact('patent', 'next'));
|
||||
}
|
||||
|
||||
//显示文章列表
|
||||
public function list(Request $request)
|
||||
{
|
||||
$type = $request->type;
|
||||
|
||||
$patents = Patent::where('status', 1)
|
||||
->when($type, function ($q) use ($type) {
|
||||
$q->where('type', $type);
|
||||
})
|
||||
->paginate();
|
||||
|
||||
return view('patents.list', compact('patents'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,160 +2,12 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\Category;
|
||||
use App\Models\DedeArchive;
|
||||
use App\Models\DedeArctype;
|
||||
use App\Traits\Tree;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
use Tree;
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setCateArticle()
|
||||
{
|
||||
$article = [];
|
||||
$lists = Category::where('content', '<>', '')->where('type', 'article')->get();
|
||||
if ($lists->isEmpty()) {
|
||||
dd('没有数据');
|
||||
}
|
||||
foreach ($lists as $key => $cate) {
|
||||
if ($cate->content != ' ') {
|
||||
$data = [
|
||||
'oldid' => 0,
|
||||
'title' => $cate->title,
|
||||
'category_id' => $cate->id,
|
||||
'writer' => 'admin',
|
||||
'source' => '未知',
|
||||
'keywords' => '',
|
||||
'status' => 1,
|
||||
'description' => $cate->description,
|
||||
'content' => $cate->content,
|
||||
];
|
||||
|
||||
$info = Article::create($data);
|
||||
$cate->article_id = $info->id;
|
||||
$cate->type = Category::TYPE_SHOW;
|
||||
$cate->save();
|
||||
$article[] = $info->id;
|
||||
}
|
||||
|
||||
}
|
||||
dump(count($article));
|
||||
}
|
||||
|
||||
public function checkArticle()
|
||||
{
|
||||
$articleids = Article::where('oldid', '>', 0)->pluck('oldid');
|
||||
$oldids = DedeArchive::pluck('id');
|
||||
$diffids = array_diff($oldids->toArray(), $articleids->toArray());
|
||||
dump(count($articleids));
|
||||
dump(count($oldids));
|
||||
dump($diffids);
|
||||
die();
|
||||
$map = [
|
||||
'id' => ['in', $diffids],
|
||||
];
|
||||
$list = DedeArchive::whereIn('id', $diffids)->get();
|
||||
foreach ($list as $key => $article) {
|
||||
$data = [
|
||||
'oldid' => $article->id,
|
||||
'title' => $article->title,
|
||||
'category_id' => $category->id ?? '0',
|
||||
'writer' => $article->writer,
|
||||
'cover' => $article->litpic,
|
||||
'source' => $article->source,
|
||||
'keywords' => $article->keywords,
|
||||
'description' => $article->description,
|
||||
'status' => 1,
|
||||
'content' => $article->info->body ?? '',
|
||||
'created_at' => date('Y-m-d H:i:s', $article->pubdate),
|
||||
];
|
||||
Article::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
//导入文章
|
||||
public function set_article()
|
||||
{
|
||||
$articles = Article::get();
|
||||
if ($articles->count() > 4) {
|
||||
dd('已经导入过数据');
|
||||
}
|
||||
$categorys = Category::get();
|
||||
$error = $success = [];
|
||||
DedeArchive::whereNotNull('litpic')->chunk(200, function ($articles) use ($categorys) {
|
||||
|
||||
foreach ($articles as $article) {
|
||||
|
||||
$category = $categorys->where('oldid', $article->typeid)->first();
|
||||
$id = $category->id ?? 0;
|
||||
if (in_array($id, [9, 10, 11, 12])) {
|
||||
$data = [
|
||||
'oldid' => $article->id,
|
||||
'title' => $article->title,
|
||||
'category_id' => $category->id ?? '0',
|
||||
'writer' => $article->writer,
|
||||
'source' => $article->source,
|
||||
'cover' => $article->litpic,
|
||||
'keywords' => $article->keywords,
|
||||
'description' => $article->description,
|
||||
'status' => 1,
|
||||
'content' => $article->info->body ?? '',
|
||||
'created_at' => date('Y-m-d H:i:s', $article->pubdate),
|
||||
];
|
||||
|
||||
$res = Article::create($data);
|
||||
if (!$res) {
|
||||
$error[] = $article->id;
|
||||
} else {
|
||||
$success[] = $article->id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
dump($error);
|
||||
dump($success);
|
||||
}
|
||||
|
||||
//导入分类
|
||||
public function set_category()
|
||||
{
|
||||
$categorys = Category::get();
|
||||
if ($categorys->count()) {
|
||||
dd('已经导入过数据');
|
||||
}
|
||||
$lists = DedeArctype::where('ishidden', 0)->select('id', 'reid as parent_id', 'typename as title', 'content')->get();
|
||||
$list = Tree::list2tree($lists->toArray(), 'id', 'parent_id', 'children', 0);
|
||||
|
||||
foreach ($list as $key => $value) {
|
||||
$info = Category::create($this->getData($value));
|
||||
if (isset($value['children']) && count($value['children']) > 0) {
|
||||
foreach ($value['children'] as $key => $children) {
|
||||
$info->children()->create($this->getData($children));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//格式化分类数据
|
||||
public function getData($category)
|
||||
{
|
||||
$data = [
|
||||
'oldid' => $category['id'],
|
||||
'parent_id' => $category['parent_id'],
|
||||
'title' => $category['title'],
|
||||
'content' => $category['content'],
|
||||
'status' => 1,
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,5 +7,12 @@ use App\Models\Traits\HasOneCover;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
use HasOneCover, BelongsToCategory;
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('article.show', $this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ArticlePicture extends Model
|
||||
{
|
||||
use BelongsToCategory;
|
||||
|
||||
public function setPicturesAttribute($pictures)
|
||||
{
|
||||
if (is_array($pictures)) {
|
||||
$this->attributes['pictures'] = json_encode($pictures);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPicturesAttribute($pictures)
|
||||
{
|
||||
return json_decode($pictures, true);
|
||||
}
|
||||
|
||||
public function getOnePicturePathAttribute(): string
|
||||
{
|
||||
$cover = $this->pictures;
|
||||
if (empty($cover)) {
|
||||
return '';
|
||||
} else {
|
||||
return Storage::disk('public')->url($cover[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -9,19 +10,24 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
|
||||
public const TYPES = [
|
||||
'article' => '文章列表',
|
||||
'show' => '文章详情',
|
||||
'advert' => '广告',
|
||||
'picture' => '图册',
|
||||
];
|
||||
use AdminBuilder, ModelTree, HasOneCover;
|
||||
|
||||
public const TYPE_SHOW = 'show';
|
||||
public const TYPE_ARTICLE = 'article';
|
||||
public const TYPE_ADVERT = 'advert';
|
||||
public const TYPE_PICTURE = 'picture';
|
||||
public const TYPE_PATENT = 'patent';
|
||||
public const TYPES = [
|
||||
self::TYPE_ARTICLE => '文章列表',
|
||||
self::TYPE_SHOW => '文章详情',
|
||||
self::TYPE_ADVERT => '图片',
|
||||
self::TYPE_PATENT => '专利',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('category.show', $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的数据
|
||||
@@ -31,7 +37,7 @@ class Category extends Model
|
||||
{
|
||||
switch ($this->type) {
|
||||
case self::TYPE_SHOW:
|
||||
return $this->hasOne(Article::class,'id','article_id');
|
||||
return $this->hasOne(Article::class, 'id', 'article_id');
|
||||
break;
|
||||
case self::TYPE_ARTICLE:
|
||||
return $this->hasMany(Article::class);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DedeAddonarticle extends Model
|
||||
{
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DedeArchive extends Model
|
||||
{
|
||||
public function info()
|
||||
{
|
||||
return $this->hasOne(DedeAddonarticle::class, 'aid');
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
|
||||
class DedeArctype extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
}
|
||||
26
app/Models/Patent.php
Normal file
26
app/Models/Patent.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
|
||||
class Patent extends Model
|
||||
{
|
||||
|
||||
use HasOneCover, BelongsToCategory;
|
||||
|
||||
public const TYPE_PATENT = 'patent';
|
||||
public const TYPE_PAPER = 'paper';
|
||||
|
||||
public const TYPES = [
|
||||
self::TYPE_PATENT => '专利',
|
||||
self::TYPE_PAPER => '论文',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('patents.show', $this);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user