first commit

This commit is contained in:
2020-09-14 14:29:29 +08:00
commit 3ac390f68f
767 changed files with 166582 additions and 0 deletions

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

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

View File

@@ -0,0 +1,38 @@
<?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', 72)->get();
}else{
$adverts = Advert::where('category_id', 73)->get();
}
View::share('all_categorys', $categorys);
View::share('adverts', $adverts);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Http\Controllers;
use App\Models\Article;
use App\Models\Category;
use App\Models\Link;
class IndexController extends Controller
{
/**
* Notes: 首页
* @Author: 玄尘
* @Date : 2020/6/1 9:11
*/
public function index()
{
$xwdt = $this->getArticle([53]); //新闻动态
$kjpt = $this->getArticle([18]); //科技平台
$zcjc = $this->getArticle([8]); //政府决策服务
$zmzj = $this->getArticle([74, 127, 88]); //专家学者
$tjgg = $this->getArticle([54]); //通知公告
$kjlt = $this->getArticle([58]); //科技发展论坛
$cxtd = $this->getArticle(Category::find(43)->getAllChildrenId(), 5); //创新团队
$info = Article::where('category_id', 1)->first(); //简介
$kxyts = $this->getArticle(Category::find(17)->getAllChildrenId(), 10); //科学研究与特色品牌建设
$yjzx = $this->getArticle([61], 2); //研究中心
$links = Link::get();
return view('index.index', compact('links', 'xwdt', 'kjpt', 'zcjc', 'zmzj', 'tjgg', 'kjlt', 'tjgg', 'kjlt', 'info', 'kxyts', 'cxtd', 'yjzx'));
}
//通用获取文章
public function getArticle($category_ids, $take = 3)
{
return Article::whereIn('category_id', $category_ids)
->select('id', 'description', 'title', 'created_at', 'cover', 'content')
->orderBy('created_at', 'desc')
->take($take)
->get();
}
}

View File

@@ -0,0 +1,199 @@
<?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;
use Illuminate\Support\Facades\DB;
class TestController extends Controller
{
use Tree;
public function index()
{
}
//检查分类
public function checkCategory()
{
$article = Article::find(913);
dd($article->get_one_cover());
dd();
$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 != '&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()
{
$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()) {
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;
}
}