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,81 @@
<?php
namespace App\Admin\Controllers\Advert;
use App\Models\Advert;
use App\Models\Category;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
class IndexController extends AdminController
{
protected $title = '广告位管理';
protected function grid()
{
$grid = new Grid(new Advert);
$grid->actions(function ($actions) {
$actions->disableView();
});
$grid->filter(function ($filter) {
$filter->column(1 / 2, function ($filter) {
$filter->like('title', '广告名称');
$filter->like('category.id', '分类名称')->select(Category::selectOptions(function ($model) {
return $model->where('status', 1)->where('type', Category::TYPE_ADVERT);
}, '所有分类'));
});
$filter->disableIdFilter();
});
$grid->column('id');
$grid->column('cover', '图片')->image('', 60, 60);
$grid->column('category.title', '分类名称');
$grid->column('title', '广告名称');
$grid->column('url', '地址');
$grid->column('sort', '排序');
return $grid;
}
/**
* Make a form builder.
* @return Form
*/
protected function form()
{
$form = new Form(new Advert);
$form->text('title', '广告名称')->required();
$form->select('category_id', '所属分类')
->options(Category::selectOptions(function ($model) {
return $model->where('status', 1)->where('type', Category::TYPE_ADVERT);
}, '选择分类'))
->rules('required|min:1', [
'required' => '必须选择所属分类',
'min' => '必须选择所属分类',
]);
$form->image('cover', '封面图片')
->rules(function ($form) {
if ($form->model()->cover != []) {
return 'nullable|image';
} else {
return 'required';
}
})
->move('images/' . date('Y/m/d'))
->removable()
->uniqueName();
$form->text('url', '链接地址');
$form->number('sort', '排序')
->default(1)
->required()
->help('数字越大越靠前');
return $form;
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Admin\Controllers\Article;
use App\Models\Article;
use App\Models\Category;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
class IndexController extends AdminController
{
protected $title = '内容管理';
public function grid()
{
$grid = new Grid(new Article);
$grid->model()->orderBy('id', 'desc');
$grid->filter(function ($filter) {
$filter->column(1 / 2, function ($filter) {
$filter->like('title', '文章标题');
$filter->like('category_id', '所属分类')->select(Category::selectOptions(function ($model) {
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
}, '所有分类'));
});
$filter->disableIdFilter();
});
$grid->column('id', '#ID#');
$grid->column('cover', '封面图片')->image('', 100);
$grid->column('category.title', '所属分类');
$grid->column('title', '文章标题');
$grid->column('sort', '序号');
$grid->column('created_at', '创建时间');
return $grid;
}
public function form()
{
$form = new Form(new Article);
$form->text('title', '文章标题')->rules('min:2');
$form->select('category_id', '所属分类')
->options(Category::selectOptions(function ($model) {
return $model->where('status', 1)->whereIn('type', [Category::TYPE_ARTICLE, Category::TYPE_SHOW]);
}, '选择分类'))
->rules('required|min:1', [
'required' => '必须选择所属分类',
'min' => '必须选择所属分类',
]);
$form->textarea('description', '内容简介');
$form->image('cover', '封面')
->move('images/' . date('Y/m/d'))
->removable()
->uniqueName();
$form->ueditor('content', '文章内容')->rules('required', ['required' => '详情不能为空']);
$form->number('sort', '序号')->default(0)->rules('required', ['required' => '序号必须填写'])->help('倒序优先');
return $form;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Admin\Controllers;
use Encore\Admin\Controllers\AuthController as BaseAuthController;
class AuthController extends BaseAuthController
{
}

View File

@@ -0,0 +1,134 @@
<?php
namespace App\Admin\Controllers\Category;
use App\Models\Article;
use App\Models\Category;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Row;
use Encore\Admin\Tree;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\Form as WidgetsForm;
class IndexController extends AdminController
{
protected $title = '分类管理';
/**
* Index interface.
* @return \Closure
*/
public function grid()
{
return function (Row $row) {
$row->column(6, $this->treeView());
$row->column(6, function (Column $column) {
$form = new WidgetsForm();
$form->select('parent_id', '上级分类')->options(Category::selectOptions(function ($model) {
return $model->where('status', 1);
}, '一级分类'));
$form->text('title', '分类名称')->rules('required');
$form->select('type', '分类类型')
->options(Category::TYPES)
->required();
$form->textarea('description', '分类简介')
->rules('nullable');
$form->image('cover', 'Logo')
->move('images/' . date('Y/m/d'))
->removable()
->uniqueName();
$form->number('order', '排序')->default(0);
$form->switch('status', '显示')->states()->default(1);
$form->action(admin_url('categories'));
$column->append((new Box('新增分类', $form))->style('success'));
});
};
}
/**
* @return Tree
*/
protected function treeView()
{
return Category::tree(function (Tree $tree) {
$tree->disableCreate();
$tree->branch(function ($branch) {
if ($branch['status'] == 1) {
$payload = "<i class='fa fa-eye text-primary'></i> ";
} else {
$payload = "<i class='fa fa-eye text-gray'></i> ";
}
$payload .= " [ID:{$branch['id']}] - ";
$payload .= " <strong>{$branch['title']}</strong> ";
$payload .= " <small>{$branch['type']}</small> ";
$payload .= " <small style='color:#999'>{$branch['description']}</small>";
return $payload;
});
});
}
/**
* Make a form builder.
* @return Form
*/
protected function form()
{
$form = new Form(new Category);
$form->select('parent_id', '上级分类')->options(Category::selectOptions(function ($model) {
return $model->where('status', 1);
}, '一级分类'));
$form->text('title', '分类名称')->rules('required');
$form->select('type', '分类类型')
->options(Category::TYPES)
->required()
->rules('required');
$form->textarea('description', '分类简介')->rows(4)->rules('nullable');
$form->image('cover', 'Logo')
->move('images/' . date('Y/m/d'))
->removable()
->uniqueName();
$form->number('order', '排序')->default(0)->help('正序优先');
$form->select('article_id', '关联文章')
->options(function ($option, $info) {
$category = $this;
if ($category) {
return Article::where('category_id', $category->id)->pluck('title', 'id');
} else {
return [0 => '没有数据'];
}
})->help('当分类类型是文章详情的时候需要选择关联文章');
$form->switch('status', '显示')->states()->default(1);
$form->saving(function (Form $form) {
if (request()->has('title')) {
if (request()->type == Category::TYPE_SHOW && empty(request()->article_id)) {
$error = new MessageBag([
'title' => '错误',
'message' => '文章类型是文章详情的时候需要选择关联文章',
]);
return back()->withInput()->with(compact('error'));
}
}
});
return $form;
}
public function destroy($id)
{
return $this->form()->destroy($id);
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Admin\Controllers;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
class ExampleController extends AdminController
{
/**
* Title for current resource.
*
* @var string
*/
protected $title = 'Example controller';
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new ExampleModel);
$grid->column('id', __('ID'))->sortable();
$grid->column('created_at', __('Created at'));
$grid->column('updated_at', __('Updated at'));
return $grid;
}
/**
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
$show = new Show(ExampleModel::findOrFail($id));
$show->field('id', __('ID'));
$show->field('created_at', __('Created at'));
$show->field('updated_at', __('Updated at'));
return $show;
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$form = new Form(new ExampleModel);
$form->display('id', __('ID'));
$form->display('created_at', __('Created At'));
$form->display('updated_at', __('Updated At'));
return $form;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Admin\Controllers;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
class HomeController extends Controller
{
public function index(Content $content)
{
return $content
->title('Dashboard')
->description('Description...')
->row(Dashboard::title())
->row(function (Row $row) {
$row->column(4, function (Column $column) {
$column->append(Dashboard::environment());
});
$row->column(4, function (Column $column) {
$column->append(Dashboard::extensions());
});
$row->column(4, function (Column $column) {
$column->append(Dashboard::dependencies());
});
});
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Admin\Controllers\Link;
use App\Models\Link;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
class IndexController extends AdminController
{
protected $title = '友情链接';
public function grid()
{
$grid = new Grid(new Link);
$grid->column('id', '#ID#');
$grid->column('title', '标题');
$grid->column('url', '地址');
$grid->column('created_at', '创建时间');
return $grid;
}
public function form()
{
$form = new Form(new Link);
$form->text('title', '标题')->required();
$form->text('url', '地址')->required();
return $form;
}
}

View File

@@ -0,0 +1,12 @@
<?php
use Illuminate\Routing\Router;
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace') . '\\Advert',
'middleware' => config('admin.route.middleware'),
], function (Router $router) {
$router->resource('adverts', 'IndexController');
});

View File

@@ -0,0 +1,12 @@
<?php
use Illuminate\Routing\Router;
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace') . '\\Article',
'middleware' => config('admin.route.middleware'),
], function (Router $router) {
$router->resource('articles', 'IndexController');
});

View File

@@ -0,0 +1,12 @@
<?php
use Illuminate\Routing\Router;
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace') . '\\Category',
'middleware' => config('admin.route.middleware'),
], function (Router $router) {
$router->resource('categories', 'IndexController');
});

12
app/Admin/Routes/link.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
use Illuminate\Routing\Router;
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace') . '\\Link',
'middleware' => config('admin.route.middleware'),
], function (Router $router) {
$router->resource('links', 'IndexController');
});

29
app/Admin/bootstrap.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
use Encore\Admin\Form;
use Encore\Admin\Grid;
Form::forget(['map', 'editor']);
Form::init(function (Form $form) {
$form->disableEditingCheck();
$form->disableCreatingCheck();
$form->disableViewCheck();
$form->tools(function (Form\Tools $tools) {
$tools->disableDelete();
$tools->disableView();
$tools->disableList();
});
});
Grid::init(function (Grid $grid) {
$grid->disableExport();
$grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->disableView();
});
$grid->disableBatchActions();
$grid->filter(function ($filter) {
$filter->disableIdFilter();
});
// $grid->expandFilter();
});

21
app/Admin/routes.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
use Illuminate\Routing\Router;
Admin::routes();
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace'),
'middleware' => config('admin.route.middleware'),
'as' => config('admin.route.prefix') . '.',
], function (Router $router) {
$router->get('/', 'HomeController@index')->name('home');
});
require __DIR__ . '/Routes/article.php';
require __DIR__ . '/Routes/category.php';
require __DIR__ . '/Routes/link.php';
require __DIR__ . '/Routes/advert.php';

42
app/Console/Kernel.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* @param \Exception $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Exception
*/
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}
}

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

82
app/Http/Kernel.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\App\Http\Middleware\TrustProxies::class,
\App\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
/**
* The priority-sorted list of middleware.
*
* This forces non-global middleware to always be in the given order.
*
* @var array
*/
protected $middlewarePriority = [
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\Authenticate::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authorize::class,
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
class CheckForMaintenanceMode extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Middleware;
use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
return $next($request);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
'password',
'password_confirmation',
];
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Middleware;
use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array|string
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
*
* @var bool
*/
protected $addHttpCookie = true;
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
}

15
app/Models/Advert.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use App\Models\Traits\BelongsToCategory;
use App\Models\Traits\HasOneCover;
use App\Models\Traits\OrderByIdDesc;
use App\Scopes\SortScope;
class Advert extends Model
{
use HasOneCover,
BelongsToCategory;
}

48
app/Models/Article.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use App\Models\Traits\BelongsToCategory;
use App\Models\Traits\HasOneCover;
class Article extends Model
{
use HasOneCover, BelongsToCategory;
public function get_content_cover()
{
preg_match("/<img.*?src=\"([^\"]+)\"[^>].*?>/isU", str_ireplace("\\", "", $this->content), $matches);
if (isset($matches[1])) {
return $matches[1];
} else {
return '';
}
}
/**
* Notes: 获取一个默认图片
* @Author: 玄尘
* @Date : 2020/6/3 16:29
* @return mixed|string
*/
public function get_one_cover()
{
if ($this->cover_path) {
$path = $this->cover_path;
} else {
$path = $this->get_content_cover();
if ($path) {
$this->cover = str_replace("/storage", "", $path);
$this->save();
$path = config('app.url') . $path;
}
}
return $path;
}
}

72
app/Models/Category.php Normal file
View File

@@ -0,0 +1,72 @@
<?php
namespace App\Models;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
class Category extends Model
{
use AdminBuilder, ModelTree;
public const TYPES = [
'article' => '文章列表',
'show' => '文章详情',
'advert' => '广告',
];
public const TYPE_SHOW = 'show';
public const TYPE_ARTICLE = 'article';
public const TYPE_ADVERT = 'advert';
/**
* 关联的数据
* @return [type] [description]
*/
public function relations()
{
switch ($this->type) {
case self::TYPE_SHOW:
return $this->hasOne(Article::class)->where('id',$this->article_id);
break;
case self::TYPE_ARTICLE:
return $this->hasMany(Article::class);
break;
case self::TYPE_ADVERT:
return $this->hasMany(Advert::class);
break;
default:
return null;
}
}
public function childrens()
{
return $this->hasMany(self::class,'parent_id');
}
public function parent()
{
return $this->hasOne(self::class,'id','parent_id');
}
public function article()
{
return $this->belongsTo(Article::class);
}
/**
* Notes: 获取当前分类及子分类ID
* @Author: <C.Jason>
* @Date : 2020/4/6 3:12 下午
* @return array
*/
public function getAllChildrenId()
{
$ids = array_keys($this->buildSelectOptions([], $this->id));
array_unshift($ids, $this->id);
return $ids;
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Models;
class DedeAddonarticle extends Model
{
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
class DedeArchive extends Model
{
public function info()
{
return $this->hasOne(DedeAddonarticle::class, 'aid');
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
class DedeArctype extends Model
{
use AdminBuilder, ModelTree;
}

8
app/Models/Link.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace App\Models;
class Link extends Model
{
//
}

22
app/Models/Model.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Model extends Eloquent
{
protected $guarded = [];
/**
* 为数组 / JSON 序列化准备日期。
*
* @param \DateTimeInterface $date
* @return string
*/
protected function serializeDate(DateTimeInterface $date)
{
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models\Traits;
use App\Models\Category;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
trait BelongsToCategory
{
/**
* 关联分类表
* @author 玄尘 2020-03-05
* @return BelongsTo
*/
public function category(): BelongsTo
{
return $this->belongsTo(Category::class)->withDefault();
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models\Traits;
use Illuminate\Support\Facades\Storage;
trait HasOneCover
{
/**
* 拼接图片全地址
* @author 玄尘 2020-03-05
* @return string
*/
public function getCoverPathAttribute(): ?string
{
if ($this->cover) {
return Storage::url($this->cover);
} else {
return '';
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Providers;
use Encore\Admin\Config\Config;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
//add fixed sql
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
Schema::defaultStringLength(191); //add fixed sql
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$table = config('admin.extensions.config.table', 'admin_config');
if (Schema::hasTable($table)) {
Config::load();
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
// 'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* The path to the "home" route for your application.
*
* @var string
*/
public const HOME = '/home';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
}

90
app/Traits/Tree.php Normal file
View File

@@ -0,0 +1,90 @@
<?php
// +------------------------------------------------+
// | http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace App\Traits;
/**
* 生成多层树状下拉选框的工具
*/
trait Tree
{
/**
* 用于树型数组完成递归格式的全局变量
*/
private static $formatTree;
/**
* 生成多层树,供下拉选框使用
*/
public static function toFormatTree($list, $title = 'title', $pk = 'id', $pid = 'pid', $root = 0)
{
$list = self::list2tree($list, $pk, $pid, '_child', $root);
self::$formatTree = [];
self::_toFormatTree($list, 0, $title);
return self::$formatTree;
}
/**
* 把数据集转换成Tree
* @param array $list 要转换的数据集
* @param string $pk [description]
* @param string $pid [description]
* @param string $child [description]
* @param integer $root [description]
* @return array
*/
public static function list2tree($list, $pk = 'id', $pid = 'pid', $child = 'children', $root = 0)
{
$tree = [];
if (is_array($list)) {
$refer = [];
foreach ($list as $key => $data) {
$refer[$data[$pk]] = &$list[$key];
}
foreach ($list as $key => $data) {
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] = &$list[$key];
} else {
if (isset($refer[$parentId])) {
$parent = &$refer[$parentId];
$parent[$child][] = &$list[$key];
}
}
}
}
return $tree;
}
/**
* 将格式数组转换为树
* @param array $list
* @param integer $level 进行递归时传递用的参数
* @author 小陈叔叔 <Jason.Chen[cjango.com]>
*/
private static function _toFormatTree($list, $level = 0, $title = 'title')
{
foreach ($list as $key => $val) {
$tmp_str = str_repeat("&nbsp;", $level * 4);
$tmp_str .= "└&nbsp;";
$val['level'] = $level;
$val['title_show'] = $level == 0 ? $val[$title] . "&nbsp;" : $tmp_str . $val[$title];
if (!array_key_exists('_child', $val)) {
array_push(self::$formatTree, $val);
} else {
$tmp_ary = $val['_child'];
unset($val['_child']);
array_push(self::$formatTree, $val);
self::_toFormatTree($tmp_ary, $level + 1, $title); //进行下一层递归
}
}
return;
}
}

39
app/User.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}