This commit is contained in:
2021-03-24 09:51:17 +08:00
commit ae1ba1d4e9
719 changed files with 171752 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Article;
use Illuminate\Http\Request;
class ArticleController extends Controller
{
/**
* 显示分类
* @param \App\Models\Article $article
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View [type] [description]
*/
public function show(Article $article)
{
$category = $article->category;
$parent = getTopCate($category->id);
$next = Article::where('id', '>', $article->id)
->where('category_id', $article->category_id)
->where('status', 1)
->first();
return view('article.show', compact('article', 'next', 'parent', 'category'));
}
//搜索
public function search(Request $request)
{
$title = $request->title;
$articles = Article::where('status', 1)
->when($title, function ($q) use ($title) {
$q->where('title', 'like', "%{$title}%");
})
->paginate();
return view('article.search', compact('articles'));
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ConfirmsPasswords;
class ConfirmPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Confirm Password Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password confirmations and
| uses a simple trait to include the behavior. You're free to explore
| this trait and override any functions that require customization.
|
*/
use ConfirmsPasswords;
/**
* Where to redirect users when the intended url fails.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\VerifiesEmails;
class VerificationController extends Controller
{
/*
|--------------------------------------------------------------------------
| Email Verification Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling email verification for any
| user that recently registered with the application. Emails may also
| be re-sent if the user didn't receive the original email message.
|
*/
use VerifiesEmails;
/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Category;
class CategoryController extends Controller
{
/**
* 显示分类
* @param Category $category [description]
* @return [type] [description]
*/
public function index(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()->paginate(8);
$parent = $category;
if ($category->childrens->isEmpty() && $category->parent) {
$parent = $category->parent;
}
$advert = Advert::where('category_id', 73)->first();
return view('category.show', compact('articles', 'category', 'parent', 'advert'));
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Category;
use App\Models\Link;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\View;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function __construct()
{
//顶部分类
$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();
View::share('all_categorys', $categorys);
View::share('links', $links);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Article;
use App\Models\Link;
class IndexController extends Controller
{
/**
* Notes: 首页
* @Author: 玄尘
* @Date : 2020/6/1 9:11
*/
public function index()
{
$fydt = $this->getArticle([6], 9); //分院动态
$kydt = $this->getArticle([9], 9); //科研动态
$ldbz = $this->getArticle([3], 4); //领导班子
$kycg = $this->getArticle([10], 8); //科研成果
$rctd = $this->getArticle([4], 9); //人才团队介绍
$info = Article::where('category_id', 2)->first(); //院所介绍
$links = Link::get();
$advert = Advert::where('category_id', 26)->latest('sort')->first();
$center_advert = Advert::where('category_id', 28)->latest('sort')->first();
return view('index.index', compact('advert', 'center_advert', 'fydt', 'kydt', 'ldbz', 'kycg', 'rctd', 'info'));
}
//通用获取文章
public function getArticle($category_ids, $take = 3)
{
return Article::whereIn('category_id', $category_ids)
->select('id', 'description', 'title', 'created_at', 'cover', 'content')
->latest('sort')
->latest()
->take($take)
->get();
}
}

View File

@@ -0,0 +1,210 @@
<?php
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 checkCategory()
{
// $lists = Category::where('created_at','2020-06-03 15:57:55')->get();
// $i=1;
// foreach ($lists as $info){
// $old = DedeArctype::select('id', 'reid as parent_id', 'typename as title', 'content')->find($info->oldid);
// $cate = Category::where('oldid',$old->parent_id)->first();
// $info->parent_id = $cate->id;
// $info->save();
// $i++;
// }
// dd($i);
// dump(count($lists));
// dd();
$cateids = Category::where('oldid', '>', 0)->pluck('oldid');
$oldids = DedeArctype::where('ishidden', 0)->pluck('id');
$diffids = array_diff($oldids->toArray(), $cateids->toArray());
dump(count($cateids));
dump(count($oldids));
dump($diffids);
dd();
foreach ($diffids as $diffid) {
$info = DedeArctype::where('id', $diffid)
->where('ishidden', 0)
->select('id', 'reid as parent_id', 'typename as title', 'content')
->first();
$data = $this->getData($info);
Category::create($data);
}
}
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,
'created_at' => $cate->created_at,
];
$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()
{
$lists = Article::where('category_id', 0)->get();
foreach ($lists as $list) {
$old = DedeArchive::find($list->oldid);
$cate = Category::where('oldid', $old->typeid)->first();
if (!$cate || !$old) {
dump($old);
dump($cate);
dd('出问题了');
}
$list->category_id = $cate->id;
$list->save();
}
dd();
$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();
$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() > 1) {
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;
}
}