first push
This commit is contained in:
28
app/Http/Controllers/ArticleController.php
Normal file
28
app/Http/Controllers/ArticleController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示分类
|
||||
* @param Category $category [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function show(Article $article)
|
||||
{
|
||||
$parent = $category = $article->category;
|
||||
if ($category->childrens->isEmpty()) {
|
||||
$parent = $category->parent;
|
||||
}
|
||||
$advert = Advert::where('category_id',73)->first();
|
||||
|
||||
return view('article.show', compact('article', 'parent', 'category','advert'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Normal file
40
app/Http/Controllers/Auth/ConfirmPasswordController.php
Normal 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');
|
||||
}
|
||||
}
|
||||
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
22
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal 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;
|
||||
}
|
||||
40
app/Http/Controllers/Auth/LoginController.php
Normal file
40
app/Http/Controllers/Auth/LoginController.php
Normal 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');
|
||||
}
|
||||
}
|
||||
73
app/Http/Controllers/Auth/RegisterController.php
Normal file
73
app/Http/Controllers/Auth/RegisterController.php
Normal 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']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
30
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
30
app/Http/Controllers/Auth/ResetPasswordController.php
Normal 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;
|
||||
}
|
||||
42
app/Http/Controllers/Auth/VerificationController.php
Normal file
42
app/Http/Controllers/Auth/VerificationController.php
Normal 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');
|
||||
}
|
||||
}
|
||||
33
app/Http/Controllers/CategoryController.php
Normal file
33
app/Http/Controllers/CategoryController.php
Normal 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)->paginate();
|
||||
$parent = $category;
|
||||
if ($category->childrens->isEmpty()) {
|
||||
$parent = $category->parent;
|
||||
}
|
||||
|
||||
$advert = Advert::where('category_id',73)->first();
|
||||
|
||||
return view('category.show', compact('articles', 'category', 'parent','advert'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
37
app/Http/Controllers/Controller.php
Normal file
37
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Category;
|
||||
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', 'desc')
|
||||
->select('id', 'title')
|
||||
->get();
|
||||
|
||||
//地步友情链接
|
||||
if (url()->current() == route('index.index')) {
|
||||
$adverts = Advert::where('category_id', 26)->get();
|
||||
View::share('adverts', $adverts);
|
||||
|
||||
}
|
||||
View::share('all_categorys', $categorys);
|
||||
}
|
||||
|
||||
}
|
||||
40
app/Http/Controllers/IndexController.php
Normal file
40
app/Http/Controllers/IndexController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
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();
|
||||
|
||||
return view('index.index', compact('links', '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();
|
||||
}
|
||||
|
||||
}
|
||||
197
app/Http/Controllers/TestController.php
Normal file
197
app/Http/Controllers/TestController.php
Normal file
@@ -0,0 +1,197 @@
|
||||
<?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);
|
||||
|
||||
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 != ' ') {
|
||||
$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();
|
||||
// $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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user