firstpush
This commit is contained in:
45
app/Http/Controllers/ArticleController.php
Normal file
45
app/Http/Controllers/ArticleController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePicture;
|
||||
use App\Models\Category;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
public function index(Category $category)
|
||||
{
|
||||
$articles = Article::where('category_id', $category->id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate(5);
|
||||
|
||||
return view('articles.index', compact('articles', 'category'));
|
||||
}
|
||||
|
||||
public function show(Article $article)
|
||||
{
|
||||
$category = $article->category;
|
||||
return view('articles.show', compact('article', 'category'));
|
||||
}
|
||||
|
||||
public function category(Category $category)
|
||||
{
|
||||
$article = Article::where('category_id', $category->id)->first();
|
||||
|
||||
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'));
|
||||
}
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
||||
21
app/Http/Controllers/CategoryController.php
Normal file
21
app/Http/Controllers/CategoryController.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
36
app/Http/Controllers/Controller.php
Normal file
36
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
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('parent_id', 0)
|
||||
->where('status', 1)
|
||||
->where('top_show', 1)
|
||||
->select('id', 'title', 'type', 'order', 'article_id')
|
||||
->orderBy('order', 'asc')
|
||||
->get();
|
||||
|
||||
$links = Link::get();
|
||||
|
||||
View::share('all_categorys', $categorys);
|
||||
View::share('links', $links);
|
||||
}
|
||||
|
||||
}
|
||||
37
app/Http/Controllers/IndexController.php
Normal file
37
app/Http/Controllers/IndexController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Advert;
|
||||
use App\Models\Article;
|
||||
use App\Models\ArticlePicture;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 首页
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/6/1 9:11
|
||||
*/
|
||||
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();
|
||||
|
||||
return view('index.index', compact('ssp', 'all_articles', 'danwei', 'ysbj', 'dcyfx', 'yyjcyj', 'jsyt', 'kyyyy', 'qkys', 'center_advert', 'qikan_advert'));
|
||||
}
|
||||
|
||||
}
|
||||
161
app/Http/Controllers/TestController.php
Normal file
161
app/Http/Controllers/TestController.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?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 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user