first
This commit is contained in:
10
app/Admin/Controllers/AuthController.php
Normal file
10
app/Admin/Controllers/AuthController.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Encore\Admin\Controllers\AuthController as BaseAuthController;
|
||||
|
||||
class AuthController extends BaseAuthController
|
||||
{
|
||||
|
||||
}
|
||||
183
app/Admin/Controllers/Dashboard.php
Normal file
183
app/Admin/Controllers/Dashboard.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Encore\Admin\Admin;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\View\View;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
class Dashboard
|
||||
{
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
public static function title()
|
||||
{
|
||||
return view('admin.dashboard.title');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
public static function environment()
|
||||
{
|
||||
$envs = [
|
||||
['name' => 'PHP version', 'value' => 'PHP/'.PHP_VERSION],
|
||||
['name' => 'Laravel version', 'value' => app()->version()],
|
||||
['name' => 'CGI', 'value' => php_sapi_name()],
|
||||
['name' => 'Uname', 'value' => php_uname()],
|
||||
['name' => 'Server', 'value' => Arr::get($_SERVER, 'SERVER_SOFTWARE')],
|
||||
|
||||
['name' => 'Cache driver', 'value' => config('cache.default')],
|
||||
['name' => 'Session driver', 'value' => config('session.driver')],
|
||||
['name' => 'Queue driver', 'value' => config('queue.default')],
|
||||
|
||||
['name' => 'Timezone', 'value' => config('app.timezone')],
|
||||
['name' => 'Locale', 'value' => config('app.locale')],
|
||||
['name' => 'Env', 'value' => config('app.env')],
|
||||
['name' => 'URL', 'value' => config('app.url')],
|
||||
];
|
||||
|
||||
return view('admin.dashboard.environment', compact('envs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory|View
|
||||
*/
|
||||
public static function extensions()
|
||||
{
|
||||
$extensions = [
|
||||
'user' => [
|
||||
'name' => '用户模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-user-module',
|
||||
'icon' => 'users',
|
||||
],
|
||||
'chain' => [
|
||||
'name' => '区块链管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-chain-module',
|
||||
'icon' => 'chain',
|
||||
],
|
||||
'lottery' => [
|
||||
'name' => '抽奖模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-lottery-module',
|
||||
'icon' => 'gavel',
|
||||
],
|
||||
'task' => [
|
||||
'name' => '任务模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-task-module',
|
||||
'icon' => 'hourglass-end',
|
||||
],
|
||||
'cms' => [
|
||||
'name' => '内容管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-cms-module',
|
||||
'icon' => 'book',
|
||||
],
|
||||
'appversion' => [
|
||||
'name' => 'App版本',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-appversion-module',
|
||||
'icon' => 'apple',
|
||||
],
|
||||
'mall' => [
|
||||
'name' => '多用户商城',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-mall-module',
|
||||
'icon' => 'shopping-cart',
|
||||
],
|
||||
'payment' => [
|
||||
'name' => '支付模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-payment-module',
|
||||
'icon' => 'paypal',
|
||||
],
|
||||
'company' => [
|
||||
'name' => '企业管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-company-module',
|
||||
'icon' => 'black-tie',
|
||||
],
|
||||
'coupon' => [
|
||||
'name' => '优惠券模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-coupon-module',
|
||||
'icon' => 'qrcode',
|
||||
],
|
||||
'settlement' => [
|
||||
'name' => '结算模块',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-settlement-module',
|
||||
'icon' => 'sliders',
|
||||
],
|
||||
'configuration' => [
|
||||
'name' => '参数配置',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-configuration-module',
|
||||
'icon' => 'cogs',
|
||||
],
|
||||
'withdraw' => [
|
||||
'name' => '提现管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-withdraw-module',
|
||||
'icon' => 'clock-o',
|
||||
],
|
||||
'notification' => [
|
||||
'name' => '消息中心',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-notification-module',
|
||||
'icon' => 'envelope',
|
||||
],
|
||||
'linker' => [
|
||||
'name' => '链接管理',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-linker-module',
|
||||
'icon' => 'link',
|
||||
],
|
||||
'storage' => [
|
||||
'name' => '文件存储',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-storage-module',
|
||||
'icon' => 'file',
|
||||
],
|
||||
'omniform' => [
|
||||
'name' => '万能表单',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-omni-form-module',
|
||||
'icon' => 'wpforms',
|
||||
],
|
||||
'tao' => [
|
||||
'name' => '淘宝客',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-tao-module',
|
||||
'icon' => 'simplybuilt',
|
||||
],
|
||||
'market' => [
|
||||
'name' => '交易市场',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-market-module',
|
||||
'icon' => 'asl-interpreting',
|
||||
],
|
||||
'tokenmall' => [
|
||||
'name' => '区块链商城',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-token-mall-module',
|
||||
'icon' => 'flask',
|
||||
],
|
||||
'acme' => [
|
||||
'name' => 'SSL免费证书',
|
||||
'link' => 'https://git.yuzhankeji.cn/UzTech/laravel-acme-module',
|
||||
'icon' => 'html5',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($extensions as $key => &$extension) {
|
||||
$module = Module::find($key);
|
||||
|
||||
if ($module) {
|
||||
$extension['installed'] = (int) $module->isEnabled();
|
||||
} else {
|
||||
$extension['installed'] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
return view('admin.dashboard.extensions', compact('extensions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function dependencies(): string
|
||||
{
|
||||
$json = file_get_contents(base_path('composer.json'));
|
||||
|
||||
$dependencies = json_decode($json, true)['require'];
|
||||
|
||||
return Admin::component('admin.dashboard.dependencies', compact('dependencies'));
|
||||
}
|
||||
}
|
||||
46
app/Admin/Controllers/HomeController.php
Normal file
46
app/Admin/Controllers/HomeController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Encore\Admin\Layout\Column;
|
||||
use Encore\Admin\Layout\Content;
|
||||
use Encore\Admin\Layout\Row;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Notes : 数据看板
|
||||
*
|
||||
* @Date : 2021/3/10 5:12 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param Content $content
|
||||
* @return Content
|
||||
*/
|
||||
public function index(Content $content): Content
|
||||
{
|
||||
if (config('app.debug')) {
|
||||
return $content
|
||||
->title(__('admin.menu_titles.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::dependencies());
|
||||
});
|
||||
|
||||
$row->column(4, function (Column $column) {
|
||||
$column->append(Dashboard::extensions());
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return $content
|
||||
->title(__('admin.menu_titles.dashboard'))
|
||||
->description('Description...');
|
||||
}
|
||||
}
|
||||
}
|
||||
105
app/Admin/Controllers/ModuleController.php
Normal file
105
app/Admin/Controllers/ModuleController.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Models\Module;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Grid;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Nwidart\Modules\Facades\Module as ModuleManager;
|
||||
|
||||
class ModuleController extends AdminController
|
||||
{
|
||||
protected $title = '模块管理';
|
||||
|
||||
/**
|
||||
* Notes : 模块列表
|
||||
*
|
||||
* @Date : 2021/10/28 9:18 上午
|
||||
* @Author : <Jason.C>
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid(): Grid
|
||||
{
|
||||
$grid = new Grid(new Module());
|
||||
|
||||
$grid->disableBatchActions();
|
||||
$grid->disableFilter();
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableActions();
|
||||
|
||||
$grid->column('name', '模块名称');
|
||||
$grid->column('alias', '别名');
|
||||
$grid->column('version', '版本');
|
||||
$grid->column('author', '作者');
|
||||
$grid->column('description', '模块简介');
|
||||
$grid->column('enabled', '状态')->bool();
|
||||
$grid->column('id', '操作')->display(function () {
|
||||
if ($this->enabled) {
|
||||
return sprintf('<a href="%s">%s</a>', route('admin.module.disable', $this->name), '禁用');
|
||||
} else {
|
||||
return sprintf('<a href="%s">%s</a>', route('admin.module.enable', $this->name), '启用');
|
||||
}
|
||||
});
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 禁用模块
|
||||
*
|
||||
* @Date : 2021/3/11 1:13 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string $name
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function disable(string $name): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$module = ModuleManager::find($name);
|
||||
|
||||
$module->disable();
|
||||
|
||||
$class = sprintf('\\%s\\%s\\%s', config('modules.namespace'), $module->getName(), $module->getName());
|
||||
|
||||
if (class_exists($class)) {
|
||||
call_user_func([$class, 'uninstall']);
|
||||
}
|
||||
|
||||
admin_success('Success', $name . '模块禁用成功');
|
||||
} catch (\Exception $exception) {
|
||||
admin_error('Error', $exception->getMessage());
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 启用模块
|
||||
*
|
||||
* @Date : 2021/3/11 1:13 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string $name
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function enable(string $name): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$module = ModuleManager::find($name);
|
||||
|
||||
$module->enable();
|
||||
|
||||
$class = sprintf('\\%s\\%s\\%s', config('modules.namespace'), $module->getName(), $module->getName());
|
||||
|
||||
if (class_exists($class)) {
|
||||
call_user_func([$class, 'install']);
|
||||
}
|
||||
|
||||
admin_success('Success', $name . '模块启用成功');
|
||||
} catch (\Exception $exception) {
|
||||
admin_error('Error', $exception->getMessage());
|
||||
}
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
35
app/Admin/Extensions/CleanCache.php
Normal file
35
app/Admin/Extensions/CleanCache.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Extensions;
|
||||
|
||||
use Encore\Admin\Actions\Action;
|
||||
use Encore\Admin\Actions\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class CleanCache extends Action
|
||||
{
|
||||
protected $selector = '.clear-cache';
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
Artisan::call('modelCache:clear');
|
||||
return $this->response()->success('清理完成')->refresh();
|
||||
}
|
||||
|
||||
public function dialog()
|
||||
{
|
||||
$this->confirm('确认清除缓存');
|
||||
}
|
||||
|
||||
public function html(): string
|
||||
{
|
||||
return <<<HTML
|
||||
<li>
|
||||
<a class="clear-cache" href="#">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</li>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
21
app/Admin/Extensions/FormQrCode.php
Normal file
21
app/Admin/Extensions/FormQrCode.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Extensions;
|
||||
|
||||
use Encore\Admin\Form\Field;
|
||||
|
||||
class FormQrCode extends Field
|
||||
{
|
||||
protected $view = 'admin.form.qr_code';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$google2fa = app('pragmarx.google2fa');
|
||||
$this->value = $google2fa->getQRCodeUrl(
|
||||
$this->data['username'],
|
||||
$this->data['name'],
|
||||
$this->data['g2fa_secret']
|
||||
);
|
||||
return parent::render();
|
||||
}
|
||||
}
|
||||
12
app/Admin/Routes/modules.php
Normal file
12
app/Admin/Routes/modules.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group([
|
||||
'prefix' => 'modules',
|
||||
], function (Router $router) {
|
||||
$router->get('', 'ModuleController@index');
|
||||
$router->get('{name}/disable', 'ModuleController@disable')->name('module.disable');
|
||||
$router->get('{name}/enable', 'ModuleController@enable')->name('module.enable');
|
||||
});
|
||||
94
app/Admin/Traits/WithUploads.php
Normal file
94
app/Admin/Traits/WithUploads.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Traits;
|
||||
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Form\Field\Image;
|
||||
use Encore\Admin\Form\Field\MultipleFile;
|
||||
use Encore\Admin\Form\Field\MultipleImage;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
|
||||
trait WithUploads
|
||||
{
|
||||
/**
|
||||
* Notes : 单张封面图上传
|
||||
*
|
||||
* @Date : 2021/4/25 2:06 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param Form $form
|
||||
* @param string $filed
|
||||
* @param string $label
|
||||
* @return Image
|
||||
*/
|
||||
public function cover(Renderable $form, string $filed = 'cover', string $label = '封面图片'): Image
|
||||
{
|
||||
$cover = $form->image($filed, $label)
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->uniqueName()
|
||||
->removable()
|
||||
->retainable();
|
||||
|
||||
$waterConfig = config('admin.image_water');
|
||||
|
||||
if (! empty($waterConfig)) {
|
||||
$cover->insert(...$waterConfig);
|
||||
}
|
||||
|
||||
$coverThumb = config('admin.cover_thumb');
|
||||
|
||||
if (! empty($coverThumb)) {
|
||||
$cover->thumbnail($coverThumb);
|
||||
}
|
||||
return $cover;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 统一的多图上传
|
||||
*
|
||||
* @Date : 2021/4/25 2:06 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param Form $form
|
||||
* @param string $filed
|
||||
* @param string $label
|
||||
* @return MultipleImage
|
||||
*/
|
||||
public function pictures(Renderable $form, string $filed = 'pictures', string $label = '多图轮播'): MultipleImage
|
||||
{
|
||||
$pictures = $form->multipleImage($filed, $label)
|
||||
->move('images/'.date('Y/m/d'))
|
||||
->uniqueName()
|
||||
->removable()
|
||||
->retainable();
|
||||
|
||||
// 多图如果开启排序的话,会报错,暂时没由解决办法 ->sortable()
|
||||
$waterConfig = config('admin.image_water');
|
||||
|
||||
if (! empty($waterConfig)) {
|
||||
$pictures->insert(...$waterConfig);
|
||||
}
|
||||
return $pictures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 统一的附件上传
|
||||
*
|
||||
* @Date : 2021/4/25 3:03 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param Renderable $form
|
||||
* @param string $filed
|
||||
* @param string $label
|
||||
* @return MultipleFile
|
||||
*/
|
||||
public function attachments(
|
||||
Renderable $form,
|
||||
string $filed = 'attachments',
|
||||
string $label = '内容附件'
|
||||
): MultipleFile {
|
||||
return $form->multipleFile($filed, $label)
|
||||
->move('attachments/'.date('Y/m/d'))
|
||||
->uniqueName()
|
||||
->removable()
|
||||
->retainable()
|
||||
->sortable();
|
||||
}
|
||||
}
|
||||
51
app/Admin/bootstrap.php
Normal file
51
app/Admin/bootstrap.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use App\Admin\Extensions\CleanCache;
|
||||
use App\Admin\Extensions\FormQrCode;
|
||||
use Encore\Admin\Facades\Admin;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Show;
|
||||
use Encore\Admin\Widgets\Navbar;
|
||||
|
||||
Form::forget(['map', 'editor']);
|
||||
|
||||
Admin::navbar(function (Navbar $navbar) {
|
||||
$navbar->right(new CleanCache());
|
||||
$navbar->right(new Navbar\Fullscreen());
|
||||
});
|
||||
|
||||
Form::init(function (Form $form) {
|
||||
$form->disableEditingCheck();
|
||||
$form->disableCreatingCheck();
|
||||
$form->disableViewCheck();
|
||||
|
||||
$form->tools(function (Form\Tools $tools) {
|
||||
$tools->disableView();
|
||||
// $tools->disableDelete();
|
||||
// $tools->disableList();
|
||||
});
|
||||
});
|
||||
|
||||
Show::init(function (Show $show) {
|
||||
$show->panel()
|
||||
->tools(function ($tools) {
|
||||
// $tools->disableEdit();
|
||||
// $tools->disableList();
|
||||
$tools->disableDelete();
|
||||
});;
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
Form::extend('qrCode', FormQrCode::class);
|
||||
20
app/Admin/routes.php
Normal file
20
app/Admin/routes.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use Encore\Admin\Facades\Admin;
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Admin::routes();
|
||||
|
||||
Route::group([
|
||||
'prefix' => config('admin.route.prefix'),
|
||||
'namespace' => config('admin.route.namespace'),
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
'as' => config('admin.route.as'),
|
||||
], function (Router $router) {
|
||||
$router->get('/', 'HomeController@index')->name('home');
|
||||
|
||||
foreach (glob(admin_path('Routes') . '/*.php') as $routeFile) {
|
||||
require $routeFile;
|
||||
}
|
||||
});
|
||||
11
app/Api/Controllers/Controller.php
Normal file
11
app/Api/Controllers/Controller.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Jason\Api\Traits\ApiResponse;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use ApiResponse;
|
||||
}
|
||||
13
app/Api/Controllers/IndexController.php
Normal file
13
app/Api/Controllers/IndexController.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Controllers;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return $this->success('Json Api is ready');
|
||||
}
|
||||
}
|
||||
19
app/Api/Resources/BaseCollection.php
Normal file
19
app/Api/Resources/BaseCollection.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class BaseCollection extends ResourceCollection
|
||||
{
|
||||
protected function page(): array
|
||||
{
|
||||
return [
|
||||
'current' => $this->currentPage(),
|
||||
'total_page' => $this->lastPage(),
|
||||
'per_page' => $this->perPage(),
|
||||
'has_more' => $this->hasMorePages(),
|
||||
'total' => $this->total(),
|
||||
];
|
||||
}
|
||||
}
|
||||
1
app/Api/bootstrap.php
Normal file
1
app/Api/bootstrap.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php
|
||||
26
app/Api/routes.php
Normal file
26
app/Api/routes.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
//Route::get('/', 'IndexController@index')->name('home');
|
||||
|
||||
/**
|
||||
* 分组的路由示例
|
||||
*/
|
||||
Route::group([
|
||||
// 'as' => '',
|
||||
// 'domain' => '',
|
||||
// 'middleware' => '',
|
||||
// 'namespace' => '',
|
||||
// 'prefix' => '',
|
||||
], function (Router $router) {
|
||||
$router->get('/', 'IndexController@index')->name('home');
|
||||
});
|
||||
|
||||
/**
|
||||
* 文件夹引入的示例
|
||||
*/
|
||||
//foreach (glob(app_path('Api/Routes') . '/*.php') as $routeFile) {
|
||||
// require $routeFile;
|
||||
//}
|
||||
52
app/Console/Kernel.php
Normal file
52
app/Console/Kernel.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Nwidart\Modules\Facades\Module as ModuleManager;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
$this->modules($schedule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 要执行任务的位置增加Console\Kernel类
|
||||
* 类中 runCommand(Schedule $schedule)
|
||||
* 模型中的command在模型的ServiceProvider自行注册
|
||||
*
|
||||
* @param Schedule $schedule
|
||||
*/
|
||||
protected function modules(Schedule $schedule)
|
||||
{
|
||||
$data = ModuleManager::toCollection();
|
||||
foreach ($data as $name => $module) {
|
||||
$class = "\\Modules\\$name\\Console\\Kernel";
|
||||
if (class_exists($class)) {
|
||||
$runKernel = resolve($class);
|
||||
$runKernel->runCommand($schedule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
// $this->load(__DIR__.'/Commands');
|
||||
}
|
||||
|
||||
}
|
||||
44
app/Exceptions/Handler.php
Normal file
44
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Jason\Api\Traits\ApiException;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
use ApiException;
|
||||
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array<int, class-string<Throwable>>
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
28
app/Http/Controllers/Controller.php
Normal file
28
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Jason\Api\Traits\ApiResponse;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
/**
|
||||
* Notes : 授权token返回格式
|
||||
*
|
||||
* @Date : 2021/3/16 5:00 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string $token
|
||||
* @return array
|
||||
*/
|
||||
protected function respondWithToken(string $token): array
|
||||
{
|
||||
return [
|
||||
'access_token' => $token,
|
||||
'token_type' => 'Bearer',
|
||||
'expires_in' => auth('api')->factory()->getTTL() * 60,
|
||||
];
|
||||
}
|
||||
}
|
||||
68
app/Http/Kernel.php
Normal file
68
app/Http/Kernel.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\App\Http\Middleware\SetServerId::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
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' => [
|
||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::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,
|
||||
];
|
||||
}
|
||||
22
app/Http/Middleware/Authenticate.php
Normal file
22
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request): ?string
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal 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<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
34
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
34
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @param string|null ...$guards
|
||||
* @return Response|RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
29
app/Http/Middleware/SetServerId.php
Normal file
29
app/Http/Middleware/SetServerId.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SetServerId
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置响应的 server id,便于故障判断
|
||||
*
|
||||
* @Author <Jason.C>
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$response = $next($request);
|
||||
$response->headers->add([
|
||||
'X-Server-Id' => env('SERVER_ID'),
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
19
app/Http/Middleware/TrimStrings.php
Normal file
19
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
20
app/Http/Middleware/TrustHosts.php
Normal file
20
app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
28
app/Http/Middleware/TrustProxies.php
Normal file
28
app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
45
app/Models/Google2FA.php
Normal file
45
app/Models/Google2FA.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
class Google2FA extends Model
|
||||
{
|
||||
protected $casts = [
|
||||
'status' => 'boolean',
|
||||
];
|
||||
|
||||
public function subscriber(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 更新密钥
|
||||
*
|
||||
* @Date : 2022/11/30 20:51
|
||||
* @Author : <Jason.C>
|
||||
*/
|
||||
public function upgrade()
|
||||
{
|
||||
$google2fa = app('pragmarx.google2fa');
|
||||
|
||||
$this->secret = $google2fa->generateSecretKey(32);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 验证
|
||||
*
|
||||
* @Date : 2022/11/30 20:49
|
||||
* @Author : <Jason.C>
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public function verify(string $value): bool
|
||||
{
|
||||
$google2fa = app('pragmarx.google2fa');
|
||||
return $google2fa->verifyGoogle2FA($this->secret, $value);
|
||||
}
|
||||
}
|
||||
27
app/Models/Model.php
Normal file
27
app/Models/Model.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Macroable;
|
||||
use Encore\Admin\Traits\DefaultDatetimeFormat;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
|
||||
class Model extends Eloquent
|
||||
{
|
||||
use DefaultDatetimeFormat,
|
||||
Macroable;
|
||||
|
||||
/**
|
||||
* 禁止批量写入的字段
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 修改模型默认分页数量,为了配合API端使用的
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $perPage = 10;
|
||||
}
|
||||
49
app/Models/Module.php
Normal file
49
app/Models/Module.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Nwidart\Modules\Facades\Module as ModuleManager;
|
||||
|
||||
class Module extends Model
|
||||
{
|
||||
/**
|
||||
* Notes : 自定义返回数据
|
||||
*
|
||||
* @Date : 2021/3/11 9:59 上午
|
||||
* @Author : <Jason.C>
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function paginate(): LengthAwarePaginator
|
||||
{
|
||||
$perPage = Request::get('per_page', 20);
|
||||
$page = Request::get('page', 1);
|
||||
|
||||
$data = ModuleManager::toCollection();
|
||||
|
||||
$chunk = $data->forPage($page, $perPage);
|
||||
|
||||
$modules = $chunk->map(function ($module) {
|
||||
return [
|
||||
'id' => $module->getName(),
|
||||
'name' => $module->getName(),
|
||||
'alias' => $module->getAlias(),
|
||||
'description' => $module->getDescription(),
|
||||
'priority' => $module->getPriority(),
|
||||
'keywords' => $module->get('keywords'),
|
||||
'requires' => $module->getRequires(),
|
||||
'enabled' => $module->isEnabled(),
|
||||
'version' => $module->get('version'),
|
||||
'author' => $module->get('author'),
|
||||
];
|
||||
});
|
||||
|
||||
$modules = static::hydrate($modules->toArray());
|
||||
$paginator = new LengthAwarePaginator($modules, ModuleManager::count(), $perPage);
|
||||
$paginator->setPath(url()->current());
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
}
|
||||
28
app/Providers/AppServiceProvider.php
Normal file
28
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
30
app/Providers/AuthServiceProvider.php
Normal file
30
app/Providers/AuthServiceProvider.php
Normal 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<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
21
app/Providers/BroadcastServiceProvider.php
Normal file
21
app/Providers/BroadcastServiceProvider.php
Normal 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');
|
||||
}
|
||||
}
|
||||
32
app/Providers/EventServiceProvider.php
Normal file
32
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
63
app/Providers/RouteServiceProvider.php
Normal file
63
app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* This is used by Laravel authentication to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
/**
|
||||
* The controller namespace for the application.
|
||||
*
|
||||
* When present, controller route declarations will automatically be prefixed with this namespace.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $namespace = 'App\\Http\\Controllers';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the rate limiters for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureRateLimiting()
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(env('RATE_LIMITER', 60))->by(optional($request->user())->id ?: $request->ip());
|
||||
});
|
||||
}
|
||||
}
|
||||
43
app/Rules/AdminG2FARule.php
Normal file
43
app/Rules/AdminG2FARule.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Encore\Admin\Auth\Database\Administrator;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class AdminG2FARule implements Rule
|
||||
{
|
||||
protected array $formData;
|
||||
|
||||
protected string $errorMessage = '身份校验码 校验失败';
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->formData = $data;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
$user = Administrator::where('username', $this->formData['username'])->first();
|
||||
|
||||
if ($user && $user->use_g2fa) {
|
||||
if (blank($value)) {
|
||||
$this->errorMessage = '身份校验码 必须填写';
|
||||
return false;
|
||||
}
|
||||
if (strlen($value) != 6) {
|
||||
$this->errorMessage = '身份校验码 必须是6位';
|
||||
return false;
|
||||
}
|
||||
|
||||
$google2fa = app('pragmarx.google2fa');
|
||||
return $google2fa->verifyGoogle2FA($user->g2fa_secret, $value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function message(): string
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
}
|
||||
69
app/Rules/IdCardRule.php
Normal file
69
app/Rules/IdCardRule.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class IdCardRule implements Rule
|
||||
{
|
||||
protected string $errorMessage = '身份证号码 校验错误';
|
||||
|
||||
/**
|
||||
* Notes : 校验
|
||||
*
|
||||
* @Date : 2021/6/23 2:59 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
if (strlen($value) !== 18) {
|
||||
$this->errorMessage = '请输入18位身份证号码';
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isIdCard($value);
|
||||
}
|
||||
|
||||
private function isIdCard($id): bool
|
||||
{
|
||||
$id = strtoupper($id);
|
||||
$regx = "/(^\d{17}([0-9]|X)$)/";
|
||||
$arr_split = [];
|
||||
if (! preg_match($regx, $id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
|
||||
@preg_match($regx, $id, $arr_split);
|
||||
$dtm_birth = $arr_split[2].'/'.$arr_split[3].'/'.$arr_split[4];
|
||||
if (! strtotime($dtm_birth)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$arr_int = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
||||
$arr_ch = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
|
||||
$sign = 0;
|
||||
for ($i = 0; $i < 17; $i++) {
|
||||
$b = (int) $id[$i];
|
||||
$w = $arr_int[$i];
|
||||
$sign += $b * $w;
|
||||
}
|
||||
$n = $sign % 11;
|
||||
$val_num = $arr_ch[$n];
|
||||
|
||||
return ! ($val_num !== substr($id, 17, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取校验错误信息
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message(): string
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
}
|
||||
23
app/Scopes/OrderByIdDescScope.php
Normal file
23
app/Scopes/OrderByIdDescScope.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class OrderByIdDescScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Notes : ID倒序的作用域
|
||||
*
|
||||
* @Date : 2021/11/10 10:16 上午
|
||||
* @Author : <Jason.C>
|
||||
* @param Builder $builder
|
||||
* @param Model $model
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
$builder->orderByDesc('id');
|
||||
}
|
||||
}
|
||||
23
app/Scopes/OrderByOrderAscScope.php
Normal file
23
app/Scopes/OrderByOrderAscScope.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class OrderByOrderAscScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Notes : 按照 order 字段 正序排序的作用域
|
||||
*
|
||||
* @Date : 2021/11/10 10:16 上午
|
||||
* @Author : <Jason.C>
|
||||
* @param Builder $builder
|
||||
* @param Model $model
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
$builder->orderBy('order')->orderByDesc('id');
|
||||
}
|
||||
}
|
||||
87
app/Traits/HasClicks.php
Normal file
87
app/Traits/HasClicks.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* 预期给所有拥有浏览计数的模型使用
|
||||
* 使用缓存,计算浏览量,定期更新缓存至数据库中
|
||||
*/
|
||||
trait HasClicks
|
||||
{
|
||||
protected int $saveRate = 20;
|
||||
|
||||
/**
|
||||
* Notes : 获取点击量的字段
|
||||
*
|
||||
* @Date : 2021/3/17 9:39 上午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
private function getClicksField(): string
|
||||
{
|
||||
return $this->clicks_filed ?? 'clicks';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 获取缓存前缀
|
||||
*
|
||||
* @Date : 2021/3/16 5:52 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
private function getClickCachePrefix(): string
|
||||
{
|
||||
return $this->cachePrefix ?? class_basename(__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 生成一个缓存KEY
|
||||
*
|
||||
* @Date : 2021/3/16 5:52 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string|null $appends
|
||||
* @return string
|
||||
*/
|
||||
private function getCacheKey(string $appends = null): string
|
||||
{
|
||||
return $this->getClickCachePrefix().':'.$this->getKey().':'.$appends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 增加点击量
|
||||
*
|
||||
* @Date : 2021/3/17 9:20 上午
|
||||
* @Author : <Jason.C>
|
||||
* @param int $step
|
||||
*/
|
||||
public function incrementClicks(int $step = 1): void
|
||||
{
|
||||
Cache::increment($this->getCacheKey('clicks'), $step);
|
||||
|
||||
if (rand(1, $this->saveRate) === 1) {
|
||||
$this->update([$this->getClicksField() => $this->clicks]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 获取缓存的浏览次数
|
||||
*
|
||||
* @Date : 2021/3/16 5:52 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return int
|
||||
*/
|
||||
public function getClicksAttribute(): int
|
||||
{
|
||||
$clicks = Cache::get($this->getCacheKey('clicks'));
|
||||
|
||||
if (is_null($clicks)) {
|
||||
return Cache::rememberForever($this->getCacheKey('clicks'), function () {
|
||||
return $this->getAttributes()[$this->getClicksField()];
|
||||
});
|
||||
} else {
|
||||
return $clicks;
|
||||
}
|
||||
}
|
||||
}
|
||||
86
app/Traits/HasCovers.php
Normal file
86
app/Traits/HasCovers.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait HasCovers
|
||||
{
|
||||
/**
|
||||
* Notes : 获取封面图片字段(单图)
|
||||
*
|
||||
* @Date : 2021/3/16 4:34 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
public function getCoverField(): string
|
||||
{
|
||||
return $this->cover_field ?? 'cover';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 获取图片字段(多图)
|
||||
*
|
||||
* @Date : 2021/3/16 4:35 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
public function getPicturesField(): string
|
||||
{
|
||||
return $this->pictures_field ?? 'pictures';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 解析单图地址
|
||||
*
|
||||
* @Date : 2021/3/16 4:54 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
public function getCoverUrlAttribute(): string
|
||||
{
|
||||
$cover = $this->getAttribute($this->getCoverField());
|
||||
|
||||
return $this->parseImageUrl($cover);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 解析多图地址
|
||||
*
|
||||
* @Date : 2021/3/16 4:54 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return array
|
||||
*/
|
||||
public function getPicturesUrlAttribute(): array
|
||||
{
|
||||
$pictures = $this->getAttribute($this->getPicturesField());
|
||||
|
||||
if (empty($pictures)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($pictures)->map(function ($picture) {
|
||||
return $this->parseImageUrl($picture);
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 解析图片文件的实际展示地址
|
||||
*
|
||||
* @Date : 2021/3/16 4:53 下午
|
||||
* @Author : <Jason.C>
|
||||
* @param string|null $image
|
||||
* @return string
|
||||
*/
|
||||
protected function parseImageUrl(?string $image): string
|
||||
{
|
||||
if (empty($image)) {
|
||||
return '';
|
||||
} elseif (Str::startsWith($image, 'http')) {
|
||||
return $image;
|
||||
} else {
|
||||
return Storage::url($image);
|
||||
}
|
||||
}
|
||||
}
|
||||
91
app/Traits/HasStatus.php
Normal file
91
app/Traits/HasStatus.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
trait HasStatus
|
||||
{
|
||||
/**
|
||||
* Notes : 获取状态字段,主模型可配置 $status_field
|
||||
*
|
||||
* @Date : 2021/3/16 4:34 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
protected function getStatusField(): string
|
||||
{
|
||||
return $this->status_field ?? 'status';
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 获取各状态的名称
|
||||
*
|
||||
* @Date : 2021/5/27 11:50 上午
|
||||
* @Author : <Jason.C>
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getStatusMap(): array
|
||||
{
|
||||
return isset($this->status_map) && ! empty($this->status_map) ? $this->status_map : [
|
||||
0 => '待审核',
|
||||
1 => '正常',
|
||||
2 => '驳回',
|
||||
3 => '关闭',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 正常显示的数据
|
||||
*
|
||||
* @Author:<Mr.Wang>
|
||||
* @Date :2021-04-09
|
||||
* @param Builder $query
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeShown(Builder $query): Builder
|
||||
{
|
||||
return $query->where($this->getStatusField(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 不显示的数据
|
||||
*
|
||||
* @Author :<Mr.Wang>
|
||||
* @Date :2021-04-09
|
||||
* @param Builder $query
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeHidden(Builder $query): Builder
|
||||
{
|
||||
return $query->where($this->getStatusField(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 状态查询
|
||||
*
|
||||
* @Date : 2021/6/28 10:25 上午
|
||||
* @Author : <Jason.C>
|
||||
* @param Builder $query
|
||||
* @param int $status
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeOfStatus(Builder $query, int $status): Builder
|
||||
{
|
||||
return $query->where($this->getStatusField(), $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 获取状态的文本信息
|
||||
*
|
||||
* @Date : 2021/4/25 2:10 下午
|
||||
* @Author : <Jason.C>
|
||||
* @return string
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
$map = $this->getStatusMap();
|
||||
|
||||
return $map[$this->{$this->getStatusField()}] ?? '未知';
|
||||
}
|
||||
}
|
||||
48
app/Traits/Macroable.php
Normal file
48
app/Traits/Macroable.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait Macroable
|
||||
{
|
||||
use \Illuminate\Support\Traits\Macroable {
|
||||
__call as macroCall;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRelationValue($key)
|
||||
{
|
||||
$relation = parent::getRelationValue($key);
|
||||
if (! $relation && static::hasMacro($key)) {
|
||||
return $this->getRelationshipFromMethod($key);
|
||||
}
|
||||
|
||||
return $relation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (static::hasMacro($method)) {
|
||||
return $this->macroCall($method, $parameters);
|
||||
}
|
||||
|
||||
return parent::__call($method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return parent::__callStatic($method, $parameters);
|
||||
}
|
||||
}
|
||||
21
app/Traits/OrderByIdDesc.php
Normal file
21
app/Traits/OrderByIdDesc.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Scopes\OrderByIdDescScope;
|
||||
|
||||
trait OrderByIdDesc
|
||||
{
|
||||
/**
|
||||
* Notes: 初始化trait,自动在模型中,注入作用域
|
||||
* 需要对拥有排序的模型,不需要使用排序的时候
|
||||
* Model::withoutGlobalScope(new OrderByIdDescScope)
|
||||
*
|
||||
* @Author: <C.Jason>
|
||||
* @Date : 2020/1/19 1:42 下午
|
||||
*/
|
||||
public static function bootOrderByIdDesc(): void
|
||||
{
|
||||
static::addGlobalScope(new OrderByIdDescScope);
|
||||
}
|
||||
}
|
||||
22
app/Traits/OrderByOrderAsc.php
Normal file
22
app/Traits/OrderByOrderAsc.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Scopes\OrderByIdDescScope;
|
||||
use App\Scopes\OrderByOrderAscScope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
trait OrderByOrderAsc
|
||||
{
|
||||
/**
|
||||
* Notes: 初始化trait,自动在模型中,注入作用域
|
||||
* 取消排序参考 OrderByIdDesc
|
||||
*
|
||||
* @Author: <C.Jason>
|
||||
* @Date : 2020/1/19 1:42 下午
|
||||
*/
|
||||
public static function bootOrderByOrderAsc(): void
|
||||
{
|
||||
static::addGlobalScope(new OrderByOrderAscScope());
|
||||
}
|
||||
}
|
||||
24
app/Traits/WithGoogle2FA.php
Normal file
24
app/Traits/WithGoogle2FA.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\Google2FA;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
|
||||
trait WithGoogle2FA
|
||||
{
|
||||
public static function bootWithGoogle2FA()
|
||||
{
|
||||
self::created(function ($model) {
|
||||
$google2fa = app('pragmarx.google2fa');
|
||||
$model->google2fa()->create([
|
||||
'secret' => $google2fa->generateSecretKey(32),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function google2fa(): MorphOne
|
||||
{
|
||||
return $this->morphOne(Google2FA::class, 'subscriber');
|
||||
}
|
||||
}
|
||||
67
app/Traits/WithPosition.php
Normal file
67
app/Traits/WithPosition.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
trait WithPosition
|
||||
{
|
||||
/**
|
||||
* Notes : 获取定位的数组
|
||||
*
|
||||
* @Date : 2021/7/2 11:31 上午
|
||||
* @Author : <Jason.C>
|
||||
*/
|
||||
protected function getPositionMap(): array
|
||||
{
|
||||
return $this->position_map ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 定位查询作用域
|
||||
*
|
||||
* @Author: Mr.wang
|
||||
* @Date : 2021/5/11 10:48
|
||||
* @param Builder $query
|
||||
* @param int $pos
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeOfPosition(Builder $query, int $pos): Builder
|
||||
{
|
||||
return $query->whereRaw('position & '.$pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 设置定位
|
||||
*
|
||||
* @Author: Mr.wang
|
||||
* @Date : 2020/5/11 10:48
|
||||
* @param array $value
|
||||
*/
|
||||
protected function setPositionAttribute(array $value): void
|
||||
{
|
||||
if (! blank($value)) {
|
||||
$this->attributes['position'] = array_sum($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 获取定位数据
|
||||
*
|
||||
* @Author: Mr.wang
|
||||
* @Date : 2020/5/11 10:48
|
||||
* @param int $value
|
||||
* @return array
|
||||
*/
|
||||
protected function getPositionAttribute(int $value): array
|
||||
{
|
||||
$position = [];
|
||||
foreach ($this->getPositionMap() as $k => $v) {
|
||||
if ($k & $value) {
|
||||
$position[] = $k;
|
||||
}
|
||||
}
|
||||
|
||||
return $position;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user