From c5875602c18570578d07fb4bb0b317f057c98901 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Wed, 28 Dec 2022 00:25:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/Mqtt.php | 2 - app/Console/Commands/Status.php | 3 +- app/Console/Kernel.php | 2 +- app/Exceptions/Handler.php | 8 +- app/Helpers/ApiResponse.php | 107 ++++++++++-------- .../Controllers/Admin/AdminController.php | 20 ++-- .../Admin/ApplicationController.php | 45 ++++---- .../Controllers/Admin/DeviceController.php | 1 - app/Http/Controllers/Admin/HostController.php | 2 +- .../Controllers/Admin/ModuleController.php | 20 ++-- app/Http/Controllers/Admin/UserController.php | 2 +- .../Controllers/Admin/UserGroupController.php | 52 ++++----- app/Http/Controllers/Api/ModuleController.php | 2 +- app/Http/Controllers/Api/ReplyController.php | 2 +- .../Controllers/Api/WorkOrderController.php | 5 +- .../Application/ModuleController.php | 4 +- .../Application/MqttAuthController.php | 44 +++---- .../Controllers/Modules/ModuleController.php | 13 +-- .../Controllers/Modules/ReplyController.php | 1 - .../Controllers/Modules/TaskController.php | 1 - app/Http/Controllers/Web/AuthController.php | 1 - app/Http/Kernel.php | 81 ++++++++----- app/Http/Middleware/Authenticate.php | 3 +- app/Http/Middleware/JsonResponse.php | 8 +- .../Middleware/RedirectIfAuthenticated.php | 10 +- app/Http/Middleware/ValidateUserIfBanned.php | 8 +- .../User/WorkOrder/WorkOrderRequest.php | 1 - app/Jobs/CheckHostIfExistsOnModule.php | 3 +- app/Jobs/DeleteHost.php | 4 +- app/Jobs/Module/FetchModule.php | 5 +- app/Jobs/Module/Host.php | 1 - app/Jobs/Module/PushHost.php | 1 - app/Jobs/Module/PushWorkOrder.php | 1 - app/Jobs/Module/WorkOrder/Reply.php | 1 - app/Jobs/Module/WorkOrder/WorkOrder.php | 1 - app/Models/Admin.php | 27 +++-- app/Models/Host.php | 83 +++++++------- app/Models/Module.php | 104 ++++++++--------- app/Models/PersonalAccessToken.php | 90 ++++++++------- app/Models/Task.php | 70 ++++++------ app/Models/Transaction.php | 36 +++--- app/Models/User.php | 87 +++++++------- app/Models/WorkOrder/Reply.php | 80 ++++++------- app/Models/WorkOrder/WorkOrder.php | 97 ++++++++-------- app/Notifications/ModuleEarnings.php | 1 - app/Notifications/WeComChannel.php | 18 +-- app/Observers/BalanceObserve.php | 10 +- app/Observers/WorkOrder/ReplyObserver.php | 10 +- app/Observers/WorkOrder/WorkOrderObserver.php | 10 +- app/Providers/EventServiceProvider.php | 12 +- app/Support/EmqxSupport.php | 50 ++++---- app/View/Components/BasicCard.php | 5 +- app/View/Components/HostStatus.php | 5 +- app/View/Components/ModuleEarning.php | 5 +- app/View/Components/ModuleScript.php | 5 +- app/View/Components/Payment.php | 5 +- app/View/Components/WorkOrderStatus.php | 5 +- 57 files changed, 680 insertions(+), 600 deletions(-) diff --git a/app/Console/Commands/Mqtt.php b/app/Console/Commands/Mqtt.php index d30de0b..cc3988f 100644 --- a/app/Console/Commands/Mqtt.php +++ b/app/Console/Commands/Mqtt.php @@ -89,8 +89,6 @@ public function handle() } - - return Command::SUCCESS; // // 开启新的进程,处理 MQTT 消息 diff --git a/app/Console/Commands/Status.php b/app/Console/Commands/Status.php index 52c315f..c39fbc5 100644 --- a/app/Console/Commands/Status.php +++ b/app/Console/Commands/Status.php @@ -2,8 +2,8 @@ namespace App\Console\Commands; -use Illuminate\Support\Facades\DB; use Illuminate\Console\Command; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Redis; class Status extends Command @@ -50,7 +50,6 @@ public function handle() $mysql_version = DB::select('select version() as version')[0]->version; - $this->warn('MySQL 版本: ' . $mysql_version); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5d432f7..36e9d18 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -19,7 +19,7 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. * - * @param \Illuminate\Console\Scheduling\Schedule $schedule + * @param Schedule $schedule * * @return void */ diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7699d3d..83aacd6 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -15,7 +15,7 @@ class Handler extends ExceptionHandler /** * A list of exception types with their corresponding custom log levels. * - * @var array, \Psr\Log\LogLevel::*> + * @var array, \Psr\Log\LogLevel::*> */ protected $levels = [ // @@ -24,7 +24,7 @@ class Handler extends ExceptionHandler /** * A list of the exception types that are not reported. * - * @var array> + * @var array> */ protected $dontReport = [ // @@ -66,8 +66,8 @@ public function register(): void /** * Convert an authentication exception into an unauthenticated response. * - * @param Request $request - * @param AuthenticationException $exception + * @param Request $request + * @param AuthenticationException $exception * * @return JsonResponse|RedirectResponse */ diff --git a/app/Helpers/ApiResponse.php b/app/Helpers/ApiResponse.php index c765082..65668db 100644 --- a/app/Helpers/ApiResponse.php +++ b/app/Helpers/ApiResponse.php @@ -3,7 +3,6 @@ namespace App\Helpers; use Illuminate\Http\JsonResponse; -use Illuminate\Pagination\Paginator; trait ApiResponse { @@ -26,14 +25,9 @@ public function moduleResponse($response, int $status = 200): JsonResponse }; } - public function notFound($message = 'Not found'): JsonResponse + public function success($data = [], $status = 200): JsonResponse { - return $this->error($message, 404); - } - - public function error($message = '', $code = 400): JsonResponse - { - return $this->apiResponse($message, $code); + return $this->apiResponse($data, $status); } public function apiResponse($data = [], $status = 200): JsonResponse @@ -48,14 +42,14 @@ public function apiResponse($data = [], $status = 200): JsonResponse return response()->json($data, $status)->setEncodingOptions(JSON_UNESCAPED_UNICODE); } - public function forbidden($message = 'Forbidden'): JsonResponse + public function created($message = 'Created'): JsonResponse { - return $this->error($message, 403); + return $this->success($message, 201); } - public function unauthorized($message = 'Unauthorized'): JsonResponse + public function noContent($message = 'No content'): JsonResponse { - return $this->error($message, 401); + return $this->success($message, 204); } public function badRequest($message = 'Bad request'): JsonResponse @@ -63,82 +57,97 @@ public function badRequest($message = 'Bad request'): JsonResponse return $this->error($message); } + public function error($message = '', $code = 400): JsonResponse + { + return $this->apiResponse($message, $code); + } + // bad request - public function created($message = 'Created'): JsonResponse + public function serviceUnavailable($message = 'Service unavailable'): JsonResponse { - return $this->success($message, 201); + return $this->error($message, 503); } // created - public function success($data = [], $status = 200): JsonResponse + public function forbidden($message = 'Forbidden'): JsonResponse { - return $this->apiResponse($data, $status); + return $this->error($message, 403); } // accepted + public function notFound($message = 'Not found'): JsonResponse + { + return $this->error($message, 404); + } + + // no content + + public function methodNotAllowed($message = 'Method not allowed'): JsonResponse + { + return $this->error($message, 405); + } + + // updated + + public function tooManyRequests($message = 'Too many requests'): JsonResponse + { + return $this->error($message, 429); + } + + // deleted + + public function serverError($message = 'Server error'): JsonResponse + { + return $this->error($message, 500); + } + + // not allowed + + public function unauthorized($message = 'Unauthorized'): JsonResponse + { + return $this->error($message, 401); + } + + // conflict + public function accepted($message = 'Accepted'): JsonResponse { return $this->success($message, 202); } - // no content - public function noContent($message = 'No content'): JsonResponse - { - return $this->success($message, 204); - } + // too many requests - // updated public function updated($message = 'Updated'): JsonResponse { return $this->success($message, 200); } - // deleted + // server error + public function deleted($message = 'Deleted'): JsonResponse { return $this->success($message, 200); } - // not allowed + // service unavailable + public function notAllowed($message = 'Not allowed'): JsonResponse { return $this->error($message, 405); } - // conflict + // method not allowed + public function conflict($message = 'Conflict'): JsonResponse { return $this->error($message, 409); } - // too many requests - public function tooManyRequests($message = 'Too many requests'): JsonResponse - { - return $this->error($message, 429); - } - - // server error - public function serverError($message = 'Server error'): JsonResponse - { - return $this->error($message, 500); - } - - // service unavailable - public function serviceUnavailable($message = 'Service unavailable'): JsonResponse - { - return $this->error($message, 503); - } - - // method not allowed - public function methodNotAllowed($message = 'Method not allowed'): JsonResponse - { - return $this->error($message, 405); - } - // not acceptable + public function notAcceptable($message = 'Not acceptable'): JsonResponse { return $this->error($message, 406); diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index 6669f1b..20bd896 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -23,16 +23,6 @@ public function index(): View return view('admin.admins.index', compact('admins')); } - /** - * Show the form for creating a new resource. - * - * @return View - */ - public function create(): View - { - return view('admin.admins.create'); - } - /** * Store a newly created resource in storage. * @@ -59,6 +49,16 @@ public function store(Request $request): RedirectResponse return redirect()->route('admin.admins.edit', $admin)->with('success', '管理员创建成功,密码为:' . $password . '。'); } + /** + * Show the form for creating a new resource. + * + * @return View + */ + public function create(): View + { + return view('admin.admins.create'); + } + /** * Show the form for editing the specified resource. * diff --git a/app/Http/Controllers/Admin/ApplicationController.php b/app/Http/Controllers/Admin/ApplicationController.php index 0eaeb53..46f6734 100644 --- a/app/Http/Controllers/Admin/ApplicationController.php +++ b/app/Http/Controllers/Admin/ApplicationController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; use App\Models\Application; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; @@ -23,22 +24,11 @@ public function index() return view('admin.applications.index', compact('applications')); } - /** - * Show the form for creating a new resource. - * - * @return View - */ - public function create() - { - // - - return view('admin.applications.create'); - } - /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request + * @param Request $request + * * @return View */ public function store(Request $request) @@ -56,12 +46,24 @@ public function store(Request $request) return view('admin.applications.edit', compact('application')); } + /** + * Show the form for creating a new resource. + * + * @return View + */ + public function create() + { + // + + return view('admin.applications.create'); + } + /** * Display the specified resource. * - * @param \App\Models\Application $application + * @param Application $application * - * @return \Illuminate\Http\RedirectResponse + * @return RedirectResponse */ public function show(Application $application) { @@ -73,7 +75,8 @@ public function show(Application $application) /** * Show the form for editing the specified resource. * - * @param \App\Models\Application $application + * @param Application $application + * * @return View */ public function edit(Application $application) @@ -86,10 +89,10 @@ public function edit(Application $application) /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request - * @param \App\Models\Application $application + * @param Request $request + * @param Application $application * - * @return \Illuminate\Http\RedirectResponse + * @return RedirectResponse */ public function update(Request $request, Application $application) { @@ -109,9 +112,9 @@ public function update(Request $request, Application $application) /** * Remove the specified resource from storage. * - * @param \App\Models\Application $application + * @param Application $application * - * @return \Illuminate\Http\RedirectResponse + * @return RedirectResponse */ public function destroy(Application $application) { diff --git a/app/Http/Controllers/Admin/DeviceController.php b/app/Http/Controllers/Admin/DeviceController.php index 0f0fd4d..143a1d9 100644 --- a/app/Http/Controllers/Admin/DeviceController.php +++ b/app/Http/Controllers/Admin/DeviceController.php @@ -7,7 +7,6 @@ use App\Support\EmqxSupport; use Illuminate\Http\Client\ConnectionException; use Illuminate\Http\Request; -use Illuminate\Pagination\Paginator; class DeviceController extends Controller { diff --git a/app/Http/Controllers/Admin/HostController.php b/app/Http/Controllers/Admin/HostController.php index 6b60832..42f4ed7 100644 --- a/app/Http/Controllers/Admin/HostController.php +++ b/app/Http/Controllers/Admin/HostController.php @@ -29,7 +29,7 @@ public function index(Request $request): View } } - $hosts = $hosts->paginate(50)->withQueryString();; + $hosts = $hosts->paginate(50)->withQueryString(); return view('admin.hosts.index', compact('hosts')); } diff --git a/app/Http/Controllers/Admin/ModuleController.php b/app/Http/Controllers/Admin/ModuleController.php index 80a0045..d79a240 100644 --- a/app/Http/Controllers/Admin/ModuleController.php +++ b/app/Http/Controllers/Admin/ModuleController.php @@ -66,6 +66,16 @@ public function store(Request $request): RedirectResponse } + private function rules(): array + { + return [ + 'id' => 'required|string|max:255', + 'name' => 'required|string|max:255', + 'url' => 'required|url', + 'status' => 'required|string|in:up,down,maintenance', + ]; + } + /** * Display the specified resource. * @@ -148,16 +158,6 @@ public function destroy(Module $module): RedirectResponse return redirect()->route('admin.modules.index')->with('success', '模块已删除。'); } - private function rules(): array - { - return [ - 'id' => 'required|string|max:255', - 'name' => 'required|string|max:255', - 'url' => 'required|url', - 'status' => 'required|string|in:up,down,maintenance', - ]; - } - public function allows(Module $module) { $allows = ModuleAllow::where('module_id', $module->id)->with('allowed_module')->paginate(50); diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index beea64e..2fbbb74 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -38,7 +38,7 @@ public function index(Request $request): View $users = $users->where('email', 'like', '%' . $request->email . '%'); } - $users = $users->with('user_group')->paginate(50)->withQueryString();; + $users = $users->with('user_group')->paginate(50)->withQueryString(); return view('admin.users.index', compact('users')); } diff --git a/app/Http/Controllers/Admin/UserGroupController.php b/app/Http/Controllers/Admin/UserGroupController.php index 9ada3ef..edb2834 100644 --- a/app/Http/Controllers/Admin/UserGroupController.php +++ b/app/Http/Controllers/Admin/UserGroupController.php @@ -23,6 +23,32 @@ public function index() return view('admin.user-groups.index', compact('user_groups')); } + /** + * Store a newly created resource in storage. + * + * @param Request $request + * + * @return RedirectResponse + */ + public function store(Request $request) + { + $request->validate($this->rules()); + + $user_group = UserGroup::create($request->all()); + + return redirect()->route('admin.user-groups.edit', $user_group)->with('success', '用户组新建成功。'); + } + + private function rules(): array + { + return [ + 'name' => 'required|string', + 'color' => 'regex:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', + 'discount' => 'required|numeric|min:0|max:100', + 'exempt' => 'required|boolean', + ]; + } + /** * Show the form for creating a new resource. * @@ -35,22 +61,6 @@ public function create(): View return view('admin.user-groups.create'); } - /** - * Store a newly created resource in storage. - * - * @param \Illuminate\Http\Request $request - * - * @return \Illuminate\Http\RedirectResponse - */ - public function store(Request $request) - { - $request->validate($this->rules()); - - $user_group = UserGroup::create($request->all()); - - return redirect()->route('admin.user-groups.edit', $user_group)->with('success', '用户组新建成功。'); - } - /** * Display the specified resource. * @@ -110,14 +120,4 @@ public function destroy(UserGroup $user_group) return redirect()->route('admin.user-groups.index')->with('success', '用户组删除成功。'); } - - private function rules(): array - { - return [ - 'name' => 'required|string', - 'color' => 'regex:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', - 'discount' => 'required|numeric|min:0|max:100', - 'exempt' => 'required|boolean', - ]; - } } diff --git a/app/Http/Controllers/Api/ModuleController.php b/app/Http/Controllers/Api/ModuleController.php index 71f0fce..803be13 100644 --- a/app/Http/Controllers/Api/ModuleController.php +++ b/app/Http/Controllers/Api/ModuleController.php @@ -5,8 +5,8 @@ use App\Http\Controllers\Controller; use App\Models\Module; use Illuminate\Http\JsonResponse; -use Illuminate\Http\Response; use Illuminate\Http\Request; +use Illuminate\Http\Response; class ModuleController extends Controller { diff --git a/app/Http/Controllers/Api/ReplyController.php b/app/Http/Controllers/Api/ReplyController.php index 07bf4c8..322f6b0 100644 --- a/app/Http/Controllers/Api/ReplyController.php +++ b/app/Http/Controllers/Api/ReplyController.php @@ -15,7 +15,7 @@ class ReplyController extends Controller /** * Display a listing of the resource. * - * @return \Illuminate\Http\JsonResponse + * @return JsonResponse */ public function index(WorkOrder $workOrder) { diff --git a/app/Http/Controllers/Api/WorkOrderController.php b/app/Http/Controllers/Api/WorkOrderController.php index bfbdadf..58075c0 100644 --- a/app/Http/Controllers/Api/WorkOrderController.php +++ b/app/Http/Controllers/Api/WorkOrderController.php @@ -6,6 +6,7 @@ use App\Models\WorkOrder\WorkOrder; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Validation\ValidationException; use function auth; class WorkOrderController extends Controller @@ -18,7 +19,7 @@ public function index(WorkOrder $workOrder): JsonResponse } /** - * @throws \Illuminate\Validation\ValidationException + * @throws ValidationException */ public function store(Request $request) { @@ -56,7 +57,7 @@ public function show(WorkOrder $workOrder): JsonResponse } /** - * @throws \Illuminate\Validation\ValidationException + * @throws ValidationException */ public function update(Request $request, WorkOrder $workOrder) { diff --git a/app/Http/Controllers/Application/ModuleController.php b/app/Http/Controllers/Application/ModuleController.php index 5a84345..e0b12b9 100644 --- a/app/Http/Controllers/Application/ModuleController.php +++ b/app/Http/Controllers/Application/ModuleController.php @@ -4,7 +4,6 @@ use App\Http\Controllers\Controller; use App\Models\Module; -use Illuminate\Http\Request; class ModuleController extends Controller { @@ -17,7 +16,8 @@ class ModuleController extends Controller // } - public function show(Module $module) { + public function show(Module $module) + { return $this->success($module); diff --git a/app/Http/Controllers/Application/MqttAuthController.php b/app/Http/Controllers/Application/MqttAuthController.php index 4db0de3..6ccb03d 100644 --- a/app/Http/Controllers/Application/MqttAuthController.php +++ b/app/Http/Controllers/Application/MqttAuthController.php @@ -63,6 +63,28 @@ public function authentication(Request $request) } } + private function ignore() + { + return response([ + 'result' => 'ignore', + ], 200); + } + + private function allow() + { + return response([ + 'result' => 'allow', + 'is_superuser' => false, + ], 200); + } + + private function deny() + { + return response([ + 'result' => 'deny', + ], 200); + } + public function authorization(Request $request) { // 禁止订阅保留的 @@ -130,26 +152,4 @@ public function authorization(Request $request) return $this->deny(); } } - - private function deny() - { - return response([ - 'result' => 'deny', - ], 200); - } - - private function ignore() - { - return response([ - 'result' => 'ignore', - ], 200); - } - - private function allow() - { - return response([ - 'result' => 'allow', - 'is_superuser' => false, - ], 200); - } } diff --git a/app/Http/Controllers/Modules/ModuleController.php b/app/Http/Controllers/Modules/ModuleController.php index 0dc76b4..124d995 100644 --- a/app/Http/Controllers/Modules/ModuleController.php +++ b/app/Http/Controllers/Modules/ModuleController.php @@ -7,7 +7,6 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Http\Response; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; class ModuleController extends Controller @@ -33,6 +32,12 @@ public function call(Request $request, Module $module) return $this->moduleResponse($response['json'], $response['status']); } + private function fixPath(Request $request, Module $module, $prefix): string + { + $path = substr($request->path(), strlen("/{$prefix}/modules/{$module->id}")); + return preg_replace('/[^a-zA-Z0-9\/]/', '', $path); + } + public function exportCall(Request $request, Module $module): Response|JsonResponse { $path = $this->fixPath($request, $module, 'modules'); @@ -46,10 +51,4 @@ public function exportCall(Request $request, Module $module): Response|JsonRespo return $this->moduleResponse($response['json'], $response['status']); } - - private function fixPath(Request $request, Module $module, $prefix): string - { - $path = substr($request->path(), strlen("/{$prefix}/modules/{$module->id}")); - return preg_replace('/[^a-zA-Z0-9\/]/', '', $path); - } } diff --git a/app/Http/Controllers/Modules/ReplyController.php b/app/Http/Controllers/Modules/ReplyController.php index 3a8dbbf..7993206 100644 --- a/app/Http/Controllers/Modules/ReplyController.php +++ b/app/Http/Controllers/Modules/ReplyController.php @@ -7,7 +7,6 @@ use App\Models\WorkOrder\WorkOrder; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Log; class ReplyController extends Controller { diff --git a/app/Http/Controllers/Modules/TaskController.php b/app/Http/Controllers/Modules/TaskController.php index 90e9c08..c1dfff8 100644 --- a/app/Http/Controllers/Modules/TaskController.php +++ b/app/Http/Controllers/Modules/TaskController.php @@ -6,7 +6,6 @@ use App\Models\Task; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Http\Response; use Illuminate\Validation\ValidationException; class TaskController extends Controller diff --git a/app/Http/Controllers/Web/AuthController.php b/app/Http/Controllers/Web/AuthController.php index ae19726..671c73f 100644 --- a/app/Http/Controllers/Web/AuthController.php +++ b/app/Http/Controllers/Web/AuthController.php @@ -13,7 +13,6 @@ use Illuminate\Support\Str; use function back; use function config; -use function now; use function redirect; use function session; use function view; diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index faaa61e..4d28028 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -2,7 +2,32 @@ namespace App\Http; +use App\Http\Middleware\Admin\ValidateReferer; +use App\Http\Middleware\Authenticate; +use App\Http\Middleware\EncryptCookies; +use App\Http\Middleware\JsonResponse; +use App\Http\Middleware\PreventRequestsDuringMaintenance; +use App\Http\Middleware\RedirectIfAuthenticated; +use App\Http\Middleware\TrimStrings; +use App\Http\Middleware\TrustProxies; +use App\Http\Middleware\ValidateSignature; +use App\Http\Middleware\ValidateUserIfBanned; +use App\Http\Middleware\VerifyCsrfToken; +use Fruitcake\Cors\HandleCors; +use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth; +use Illuminate\Auth\Middleware\Authorize; +use Illuminate\Auth\Middleware\EnsureEmailIsVerified; +use Illuminate\Auth\Middleware\RequirePassword; +use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; use Illuminate\Foundation\Http\Kernel as HttpKernel; +use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull; +use Illuminate\Foundation\Http\Middleware\ValidatePostSize; +use Illuminate\Http\Middleware\SetCacheHeaders; +use Illuminate\Routing\Middleware\SubstituteBindings; +use Illuminate\Routing\Middleware\ThrottleRequests; +use Illuminate\Session\Middleware\AuthenticateSession; +use Illuminate\Session\Middleware\StartSession; +use Illuminate\View\Middleware\ShareErrorsFromSession; class Kernel extends HttpKernel { @@ -15,13 +40,13 @@ class Kernel extends HttpKernel */ protected $middleware = [ // \App\Http\Middleware\TrustHosts::class, - \App\Http\Middleware\TrustProxies::class, + TrustProxies::class, // \Illuminate\Http\Middleware\HandleCors::class, - \App\Http\Middleware\PreventRequestsDuringMaintenance::class, - \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, - \App\Http\Middleware\TrimStrings::class, - \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, - \Fruitcake\Cors\HandleCors::class, + PreventRequestsDuringMaintenance::class, + ValidatePostSize::class, + TrimStrings::class, + ConvertEmptyStringsToNull::class, + HandleCors::class, ]; /** @@ -31,24 +56,24 @@ class Kernel extends HttpKernel */ protected $middlewareGroups = [ 'web' => [ - \App\Http\Middleware\EncryptCookies::class, - \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, - \Illuminate\Session\Middleware\StartSession::class, - \Illuminate\View\Middleware\ShareErrorsFromSession::class, - \App\Http\Middleware\VerifyCsrfToken::class, - \Illuminate\Routing\Middleware\SubstituteBindings::class, + EncryptCookies::class, + AddQueuedCookiesToResponse::class, + StartSession::class, + ShareErrorsFromSession::class, + VerifyCsrfToken::class, + SubstituteBindings::class, ], 'api' => [ - \App\Http\Middleware\JsonResponse::class, + JsonResponse::class, // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, 'throttle:api', - \Illuminate\Routing\Middleware\SubstituteBindings::class, + SubstituteBindings::class, ], 'module' => [ - \App\Http\Middleware\JsonResponse::class, - \Illuminate\Routing\Middleware\SubstituteBindings::class, + JsonResponse::class, + SubstituteBindings::class, ], ]; @@ -60,17 +85,17 @@ class Kernel extends HttpKernel * @var array */ protected $routeMiddleware = [ - 'auth' => \App\Http\Middleware\Authenticate::class, - 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, - 'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::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' => \App\Http\Middleware\ValidateSignature::class, - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, - 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, - 'banned' => \App\Http\Middleware\ValidateUserIfBanned::class, - 'admin.validateReferer' => \App\Http\Middleware\Admin\ValidateReferer::class, + 'auth' => Authenticate::class, + 'auth.basic' => AuthenticateWithBasicAuth::class, + 'auth.session' => AuthenticateSession::class, + 'cache.headers' => SetCacheHeaders::class, + 'can' => Authorize::class, + 'guest' => RedirectIfAuthenticated::class, + 'password.confirm' => RequirePassword::class, + 'signed' => ValidateSignature::class, + 'throttle' => ThrottleRequests::class, + 'verified' => EnsureEmailIsVerified::class, + 'banned' => ValidateUserIfBanned::class, + 'admin.validateReferer' => ValidateReferer::class, ]; } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 54222f1..063a8b4 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -3,13 +3,14 @@ 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 \Illuminate\Http\Request $request + * @param Request $request * * @return string|null */ diff --git a/app/Http/Middleware/JsonResponse.php b/app/Http/Middleware/JsonResponse.php index 3d91c48..bafd5c3 100644 --- a/app/Http/Middleware/JsonResponse.php +++ b/app/Http/Middleware/JsonResponse.php @@ -3,17 +3,19 @@ namespace App\Http\Middleware; use Closure; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; class JsonResponse { /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next + * @param Request $request + * @param Closure(Request): (Response|RedirectResponse) $next * - * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse + * @return Response|RedirectResponse */ public function handle(Request $request, Closure $next) { diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index e42eb4a..75f59b2 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -4,7 +4,9 @@ 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 @@ -12,11 +14,11 @@ class RedirectIfAuthenticated /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next - * @param string|null ...$guards + * @param Request $request + * @param Closure(Request): (Response|RedirectResponse) $next + * @param string|null ...$guards * - * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse + * @return Response|RedirectResponse */ public function handle(Request $request, Closure $next, ...$guards) { diff --git a/app/Http/Middleware/ValidateUserIfBanned.php b/app/Http/Middleware/ValidateUserIfBanned.php index ffce2c2..6c3939e 100644 --- a/app/Http/Middleware/ValidateUserIfBanned.php +++ b/app/Http/Middleware/ValidateUserIfBanned.php @@ -3,17 +3,19 @@ namespace App\Http\Middleware; use Closure; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; class ValidateUserIfBanned { /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next + * @param Request $request + * @param Closure(Request): (Response|RedirectResponse) $next * - * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse + * @return Response|RedirectResponse */ public function handle(Request $request, Closure $next) { diff --git a/app/Http/Requests/User/WorkOrder/WorkOrderRequest.php b/app/Http/Requests/User/WorkOrder/WorkOrderRequest.php index ad312e5..1224701 100644 --- a/app/Http/Requests/User/WorkOrder/WorkOrderRequest.php +++ b/app/Http/Requests/User/WorkOrder/WorkOrderRequest.php @@ -2,7 +2,6 @@ namespace App\Http\Requests\User\WorkOrder; -use App\Models\WorkOrder\WorkOrder; use Illuminate\Foundation\Http\FormRequest; class WorkOrderRequest extends FormRequest diff --git a/app/Jobs/CheckHostIfExistsOnModule.php b/app/Jobs/CheckHostIfExistsOnModule.php index 1bea4ac..11c82a9 100644 --- a/app/Jobs/CheckHostIfExistsOnModule.php +++ b/app/Jobs/CheckHostIfExistsOnModule.php @@ -8,7 +8,6 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; class CheckHostIfExistsOnModule implements ShouldQueue @@ -45,7 +44,7 @@ public function handle(): void if ($response->status() === 404) { Log::warning($host->module->name . ' ' . $host->name . ' ' . $host->id . ' 不存在,删除。'); - dispatch(new \App\Jobs\Module\Host($host, 'delete')); + dispatch(new Module\Host($host, 'delete')); } } }); diff --git a/app/Jobs/DeleteHost.php b/app/Jobs/DeleteHost.php index 9b5a5f7..5b85e89 100644 --- a/app/Jobs/DeleteHost.php +++ b/app/Jobs/DeleteHost.php @@ -34,14 +34,14 @@ public function handle(): void // 查找暂停时间超过 3 天的 host Host::where('status', 'suspended')->where('suspended_at', '<', now()->subDays(3))->chunk(100, function ($hosts) { foreach ($hosts as $host) { - dispatch(new \App\Jobs\Module\Host($host, 'delete')); + dispatch(new Module\Host($host, 'delete')); } }); // 查找部署时间超过3天以上的 host Host::where('status', 'pending')->where('created_at', '<', now()->subDays(3))->chunk(100, function ($hosts) { foreach ($hosts as $host) { - dispatch(new \App\Jobs\Module\Host($host, 'delete')); + dispatch(new Module\Host($host, 'delete')); } }); } diff --git a/app/Jobs/Module/FetchModule.php b/app/Jobs/Module/FetchModule.php index 210ff2d..a67c861 100644 --- a/app/Jobs/Module/FetchModule.php +++ b/app/Jobs/Module/FetchModule.php @@ -4,13 +4,12 @@ use App\Events\ServerEvent; use App\Models\Module; -use GuzzleHttp\Exception\ConnectException; +use Exception; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; class FetchModule implements ShouldQueue @@ -51,7 +50,7 @@ public function handle() foreach ($modules as $module) { try { $response = $module->http()->get('remote'); - } catch (\Exception $e) { + } catch (Exception $e) { Log::error($e->getMessage()); continue; } diff --git a/app/Jobs/Module/Host.php b/app/Jobs/Module/Host.php index 8f006a7..e95e1e7 100644 --- a/app/Jobs/Module/Host.php +++ b/app/Jobs/Module/Host.php @@ -7,7 +7,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Http; // use Illuminate\Contracts\Queue\ShouldBeUnique; diff --git a/app/Jobs/Module/PushHost.php b/app/Jobs/Module/PushHost.php index 918f51c..588e03f 100644 --- a/app/Jobs/Module/PushHost.php +++ b/app/Jobs/Module/PushHost.php @@ -7,7 +7,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Http; // use Illuminate\Contracts\Queue\ShouldBeUnique; diff --git a/app/Jobs/Module/PushWorkOrder.php b/app/Jobs/Module/PushWorkOrder.php index 9eee570..e530509 100644 --- a/app/Jobs/Module/PushWorkOrder.php +++ b/app/Jobs/Module/PushWorkOrder.php @@ -8,7 +8,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; // use Illuminate\Contracts\Queue\ShouldBeUnique; diff --git a/app/Jobs/Module/WorkOrder/Reply.php b/app/Jobs/Module/WorkOrder/Reply.php index 936be09..a4cc31d 100644 --- a/app/Jobs/Module/WorkOrder/Reply.php +++ b/app/Jobs/Module/WorkOrder/Reply.php @@ -8,7 +8,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Http; // use Illuminate\Contracts\Queue\ShouldBeUnique; diff --git a/app/Jobs/Module/WorkOrder/WorkOrder.php b/app/Jobs/Module/WorkOrder/WorkOrder.php index d91f878..a4627c4 100644 --- a/app/Jobs/Module/WorkOrder/WorkOrder.php +++ b/app/Jobs/Module/WorkOrder/WorkOrder.php @@ -8,7 +8,6 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Http; // use Illuminate\Contracts\Queue\ShouldBeUnique; diff --git a/app/Models/Admin.php b/app/Models/Admin.php index 19ac875..686f4f3 100644 --- a/app/Models/Admin.php +++ b/app/Models/Admin.php @@ -2,9 +2,12 @@ namespace App\Models; +use Eloquent; use GeneaLabs\LaravelModelCaching\Traits\Cachable; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Support\Carbon; /** * App\Models\Admin @@ -13,18 +16,18 @@ * @property string $email * @property string $password * @property string|null $remember_token - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @method static \Illuminate\Database\Eloquent\Builder|Admin newModelQuery() - * @method static \Illuminate\Database\Eloquent\Builder|Admin newQuery() - * @method static \Illuminate\Database\Eloquent\Builder|Admin query() - * @method static \Illuminate\Database\Eloquent\Builder|Admin whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|Admin whereEmail($value) - * @method static \Illuminate\Database\Eloquent\Builder|Admin whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|Admin wherePassword($value) - * @method static \Illuminate\Database\Eloquent\Builder|Admin whereRememberToken($value) - * @method static \Illuminate\Database\Eloquent\Builder|Admin whereUpdatedAt($value) - * @mixin \Eloquent + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @method static Builder|Admin newModelQuery() + * @method static Builder|Admin newQuery() + * @method static Builder|Admin query() + * @method static Builder|Admin whereCreatedAt($value) + * @method static Builder|Admin whereEmail($value) + * @method static Builder|Admin whereId($value) + * @method static Builder|Admin wherePassword($value) + * @method static Builder|Admin whereRememberToken($value) + * @method static Builder|Admin whereUpdatedAt($value) + * @mixin Eloquent */ class Admin extends Authenticatable { diff --git a/app/Models/Host.php b/app/Models/Host.php index 5da99b7..49928d1 100644 --- a/app/Models/Host.php +++ b/app/Models/Host.php @@ -4,11 +4,12 @@ use App\Events\UserEvent; use App\Models\WorkOrder\WorkOrder; +use GeneaLabs\LaravelModelCaching\CachedBuilder; use GeneaLabs\LaravelModelCaching\Traits\Cachable; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToAlias; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; /** @@ -23,51 +24,51 @@ * @property mixed|null $configuration * @property string $status * @property int|null $hour - * @property \Illuminate\Support\Carbon|null $suspended_at + * @property Carbon|null $suspended_at * @property string|null $deleted_at - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property-read \App\Models\Module $module - * @property-read \App\Models\User $user + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Module $module + * @property-read User $user * @property-read Collection|WorkOrder[] $workOrders * @property-read int|null $work_orders_count - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host active() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host all($columns = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host avg($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host cache(array $tags = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host cachedValue(array $arguments, string $cacheKey) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host count($columns = '*') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host disableCache() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host disableModelCaching() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host exists() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host flushCache(array $tags = []) + * @method static CachedBuilder|Host active() + * @method static CachedBuilder|Host all($columns = []) + * @method static CachedBuilder|Host avg($column) + * @method static CachedBuilder|Host cache(array $tags = []) + * @method static CachedBuilder|Host cachedValue(array $arguments, string $cacheKey) + * @method static CachedBuilder|Host count($columns = '*') + * @method static CachedBuilder|Host disableCache() + * @method static CachedBuilder|Host disableModelCaching() + * @method static CachedBuilder|Host exists() + * @method static CachedBuilder|Host flushCache(array $tags = []) * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host * getModelCacheCooldown(\Illuminate\Database\Eloquent\Model $instance) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host inRandomOrder($seed = '') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host insert(array $values) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host isCachable() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host max($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host min($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host newModelQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host newQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host query() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host sum($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host thisUser($module = null) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host truncate() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereConfiguration($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereCreatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereDeletedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereHour($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereManagedPrice($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereModuleId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereName($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host wherePrice($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereStatus($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereSuspendedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereUpdatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host whereUserId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Host withCacheCooldownSeconds(?int $seconds = null) + * @method static CachedBuilder|Host inRandomOrder($seed = '') + * @method static CachedBuilder|Host insert(array $values) + * @method static CachedBuilder|Host isCachable() + * @method static CachedBuilder|Host max($column) + * @method static CachedBuilder|Host min($column) + * @method static CachedBuilder|Host newModelQuery() + * @method static CachedBuilder|Host newQuery() + * @method static CachedBuilder|Host query() + * @method static CachedBuilder|Host sum($column) + * @method static CachedBuilder|Host thisUser($module = null) + * @method static CachedBuilder|Host truncate() + * @method static CachedBuilder|Host whereConfiguration($value) + * @method static CachedBuilder|Host whereCreatedAt($value) + * @method static CachedBuilder|Host whereDeletedAt($value) + * @method static CachedBuilder|Host whereHour($value) + * @method static CachedBuilder|Host whereId($value) + * @method static CachedBuilder|Host whereManagedPrice($value) + * @method static CachedBuilder|Host whereModuleId($value) + * @method static CachedBuilder|Host whereName($value) + * @method static CachedBuilder|Host wherePrice($value) + * @method static CachedBuilder|Host whereStatus($value) + * @method static CachedBuilder|Host whereSuspendedAt($value) + * @method static CachedBuilder|Host whereUpdatedAt($value) + * @method static CachedBuilder|Host whereUserId($value) + * @method static CachedBuilder|Host withCacheCooldownSeconds(?int $seconds = null) */ class Host extends Model { diff --git a/app/Models/Module.php b/app/Models/Module.php index 252aabc..a5ea63e 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -2,6 +2,8 @@ namespace App\Models; +use Eloquent; +use GeneaLabs\LaravelModelCaching\CachedBuilder; use GeneaLabs\LaravelModelCaching\Traits\Cachable; use GuzzleHttp\Exception\ConnectException; use Illuminate\Foundation\Auth\User as Authenticatable; @@ -21,34 +23,34 @@ * @property string|null $api_token * @property string|null $url * @property string|null $wecom_key 企业微信机器人 key - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module all($columns = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module avg($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module cache(array $tags = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module cachedValue(array $arguments, string $cacheKey) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module count($columns = '*') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module disableCache() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module disableModelCaching() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module exists() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module flushCache(array $tags = []) + * @method static CachedBuilder|Module all($columns = []) + * @method static CachedBuilder|Module avg($column) + * @method static CachedBuilder|Module cache(array $tags = []) + * @method static CachedBuilder|Module cachedValue(array $arguments, string $cacheKey) + * @method static CachedBuilder|Module count($columns = '*') + * @method static CachedBuilder|Module disableCache() + * @method static CachedBuilder|Module disableModelCaching() + * @method static CachedBuilder|Module exists() + * @method static CachedBuilder|Module flushCache(array $tags = []) * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module * getModelCacheCooldown(\Illuminate\Database\Eloquent\Model $instance) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module inRandomOrder($seed = '') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module insert(array $values) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module isCachable() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module max($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module min($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module newModelQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module newQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module query() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module sum($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module truncate() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module whereApiToken($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module whereId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module whereName($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module whereUrl($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module whereWecomKey($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Module withCacheCooldownSeconds(?int $seconds = null) - * @mixin \Eloquent + * @method static CachedBuilder|Module inRandomOrder($seed = '') + * @method static CachedBuilder|Module insert(array $values) + * @method static CachedBuilder|Module isCachable() + * @method static CachedBuilder|Module max($column) + * @method static CachedBuilder|Module min($column) + * @method static CachedBuilder|Module newModelQuery() + * @method static CachedBuilder|Module newQuery() + * @method static CachedBuilder|Module query() + * @method static CachedBuilder|Module sum($column) + * @method static CachedBuilder|Module truncate() + * @method static CachedBuilder|Module whereApiToken($value) + * @method static CachedBuilder|Module whereId($value) + * @method static CachedBuilder|Module whereName($value) + * @method static CachedBuilder|Module whereUrl($value) + * @method static CachedBuilder|Module whereWecomKey($value) + * @method static CachedBuilder|Module withCacheCooldownSeconds(?int $seconds = null) + * @mixin Eloquent */ class Module extends Authenticatable { @@ -100,6 +102,31 @@ public function remote($func, $requests): array return $this->getResponse($response); } + public function http(): PendingRequest + { + return Http::module($this->api_token, $this->url)->acceptJson()->timeout(5); + } + + private function getResponse(Response $response): array + { + $json = $response->json(); + $status = $response->status(); + + $success = true; + + // if status code is not 20x + if ($status < 200 || $status >= 300) { + $success = false; + } + + return [ + 'body' => $response->body(), + 'json' => $json, + 'status' => $status, + 'success' => $success, + ]; + } + public function request($method, $path, $requests): array { return $this->baseRequest($method, "functions/{$path}", $requests); @@ -140,26 +167,6 @@ public function moduleRequest($method, $path, $requests): array return $this->getResponse($response); } - private function getResponse(Response $response): array - { - $json = $response->json(); - $status = $response->status(); - - $success = true; - - // if status code is not 20x - if ($status < 200 || $status >= 300) { - $success = false; - } - - return [ - 'body' => $response->body(), - 'json' => $json, - 'status' => $status, - 'success' => $success, - ]; - } - public function check($module_id = null): bool { if ($module_id) { @@ -183,11 +190,6 @@ public function check($module_id = null): bool return $success; } - public function http(): PendingRequest - { - return Http::module($this->api_token, $this->url)->acceptJson()->timeout(5); - } - #[ArrayShape(['transactions' => "array"])] public function calculate(): array { diff --git a/app/Models/PersonalAccessToken.php b/app/Models/PersonalAccessToken.php index 8408629..979b63b 100644 --- a/app/Models/PersonalAccessToken.php +++ b/app/Models/PersonalAccessToken.php @@ -2,56 +2,62 @@ namespace App\Models; +use Eloquent; +use GeneaLabs\LaravelModelCaching\CachedBuilder; use GeneaLabs\LaravelModelCaching\Traits\Cachable; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Carbon; use Laravel\Sanctum\PersonalAccessToken as SanctumPersonalAccessToken; /** * App\Models\PersonalAccessToken * - * @property int $id - * @property string $tokenable_type - * @property int $tokenable_id - * @property string $name - * @property string $token - * @property array|null $abilities - * @property \Illuminate\Support\Carbon|null $last_used_at - * @property \Illuminate\Support\Carbon|null $expires_at - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $tokenable - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken all($columns = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken avg($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken cache(array $tags = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken cachedValue(array $arguments, string $cacheKey) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken count($columns = '*') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken disableCache() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken disableModelCaching() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken exists() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken flushCache(array $tags = []) + * @property int $id + * @property string $tokenable_type + * @property int $tokenable_id + * @property string $name + * @property string $token + * @property array|null $abilities + * @property Carbon|null $last_used_at + * @property Carbon|null $expires_at + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Model|Eloquent $tokenable + * @method static CachedBuilder|PersonalAccessToken all($columns = []) + * @method static CachedBuilder|PersonalAccessToken avg($column) + * @method static CachedBuilder|PersonalAccessToken cache(array $tags = []) + * @method static CachedBuilder|PersonalAccessToken cachedValue(array $arguments, string + * $cacheKey) + * @method static CachedBuilder|PersonalAccessToken count($columns = '*') + * @method static CachedBuilder|PersonalAccessToken disableCache() + * @method static CachedBuilder|PersonalAccessToken disableModelCaching() + * @method static CachedBuilder|PersonalAccessToken exists() + * @method static CachedBuilder|PersonalAccessToken flushCache(array $tags = []) * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken * getModelCacheCooldown(\Illuminate\Database\Eloquent\Model $instance) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken inRandomOrder($seed = '') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken insert(array $values) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken isCachable() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken max($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken min($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken newModelQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken newQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken query() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken sum($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken truncate() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereAbilities($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereCreatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereExpiresAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereLastUsedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereName($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereToken($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereTokenableId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereTokenableType($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken whereUpdatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|PersonalAccessToken withCacheCooldownSeconds(?int $seconds = null) - * @mixin \Eloquent + * @method static CachedBuilder|PersonalAccessToken inRandomOrder($seed = '') + * @method static CachedBuilder|PersonalAccessToken insert(array $values) + * @method static CachedBuilder|PersonalAccessToken isCachable() + * @method static CachedBuilder|PersonalAccessToken max($column) + * @method static CachedBuilder|PersonalAccessToken min($column) + * @method static CachedBuilder|PersonalAccessToken newModelQuery() + * @method static CachedBuilder|PersonalAccessToken newQuery() + * @method static CachedBuilder|PersonalAccessToken query() + * @method static CachedBuilder|PersonalAccessToken sum($column) + * @method static CachedBuilder|PersonalAccessToken truncate() + * @method static CachedBuilder|PersonalAccessToken whereAbilities($value) + * @method static CachedBuilder|PersonalAccessToken whereCreatedAt($value) + * @method static CachedBuilder|PersonalAccessToken whereExpiresAt($value) + * @method static CachedBuilder|PersonalAccessToken whereId($value) + * @method static CachedBuilder|PersonalAccessToken whereLastUsedAt($value) + * @method static CachedBuilder|PersonalAccessToken whereName($value) + * @method static CachedBuilder|PersonalAccessToken whereToken($value) + * @method static CachedBuilder|PersonalAccessToken whereTokenableId($value) + * @method static CachedBuilder|PersonalAccessToken whereTokenableType($value) + * @method static CachedBuilder|PersonalAccessToken whereUpdatedAt($value) + * @method static CachedBuilder|PersonalAccessToken withCacheCooldownSeconds(?int + * $seconds = null) + * @mixin Eloquent */ class PersonalAccessToken extends SanctumPersonalAccessToken { diff --git a/app/Models/Task.php b/app/Models/Task.php index c9c3bdb..1b1be0d 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -4,10 +4,12 @@ use App\Events\UserEvent; use App\Exceptions\CommonException; -use GeneaLabs\LaravelModelCaching\Traits\Cachable; +use Eloquent; +use GeneaLabs\LaravelModelCaching\CachedBuilder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Cache; use Ramsey\Uuid\Uuid; use function auth; @@ -22,41 +24,41 @@ * @property string $status * @property int $user_id * @property int $host_id - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property-read \App\Models\Host $host - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task all($columns = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task avg($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task cache(array $tags = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task cachedValue(array $arguments, string $cacheKey) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task count($columns = '*') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task disableCache() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task disableModelCaching() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task exists() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task flushCache(array $tags = []) + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Host $host + * @method static CachedBuilder|Task all($columns = []) + * @method static CachedBuilder|Task avg($column) + * @method static CachedBuilder|Task cache(array $tags = []) + * @method static CachedBuilder|Task cachedValue(array $arguments, string $cacheKey) + * @method static CachedBuilder|Task count($columns = '*') + * @method static CachedBuilder|Task disableCache() + * @method static CachedBuilder|Task disableModelCaching() + * @method static CachedBuilder|Task exists() + * @method static CachedBuilder|Task flushCache(array $tags = []) * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task * getModelCacheCooldown(\Illuminate\Database\Eloquent\Model $instance) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task inRandomOrder($seed = '') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task insert(array $values) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task isCachable() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task max($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task min($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task newModelQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task newQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task query() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task sum($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task truncate() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task user() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task whereCreatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task whereHostId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task whereId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task whereProgress($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task whereStatus($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task whereTitle($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task whereUpdatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task whereUserId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Task withCacheCooldownSeconds(?int $seconds = null) - * @mixin \Eloquent + * @method static CachedBuilder|Task inRandomOrder($seed = '') + * @method static CachedBuilder|Task insert(array $values) + * @method static CachedBuilder|Task isCachable() + * @method static CachedBuilder|Task max($column) + * @method static CachedBuilder|Task min($column) + * @method static CachedBuilder|Task newModelQuery() + * @method static CachedBuilder|Task newQuery() + * @method static CachedBuilder|Task query() + * @method static CachedBuilder|Task sum($column) + * @method static CachedBuilder|Task truncate() + * @method static CachedBuilder|Task user() + * @method static CachedBuilder|Task whereCreatedAt($value) + * @method static CachedBuilder|Task whereHostId($value) + * @method static CachedBuilder|Task whereId($value) + * @method static CachedBuilder|Task whereProgress($value) + * @method static CachedBuilder|Task whereStatus($value) + * @method static CachedBuilder|Task whereTitle($value) + * @method static CachedBuilder|Task whereUpdatedAt($value) + * @method static CachedBuilder|Task whereUserId($value) + * @method static CachedBuilder|Task withCacheCooldownSeconds(?int $seconds = null) + * @mixin Eloquent */ class Task extends Model { diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index cbfcfa5..074a44a 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -60,24 +60,6 @@ public function scopeThisUser($query) return $query->where('user_id', auth()->id()); } - private function addLog($user_id, $data) - { - $user = User::find($user_id); - - $current = [ - 'balance' => (float)$user->balance, - 'user_id' => intval($user_id), - ]; - - // merge - $data = array_merge($data, $current); - - // add expired at - $data['expired_at'] = now()->addSeconds(7); - - return $this->create($data); - } - public function reduceAmount($user_id, $amount = 0, $description = '扣除费用请求。') { @@ -116,6 +98,24 @@ public function addPayoutBalance($user_id, $amount, $description, $module_id = n return $this->addLog($user_id, $data); } + private function addLog($user_id, $data) + { + $user = User::find($user_id); + + $current = [ + 'balance' => (float)$user->balance, + 'user_id' => intval($user_id), + ]; + + // merge + $data = array_merge($data, $current); + + // add expired at + $data['expired_at'] = now()->addSeconds(7); + + return $this->create($data); + } + public function reduceAmountModuleFail($user_id, $module_id, $amount = 0, $description = '扣除费用请求。') { diff --git a/app/Models/User.php b/app/Models/User.php index 64cd3e6..a6af21f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -5,12 +5,19 @@ // use Illuminate\Contracts\Auth\MustVerifyEmail; use App\Exceptions\CommonException; use App\Exceptions\User\BalanceNotEnoughException; +use Database\Factories\UserFactory; +use Eloquent; +use GeneaLabs\LaravelModelCaching\CachedBuilder; use GeneaLabs\LaravelModelCaching\Traits\Cachable; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\DatabaseNotification; +use Illuminate\Notifications\DatabaseNotificationCollection; use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Carbon; use Laravel\Sanctum\HasApiTokens; /** @@ -22,69 +29,69 @@ * $name * @property string * $email - * @property \Illuminate\Support\Carbon|null + * @property Carbon|null * $email_verified_at * @property string|null * $password * @property float * $balance - * @property \Illuminate\Support\Carbon|null + * @property Carbon|null * $banned_at 封禁时间 * @property string|null * $banned_reason * @property string|null * $remember_token - * @property \Illuminate\Support\Carbon|null + * @property Carbon|null * $created_at - * @property \Illuminate\Support\Carbon|null + * @property Carbon|null * $updated_at - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Host[] + * @property-read Collection|Host[] * $hosts * @property-read int|null * $hosts_count - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] + * @property-read DatabaseNotificationCollection|DatabaseNotification[] * $notifications * @property-read int|null * $notifications_count - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\PersonalAccessToken[] + * @property-read Collection|PersonalAccessToken[] * $tokens * @property-read int|null * $tokens_count - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User all($columns = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User avg($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User cache(array $tags = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User cachedValue(array $arguments, string $cacheKey) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User count($columns = '*') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User disableCache() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User disableModelCaching() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User exists() - * @method static \Database\Factories\UserFactory factory(...$parameters) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User flushCache(array $tags = []) + * @method static CachedBuilder|User all($columns = []) + * @method static CachedBuilder|User avg($column) + * @method static CachedBuilder|User cache(array $tags = []) + * @method static CachedBuilder|User cachedValue(array $arguments, string $cacheKey) + * @method static CachedBuilder|User count($columns = '*') + * @method static CachedBuilder|User disableCache() + * @method static CachedBuilder|User disableModelCaching() + * @method static CachedBuilder|User exists() + * @method static UserFactory factory(...$parameters) + * @method static CachedBuilder|User flushCache(array $tags = []) * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User * getModelCacheCooldown(\Illuminate\Database\Eloquent\Model $instance) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User inRandomOrder($seed = '') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User insert(array $values) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User isCachable() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User max($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User min($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User newModelQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User newQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User query() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User sum($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User truncate() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereBalance($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereBannedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereBannedReason($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereCreatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereEmail($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereEmailVerifiedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereName($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User wherePassword($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereRememberToken($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User whereUpdatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|User withCacheCooldownSeconds(?int $seconds = null) - * @mixin \Eloquent + * @method static CachedBuilder|User inRandomOrder($seed = '') + * @method static CachedBuilder|User insert(array $values) + * @method static CachedBuilder|User isCachable() + * @method static CachedBuilder|User max($column) + * @method static CachedBuilder|User min($column) + * @method static CachedBuilder|User newModelQuery() + * @method static CachedBuilder|User newQuery() + * @method static CachedBuilder|User query() + * @method static CachedBuilder|User sum($column) + * @method static CachedBuilder|User truncate() + * @method static CachedBuilder|User whereBalance($value) + * @method static CachedBuilder|User whereBannedAt($value) + * @method static CachedBuilder|User whereBannedReason($value) + * @method static CachedBuilder|User whereCreatedAt($value) + * @method static CachedBuilder|User whereEmail($value) + * @method static CachedBuilder|User whereEmailVerifiedAt($value) + * @method static CachedBuilder|User whereId($value) + * @method static CachedBuilder|User whereName($value) + * @method static CachedBuilder|User wherePassword($value) + * @method static CachedBuilder|User whereRememberToken($value) + * @method static CachedBuilder|User whereUpdatedAt($value) + * @method static CachedBuilder|User withCacheCooldownSeconds(?int $seconds = null) + * @mixin Eloquent */ class User extends Authenticatable { diff --git a/app/Models/WorkOrder/Reply.php b/app/Models/WorkOrder/Reply.php index bef9f8c..53ead6b 100644 --- a/app/Models/WorkOrder/Reply.php +++ b/app/Models/WorkOrder/Reply.php @@ -5,54 +5,56 @@ use App\Events\UserEvent; use App\Exceptions\CommonException; use App\Models\User; +use Eloquent; +use GeneaLabs\LaravelModelCaching\CachedBuilder; use GeneaLabs\LaravelModelCaching\Traits\Cachable; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Support\Carbon; /** * App\Models\WorkOrder\Reply * - * @property int $id - * @property string $content - * @property int $work_order_id - * @property int|null $user_id - * @property int $is_pending - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property-read User|null $user - * @property-read \App\Models\WorkOrder\WorkOrder $workOrder - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply all($columns = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply avg($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply cache(array $tags = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply cachedValue(array $arguments, string $cacheKey) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply count($columns = '*') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply disableCache() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply disableModelCaching() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply exists() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply flushCache(array $tags = []) + * @property int $id + * @property string $content + * @property int $work_order_id + * @property int|null $user_id + * @property int $is_pending + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read User|null $user + * @property-read WorkOrder $workOrder + * @method static CachedBuilder|Reply all($columns = []) + * @method static CachedBuilder|Reply avg($column) + * @method static CachedBuilder|Reply cache(array $tags = []) + * @method static CachedBuilder|Reply cachedValue(array $arguments, string $cacheKey) + * @method static CachedBuilder|Reply count($columns = '*') + * @method static CachedBuilder|Reply disableCache() + * @method static CachedBuilder|Reply disableModelCaching() + * @method static CachedBuilder|Reply exists() + * @method static CachedBuilder|Reply flushCache(array $tags = []) * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply * getModelCacheCooldown(\Illuminate\Database\Eloquent\Model $instance) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply inRandomOrder($seed = '') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply insert(array $values) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply isCachable() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply max($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply min($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply newModelQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply newQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply query() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply sum($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply truncate() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply whereContent($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply whereCreatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply whereId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply whereIsPending($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply whereUpdatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply whereUserId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply whereWorkOrderId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply withCacheCooldownSeconds(?int $seconds = null) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|Reply workOrderId($work_order_id) - * @mixin \Eloquent + * @method static CachedBuilder|Reply inRandomOrder($seed = '') + * @method static CachedBuilder|Reply insert(array $values) + * @method static CachedBuilder|Reply isCachable() + * @method static CachedBuilder|Reply max($column) + * @method static CachedBuilder|Reply min($column) + * @method static CachedBuilder|Reply newModelQuery() + * @method static CachedBuilder|Reply newQuery() + * @method static CachedBuilder|Reply query() + * @method static CachedBuilder|Reply sum($column) + * @method static CachedBuilder|Reply truncate() + * @method static CachedBuilder|Reply whereContent($value) + * @method static CachedBuilder|Reply whereCreatedAt($value) + * @method static CachedBuilder|Reply whereId($value) + * @method static CachedBuilder|Reply whereIsPending($value) + * @method static CachedBuilder|Reply whereUpdatedAt($value) + * @method static CachedBuilder|Reply whereUserId($value) + * @method static CachedBuilder|Reply whereWorkOrderId($value) + * @method static CachedBuilder|Reply withCacheCooldownSeconds(?int $seconds = null) + * @method static CachedBuilder|Reply workOrderId($work_order_id) + * @mixin Eloquent */ class Reply extends Model { diff --git a/app/Models/WorkOrder/WorkOrder.php b/app/Models/WorkOrder/WorkOrder.php index 897dafe..2769ca8 100644 --- a/app/Models/WorkOrder/WorkOrder.php +++ b/app/Models/WorkOrder/WorkOrder.php @@ -7,63 +7,66 @@ use App\Models\Host; use App\Models\Module; use App\Models\User; +use Eloquent; +use GeneaLabs\LaravelModelCaching\CachedBuilder; use GeneaLabs\LaravelModelCaching\Traits\Cachable; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Carbon; /** * App\Models\WorkOrder\WorkOrder * * @property int $id - * @property string $title - * @property string $content - * @property int $user_id - * @property string $module_id - * @property int|null $host_id - * @property string $status - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property-read Host|null $host - * @property-read Module $module - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\WorkOrder\Reply[] $replies - * @property-read int|null $replies_count - * @property-read User $user - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder all($columns = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder avg($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder cache(array $tags = []) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder cachedValue(array $arguments, string $cacheKey) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder count($columns = '*') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder disableCache() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder disableModelCaching() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder exists() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder flushCache(array $tags = []) + * @property string $title + * @property string $content + * @property int $user_id + * @property string $module_id + * @property int|null $host_id + * @property string $status + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * @property-read Host|null $host + * @property-read Module $module + * @property-read Collection|Reply[] $replies + * @property-read int|null $replies_count + * @property-read User $user + * @method static CachedBuilder|WorkOrder all($columns = []) + * @method static CachedBuilder|WorkOrder avg($column) + * @method static CachedBuilder|WorkOrder cache(array $tags = []) + * @method static CachedBuilder|WorkOrder cachedValue(array $arguments, string $cacheKey) + * @method static CachedBuilder|WorkOrder count($columns = '*') + * @method static CachedBuilder|WorkOrder disableCache() + * @method static CachedBuilder|WorkOrder disableModelCaching() + * @method static CachedBuilder|WorkOrder exists() + * @method static CachedBuilder|WorkOrder flushCache(array $tags = []) * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder * getModelCacheCooldown(\Illuminate\Database\Eloquent\Model $instance) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder inRandomOrder($seed = '') - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder insert(array $values) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder isCachable() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder max($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder min($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder newModelQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder newQuery() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder query() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder sum($column) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder thisModule() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder thisUser() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder truncate() - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereContent($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereCreatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereHostId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereModuleId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereStatus($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereTitle($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereUpdatedAt($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder whereUserId($value) - * @method static \GeneaLabs\LaravelModelCaching\CachedBuilder|WorkOrder withCacheCooldownSeconds(?int $seconds = null) - * @mixin \Eloquent + * @method static CachedBuilder|WorkOrder inRandomOrder($seed = '') + * @method static CachedBuilder|WorkOrder insert(array $values) + * @method static CachedBuilder|WorkOrder isCachable() + * @method static CachedBuilder|WorkOrder max($column) + * @method static CachedBuilder|WorkOrder min($column) + * @method static CachedBuilder|WorkOrder newModelQuery() + * @method static CachedBuilder|WorkOrder newQuery() + * @method static CachedBuilder|WorkOrder query() + * @method static CachedBuilder|WorkOrder sum($column) + * @method static CachedBuilder|WorkOrder thisModule() + * @method static CachedBuilder|WorkOrder thisUser() + * @method static CachedBuilder|WorkOrder truncate() + * @method static CachedBuilder|WorkOrder whereContent($value) + * @method static CachedBuilder|WorkOrder whereCreatedAt($value) + * @method static CachedBuilder|WorkOrder whereHostId($value) + * @method static CachedBuilder|WorkOrder whereId($value) + * @method static CachedBuilder|WorkOrder whereModuleId($value) + * @method static CachedBuilder|WorkOrder whereStatus($value) + * @method static CachedBuilder|WorkOrder whereTitle($value) + * @method static CachedBuilder|WorkOrder whereUpdatedAt($value) + * @method static CachedBuilder|WorkOrder whereUserId($value) + * @method static CachedBuilder|WorkOrder withCacheCooldownSeconds(?int $seconds = null) + * @mixin Eloquent */ class WorkOrder extends Model { @@ -120,7 +123,7 @@ protected static function boot() // updated static::updated(function ($model) { - dispatch(new \App\Jobs\Module\WorkOrder\WorkOrder($model, 'put')); + dispatch(new WorkOrderJob($model, 'put')); }); } diff --git a/app/Notifications/ModuleEarnings.php b/app/Notifications/ModuleEarnings.php index 0ec6eb1..a6b6e1e 100644 --- a/app/Notifications/ModuleEarnings.php +++ b/app/Notifications/ModuleEarnings.php @@ -4,7 +4,6 @@ use App\Models\Module; use Illuminate\Bus\Queueable; -use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; diff --git a/app/Notifications/WeComChannel.php b/app/Notifications/WeComChannel.php index df859e5..fcc4d23 100644 --- a/app/Notifications/WeComChannel.php +++ b/app/Notifications/WeComChannel.php @@ -3,7 +3,6 @@ namespace App\Notifications; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; @@ -24,7 +23,8 @@ public function __construct() /** * Get the notification's delivery channels. * - * @param mixed $notifiable + * @param mixed $notifiable + * * @return array */ public function via($notifiable) @@ -35,21 +35,23 @@ public function via($notifiable) /** * Get the mail representation of the notification. * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage + * @param mixed $notifiable + * + * @return MailMessage */ public function toMail($notifiable) { return (new MailMessage) - ->line('The introduction to the notification.') - ->action('Notification Action', url('/')) - ->line('Thank you for using our application!'); + ->line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); } /** * Get the array representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable + * * @return array */ public function toArray($notifiable) diff --git a/app/Observers/BalanceObserve.php b/app/Observers/BalanceObserve.php index 7c9f379..5f02c4d 100644 --- a/app/Observers/BalanceObserve.php +++ b/app/Observers/BalanceObserve.php @@ -10,7 +10,7 @@ class BalanceObserve /** * Handle the Balance "created" event. * - * @param \App\Models\Balance $balance + * @param Balance $balance * * @return array */ @@ -24,7 +24,7 @@ public function created(Balance $balance) /** * Handle the Balance "updated" event. * - * @param \App\Models\Balance $balance + * @param Balance $balance * * @return array */ @@ -38,7 +38,7 @@ public function updated(Balance $balance) /** * Handle the Balance "deleted" event. * - * @param \App\Models\Balance $balance + * @param Balance $balance * * @return void */ @@ -50,7 +50,7 @@ public function deleted(Balance $balance) /** * Handle the Balance "restored" event. * - * @param \App\Models\Balance $balance + * @param Balance $balance * * @return void */ @@ -62,7 +62,7 @@ public function restored(Balance $balance) /** * Handle the Balance "force deleted" event. * - * @param \App\Models\Balance $balance + * @param Balance $balance * * @return void */ diff --git a/app/Observers/WorkOrder/ReplyObserver.php b/app/Observers/WorkOrder/ReplyObserver.php index 9f4a1b5..2aefd04 100644 --- a/app/Observers/WorkOrder/ReplyObserver.php +++ b/app/Observers/WorkOrder/ReplyObserver.php @@ -10,7 +10,7 @@ class ReplyObserver /** * Handle the Reply "created" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param Reply $reply * * @return void|null */ @@ -24,7 +24,7 @@ public function created(Reply $reply) /** * Handle the Reply "updated" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param Reply $reply * * @return void */ @@ -36,7 +36,7 @@ public function updated(Reply $reply) /** * Handle the Reply "deleted" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param Reply $reply * * @return void */ @@ -48,7 +48,7 @@ public function deleted(Reply $reply) /** * Handle the Reply "restored" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param Reply $reply * * @return void */ @@ -60,7 +60,7 @@ public function restored(Reply $reply) /** * Handle the Reply "force deleted" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param Reply $reply * * @return void */ diff --git a/app/Observers/WorkOrder/WorkOrderObserver.php b/app/Observers/WorkOrder/WorkOrderObserver.php index 40c0f10..829c102 100644 --- a/app/Observers/WorkOrder/WorkOrderObserver.php +++ b/app/Observers/WorkOrder/WorkOrderObserver.php @@ -11,7 +11,7 @@ class WorkOrderObserver /** * Handle the WorkOrder "created" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param WorkOrder $workOrder * * @return void|null */ @@ -25,7 +25,7 @@ public function created(WorkOrder $workOrder) /** * Handle the WorkOrder "updated" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param WorkOrder $workOrder * * @return void|null */ @@ -41,7 +41,7 @@ public function updated(WorkOrder $workOrder) /** * Handle the WorkOrder "deleted" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param WorkOrder $workOrder * * @return void */ @@ -53,7 +53,7 @@ public function deleted(WorkOrder $workOrder) /** * Handle the WorkOrder "restored" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param WorkOrder $workOrder * * @return void */ @@ -65,7 +65,7 @@ public function restored(WorkOrder $workOrder) /** * Handle the WorkOrder "force deleted" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param WorkOrder $workOrder * * @return void */ diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index b8850e5..e218afd 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -2,6 +2,12 @@ namespace App\Providers; +use App\Models\Balance; +use App\Models\WorkOrder\Reply; +use App\Models\WorkOrder\WorkOrder; +use App\Observers\BalanceObserve; +use App\Observers\WorkOrder\ReplyObserver; +use App\Observers\WorkOrder\WorkOrderObserver; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -28,9 +34,9 @@ public function boot() { // - \App\Models\WorkOrder\WorkOrder::observe(\App\Observers\WorkOrder\WorkOrderObserver::class); - \App\Models\WorkOrder\Reply::observe(\App\Observers\WorkOrder\ReplyObserver::class); - \App\Models\Balance::observe(\App\Observers\BalanceObserve::class); + WorkOrder::observe(WorkOrderObserver::class); + Reply::observe(ReplyObserver::class); + Balance::observe(BalanceObserve::class); } /** diff --git a/app/Support/EmqxSupport.php b/app/Support/EmqxSupport.php index cda12c2..3fb5ee0 100644 --- a/app/Support/EmqxSupport.php +++ b/app/Support/EmqxSupport.php @@ -8,31 +8,6 @@ class EmqxSupport { - private function api(): PendingRequest - { - return Http::baseUrl(config('emqx.api_url'))->withBasicAuth(config('emqx.api_key'), config('emqx.api_secret')); - } - - /** - * @throws EmqxSupportException - */ - public function clients($params = []) - { - // merge params - $params = array_merge([ - 'limit' => 100, - 'isTrusted' => true, - ], $params); - - $response = $this->api()->get('clients', $params); - - if ($response->successful()) { - return $response->json(); - } else { - throw new EmqxSupportException('无法获取客户端列表。'); - } - } - public function kickClient($client_id = null, $username = null): void { // 如果都为空,直接返回 @@ -59,4 +34,29 @@ public function kickClient($client_id = null, $username = null): void } } } + + private function api(): PendingRequest + { + return Http::baseUrl(config('emqx.api_url'))->withBasicAuth(config('emqx.api_key'), config('emqx.api_secret')); + } + + /** + * @throws EmqxSupportException + */ + public function clients($params = []) + { + // merge params + $params = array_merge([ + 'limit' => 100, + 'isTrusted' => true, + ], $params); + + $response = $this->api()->get('clients', $params); + + if ($response->successful()) { + return $response->json(); + } else { + throw new EmqxSupportException('无法获取客户端列表。'); + } + } } diff --git a/app/View/Components/BasicCard.php b/app/View/Components/BasicCard.php index 8c4bbda..09b36ca 100644 --- a/app/View/Components/BasicCard.php +++ b/app/View/Components/BasicCard.php @@ -2,6 +2,9 @@ namespace App\View\Components; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\View\Component; class BasicCard extends Component @@ -23,7 +26,7 @@ public function __construct($title) /** * Get the view / contents that represent the component. * - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + * @return Application|Factory|View */ public function render() { diff --git a/app/View/Components/HostStatus.php b/app/View/Components/HostStatus.php index 4ba9acf..3274220 100644 --- a/app/View/Components/HostStatus.php +++ b/app/View/Components/HostStatus.php @@ -2,6 +2,9 @@ namespace App\View\Components; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\View\Component; class HostStatus extends Component @@ -23,7 +26,7 @@ public function __construct($status) /** * Get the view / contents that represent the component. * - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + * @return Application|Factory|View */ public function render() { diff --git a/app/View/Components/ModuleEarning.php b/app/View/Components/ModuleEarning.php index 9bbe7c6..33f8503 100644 --- a/app/View/Components/ModuleEarning.php +++ b/app/View/Components/ModuleEarning.php @@ -3,6 +3,9 @@ namespace App\View\Components; use App\Models\Module; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\View\Component; class ModuleEarning extends Component @@ -24,7 +27,7 @@ public function __construct(Module $module) /** * Get the view / contents that represent the component. * - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + * @return Application|Factory|View */ public function render() { diff --git a/app/View/Components/ModuleScript.php b/app/View/Components/ModuleScript.php index f33ba0a..261495e 100644 --- a/app/View/Components/ModuleScript.php +++ b/app/View/Components/ModuleScript.php @@ -3,6 +3,9 @@ namespace App\View\Components; use App\Models\Module; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\View\Component; class ModuleScript extends Component @@ -20,7 +23,7 @@ public function __construct() /** * Get the view / contents that represent the component. * - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + * @return Application|Factory|View */ public function render() { diff --git a/app/View/Components/Payment.php b/app/View/Components/Payment.php index 83b4789..792ad95 100644 --- a/app/View/Components/Payment.php +++ b/app/View/Components/Payment.php @@ -2,6 +2,9 @@ namespace App\View\Components; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\View\Component; class Payment extends Component @@ -22,7 +25,7 @@ public function __construct($payment) /** * Get the view / contents that represent the component. * - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + * @return Application|Factory|View */ public function render() { diff --git a/app/View/Components/WorkOrderStatus.php b/app/View/Components/WorkOrderStatus.php index 651e61a..a6a607e 100644 --- a/app/View/Components/WorkOrderStatus.php +++ b/app/View/Components/WorkOrderStatus.php @@ -2,6 +2,9 @@ namespace App\View\Components; +use Illuminate\Contracts\Foundation\Application; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; use Illuminate\View\Component; class WorkOrderStatus extends Component @@ -23,7 +26,7 @@ public function __construct($status) /** * Get the view / contents that represent the component. * - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + * @return Application|Factory|View */ public function render() {