初步完成

This commit is contained in:
2020-09-11 10:27:23 +08:00
parent 9c6d4da51e
commit 49c3511dbe
43 changed files with 3437 additions and 1188 deletions

View File

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

View File

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

View File

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

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

View File

@@ -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 != '&nbsp;') {
$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;
}
}