From a0e80defa030eafa97e7b5f410685a91cfcc9e40 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 7 Feb 2023 17:03:47 +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/Admin/Create.php | 2 +- app/Console/Commands/BanUser.php | 2 +- app/Console/Commands/CalcModule.php | 6 +- app/Console/Commands/Cluster/Log.php | 4 +- app/Console/Commands/Cluster/Restart.php | 4 +- app/Console/Commands/Cluster/Sync.php | 2 +- app/Console/Commands/Cluster/Upload.php | 8 +- app/Console/Commands/Cluster/Work.php | 8 +- app/Console/Commands/Count.php | 22 ++--- app/Console/Commands/GetUser.php | 12 +-- app/Console/Commands/HostCost.php | 4 +- app/Console/Commands/ReduceBalance.php | 6 +- app/Console/Commands/Status.php | 24 ++--- app/Console/Commands/UnbanUser.php | 2 +- app/Console/Commands/UserAddBalance.php | 10 +- app/Console/Kernel.php | 5 +- app/Events/Users.php | 2 +- app/Exceptions/Handler.php | 5 +- app/Helpers/Auth/AuthenticatesUsers.php | 86 ++++++++-------- app/Helpers/Auth/ConfirmsPasswords.php | 30 +++--- app/Helpers/Auth/RegistersUsers.php | 12 ++- app/Helpers/Auth/ResetsPasswords.php | 73 +++++++------- app/Helpers/Auth/SendsPasswordResetEmails.php | 51 +++++----- app/Helpers/Auth/ThrottlesLogins.php | 98 ++++++++++--------- app/Helpers/Auth/VerifiesEmails.php | 56 ++++++----- app/Helpers/Lock.php | 2 +- .../Controllers/Admin/AdminController.php | 20 ++-- .../Admin/ApplicationController.php | 19 ++-- app/Http/Controllers/Admin/AuthController.php | 5 +- .../Controllers/Admin/DeviceController.php | 2 +- app/Http/Controllers/Admin/HostController.php | 16 +-- .../Controllers/Admin/ModuleController.php | 28 +++--- .../Admin/NotificationController.php | 16 +-- .../Controllers/Admin/ReplyController.php | 22 +++-- app/Http/Controllers/Admin/UserController.php | 34 ++++--- .../Controllers/Admin/UserGroupController.php | 17 ++-- .../Controllers/Admin/WorkOrderController.php | 19 ++-- .../Controllers/Api/BalanceController.php | 6 +- app/Http/Controllers/Api/ForumController.php | 24 ++--- app/Http/Controllers/Api/HostController.php | 8 +- app/Http/Controllers/Api/ModuleController.php | 2 +- app/Http/Controllers/Api/ReplyController.php | 12 ++- .../Controllers/Api/WorkOrderController.php | 2 +- .../Application/MqttAuthController.php | 8 +- .../Module/AuthRequestController.php | 6 +- .../Controllers/Module/DeviceController.php | 2 +- .../Controllers/Module/HostController.php | 16 +-- .../Controllers/Module/ReplyController.php | 3 +- .../Controllers/Module/TaskController.php | 11 ++- .../Controllers/Module/UserController.php | 6 +- .../Controllers/Public/RealNameController.php | 4 +- .../Web/Auth/RegisterController.php | 6 +- app/Http/Controllers/Web/AuthController.php | 14 +-- .../Controllers/Web/BalanceController.php | 21 ++-- .../Controllers/Web/RealNameController.php | 8 +- .../Controllers/Web/TransferController.php | 2 +- app/Http/Middleware/AddHeaders.php | 5 +- app/Http/Middleware/Admin/ValidateReferer.php | 5 +- app/Http/Middleware/Authenticate.php | 5 +- app/Http/Middleware/JsonResponse.php | 3 +- app/Http/Middleware/RealNamed.php | 7 +- .../Middleware/RedirectIfAuthenticated.php | 5 +- app/Http/Middleware/ValidateUserIfBanned.php | 5 +- app/Http/Requests/BaseRequest.php | 4 +- app/Http/Requests/User/HostRequest.php | 2 +- app/Jobs/Host/HostJob.php | 8 +- app/Jobs/Host/PushHostJob.php | 2 +- app/Jobs/Host/RealHostCostJob.php | 4 +- app/Jobs/Host/UpdateOrDeleteHostJob.php | 8 +- app/Jobs/Module/SendModuleEarningsJob.php | 4 +- app/Jobs/Support/EMQXKickClientJob.php | 2 +- app/Jobs/User/CheckAndChargeBalanceJob.php | 2 +- app/Jobs/User/SetBirthdayGroupJob.php | 2 +- app/Jobs/WorkOrder/PushWorkOrderJob.php | 4 +- app/Jobs/WorkOrder/Reply.php | 10 +- app/Jobs/WorkOrder/WorkOrder.php | 8 +- app/Models/Balance.php | 8 +- app/Models/Host.php | 16 +-- app/Models/PersonalAccessToken.php | 5 +- app/Models/Task.php | 6 +- app/Models/User.php | 30 +++--- app/Models/UserGroup.php | 7 +- app/Models/WorkOrder/Reply.php | 6 +- app/Models/WorkOrder/WorkOrder.php | 26 ++--- app/Notifications/Channels/WeComChannel.php | 13 +-- app/Notifications/Channels/WebChannel.php | 7 +- .../User/TodayIsUserBirthday.php | 2 +- app/Notifications/WorkOrder/WorkOrder.php | 13 ++- app/Policies/WorkOrder/WorkOrderPolicy.php | 15 +-- app/Support/ClusterSupport.php | 19 ++-- app/Support/EmqxSupport.php | 6 +- app/Support/RealNameSupport.php | 25 ++--- 92 files changed, 653 insertions(+), 541 deletions(-) diff --git a/app/Console/Commands/Admin/Create.php b/app/Console/Commands/Admin/Create.php index 963687f..e7d192d 100644 --- a/app/Console/Commands/Admin/Create.php +++ b/app/Console/Commands/Admin/Create.php @@ -51,7 +51,7 @@ public function handle(): int ]); // 输出信息 - $this->info('管理员创建成功,ID为:'.$admin->id); + $this->info('管理员创建成功,ID为:' . $admin->id); return CommandAlias::SUCCESS; } diff --git a/app/Console/Commands/BanUser.php b/app/Console/Commands/BanUser.php index 18f1ff4..0df5887 100644 --- a/app/Console/Commands/BanUser.php +++ b/app/Console/Commands/BanUser.php @@ -46,7 +46,7 @@ public function handle(): int $user = (new User)->find($user_id); - $this->info('封禁: '.$user->name); + $this->info('封禁: ' . $user->name); $this->confirm('确定要继续吗?如果继续,将会暂停所有的主机,并且吊销所有 Token。'); diff --git a/app/Console/Commands/CalcModule.php b/app/Console/Commands/CalcModule.php index b3f5d0f..00356e5 100644 --- a/app/Console/Commands/CalcModule.php +++ b/app/Console/Commands/CalcModule.php @@ -39,11 +39,11 @@ public function __construct() public function handle(): int { $this->warn('开始计算集成模块收益。'); - $this->warn('当前时间: '.now()); + $this->warn('当前时间: ' . now()); (new Module)->chunk(100, function ($modules) { foreach ($modules as $module) { - $this->warn('模块: '.$module->name); + $this->warn('模块: ' . $module->name); $years = $module->calculate(); foreach ($years as $year => $months) { @@ -63,7 +63,7 @@ public function handle(): int }); $this->warn('计算模块收益完成。'); - $this->warn('完成时间: '.now()); + $this->warn('完成时间: ' . now()); return 1; } diff --git a/app/Console/Commands/Cluster/Log.php b/app/Console/Commands/Cluster/Log.php index 16a226f..b3b13c0 100644 --- a/app/Console/Commands/Cluster/Log.php +++ b/app/Console/Commands/Cluster/Log.php @@ -40,11 +40,11 @@ private function format(string $event, array $message = []) { $status = $this->switch($event, $message['data']); - if (! $status) { + if (!$status) { return; } - $message = "[{$message['node']['type']}] {$message['node']['id']}:$event: ".$status; + $message = "[{$message['node']['type']}] {$message['node']['id']}:$event: " . $status; $this->info($message); } diff --git a/app/Console/Commands/Cluster/Restart.php b/app/Console/Commands/Cluster/Restart.php index cfaf2ce..37c5171 100644 --- a/app/Console/Commands/Cluster/Restart.php +++ b/app/Console/Commands/Cluster/Restart.php @@ -32,13 +32,13 @@ public function handle(): int // 检测 service 参数 $service = $this->argument('service'); - if (! in_array($service, ['web', 'all'])) { + if (!in_array($service, ['web', 'all'])) { $this->error('service 参数错误,只能是 web 或 all。'); return CommandAlias::FAILURE; } - ClusterSupport::publish('cluster.restart.'.$service); + ClusterSupport::publish('cluster.restart.' . $service); $this->info('已经向集群广播重启命令,等待集群响应。'); diff --git a/app/Console/Commands/Cluster/Sync.php b/app/Console/Commands/Cluster/Sync.php index 6c32bf3..d51ecaf 100644 --- a/app/Console/Commands/Cluster/Sync.php +++ b/app/Console/Commands/Cluster/Sync.php @@ -44,7 +44,7 @@ public function handle(): int $confirm = $this->ask('主节点同步将会恢复上一次数据,确定吗?', true); } - if (! $confirm) { + if (!$confirm) { $this->warn('已取消。'); return CommandAlias::SUCCESS; diff --git a/app/Console/Commands/Cluster/Upload.php b/app/Console/Commands/Cluster/Upload.php index 4baaf86..5869749 100644 --- a/app/Console/Commands/Cluster/Upload.php +++ b/app/Console/Commands/Cluster/Upload.php @@ -91,7 +91,7 @@ public function upload($node_type) // 相对路径 $cache = 'config'; - $cacheZip = $cache.'.zip'; + $cacheZip = $cache . '.zip'; $zip = new ZipArchive(); $zip->open($cacheZip, ZipArchive::CREATE); $this->addFileToZip($cache, $zip); @@ -151,10 +151,10 @@ public function addFileToZip(string $path, ZipArchive $zip): void $handler = opendir($path); while (($filename = readdir($handler)) !== false) { if ($filename != '.' && $filename != '..') { - if (is_dir($path.'/'.$filename)) { - $this->addFileToZip($path.'/'.$filename, $zip); + if (is_dir($path . '/' . $filename)) { + $this->addFileToZip($path . '/' . $filename, $zip); } else { - $zip->addFile($path.'/'.$filename); + $zip->addFile($path . '/' . $filename); } } } diff --git a/app/Console/Commands/Cluster/Work.php b/app/Console/Commands/Cluster/Work.php index c5e1666..844f0c0 100644 --- a/app/Console/Commands/Cluster/Work.php +++ b/app/Console/Commands/Cluster/Work.php @@ -32,7 +32,7 @@ class Work extends Command public function handle(): int { // 检测目录下是否有 rr - if (! file_exists(base_path('rr'))) { + if (!file_exists(base_path('rr'))) { $this->warn('未找到 rr 文件,将自动下载。'); // 获取操作系统是 darwin 还是 linux @@ -70,7 +70,7 @@ public function handle(): int // 关闭 Octane Artisan::call('octane:stop'); - if (! config('settings.node.ip')) { + if (!config('settings.node.ip')) { $this->error('请先配置节点 IP。'); return CommandAlias::FAILURE; @@ -94,14 +94,14 @@ public function handle(): int $this->error('无法创建子进程。'); return CommandAlias::FAILURE; - } elseif ($pid === 0) { + } else if ($pid === 0) { // 再打开一个,负责 octane $pid = pcntl_fork(); if ($pid === -1) { $this->error('无法创建子进程。'); return CommandAlias::FAILURE; - } elseif ($pid === 0) { + } else if ($pid === 0) { // 子进程 $this->info('正在启动 Web。'); diff --git a/app/Console/Commands/Count.php b/app/Console/Commands/Count.php index 7f2da61..4685871 100644 --- a/app/Console/Commands/Count.php +++ b/app/Console/Commands/Count.php @@ -86,17 +86,17 @@ public function handle(): int $this->info('完成。'); - $this->warn('用户数量: '.$users); - $this->warn('主机数量: '.$hosts); - $this->warn('正在部署的主机数量: '.$pending_hosts); - $this->warn('已停止的主机数量: '.$stopped_hosts); - $this->warn('部署失败的主机数量: '.$error_hosts); - $this->warn('正常的主机数量: '.$active_hosts); - $this->warn('暂停的主机数量: '.$suspended_hosts); - $this->warn('服务器数量: '.$servers); - $this->warn('工单数量: '.$workOrders); - $this->warn('工单回复数量: '.$replies); - $this->warn('今年的交易记录: '.$transactions.' 条'); + $this->warn('用户数量: ' . $users); + $this->warn('主机数量: ' . $hosts); + $this->warn('正在部署的主机数量: ' . $pending_hosts); + $this->warn('已停止的主机数量: ' . $stopped_hosts); + $this->warn('部署失败的主机数量: ' . $error_hosts); + $this->warn('正常的主机数量: ' . $active_hosts); + $this->warn('暂停的主机数量: ' . $suspended_hosts); + $this->warn('服务器数量: ' . $servers); + $this->warn('工单数量: ' . $workOrders); + $this->warn('工单回复数量: ' . $replies); + $this->warn('今年的交易记录: ' . $transactions . ' 条'); return 0; } diff --git a/app/Console/Commands/GetUser.php b/app/Console/Commands/GetUser.php index d470fc8..34b1ff6 100644 --- a/app/Console/Commands/GetUser.php +++ b/app/Console/Commands/GetUser.php @@ -49,10 +49,10 @@ public function handle(): int $this->warn('用户基本信息'); - $this->info('用户 ID: '.$user->id); - $this->info('名称: '.$user->name); - $this->info('邮箱: '.$user->email); - $this->info('余额:'.$user->balance.' 元'); + $this->info('用户 ID: ' . $user->id); + $this->info('名称: ' . $user->name); + $this->info('邮箱: ' . $user->email); + $this->info('余额:' . $user->balance . ' 元'); $this->warn('前 10 条充值记录'); @@ -60,7 +60,7 @@ public function handle(): int // 倒序输出 foreach (array_reverse($balances->toArray()) as $balance) { - $this->info('['.$balance['paid_at'].'] 支付方式: '.$balance['payment'].' 金额:'.$balance['amount'].' 元'); + $this->info('[' . $balance['paid_at'] . '] 支付方式: ' . $balance['payment'] . ' 金额:' . $balance['amount'] . ' 元'); } $this->warn('前 10 个主机'); @@ -69,7 +69,7 @@ public function handle(): int // 倒序 foreach (array_reverse($hosts->toArray()) as $host) { - $this->info('['.$host['module']['name'].']('.$host['price'].' 元) '.$host['name']); + $this->info('[' . $host['module']['name'] . '](' . $host['price'] . ' 元) ' . $host['name']); } return 0; diff --git a/app/Console/Commands/HostCost.php b/app/Console/Commands/HostCost.php index 652f6b0..d78b707 100644 --- a/app/Console/Commands/HostCost.php +++ b/app/Console/Commands/HostCost.php @@ -35,7 +35,7 @@ public function handle(): int if ($this->confirm('如果不指定主机名,将会扣除所有主机的费用,是否继续?', true)) { (new Host)->chunk(100, function ($hosts) { foreach ($hosts as $host) { - $this->info('正在扣除主机 '.$host->name.' 的费用: '.$host->getPrice().' 元'); + $this->info('正在扣除主机 ' . $host->name . ' 的费用: ' . $host->getPrice() . ' 元'); $host->cost(); } }); @@ -43,7 +43,7 @@ public function handle(): int } else { $host_model = (new Host)->where('id', $host)->firstOrFail(); - if ($this->confirm('是否扣除主机 '.$host_model->name.' 的费用?', true)) { + if ($this->confirm('是否扣除主机 ' . $host_model->name . ' 的费用?', true)) { $host_model->cost(); } } diff --git a/app/Console/Commands/ReduceBalance.php b/app/Console/Commands/ReduceBalance.php index 709fc7b..c570217 100644 --- a/app/Console/Commands/ReduceBalance.php +++ b/app/Console/Commands/ReduceBalance.php @@ -47,11 +47,11 @@ public function handle(): void $user = (new User)->find($user_id); - $this->warn('扣除金额: '.$amount.' 元'); + $this->warn('扣除金额: ' . $amount . ' 元'); - $this->warn('用户当前余额:'.$user->balance.' 元'); + $this->warn('用户当前余额:' . $user->balance . ' 元'); - $this->warn('剩余余额:'.$user->balance - $amount.' 元'); + $this->warn('剩余余额:' . $user->balance - $amount . ' 元'); $confirm = $this->confirm('确认扣除?'); diff --git a/app/Console/Commands/Status.php b/app/Console/Commands/Status.php index b9a9e6b..d3b98e6 100644 --- a/app/Console/Commands/Status.php +++ b/app/Console/Commands/Status.php @@ -42,19 +42,19 @@ public function handle(): int $this->warn('===== 运行环境 ====='); // php version - $this->info('PHP 版本: '.PHP_VERSION); + $this->info('PHP 版本: ' . PHP_VERSION); // get mysql version /** @noinspection UnknownColumnInspection */ $mysql_version = DB::select('select version() as version')[0]->version; - $this->warn('MySQL 版本: '.$mysql_version); + $this->warn('MySQL 版本: ' . $mysql_version); $redis_info = Redis::info(); // get redis version $redis_version = $redis_info['redis_version']; - $this->warn('Redis 版本: '.$redis_version); + $this->warn('Redis 版本: ' . $redis_version); // 是否是 Redis 集群 $redis_cluster = $redis_info['cluster_enabled']; @@ -67,42 +67,42 @@ public function handle(): int // redis 操作系统 $redis_os = $redis_info['os']; - $this->warn('Redis 操作系统: '.$redis_os); + $this->warn('Redis 操作系统: ' . $redis_os); // redis process id $redis_pid = $redis_info['process_id']; - $this->warn('Redis 进程 ID: '.$redis_pid); + $this->warn('Redis 进程 ID: ' . $redis_pid); // redis used memory $redis_used_memory = $redis_info['used_memory_human']; - $this->info('Redis 内存: '.$redis_used_memory); + $this->info('Redis 内存: ' . $redis_used_memory); // redis memory peak $redis_memory_peak = $redis_info['used_memory_peak_human']; - $this->info('Redis 内存峰值: '.$redis_memory_peak); + $this->info('Redis 内存峰值: ' . $redis_memory_peak); // redis memory lua $redis_memory_lua = $redis_info['used_memory_lua_human']; - $this->info('Redis Lua 内存: '.$redis_memory_lua); + $this->info('Redis Lua 内存: ' . $redis_memory_lua); // redis 连接 $redis_connected_clients = $redis_info['connected_clients']; - $this->info('Redis 连接数量: '.$redis_connected_clients); + $this->info('Redis 连接数量: ' . $redis_connected_clients); // redis 命中率 $redis_keyspace_hits = $redis_info['keyspace_hits']; $redis_keyspace_misses = $redis_info['keyspace_misses']; $redis_keyspace_hit_rate = round($redis_keyspace_hits / ($redis_keyspace_hits + $redis_keyspace_misses) * 100, 2); - $this->info('Redis 命中率: '.$redis_keyspace_hit_rate.'%'); + $this->info('Redis 命中率: ' . $redis_keyspace_hit_rate . '%'); // redis 总连接数 $redis_total_connections_received = $redis_info['total_connections_received']; - $this->info('Redis 总连接数: '.$redis_total_connections_received); + $this->info('Redis 总连接数: ' . $redis_total_connections_received); // redis total commands $redis_total_commands_processed = $redis_info['total_commands_processed']; - $this->info('Redis 总命令数: '.$redis_total_commands_processed); + $this->info('Redis 总命令数: ' . $redis_total_commands_processed); $this->warn('===== 莱云 统计 ====='); $this->warn('要获取 莱云 统计信息,请运行 count 命令。'); diff --git a/app/Console/Commands/UnbanUser.php b/app/Console/Commands/UnbanUser.php index 78b2e36..3da8f29 100644 --- a/app/Console/Commands/UnbanUser.php +++ b/app/Console/Commands/UnbanUser.php @@ -44,7 +44,7 @@ public function handle(): void $user = (new User)->find($user_id); - $this->info('解除封禁: '.$user->name); + $this->info('解除封禁: ' . $user->name); $user->banned_at = null; $user->save(); diff --git a/app/Console/Commands/UserAddBalance.php b/app/Console/Commands/UserAddBalance.php index a531000..d100ab0 100644 --- a/app/Console/Commands/UserAddBalance.php +++ b/app/Console/Commands/UserAddBalance.php @@ -47,10 +47,10 @@ public function handle(): int // find user $user = (new User)->findOrFail($user_id); - $this->info($user->name.', 当前余额: '.$user->balance.' 元'); + $this->info($user->name . ', 当前余额: ' . $user->balance . ' 元'); - $this->info('充值后余额: '.($user->balance + $amount).' 元'); - if (! $this->confirm('确认充值 '.$amount.' 元?')) { + $this->info('充值后余额: ' . ($user->balance + $amount) . ' 元'); + if (!$this->confirm('确认充值 ' . $amount . ' 元?')) { $this->info('已取消。'); return 0; @@ -58,14 +58,14 @@ public function handle(): int $transaction = new Transaction(); - $description = '控制台充值 '.$amount.' 元'; + $description = '控制台充值 ' . $amount . ' 元'; $transaction->addAmount($user->id, 'console', $amount, $description, true); $this->info('充值成功。'); $user->refresh(); - $this->info($user->name.', 当前余额: '.$user->balance); + $this->info($user->name . ', 当前余额: ' . $user->balance); return 0; } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ec63590..dfe61d2 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -21,7 +21,8 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. * - * @param Schedule $schedule + * @param Schedule $schedule + * * @return void */ protected function schedule(Schedule $schedule): void @@ -69,7 +70,7 @@ protected function schedule(Schedule $schedule): void */ protected function commands(): void { - $this->load(__DIR__.'/Commands'); + $this->load(__DIR__ . '/Commands'); require base_path('routes/console.php'); } diff --git a/app/Events/Users.php b/app/Events/Users.php index 5202abb..a545e74 100644 --- a/app/Events/Users.php +++ b/app/Events/Users.php @@ -72,7 +72,7 @@ public function __construct(User|int $user, string $event, array|Model $data) public function broadcastOn(): PrivateChannel { - return new PrivateChannel('users.'.$this->user->id); + return new PrivateChannel('users.' . $this->user->id); } public function broadcastAs(): string diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 9ed93af..b81fa02 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -67,8 +67,9 @@ 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 */ protected function unauthenticated($request, AuthenticationException $exception): JsonResponse|RedirectResponse diff --git a/app/Helpers/Auth/AuthenticatesUsers.php b/app/Helpers/Auth/AuthenticatesUsers.php index 1070b14..d4dfc16 100644 --- a/app/Helpers/Auth/AuthenticatesUsers.php +++ b/app/Helpers/Auth/AuthenticatesUsers.php @@ -28,7 +28,8 @@ public function showLoginForm(): View /** * Handle a login request to the application. * - * @param Request $request + * @param Request $request + * * @return Response * * @throws ValidationException @@ -66,7 +67,8 @@ public function login(Request $request): Response /** * Validate the user login request. * - * @param Request $request + * @param Request $request + * * @return void * * @throws ValidationException @@ -79,10 +81,21 @@ protected function validateLogin(Request $request): void ]); } + /** + * Get the login username to be used by the controller. + * + * @return string + */ + public function username(): string + { + return 'email'; + } + /** * Attempt to log the user into the application. * - * @param Request $request + * @param Request $request + * * @return bool */ protected function attemptLogin(Request $request): bool @@ -92,10 +105,21 @@ protected function attemptLogin(Request $request): bool ); } + /** + * Get the guard to be used during authentication. + * + * @return StatefulGuard + */ + protected function guard(): StatefulGuard + { + return Auth::guard(); + } + /** * Get the needed authorization credentials from the request. * - * @param Request $request + * @param Request $request + * * @return array */ protected function credentials(Request $request): array @@ -106,7 +130,8 @@ protected function credentials(Request $request): array /** * Send the response after the user was authenticated. * - * @param Request $request + * @param Request $request + * * @return JsonResponse|RedirectResponse */ protected function sendLoginResponse(Request $request): JsonResponse|RedirectResponse @@ -124,18 +149,6 @@ protected function sendLoginResponse(Request $request): JsonResponse|RedirectRes : redirect()->intended($this->redirectPath()); } - /** - * The user has been authenticated. - * - * @param Request $request - * @param mixed $user - * @return void - */ - protected function authenticated(Request $request, mixed $user): void - { - // - } - /** * Get the failed login response instance. * @@ -151,20 +164,11 @@ protected function sendFailedLoginResponse(): Response ]); } - /** - * Get the login username to be used by the controller. - * - * @return string - */ - public function username(): string - { - return 'email'; - } - /** * Log the user out of the application. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse|JsonResponse */ public function logout(Request $request): JsonResponse|RedirectResponse @@ -184,24 +188,28 @@ public function logout(Request $request): JsonResponse|RedirectResponse : redirect('/'); } + /** + * The user has been authenticated. + * + * @param Request $request + * @param mixed $user + * + * @return void + */ + protected function authenticated(Request $request, mixed $user): void + { + // + } + /** * The user has logged out of the application. * - * @param Request $request + * @param Request $request + * * @return void */ protected function loggedOut(Request $request): void { // } - - /** - * Get the guard to be used during authentication. - * - * @return StatefulGuard - */ - protected function guard(): StatefulGuard - { - return Auth::guard(); - } } diff --git a/app/Helpers/Auth/ConfirmsPasswords.php b/app/Helpers/Auth/ConfirmsPasswords.php index c31d433..02279e1 100644 --- a/app/Helpers/Auth/ConfirmsPasswords.php +++ b/app/Helpers/Auth/ConfirmsPasswords.php @@ -24,7 +24,8 @@ public function showConfirmForm(): View /** * Confirm the given user's password. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse|JsonResponse */ public function confirm(Request $request): JsonResponse|RedirectResponse @@ -34,19 +35,8 @@ public function confirm(Request $request): JsonResponse|RedirectResponse $this->resetPasswordConfirmationTimeout($request); return $request->wantsJson() - ? new JsonResponse([], 204) - : redirect()->intended($this->redirectPath()); - } - - /** - * Reset the password confirmation timeout. - * - * @param Request $request - * @return void - */ - protected function resetPasswordConfirmationTimeout(Request $request): void - { - $request->session()->put('auth.password_confirmed_at', time()); + ? new JsonResponse([], 204) + : redirect()->intended($this->redirectPath()); } /** @@ -70,4 +60,16 @@ protected function validationErrorMessages(): array { return []; } + + /** + * Reset the password confirmation timeout. + * + * @param Request $request + * + * @return void + */ + protected function resetPasswordConfirmationTimeout(Request $request): void + { + $request->session()->put('auth.password_confirmed_at', time()); + } } diff --git a/app/Helpers/Auth/RegistersUsers.php b/app/Helpers/Auth/RegistersUsers.php index 2129b92..963aba8 100644 --- a/app/Helpers/Auth/RegistersUsers.php +++ b/app/Helpers/Auth/RegistersUsers.php @@ -27,7 +27,8 @@ public function showRegistrationForm(): View /** * Handle a registration request for the application. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse|JsonResponse */ public function register(Request $request): JsonResponse|RedirectResponse @@ -43,8 +44,8 @@ public function register(Request $request): JsonResponse|RedirectResponse // } return $request->wantsJson() - ? new JsonResponse([], 201) - : redirect($this->redirectPath()); + ? new JsonResponse([], 201) + : redirect($this->redirectPath()); } /** @@ -60,8 +61,9 @@ protected function guard(): StatefulGuard /** * The user has been registered. * - * @param Request $request - * @param mixed $user + * @param Request $request + * @param mixed $user + * * @return void */ protected function registered(Request $request, mixed $user): void diff --git a/app/Helpers/Auth/ResetsPasswords.php b/app/Helpers/Auth/ResetsPasswords.php index 946f5f4..f6e365b 100644 --- a/app/Helpers/Auth/ResetsPasswords.php +++ b/app/Helpers/Auth/ResetsPasswords.php @@ -28,7 +28,8 @@ trait ResetsPasswords * * If no token is present, display the link request form. * - * @param Request $request + * @param Request $request + * * @return Factory|View */ public function showResetForm(Request $request): Factory|View @@ -43,7 +44,8 @@ public function showResetForm(Request $request): Factory|View /** * Reset the given user's password. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse|JsonResponse */ public function reset(Request $request): JsonResponse|RedirectResponse @@ -60,8 +62,8 @@ public function reset(Request $request): JsonResponse|RedirectResponse // database. Otherwise, we will parse the error and return the response. $response = $this->broker()->reset( $this->credentials($request), function ($user, $password) { - $this->resetPassword($user, $password); - } + $this->resetPassword($user, $password); + } ); // If the password was successfully reset, we will redirect the user back to @@ -96,10 +98,21 @@ protected function validationErrorMessages(): array return []; } + /** + * Get the broker to be used during password reset. + * + * @return PasswordBroker + */ + public function broker(): PasswordBroker + { + return Password::broker(); + } + /** * Get the password reset credentials from the request. * - * @param Request $request + * @param Request $request + * * @return array */ protected function credentials(Request $request): array @@ -112,8 +125,9 @@ protected function credentials(Request $request): array /** * Reset the given user's password. * - * @param CanResetPassword|User $user - * @param string $password + * @param CanResetPassword|User $user + * @param string $password + * * @return void */ protected function resetPassword(CanResetPassword|User $user, string $password): void @@ -132,8 +146,9 @@ protected function resetPassword(CanResetPassword|User $user, string $password): /** * Set the user's password. * - * @param CanResetPassword $user - * @param string $password + * @param CanResetPassword $user + * @param string $password + * * @return void */ protected function setUserPassword(CanResetPassword $user, string $password): void @@ -144,11 +159,22 @@ protected function setUserPassword(CanResetPassword $user, string $password): vo } } + /** + * Get the guard to be used during password reset. + * + * @return StatefulGuard + */ + protected function guard(): StatefulGuard + { + return Auth::guard(); + } + /** * Get the response for a successful password reset. * - * @param Request $request - * @param string $response + * @param Request $request + * @param string $response + * * @return RedirectResponse|JsonResponse */ protected function sendResetResponse(Request $request, string $response): JsonResponse|RedirectResponse @@ -164,8 +190,9 @@ protected function sendResetResponse(Request $request, string $response): JsonRe /** * Get the response for a failed password reset. * - * @param Request $request - * @param string $response + * @param Request $request + * @param string $response + * * @return RedirectResponse */ protected function sendResetFailedResponse(Request $request, string $response): RedirectResponse @@ -180,24 +207,4 @@ protected function sendResetFailedResponse(Request $request, string $response): ->withInput($request->only('email')) ->withErrors(['email' => trans($response)]); } - - /** - * Get the broker to be used during password reset. - * - * @return PasswordBroker - */ - public function broker(): PasswordBroker - { - return Password::broker(); - } - - /** - * Get the guard to be used during password reset. - * - * @return StatefulGuard - */ - protected function guard(): StatefulGuard - { - return Auth::guard(); - } } diff --git a/app/Helpers/Auth/SendsPasswordResetEmails.php b/app/Helpers/Auth/SendsPasswordResetEmails.php index 410448c..ca17c18 100644 --- a/app/Helpers/Auth/SendsPasswordResetEmails.php +++ b/app/Helpers/Auth/SendsPasswordResetEmails.php @@ -25,7 +25,8 @@ public function showLinkRequestForm(): View /** * Send a reset link to the given user. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse|JsonResponse */ public function sendResetLinkEmail(Request $request): JsonResponse|RedirectResponse @@ -40,14 +41,15 @@ public function sendResetLinkEmail(Request $request): JsonResponse|RedirectRespo ); return $response == Password::RESET_LINK_SENT - ? $this->sendResetLinkResponse($request, $response) - : $this->sendResetLinkFailedResponse($request, $response); + ? $this->sendResetLinkResponse($request, $response) + : $this->sendResetLinkFailedResponse($request, $response); } /** * Validate the email for the given request. * - * @param Request $request + * @param Request $request + * * @return void */ protected function validateEmail(Request $request): void @@ -55,10 +57,21 @@ protected function validateEmail(Request $request): void $request->validate(['email' => 'required|email']); } + /** + * Get the broker to be used during password reset. + * + * @return PasswordBroker + */ + public function broker(): PasswordBroker + { + return Password::broker(); + } + /** * Get the needed authentication credentials from the request. * - * @param Request $request + * @param Request $request + * * @return array */ protected function credentials(Request $request): array @@ -69,22 +82,24 @@ protected function credentials(Request $request): array /** * Get the response for a successful password reset link. * - * @param Request $request - * @param string $response + * @param Request $request + * @param string $response + * * @return RedirectResponse|JsonResponse */ protected function sendResetLinkResponse(Request $request, string $response): JsonResponse|RedirectResponse { return $request->wantsJson() - ? new JsonResponse(['message' => trans($response)], 200) - : back()->with('status', trans($response)); + ? new JsonResponse(['message' => trans($response)], 200) + : back()->with('status', trans($response)); } /** * Get the response for a failed password reset link. * - * @param Request $request - * @param string $response + * @param Request $request + * @param string $response + * * @return RedirectResponse * * @throws ValidationException @@ -98,17 +113,7 @@ protected function sendResetLinkFailedResponse(Request $request, string $respons } return back() - ->withInput($request->only('email')) - ->withErrors(['email' => trans($response)]); - } - - /** - * Get the broker to be used during password reset. - * - * @return PasswordBroker - */ - public function broker(): PasswordBroker - { - return Password::broker(); + ->withInput($request->only('email')) + ->withErrors(['email' => trans($response)]); } } diff --git a/app/Helpers/Auth/ThrottlesLogins.php b/app/Helpers/Auth/ThrottlesLogins.php index a5110f7..9911fc6 100644 --- a/app/Helpers/Auth/ThrottlesLogins.php +++ b/app/Helpers/Auth/ThrottlesLogins.php @@ -14,7 +14,8 @@ trait ThrottlesLogins /** * Determine if the user has too many failed login attempts. * - * @param Request $request + * @param Request $request + * * @return bool */ protected function hasTooManyLoginAttempts(Request $request): bool @@ -24,10 +25,43 @@ protected function hasTooManyLoginAttempts(Request $request): bool ); } + /** + * Get the rate limiter instance. + * + * @return RateLimiter + */ + protected function limiter(): RateLimiter + { + return app(RateLimiter::class); + } + + /** + * Get the throttle key for the given request. + * + * @param Request $request + * + * @return string + */ + protected function throttleKey(Request $request): string + { + return Str::transliterate(Str::lower($request->input($this->username())) . '|' . $request->ip()); + } + + /** + * Get the maximum number of attempts to allow. + * + * @return int + */ + public function maxAttempts(): int + { + return property_exists($this, 'maxAttempts') ? $this->maxAttempts : 5; + } + /** * Increment the login attempts for the user. * - * @param Request $request + * @param Request $request + * * @return void */ protected function incrementLoginAttempts(Request $request): void @@ -37,10 +71,21 @@ protected function incrementLoginAttempts(Request $request): void ); } + /** + * Get the number of minutes to throttle for. + * + * @return int + */ + public function decayMinutes(): int + { + return property_exists($this, 'decayMinutes') ? $this->decayMinutes : 1; + } + /** * Redirect the user after determining they are locked out. * - * @param Request $request + * @param Request $request + * * @return ResponseAlias * * @throws ValidationException @@ -62,7 +107,8 @@ protected function sendLockoutResponse(Request $request): ResponseAlias /** * Clear the login locks for the given user credentials. * - * @param Request $request + * @param Request $request + * * @return void */ protected function clearLoginAttempts(Request $request): void @@ -73,52 +119,12 @@ protected function clearLoginAttempts(Request $request): void /** * Fire an event when a lockout occurs. * - * @param Request $request + * @param Request $request + * * @return void */ protected function fireLockoutEvent(Request $request): void { event(new Lockout($request)); } - - /** - * Get the throttle key for the given request. - * - * @param Request $request - * @return string - */ - protected function throttleKey(Request $request): string - { - return Str::transliterate(Str::lower($request->input($this->username())).'|'.$request->ip()); - } - - /** - * Get the rate limiter instance. - * - * @return RateLimiter - */ - protected function limiter(): RateLimiter - { - return app(RateLimiter::class); - } - - /** - * Get the maximum number of attempts to allow. - * - * @return int - */ - public function maxAttempts(): int - { - return property_exists($this, 'maxAttempts') ? $this->maxAttempts : 5; - } - - /** - * Get the number of minutes to throttle for. - * - * @return int - */ - public function decayMinutes(): int - { - return property_exists($this, 'decayMinutes') ? $this->decayMinutes : 1; - } } diff --git a/app/Helpers/Auth/VerifiesEmails.php b/app/Helpers/Auth/VerifiesEmails.php index a7e0e8d..64a7d98 100644 --- a/app/Helpers/Auth/VerifiesEmails.php +++ b/app/Helpers/Auth/VerifiesEmails.php @@ -16,38 +16,40 @@ trait VerifiesEmails /** * Show the email verification notice. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse|View */ public function show(Request $request): View|RedirectResponse { return $request->user()->hasVerifiedEmail() - ? redirect($this->redirectPath()) - : view('auth.verify'); + ? redirect($this->redirectPath()) + : view('auth.verify'); } /** * Mark the authenticated user's email address as verified. * - * @param Request $request + * @param Request $request + * * @return JsonResponse|RedirectResponse * * @throws AuthorizationException */ public function verify(Request $request): JsonResponse|RedirectResponse { - if (! hash_equals((string) $request->route('id'), (string) $request->user()->getKey())) { + if (!hash_equals((string)$request->route('id'), (string)$request->user()->getKey())) { throw new AuthorizationException; } - if (! hash_equals((string) $request->route('hash'), sha1($request->user()->getEmailForVerification()))) { + if (!hash_equals((string)$request->route('hash'), sha1($request->user()->getEmailForVerification()))) { throw new AuthorizationException; } if ($request->user()->hasVerifiedEmail()) { return $request->wantsJson() - ? new JsonResponse([], 204) - : redirect($this->redirectPath()); + ? new JsonResponse([], 204) + : redirect($this->redirectPath()); } if ($request->user()->markEmailAsVerified()) { @@ -59,39 +61,41 @@ public function verify(Request $request): JsonResponse|RedirectResponse // } return $request->wantsJson() - ? new JsonResponse([], 204) - : redirect($this->redirectPath())->with('verified', true); - } - - /** - * The user has been verified. - * - * @param Request $request - * @return void - */ - protected function verified(Request $request): void - { - // + ? new JsonResponse([], 204) + : redirect($this->redirectPath())->with('verified', true); } /** * Resend the email verification notification. * - * @param Request $request + * @param Request $request + * * @return JsonResponse|RedirectResponse */ public function resend(Request $request): JsonResponse|RedirectResponse { if ($request->user()->hasVerifiedEmail()) { return $request->wantsJson() - ? new JsonResponse([], 204) - : redirect($this->redirectPath()); + ? new JsonResponse([], 204) + : redirect($this->redirectPath()); } $request->user()->sendEmailVerificationNotification(); return $request->wantsJson() - ? new JsonResponse([], 202) - : back()->with('resent', true); + ? new JsonResponse([], 202) + : back()->with('resent', true); + } + + /** + * The user has been verified. + * + * @param Request $request + * + * @return void + */ + protected function verified(Request $request): void + { + // } } diff --git a/app/Helpers/Lock.php b/app/Helpers/Lock.php index 38083f5..7ca3078 100644 --- a/app/Helpers/Lock.php +++ b/app/Helpers/Lock.php @@ -13,7 +13,7 @@ public function await($name, Closure $callback) if (config('app.env') == 'local') { return $callback(); } - $lock = Cache::lock('lock_'.$name, 5); + $lock = Cache::lock('lock_' . $name, 5); try { $lock->block(5); diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index 1a95e4c..fd9613d 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -26,7 +26,8 @@ public function index(): View /** * Store a newly created resource in storage. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse */ public function store(Request $request): RedirectResponse @@ -44,7 +45,7 @@ public function store(Request $request): RedirectResponse 'password' => bcrypt($password), ]); - return redirect()->route('admin.admins.edit', $admin)->with('success', '管理员创建成功,密码为:'.$password.'。'); + return redirect()->route('admin.admins.edit', $admin)->with('success', '管理员创建成功,密码为:' . $password . '。'); } /** @@ -60,7 +61,8 @@ public function create(): View /** * Show the form for editing the specified resource. * - * @param Admin $admin + * @param Admin $admin + * * @return View */ public function edit(Admin $admin): View @@ -71,14 +73,15 @@ public function edit(Admin $admin): View /** * Update the specified resource in storage. * - * @param Request $request - * @param Admin $admin + * @param Request $request + * @param Admin $admin + * * @return RedirectResponse */ public function update(Request $request, Admin $admin): RedirectResponse { $request->validate([ - 'email' => 'required|email|unique:admins,email,'.$admin->id, + 'email' => 'required|email|unique:admins,email,' . $admin->id, 'name' => 'required|string|max:30', ]); @@ -88,7 +91,7 @@ public function update(Request $request, Admin $admin): RedirectResponse // 随机密码 $password = Str::random(); - $msg .= ',新的密码为:'.$password; + $msg .= ',新的密码为:' . $password; $admin->password = bcrypt($password); } @@ -106,7 +109,8 @@ public function update(Request $request, Admin $admin): RedirectResponse /** * Remove the specified resource from storage. * - * @param Admin $admin + * @param Admin $admin + * * @return RedirectResponse */ public function destroy(Admin $admin): RedirectResponse diff --git a/app/Http/Controllers/Admin/ApplicationController.php b/app/Http/Controllers/Admin/ApplicationController.php index 7ec7b5a..90ca15f 100644 --- a/app/Http/Controllers/Admin/ApplicationController.php +++ b/app/Http/Controllers/Admin/ApplicationController.php @@ -25,7 +25,8 @@ public function index(): View /** * Store a newly created resource in storage. * - * @param Request $request + * @param Request $request + * * @return View */ public function store(Request $request): View @@ -58,7 +59,8 @@ public function create(): View /** * Display the specified resource. * - * @param Application $application + * @param Application $application + * * @return RedirectResponse */ public function show(Application $application): RedirectResponse @@ -71,7 +73,8 @@ public function show(Application $application): RedirectResponse /** * Show the form for editing the specified resource. * - * @param Application $application + * @param Application $application + * * @return View */ public function edit(Application $application): View @@ -84,8 +87,9 @@ public function edit(Application $application): View /** * Update the specified resource in storage. * - * @param Request $request - * @param Application $application + * @param Request $request + * @param Application $application + * * @return RedirectResponse */ public function update(Request $request, Application $application): RedirectResponse @@ -95,7 +99,7 @@ public function update(Request $request, Application $application): RedirectResp $this->validate($request, [ 'name' => 'required', 'description' => 'required', - 'api_token' => 'required|unique:applications,api_token,'.$application->id, + 'api_token' => 'required|unique:applications,api_token,' . $application->id, ]); $application->update($request->all()); @@ -106,7 +110,8 @@ public function update(Request $request, Application $application): RedirectResp /** * Remove the specified resource from storage. * - * @param Application $application + * @param Application $application + * * @return RedirectResponse */ public function destroy(Application $application): RedirectResponse diff --git a/app/Http/Controllers/Admin/AuthController.php b/app/Http/Controllers/Admin/AuthController.php index 9613d3f..e4c637b 100644 --- a/app/Http/Controllers/Admin/AuthController.php +++ b/app/Http/Controllers/Admin/AuthController.php @@ -14,7 +14,7 @@ class AuthController extends Controller */ public function index(): View|RedirectResponse { - if (! auth('admin')->check()) { + if (!auth('admin')->check()) { return view('admin.login'); } else { return redirect()->route('admin.index'); @@ -22,7 +22,8 @@ public function index(): View|RedirectResponse } /** - * @param Request $request + * @param Request $request + * * @return RedirectResponse */ public function login(Request $request): RedirectResponse diff --git a/app/Http/Controllers/Admin/DeviceController.php b/app/Http/Controllers/Admin/DeviceController.php index 7b20e1a..14922bf 100644 --- a/app/Http/Controllers/Admin/DeviceController.php +++ b/app/Http/Controllers/Admin/DeviceController.php @@ -51,7 +51,7 @@ public function destroy(Request $request): RedirectResponse $module_name = explode('.', $username)[0]; $this->dispatch(new EMQXKickClientJob(null, $module_name, false)); - $this->dispatch(new EMQXKickClientJob(null, $module_name.'.', true)); + $this->dispatch(new EMQXKickClientJob(null, $module_name . '.', true)); } return back()->with('success', '正在让它们下线。'); diff --git a/app/Http/Controllers/Admin/HostController.php b/app/Http/Controllers/Admin/HostController.php index dac0577..a0457e7 100644 --- a/app/Http/Controllers/Admin/HostController.php +++ b/app/Http/Controllers/Admin/HostController.php @@ -14,7 +14,8 @@ class HostController extends Controller * Display a listing of the resource. * * - * @param Request $request + * @param Request $request + * * @return View */ public function index(Request $request): View @@ -24,7 +25,7 @@ public function index(Request $request): View // 遍历所有的搜索条件 foreach (['name', 'module_id', 'status', 'user_id', 'price', 'managed_price', 'created_at', 'updated_at'] as $field) { if ($request->has($field)) { - $hosts = $hosts->where($field, 'like', '%'.$request->input($field).'%'); + $hosts = $hosts->where($field, 'like', '%' . $request->input($field) . '%'); } } @@ -38,7 +39,8 @@ public function index(Request $request): View /** * Show the form for editing the specified resource. * - * @param Host $host + * @param Host $host + * * @return View */ public function edit(Host $host): View @@ -49,8 +51,9 @@ public function edit(Host $host): View /** * Update the specified resource in storage. * - * @param Request $request - * @param Host $host + * @param Request $request + * @param Host $host + * * @return RedirectResponse */ public function update(Request $request, Host $host): RedirectResponse @@ -70,7 +73,8 @@ public function update(Request $request, Host $host): RedirectResponse /** * Remove the specified resource from storage. * - * @param Host $host + * @param Host $host + * * @return RedirectResponse */ public function destroy(Host $host): RedirectResponse diff --git a/app/Http/Controllers/Admin/ModuleController.php b/app/Http/Controllers/Admin/ModuleController.php index f33e11b..b5a3efb 100644 --- a/app/Http/Controllers/Admin/ModuleController.php +++ b/app/Http/Controllers/Admin/ModuleController.php @@ -16,7 +16,8 @@ class ModuleController extends Controller /** * Display a listing of the resource. * - * @param Module $module + * @param Module $module + * * @return View */ public function index(Module $module): View @@ -39,7 +40,8 @@ public function create(): View /** * Store a newly created resource in storage. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse */ public function store(Request $request): RedirectResponse @@ -79,7 +81,8 @@ private function rules(): array /** * Display the specified resource. * - * @param Module $module + * @param Module $module + * * @return View */ public function show(Module $module): View @@ -94,7 +97,8 @@ public function show(Module $module): View /** * Show the form for editing the specified resource. * - * @param Module $module + * @param Module $module + * * @return View */ public function edit(Module $module): View @@ -107,8 +111,9 @@ public function edit(Module $module): View /** * Update the specified resource in storage. * - * @param Request $request - * @param Module $module + * @param Request $request + * @param Module $module + * * @return RedirectResponse */ public function update(Request $request, Module $module): RedirectResponse @@ -122,7 +127,7 @@ public function update(Request $request, Module $module): RedirectResponse $module->status = $request->input('status'); $module->wecom_key = $request->input('wecom_key'); - if (! $request->filled('api_token')) { + if (!$request->filled('api_token')) { $module->api_token = Str::random(60); } else { $module->api_token = $request->input('api_token'); @@ -140,17 +145,17 @@ public function update(Request $request, Module $module): RedirectResponse // 充值或者扣费 if ($diff > 0) { - $description = '管理员 '.auth('admin')->user()->name.' 充值 '.$diff.' 元'; + $description = '管理员 ' . auth('admin')->user()->name . ' 充值 ' . $diff . ' 元'; $module->charge($diff, 'console', $description); } else { - $description = '管理员 '.auth('admin')->user()->name.' 扣除 '.abs($diff).' 元'; + $description = '管理员 ' . auth('admin')->user()->name . ' 扣除 ' . abs($diff) . ' 元'; $module->reduce(abs($diff), $description); } } } if ($request->input('reset_api_token')) { - $text .= ', API Token 为 '.$module->api_token.'。'; + $text .= ', API Token 为 ' . $module->api_token . '。'; } else { $text .= '。'; } @@ -161,7 +166,8 @@ public function update(Request $request, Module $module): RedirectResponse /** * Remove the specified resource from storage. * - * @param Module $module + * @param Module $module + * * @return RedirectResponse */ public function destroy(Module $module): RedirectResponse diff --git a/app/Http/Controllers/Admin/NotificationController.php b/app/Http/Controllers/Admin/NotificationController.php index 9383808..13630f9 100644 --- a/app/Http/Controllers/Admin/NotificationController.php +++ b/app/Http/Controllers/Admin/NotificationController.php @@ -17,7 +17,8 @@ class NotificationController extends Controller /** * Show the form for creating a new resource. * - * @param Request $request + * @param Request $request + * * @return View */ public function create(Request $request): View @@ -35,26 +36,26 @@ public function query(Request|array $request): User|CachedBuilder|Builder $request = $request->all(); } - if (! empty($request['user_id'])) { + if (!empty($request['user_id'])) { $users = (new User)->where('id', $request['user_id']); } else { $users = User::query(); - if (! empty($request['user'])) { + if (!empty($request['user'])) { $user = $request['user']; if ($user == 'active') { // 寻找有 host 的用户 $users = $users->whereHas('hosts'); - } elseif ($user == 'normal') { + } else if ($user == 'normal') { $users = $users->whereNull('banned_at'); - } elseif ($user == 'banned') { + } else if ($user == 'banned') { $users = $users->whereNotNull('banned_at'); } } } - if (! empty($request['module_id'])) { + if (!empty($request['module_id'])) { // 从 hosts 中找到 module_id,然后找到拥有此 host 的用户 $users = $users->whereHas('hosts', function ($query) use ($request) { $query->where('module_id', $request['module_id']); @@ -67,7 +68,8 @@ public function query(Request|array $request): User|CachedBuilder|Builder /** * Store a newly created resource in storage. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse */ public function store(Request $request): RedirectResponse diff --git a/app/Http/Controllers/Admin/ReplyController.php b/app/Http/Controllers/Admin/ReplyController.php index da63632..148acc0 100644 --- a/app/Http/Controllers/Admin/ReplyController.php +++ b/app/Http/Controllers/Admin/ReplyController.php @@ -14,8 +14,9 @@ class ReplyController extends Controller /** * Store a newly created resource in storage. * - * @param Request $request - * @param WorkOrder $work_order + * @param Request $request + * @param WorkOrder $work_order + * * @return RedirectResponse */ public function store(Request $request, WorkOrder $work_order): RedirectResponse @@ -40,8 +41,9 @@ public function store(Request $request, WorkOrder $work_order): RedirectResponse /** * Show the form for editing the specified resource. * - * @param WorkOrder $work_order - * @param Reply $reply + * @param WorkOrder $work_order + * @param Reply $reply + * * @return View */ public function edit(WorkOrder $work_order, Reply $reply): View @@ -52,9 +54,10 @@ public function edit(WorkOrder $work_order, Reply $reply): View /** * Update the specified resource in storage. * - * @param Request $request - * @param WorkOrder $work_order - * @param Reply $reply + * @param Request $request + * @param WorkOrder $work_order + * @param Reply $reply + * * @return RedirectResponse */ public function update(Request $request, WorkOrder $work_order, Reply $reply): RedirectResponse @@ -73,8 +76,9 @@ public function update(Request $request, WorkOrder $work_order, Reply $reply): R /** * Remove the specified resource from storage. * - * @param WorkOrder $work_order - * @param Reply $reply + * @param WorkOrder $work_order + * @param Reply $reply + * * @return RedirectResponse */ public function destroy(WorkOrder $work_order, Reply $reply): RedirectResponse diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 0923c3e..798db83 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -28,15 +28,15 @@ public function index(Request $request): View } if ($request->filled('name')) { - $users = $users->where('name', 'like', '%'.$request->input('name').'%'); + $users = $users->where('name', 'like', '%' . $request->input('name') . '%'); } if ($request->filled('email')) { - $users = $users->where('email', 'like', '%'.$request->input('email').'%'); + $users = $users->where('email', 'like', '%' . $request->input('email') . '%'); } if ($request->filled('real_name')) { - $users = $users->where('real_name', 'like', '%'.$request->input('real_name').'%'); + $users = $users->where('real_name', 'like', '%' . $request->input('real_name') . '%'); } if ($request->has('banned_at')) { @@ -57,20 +57,22 @@ public function index(Request $request): View /** * Display the specified resource. * - * @param User $user + * @param User $user + * * @return RedirectResponse */ public function show(User $user): RedirectResponse { Auth::guard('web')->login($user); - return back()->with('success', '您已切换到用户 '.$user->name.' 的身份。'); + return back()->with('success', '您已切换到用户 ' . $user->name . ' 的身份。'); } /** * Show the form for editing the specified resource. * - * @param User $user + * @param User $user + * * @return View */ public function edit(User $user): View @@ -86,8 +88,9 @@ public function edit(User $user): View /** * Update the specified resource in storage. * - * @param Request $request - * @param User $user + * @param Request $request + * @param User $user + * * @return RedirectResponse */ public function update(Request $request, User $user): RedirectResponse @@ -115,18 +118,18 @@ public function update(Request $request, User $user): RedirectResponse if ($request->filled('one_time_action')) { if ($one_time_action == 'clear_all_keys') { $user->tokens()->delete(); - } elseif ($one_time_action == 'suspend_all_hosts') { + } else if ($one_time_action == 'suspend_all_hosts') { $user->hosts()->update(['status' => 'suspended', 'suspended_at' => now()]); - } elseif ($one_time_action == 'stop_all_hosts') { + } else if ($one_time_action == 'stop_all_hosts') { $user->hosts()->update(['status' => 'stopped', 'suspended_at' => null]); - } elseif ($one_time_action == 'add_balance') { - $description = '管理员 '.$request->user('admin')->name.' 增加。'; + } else if ($one_time_action == 'add_balance') { + $description = '管理员 ' . $request->user('admin')->name . ' 增加。'; $user->charge($request->input('balance'), 'console', $description, [ 'add_balances_log' => true, ]); - } elseif ($one_time_action == 'reduce_balance') { - $description = '管理员 '.$request->user('admin')->name.' 扣除。'; + } else if ($one_time_action == 'reduce_balance') { + $description = '管理员 ' . $request->user('admin')->name . ' 扣除。'; $user->reduce($request->input('balance'), $description); } @@ -154,7 +157,8 @@ public function update(Request $request, User $user): RedirectResponse /** * Remove the specified resource from storage. * - * @param User $user + * @param User $user + * * @return RedirectResponse */ public function destroy(User $user): RedirectResponse diff --git a/app/Http/Controllers/Admin/UserGroupController.php b/app/Http/Controllers/Admin/UserGroupController.php index 75aab29..3ae5980 100644 --- a/app/Http/Controllers/Admin/UserGroupController.php +++ b/app/Http/Controllers/Admin/UserGroupController.php @@ -26,7 +26,8 @@ public function index(): View /** * Store a newly created resource in storage. * - * @param Request $request + * @param Request $request + * * @return RedirectResponse */ public function store(Request $request): RedirectResponse @@ -63,7 +64,8 @@ public function create(): View /** * Display the specified resource. * - * @param UserGroup $user_group + * @param UserGroup $user_group + * * @return View */ public function show(UserGroup $user_group): View @@ -76,7 +78,8 @@ public function show(UserGroup $user_group): View /** * Show the form for editing the specified resource. * - * @param UserGroup $user_group + * @param UserGroup $user_group + * * @return View */ public function edit(UserGroup $user_group): View @@ -89,8 +92,9 @@ public function edit(UserGroup $user_group): View /** * Update the specified resource in storage. * - * @param Request $request - * @param UserGroup $user_group + * @param Request $request + * @param UserGroup $user_group + * * @return RedirectResponse */ public function update(Request $request, UserGroup $user_group): RedirectResponse @@ -106,7 +110,8 @@ public function update(Request $request, UserGroup $user_group): RedirectRespons /** * Remove the specified resource from storage. * - * @param UserGroup $user_group + * @param UserGroup $user_group + * * @return RedirectResponse */ public function destroy(UserGroup $user_group): RedirectResponse diff --git a/app/Http/Controllers/Admin/WorkOrderController.php b/app/Http/Controllers/Admin/WorkOrderController.php index 7302a3d..da7d404 100644 --- a/app/Http/Controllers/Admin/WorkOrderController.php +++ b/app/Http/Controllers/Admin/WorkOrderController.php @@ -15,8 +15,9 @@ class WorkOrderController extends Controller /** * Display a listing of the resource. * - * @param Request $request - * @param WorkOrder $workOrder + * @param Request $request + * @param WorkOrder $workOrder + * * @return View */ public function index(Request $request, WorkOrder $workOrder): View @@ -35,7 +36,8 @@ public function index(Request $request, WorkOrder $workOrder): View /** * Display the specified resource. * - * @param WorkOrder $workOrder + * @param WorkOrder $workOrder + * * @return View */ public function show(WorkOrder $workOrder): View @@ -50,7 +52,8 @@ public function show(WorkOrder $workOrder): View /** * Show the form for editing the specified resource. * - * @param WorkOrder $workOrder + * @param WorkOrder $workOrder + * * @return View */ public function edit(WorkOrder $workOrder): View @@ -61,8 +64,9 @@ public function edit(WorkOrder $workOrder): View /** * Update the specified resource in storage. * - * @param Request $request - * @param WorkOrder $workOrder + * @param Request $request + * @param WorkOrder $workOrder + * * @return RedirectResponse */ public function update(Request $request, WorkOrder $workOrder): RedirectResponse @@ -83,7 +87,8 @@ public function update(Request $request, WorkOrder $workOrder): RedirectResponse /** * Remove the specified resource from storage. * - * @param WorkOrder $workOrder + * @param WorkOrder $workOrder + * * @return RedirectResponse */ public function destroy(WorkOrder $workOrder): RedirectResponse diff --git a/app/Http/Controllers/Api/BalanceController.php b/app/Http/Controllers/Api/BalanceController.php index f12066e..38cc7d7 100644 --- a/app/Http/Controllers/Api/BalanceController.php +++ b/app/Http/Controllers/Api/BalanceController.php @@ -24,7 +24,8 @@ public function index(): JsonResponse /** * Store a newly created resource in storage. * - * @param Request $request + * @param Request $request + * * @return JsonResponse */ public function store(Request $request): JsonResponse @@ -49,7 +50,8 @@ public function store(Request $request): JsonResponse /** * Display the specified resource. * - * @param Balance $balance + * @param Balance $balance + * * @return JsonResponse */ public function show(Balance $balance): JsonResponse diff --git a/app/Http/Controllers/Api/ForumController.php b/app/Http/Controllers/Api/ForumController.php index de7366a..bab931d 100644 --- a/app/Http/Controllers/Api/ForumController.php +++ b/app/Http/Controllers/Api/ForumController.php @@ -4,11 +4,11 @@ use App\Http\Controllers\Controller; use Closure; -use function config; use Illuminate\Http\Client\PendingRequest; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; +use function config; class ForumController extends Controller { @@ -19,12 +19,21 @@ class ForumController extends Controller public function __construct() { $this->baseUrl = config('settings.forum.base_url'); - $this->http = Http::baseUrl($this->baseUrl.'/api')->throw(); + $this->http = Http::baseUrl($this->baseUrl . '/api')->throw(); + } + + public function tag($tag): JsonResponse + { + $resp = $this->cache($tag, function () use ($tag) { + return $this->get('discussions?filter[tag]=' . $tag . '&page[offset]=0&sort=-createdAt'); + }); + + return $this->resp($resp); } public function cache($tag, Closure $callback) { - return Cache::remember('forum.tag:'.$tag, 60, function () use ($callback) { + return Cache::remember('forum.tag:' . $tag, 60, function () use ($callback) { return $callback(); }); } @@ -40,13 +49,4 @@ public function resp($data): JsonResponse return $this->success($data); } - - public function tag($tag): JsonResponse - { - $resp = $this->cache($tag, function () use ($tag) { - return $this->get('discussions?filter[tag]='.$tag.'&page[offset]=0&sort=-createdAt'); - }); - - return $this->resp($resp); - } } diff --git a/app/Http/Controllers/Api/HostController.php b/app/Http/Controllers/Api/HostController.php index 2b968e0..d072b24 100644 --- a/app/Http/Controllers/Api/HostController.php +++ b/app/Http/Controllers/Api/HostController.php @@ -6,10 +6,10 @@ use App\Http\Requests\User\HostRequest; use App\Jobs\Host\HostJob; use App\Models\Host; -use function auth; -use function dispatch; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Cache; +use function auth; +use function dispatch; use function now; class HostController extends Controller @@ -37,7 +37,7 @@ public function update(HostRequest $request, Host $host): JsonResponse $user = $request->user(); if ($user->balance < 0.5) { - return $this->error('余额不足,无法开启计费项目。请确保您的余额至少为 0.5 元,您当前有 '.$user->balance.' 元。'); + return $this->error('余额不足,无法开启计费项目。请确保您的余额至少为 0.5 元,您当前有 ' . $user->balance . ' 元。'); } $host->update([ @@ -74,7 +74,7 @@ public function usages(): JsonResponse { $month = now()->month; - $month_cache_key = 'user_'.auth()->id().'_month_'.$month.'_hosts_balances'; + $month_cache_key = 'user_' . auth()->id() . '_month_' . $month . '_hosts_balances'; $hosts_balances = Cache::get($month_cache_key, []); return $this->success([ diff --git a/app/Http/Controllers/Api/ModuleController.php b/app/Http/Controllers/Api/ModuleController.php index 331bc51..3ab62a3 100644 --- a/app/Http/Controllers/Api/ModuleController.php +++ b/app/Http/Controllers/Api/ModuleController.php @@ -20,7 +20,7 @@ public function index(): JsonResponse public function servers(Module $module): JsonResponse { - $servers = Cache::get('module:'.$module->id.':servers', []); + $servers = Cache::get('module:' . $module->id . ':servers', []); return $this->success($servers); } diff --git a/app/Http/Controllers/Api/ReplyController.php b/app/Http/Controllers/Api/ReplyController.php index 04ef71d..83874da 100644 --- a/app/Http/Controllers/Api/ReplyController.php +++ b/app/Http/Controllers/Api/ReplyController.php @@ -5,16 +5,17 @@ use App\Http\Controllers\Controller; use App\Models\WorkOrder\Reply; use App\Models\WorkOrder\WorkOrder; -use function auth; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use function auth; class ReplyController extends Controller { /** * Display a listing of the resource. * - * @param WorkOrder $workOrder + * @param WorkOrder $workOrder + * * @return JsonResponse */ public function index(WorkOrder $workOrder): JsonResponse @@ -27,8 +28,9 @@ public function index(WorkOrder $workOrder): JsonResponse /** * Store a newly created resource in storage. * - * @param Request $request - * @param WorkOrder $workOrder + * @param Request $request + * @param WorkOrder $workOrder + * * @return JsonResponse */ public function store(Request $request, WorkOrder $workOrder): JsonResponse @@ -42,7 +44,7 @@ public function store(Request $request, WorkOrder $workOrder): JsonResponse } // 如果工单已经关闭,那么访客不能回复 - if ($workOrder->isClosed() && ! auth('sanctum')->check()) { + if ($workOrder->isClosed() && !auth('sanctum')->check()) { return $this->error('工单已关闭,无法进行回复。'); } diff --git a/app/Http/Controllers/Api/WorkOrderController.php b/app/Http/Controllers/Api/WorkOrderController.php index b1755e9..c5c5a56 100644 --- a/app/Http/Controllers/Api/WorkOrderController.php +++ b/app/Http/Controllers/Api/WorkOrderController.php @@ -59,7 +59,7 @@ public function update(Request $request, WorkOrder $workOrder): JsonResponse ]); // 访客不能关闭 - if ($request->input('status') === 'closed' && ! auth('sanctum')->check()) { + if ($request->input('status') === 'closed' && !auth('sanctum')->check()) { return $this->forbidden('访客不能修改工单状态。'); } diff --git a/app/Http/Controllers/Application/MqttAuthController.php b/app/Http/Controllers/Application/MqttAuthController.php index acfdff9..180b896 100644 --- a/app/Http/Controllers/Application/MqttAuthController.php +++ b/app/Http/Controllers/Application/MqttAuthController.php @@ -24,7 +24,7 @@ public function authentication(Request $request): Response $module = (new Module)->where('id', $module_id)->first(); - if (! $module) { + if (!$module) { return $this->ignore(); } @@ -33,7 +33,7 @@ public function authentication(Request $request): Response } // 如果没有设置 device_id,那么就是模块自己的连接 - if (! $device_id) { + if (!$device_id) { // 让 api_token 可见 $module->makeVisible('api_token'); @@ -118,7 +118,7 @@ public function authorization(Request $request): Response $module = (new Module)->where('id', $module_id)->first(); - if (! $module) { + if (!$module) { // 不属于我们管理,跳过。 return $this->ignore(); } @@ -129,7 +129,7 @@ public function authorization(Request $request): Response // 但是,在拒绝之前,应该检查一下,是否有允许的模块 $allow = (new ModuleAllow)->where('module_id', $topics[0])->where('allowed_module_id', $module_id)->exists(); - if (! $allow) { + if (!$allow) { return $this->deny(); } } diff --git a/app/Http/Controllers/Module/AuthRequestController.php b/app/Http/Controllers/Module/AuthRequestController.php index 7c61e89..4d5bd71 100644 --- a/app/Http/Controllers/Module/AuthRequestController.php +++ b/app/Http/Controllers/Module/AuthRequestController.php @@ -24,7 +24,7 @@ public function store(Request $request): JsonResponse 'module' => $request->user('module')->toArray(), ]; - Cache::put('auth_request:'.$token, $data, 120); + Cache::put('auth_request:' . $token, $data, 120); $data['url'] = route('auth_request.show', $token); @@ -33,13 +33,13 @@ public function store(Request $request): JsonResponse public function show($token): JsonResponse { - $data = Cache::get('auth_request:'.$token); + $data = Cache::get('auth_request:' . $token); if (empty($data)) { return $this->error('Token 不存在或已过期。'); } - if (! isset($data['user'])) { + if (!isset($data['user'])) { $data['user'] = null; } diff --git a/app/Http/Controllers/Module/DeviceController.php b/app/Http/Controllers/Module/DeviceController.php index cc7fcb2..025b128 100644 --- a/app/Http/Controllers/Module/DeviceController.php +++ b/app/Http/Controllers/Module/DeviceController.php @@ -18,7 +18,7 @@ public function index(Request $request): JsonResponse try { $clients = $emqx->pagination([ - 'like_username' => $request->user('module')->id.'.', + 'like_username' => $request->user('module')->id . '.', ]); } catch (EmqxSupportException $e) { Log::error('emqx connect failed.', [$e]); diff --git a/app/Http/Controllers/Module/HostController.php b/app/Http/Controllers/Module/HostController.php index ce13d79..71095ff 100644 --- a/app/Http/Controllers/Module/HostController.php +++ b/app/Http/Controllers/Module/HostController.php @@ -5,13 +5,13 @@ use App\Http\Controllers\Controller; use App\Models\Host; use App\Models\User; -use function auth; use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Str; use Illuminate\Validation\ValidationException; +use function auth; // use App\Models\User; @@ -28,7 +28,8 @@ public function index(Request $request): Paginator /** * Store a newly created resource in storage. * - * @param Request $request + * @param Request $request + * * @return Response|JsonResponse * * @throws ValidationException @@ -72,7 +73,8 @@ public function store(Request $request): Response|JsonResponse /** * Display the specified resource. * - * @param Host $host + * @param Host $host + * * @return JsonResponse */ public function show(Host $host): JsonResponse @@ -86,8 +88,9 @@ public function show(Host $host): JsonResponse /** * Update the specified resource in storage. * - * @param Request $request - * @param Host $host + * @param Request $request + * @param Host $host + * * @return JsonResponse * * @throws ValidationException @@ -121,12 +124,13 @@ public function update(Request $request, Host $host): JsonResponse * Remove the specified resource from storage. * * @param $host + * * @return JsonResponse */ public function destroy($host): JsonResponse { // if host not instance of HostJob - if (! $host instanceof Host) { + if (!$host instanceof Host) { $host = (new Host)->findOrFail($host); } diff --git a/app/Http/Controllers/Module/ReplyController.php b/app/Http/Controllers/Module/ReplyController.php index acb8a51..f6dd507 100644 --- a/app/Http/Controllers/Module/ReplyController.php +++ b/app/Http/Controllers/Module/ReplyController.php @@ -13,7 +13,8 @@ class ReplyController extends Controller /** * Display a listing of the resource. * - * @param Request $request + * @param Request $request + * * @return JsonResponse */ public function index(Request $request): JsonResponse diff --git a/app/Http/Controllers/Module/TaskController.php b/app/Http/Controllers/Module/TaskController.php index d46dd67..2050f7e 100644 --- a/app/Http/Controllers/Module/TaskController.php +++ b/app/Http/Controllers/Module/TaskController.php @@ -17,7 +17,8 @@ class TaskController extends Controller /** * Display a listing of the resource. * - * @param Request $request + * @param Request $request + * * @return JsonResponse */ public function index(Request $request): JsonResponse @@ -30,7 +31,8 @@ public function index(Request $request): JsonResponse /** * Store a newly created resource in storage. * - * @param Request $request + * @param Request $request + * * @return JsonResponse * * @throws ValidationException @@ -52,8 +54,9 @@ public function store(Request $request): JsonResponse /** * Update the specified resource in storage. * - * @param Request $request - * @param Task $task + * @param Request $request + * @param Task $task + * * @return JsonResponse * * @throws ValidationException diff --git a/app/Http/Controllers/Module/UserController.php b/app/Http/Controllers/Module/UserController.php index ab277ee..a983c6f 100644 --- a/app/Http/Controllers/Module/UserController.php +++ b/app/Http/Controllers/Module/UserController.php @@ -24,15 +24,15 @@ public function index(Request $request): JsonResponse // 搜索 name, email, balance if ($request->has('name')) { - $users->where('name', 'like', '%'.$request->input('name').'%'); + $users->where('name', 'like', '%' . $request->input('name') . '%'); } if ($request->has('email')) { - $users->where('email', 'like', '%'.$request->input('email').'%'); + $users->where('email', 'like', '%' . $request->input('email') . '%'); } if ($request->has('balance')) { - $users->where('balance', 'like', '%'.$request->input('balance').'%'); + $users->where('balance', 'like', '%' . $request->input('balance') . '%'); } $users = $users->simplePaginate(100); diff --git a/app/Http/Controllers/Public/RealNameController.php b/app/Http/Controllers/Public/RealNameController.php index 8bc641d..3e314e2 100644 --- a/app/Http/Controllers/Public/RealNameController.php +++ b/app/Http/Controllers/Public/RealNameController.php @@ -17,7 +17,7 @@ public function verify(Request $request): JsonResponse { $result = (new RealNameSupport())->verify($request->all()); - if (! $result) { + if (!$result) { Log::warning('实名认证失败', $request->all()); return $this->error('实名认证失败。'); @@ -28,7 +28,7 @@ public function verify(Request $request): JsonResponse $user->id_card = $result['id_card']; $user->save(); - $user->reduce((string) config('settings.supports.real_name.price'), '实名认证费用。'); + $user->reduce((string)config('settings.supports.real_name.price'), '实名认证费用。'); $user->notify(new UserNotification('再次欢迎您!', '再次欢迎您!您的实人认证已通过。', true)); diff --git a/app/Http/Controllers/Web/Auth/RegisterController.php b/app/Http/Controllers/Web/Auth/RegisterController.php index b1b5fec..3826b37 100644 --- a/app/Http/Controllers/Web/Auth/RegisterController.php +++ b/app/Http/Controllers/Web/Auth/RegisterController.php @@ -44,7 +44,8 @@ public function __construct() /** * Get a validator for an incoming registration request. * - * @param array $data + * @param array $data + * * @return \Illuminate\Contracts\Validation\Validator */ protected function validator(array $data): \Illuminate\Contracts\Validation\Validator @@ -59,7 +60,8 @@ protected function validator(array $data): \Illuminate\Contracts\Validation\Vali /** * Create a new user instance after a valid registration. * - * @param array $data + * @param array $data + * * @return User */ protected function create(array $data): User diff --git a/app/Http/Controllers/Web/AuthController.php b/app/Http/Controllers/Web/AuthController.php index 5ad85e7..5a36309 100644 --- a/app/Http/Controllers/Web/AuthController.php +++ b/app/Http/Controllers/Web/AuthController.php @@ -6,13 +6,13 @@ use App\Http\Controllers\Controller; use App\Notifications\User\UserNotification; -use function back; -use function config; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cache; use Illuminate\View\View; +use function back; +use function config; use function redirect; use function session; use function view; @@ -32,13 +32,13 @@ public function index(Request $request): View|RedirectResponse $dashboardHost = parse_url(config('settings.dashboard.base_url'), PHP_URL_HOST); if ($callbackHost === $dashboardHost) { - if (! Auth::guard('web')->user()->isRealNamed()) { + if (!Auth::guard('web')->user()->isRealNamed()) { return redirect()->route('real_name.create')->with('status', '重定向已被打断,需要先实人认证。'); } $token = $request->user()->createToken('Dashboard')->plainTextToken; - return redirect($callback.'?token='.$token); + return redirect($callback . '?token=' . $token); } return redirect()->route('confirm_redirect'); @@ -111,7 +111,7 @@ public function exitSudo(): RedirectResponse public function showAuthRequest($token): View|RedirectResponse { - $data = Cache::get('auth_request:'.$token); + $data = Cache::get('auth_request:' . $token); if (empty($data)) { return redirect()->route('index')->with('error', '登录请求的 Token 不存在或已过期。'); @@ -135,7 +135,7 @@ public function storeAuthRequest(Request $request): RedirectResponse 'token' => 'required|string|max:128', ]); - $data = Cache::get('auth_request:'.$request->input('token')); + $data = Cache::get('auth_request:' . $request->input('token')); if (empty($data)) { return back()->with('error', '登录请求的 Token 不存在或已过期。'); @@ -147,7 +147,7 @@ public function storeAuthRequest(Request $request): RedirectResponse $data['user'] = $request->user('web'); - Cache::put('auth_request:'.$request->input('token'), $data, 60); + Cache::put('auth_request:' . $request->input('token'), $data, 60); return redirect()->route('index')->with('success', '登录请求已确认。'); } diff --git a/app/Http/Controllers/Web/BalanceController.php b/app/Http/Controllers/Web/BalanceController.php index 7c13564..2551a1f 100644 --- a/app/Http/Controllers/Web/BalanceController.php +++ b/app/Http/Controllers/Web/BalanceController.php @@ -72,7 +72,7 @@ public function show(Request $request, Balance $balance): RedirectResponse|JsonR $balance->load('user'); - $subject = config('app.display_name').' 充值'; + $subject = config('app.display_name') . ' 充值'; $order = [ 'out_trade_no' => $balance->order_id, @@ -90,10 +90,10 @@ public function show(Request $request, Balance $balance): RedirectResponse|JsonR $pay = Pay::alipay()->web($order); - return view('balances.alipay', ['html' => (string) $pay->getBody()]); + return view('balances.alipay', ['html' => (string)$pay->getBody()]); } - if (! isset($qr_code)) { + if (!isset($qr_code)) { return redirect()->route('index')->with('error', '支付方式错误。'); } @@ -127,7 +127,7 @@ private function xunhu_wechat( $response = Http::post(config('pay.xunhu.gateway'), $data); - if (! $response->successful()) { + if (!$response->successful()) { return redirect()->route('index')->with('error', '支付网关错误。'); } @@ -135,7 +135,7 @@ private function xunhu_wechat( $hash = $this->xunhu_hash($response); - if (! isset($response['hash']) || $response['hash'] !== $hash) { + if (!isset($response['hash']) || $response['hash'] !== $hash) { return redirect()->route('index')->with('error', '无法校验支付网关返回数据。'); } @@ -169,7 +169,7 @@ private function xunhu_hash( } } - return md5($arg.config('pay.xunhu.app_secret')); + return md5($arg . config('pay.xunhu.app_secret')); } /** @@ -182,7 +182,7 @@ public function notify( if ($payment === 'alipay') { $out_trade_no = $request->input('out_trade_no'); - } elseif ($payment === 'wechat') { + } else if ($payment === 'wechat') { $out_trade_no = $request->input('trade_order_id'); } else { abort(400, '支付方式错误'); @@ -190,7 +190,7 @@ public function notify( // 检测订单是否存在 $balance = (new Balance)->where('order_id', $out_trade_no)->with('user')->first(); - if (! $balance) { + if (!$balance) { abort(404, '找不到订单。'); } @@ -205,7 +205,7 @@ public function notify( // 处理验证 if ($payment === 'wechat') { - if (! ($request->filled('hash') || $request->filled('trade_order_id'))) { + if (!($request->filled('hash') || $request->filled('trade_order_id'))) { return $this->error('参数错误。'); } @@ -240,7 +240,8 @@ public function notify( /** * 获取交易记录 * - * @param mixed $request + * @param mixed $request + * * @return View */ public function transactions( diff --git a/app/Http/Controllers/Web/RealNameController.php b/app/Http/Controllers/Web/RealNameController.php index dfc9dd4..66029a5 100644 --- a/app/Http/Controllers/Web/RealNameController.php +++ b/app/Http/Controllers/Web/RealNameController.php @@ -25,7 +25,7 @@ public function store(Request $request): RedirectResponse $birthday = $realNameSupport->getBirthday($request->input('id_card')); // 检查年龄是否在区间内 settings.supports.real_name.min_age ~ settings.supports.real_name.max_age if (Carbon::now()->diffInYears($birthday) < config('settings.supports.real_name.min_age') || Carbon::now()->diffInYears($birthday) > config('settings.supports.real_name.max_age')) { - $message = '至少需要 '.config('settings.supports.real_name.min_age').' 岁,最大 '.config('settings.supports.real_name.max_age').' 岁。'; + $message = '至少需要 ' . config('settings.supports.real_name.min_age') . ' 岁,最大 ' . config('settings.supports.real_name.max_age') . ' 岁。'; return back()->with('error', $message); } @@ -47,14 +47,14 @@ public function store(Request $request): RedirectResponse } // 标记用户正在实名,缓存 600s - if (Cache::has('real_name:user:'.$user->id)) { + if (Cache::has('real_name:user:' . $user->id)) { // 获取缓存 - $output = Cache::get('real_name:user:'.$user->id); + $output = Cache::get('real_name:user:' . $user->id); return back()->with('error', '因为您有一个正在进行的实名认证,请等待 10 分钟后重试。')->with('output', $output); } - Cache::set('real_name:user:'.$user->id, $output, 600); + Cache::set('real_name:user:' . $user->id, $output, 600); return redirect($output); } diff --git a/app/Http/Controllers/Web/TransferController.php b/app/Http/Controllers/Web/TransferController.php index 1858031..ededd0b 100644 --- a/app/Http/Controllers/Web/TransferController.php +++ b/app/Http/Controllers/Web/TransferController.php @@ -26,7 +26,7 @@ public function transfer(Request $request): RedirectResponse ]); $to = (new User)->where('email', $request->input('to'))->first(); - if (! $to) { + if (!$to) { return back()->withErrors(['to' => '找不到用户。']); } diff --git a/app/Http/Middleware/AddHeaders.php b/app/Http/Middleware/AddHeaders.php index 782a723..d074643 100644 --- a/app/Http/Middleware/AddHeaders.php +++ b/app/Http/Middleware/AddHeaders.php @@ -11,8 +11,9 @@ class AddHeaders /** * Handle an incoming request. * - * @param Request $request - * @param Closure $next + * @param Request $request + * @param Closure $next + * * @return mixed */ public function handle(Request $request, Closure $next): mixed diff --git a/app/Http/Middleware/Admin/ValidateReferer.php b/app/Http/Middleware/Admin/ValidateReferer.php index 95274b5..58925f3 100644 --- a/app/Http/Middleware/Admin/ValidateReferer.php +++ b/app/Http/Middleware/Admin/ValidateReferer.php @@ -13,14 +13,15 @@ class ValidateReferer /** * Handle an incoming request. * - * @param Request $request + * @param Request $request * @param Closure(Request): (Response|RedirectResponse) $next + * * @return Response|RedirectResponse */ public function handle(Request $request, Closure $next): Response|RedirectResponse { // 如果 referer 不为空,且不是来自本站的请求,则返回 403 - if ($request->headers->get('referer') && ! Str::contains($request->headers->get('referer'), config('app.url'))) { + if ($request->headers->get('referer') && !Str::contains($request->headers->get('referer'), config('app.url'))) { abort(403, '来源不属于后台。'); } else { return $next($request); diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index fc29120..063a8b4 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -10,12 +10,13 @@ class Authenticate extends Middleware /** * Get the path the user should be redirected to when they are not authenticated. * - * @param Request $request + * @param Request $request + * * @return string|null */ protected function redirectTo($request): ?string { - if (! $request->expectsJson()) { + if (!$request->expectsJson()) { return route('index'); } diff --git a/app/Http/Middleware/JsonResponse.php b/app/Http/Middleware/JsonResponse.php index db44490..8fb6a0f 100644 --- a/app/Http/Middleware/JsonResponse.php +++ b/app/Http/Middleware/JsonResponse.php @@ -12,8 +12,9 @@ class JsonResponse /** * Handle an incoming request. * - * @param Request $request + * @param Request $request * @param Closure(Request): (Response|RedirectResponse) $next + * * @return Response|RedirectResponse|\Illuminate\Http\JsonResponse */ public function handle(Request $request, Closure $next): Response|\Illuminate\Http\JsonResponse|RedirectResponse diff --git a/app/Http/Middleware/RealNamed.php b/app/Http/Middleware/RealNamed.php index 2537ef4..1e70c41 100644 --- a/app/Http/Middleware/RealNamed.php +++ b/app/Http/Middleware/RealNamed.php @@ -16,9 +16,10 @@ class RealNamed /** * Handle an incoming request. * - * @param Request $request - * @param Closure $next - * @param string $guard + * @param Request $request + * @param Closure $next + * @param string $guard + * * @return Response|RedirectResponse|JsonResponse */ public function handle(Request $request, Closure $next, string $guard = 'web'): Response|RedirectResponse|JsonResponse diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index c46cda0..bfd69dd 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -14,9 +14,10 @@ class RedirectIfAuthenticated /** * Handle an incoming request. * - * @param Request $request + * @param Request $request * @param Closure(Request): (Response|RedirectResponse) $next - * @param string|null ...$guards + * @param string|null ...$guards + * * @return Response|RedirectResponse */ public function handle(Request $request, Closure $next, ...$guards): Response|RedirectResponse diff --git a/app/Http/Middleware/ValidateUserIfBanned.php b/app/Http/Middleware/ValidateUserIfBanned.php index 30ceaa0..f861f31 100644 --- a/app/Http/Middleware/ValidateUserIfBanned.php +++ b/app/Http/Middleware/ValidateUserIfBanned.php @@ -13,8 +13,9 @@ class ValidateUserIfBanned /** * Handle an incoming request. * - * @param Request $request - * @param Closure $next + * @param Request $request + * @param Closure $next + * * @return Response|RedirectResponse|JsonResponse */ public function handle(Request $request, Closure $next): Response|RedirectResponse|JsonResponse diff --git a/app/Http/Requests/BaseRequest.php b/app/Http/Requests/BaseRequest.php index 7127829..0f44362 100644 --- a/app/Http/Requests/BaseRequest.php +++ b/app/Http/Requests/BaseRequest.php @@ -13,10 +13,10 @@ class BaseRequest extends HttpRequest public function json($key = null, $default = null) { - if (! isset($this->json)) { + if (!isset($this->json)) { $content = $this->getContent(); - $parameters = Str::length($content) > static::JSON_MAX_LENGTH ? [] : (array) json_decode($content, true); + $parameters = Str::length($content) > static::JSON_MAX_LENGTH ? [] : (array)json_decode($content, true); $this->json = new ParameterBag($parameters); } diff --git a/app/Http/Requests/User/HostRequest.php b/app/Http/Requests/User/HostRequest.php index fe5f3ce..714cfe7 100644 --- a/app/Http/Requests/User/HostRequest.php +++ b/app/Http/Requests/User/HostRequest.php @@ -16,7 +16,7 @@ public function authorize(): bool { $host = $this->route('host'); - if (! ($host instanceof Host)) { + if (!($host instanceof Host)) { $host = (new Host)->where('id', $host)->first(); } diff --git a/app/Jobs/Host/HostJob.php b/app/Jobs/Host/HostJob.php index ec457b2..52765b9 100644 --- a/app/Jobs/Host/HostJob.php +++ b/app/Jobs/Host/HostJob.php @@ -42,7 +42,7 @@ public function __construct(HostModel $host, $type = 'post', $pass_unavailable = */ public function handle(): void { - if (! isset($this->host)) { + if (!isset($this->host)) { return; } @@ -66,7 +66,7 @@ public function handle(): void switch ($this->type) { case 'patch': - $response = $host->module->http()->patch('hosts/'.$host->id, $host->toArray()); + $response = $host->module->http()->patch('hosts/' . $host->id, $host->toArray()); break; case 'post': @@ -74,7 +74,7 @@ public function handle(): void break; case 'delete': - $response = $host->module->baseRequest('delete', 'hosts/'.$host->id); + $response = $host->module->baseRequest('delete', 'hosts/' . $host->id); // if successful if ($response['status'] === 404) { @@ -85,7 +85,7 @@ public function handle(): void } if ($this->type !== 'delete') { - if (! $response->successful()) { + if (!$response->successful()) { $host->status = 'error'; } diff --git a/app/Jobs/Host/PushHostJob.php b/app/Jobs/Host/PushHostJob.php index 03cf9e4..e4c3874 100644 --- a/app/Jobs/Host/PushHostJob.php +++ b/app/Jobs/Host/PushHostJob.php @@ -38,7 +38,7 @@ public function handle(): void $response = $host->module->http()->post('hosts', $host->toArray()); - if (! $response->successful()) { + if (!$response->successful()) { $host->status = 'error'; } diff --git a/app/Jobs/Host/RealHostCostJob.php b/app/Jobs/Host/RealHostCostJob.php index a68bd55..ccec366 100644 --- a/app/Jobs/Host/RealHostCostJob.php +++ b/app/Jobs/Host/RealHostCostJob.php @@ -20,8 +20,8 @@ class RealHostCostJob implements ShouldQueue /** * Create a new job instance. * - * @param Host $host - * @param string $price + * @param Host $host + * @param string $price */ public function __construct(Host $host, string $price) { diff --git a/app/Jobs/Host/UpdateOrDeleteHostJob.php b/app/Jobs/Host/UpdateOrDeleteHostJob.php index b141545..03230e2 100644 --- a/app/Jobs/Host/UpdateOrDeleteHostJob.php +++ b/app/Jobs/Host/UpdateOrDeleteHostJob.php @@ -36,14 +36,14 @@ public function handle(): void { $host = $this->host; - $response = $host->module->baseRequest('get', 'hosts/'.$host->id); + $response = $host->module->baseRequest('get', 'hosts/' . $host->id); if ($response['status'] === 200) { - Log::debug($host->module->name.' '.$host->name.' '.$host->id.' 更新成功。', $response['json']); + Log::debug($host->module->name . ' ' . $host->name . ' ' . $host->id . ' 更新成功。', $response['json']); $host->update(Arr::except($response['json'], ['id', 'user_id', 'module_id', 'created_at', 'updated_at'])); - } elseif ($response['status'] === 404) { + } else if ($response['status'] === 404) { if ($host->status !== 'unavailable') { - Log::warning($host->module->name.' '.$host->name.' '.$host->id.' 不存在,标记为不可用。'); + Log::warning($host->module->name . ' ' . $host->name . ' ' . $host->id . ' 不存在,标记为不可用。'); $host->status = 'unavailable'; $host->save(); } diff --git a/app/Jobs/Module/SendModuleEarningsJob.php b/app/Jobs/Module/SendModuleEarningsJob.php index 066f8ad..383b203 100644 --- a/app/Jobs/Module/SendModuleEarningsJob.php +++ b/app/Jobs/Module/SendModuleEarningsJob.php @@ -37,7 +37,7 @@ private function send(Module $module): void { $data = $module->calculate(); - if (! $data) { + if (!$data) { return; } @@ -68,7 +68,7 @@ private function send(Module $module): void } } - $resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='.$wecom_key, [ + $resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $wecom_key, [ 'msgtype' => 'markdown', 'markdown' => [ 'content' => $text, diff --git a/app/Jobs/Support/EMQXKickClientJob.php b/app/Jobs/Support/EMQXKickClientJob.php index 70fcd4c..8e70db9 100644 --- a/app/Jobs/Support/EMQXKickClientJob.php +++ b/app/Jobs/Support/EMQXKickClientJob.php @@ -43,7 +43,7 @@ public function handle(): void $emqx = new EmqxSupport(); if ($this->client_id) { - $emqx->api()->delete('/clients/'.$this->client_id); + $emqx->api()->delete('/clients/' . $this->client_id); } if ($this->username) { diff --git a/app/Jobs/User/CheckAndChargeBalanceJob.php b/app/Jobs/User/CheckAndChargeBalanceJob.php index b90da98..d12684b 100644 --- a/app/Jobs/User/CheckAndChargeBalanceJob.php +++ b/app/Jobs/User/CheckAndChargeBalanceJob.php @@ -31,7 +31,7 @@ public function handle(): void { (new Balance)->where('paid_at', null)->chunk(100, function ($balances) { foreach ($balances as $balance) { - if (! $this->checkAndCharge($balance, true)) { + if (!$this->checkAndCharge($balance, true)) { if (now()->diffInDays($balance->created_at) > 1) { $balance->delete(); } diff --git a/app/Jobs/User/SetBirthdayGroupJob.php b/app/Jobs/User/SetBirthdayGroupJob.php index 7050f0a..c7a5715 100644 --- a/app/Jobs/User/SetBirthdayGroupJob.php +++ b/app/Jobs/User/SetBirthdayGroupJob.php @@ -34,7 +34,7 @@ public function handle(): void { $birthday_group = (new UserGroup)->find(config('settings.user_groups.birthday_group_id')); - if (! $birthday_group) { + if (!$birthday_group) { return; } diff --git a/app/Jobs/WorkOrder/PushWorkOrderJob.php b/app/Jobs/WorkOrder/PushWorkOrderJob.php index 271e158..aa6a859 100644 --- a/app/Jobs/WorkOrder/PushWorkOrderJob.php +++ b/app/Jobs/WorkOrder/PushWorkOrderJob.php @@ -57,7 +57,7 @@ public function handle(): void try { $response = $workOrder->module->http()->retry(3, 100)->post('work-orders', $workOrder->toArray()); - if (! $response->successful()) { + if (!$response->successful()) { Log::warning('推送工单失败', [ 'work_order_id' => $workOrder->id, 'response' => $response->body(), @@ -69,7 +69,7 @@ public function handle(): void Log::warning($e->getMessage()); } - if (! $success) { + if (!$success) { $workOrder->status = 'error'; } diff --git a/app/Jobs/WorkOrder/Reply.php b/app/Jobs/WorkOrder/Reply.php index f946997..052bf91 100644 --- a/app/Jobs/WorkOrder/Reply.php +++ b/app/Jobs/WorkOrder/Reply.php @@ -47,7 +47,7 @@ public function handle(): void $reply = $this->reply->toArray(); if ($this->type == 'post') { - $response = $this->reply->workOrder->module->http()->post('work-orders/'.$this->reply->workOrder->id.'/replies', $reply); + $response = $this->reply->workOrder->module->http()->post('work-orders/' . $this->reply->workOrder->id . '/replies', $reply); if ($response->successful()) { $this->reply->update([ @@ -58,7 +58,7 @@ public function handle(): void 'is_pending' => true, ]); } - } elseif ($this->type == 'patch') { + } else if ($this->type == 'patch') { // 不更新 is_pending if ($this->reply->workOrder->isPlatform()) { $this->reply->update([ @@ -68,9 +68,9 @@ public function handle(): void return; } - $this->reply->workOrder->module->http()->patch('work-orders/'.$this->reply->workOrder->id.'/replies/'.$this->reply->id, $reply); - } elseif ($this->type == 'delete') { - $response = $this->reply->workOrder->module->http()->delete('work-orders/'.$this->reply->workOrder->id.'/replies/'.$this->reply->id); + $this->reply->workOrder->module->http()->patch('work-orders/' . $this->reply->workOrder->id . '/replies/' . $this->reply->id, $reply); + } else if ($this->type == 'delete') { + $response = $this->reply->workOrder->module->http()->delete('work-orders/' . $this->reply->workOrder->id . '/replies/' . $this->reply->id); if ($response->successful()) { $this->reply->delete(); diff --git a/app/Jobs/WorkOrder/WorkOrder.php b/app/Jobs/WorkOrder/WorkOrder.php index 3f58e16..722b513 100644 --- a/app/Jobs/WorkOrder/WorkOrder.php +++ b/app/Jobs/WorkOrder/WorkOrder.php @@ -47,17 +47,17 @@ public function handle(): void if ($this->type == 'post') { $response = $this->workOrder->module->http()->post('work-orders', $this->workOrder->toArray()); - } elseif ($this->type == 'put') { - $response = $this->workOrder->module->http()->put('work-orders/'.$this->workOrder->id, $this->workOrder->toArray()); + } else if ($this->type == 'put') { + $response = $this->workOrder->module->http()->put('work-orders/' . $this->workOrder->id, $this->workOrder->toArray()); } else { - $response = $this->workOrder->module->http()->delete('work-orders/'.$this->workOrder->id); + $response = $this->workOrder->module->http()->delete('work-orders/' . $this->workOrder->id); if ($response->successful()) { $this->workOrder->delete(); } } - if (! $response->successful()) { + if (!$response->successful()) { Log::debug('WorkOrder push failed', [ 'type' => $this->type, 'response' => $response->json(), diff --git a/app/Models/Balance.php b/app/Models/Balance.php index 06d8298..ee67711 100644 --- a/app/Models/Balance.php +++ b/app/Models/Balance.php @@ -4,11 +4,11 @@ use App\Events\Users; use App\Notifications\User\UserCharged; -use function auth; use GeneaLabs\LaravelModelCaching\Traits\Cachable; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToAlias; use Illuminate\Notifications\Notifiable; +use function auth; class Balance extends Model { @@ -36,7 +36,7 @@ protected static function boot() // $balance->remaining_amount = $balance->amount; $balance->remaining_amount = 0; - $balance->order_id = date('YmdHis').$balance->id.rand(1000, 9999); + $balance->order_id = date('YmdHis') . $balance->id . rand(1000, 9999); }); static::created(function (self $balance) { @@ -67,7 +67,7 @@ public function scopeThisUser($query) public function canPay(): bool { - return ! $this->isPaid() && ! $this->isOverdue(); + return !$this->isPaid() && !$this->isOverdue(); } public function isPaid(): bool @@ -77,6 +77,6 @@ public function isPaid(): bool public function isOverdue(): bool { - return $this->created_at->diffInDays(now()) > 1 && ! $this->isPaid(); + return $this->created_at->diffInDays(now()) > 1 && !$this->isPaid(); } } diff --git a/app/Models/Host.php b/app/Models/Host.php index cced7d2..c4aab17 100644 --- a/app/Models/Host.php +++ b/app/Models/Host.php @@ -102,13 +102,13 @@ protected static function boot() // }); static::deleting(function ($model) { - Cache::forget('user_tasks_'.$model->user_id); + Cache::forget('user_tasks_' . $model->user_id); }); static::deleted(function ($model) { broadcast(new Users($model->user_id, 'hosts.deleted', $model)); - Cache::forget('user_tasks_'.$model->user_id); - Cache::forget('user_hosts_'.$model->user_id); + Cache::forget('user_tasks_' . $model->user_id); + Cache::forget('user_hosts_' . $model->user_id); }); } @@ -184,7 +184,7 @@ public function cost(string $amount = null, $auto = true): bool $real_price = $amount ?? $this->price; - if (! $amount) { + if (!$amount) { if ($this->managed_price) { $real_price = $this->managed_price; } @@ -195,7 +195,7 @@ public function cost(string $amount = null, $auto = true): bool if ($user_group->discount !== 100 && $user_group->discount !== null) { $real_price = bcmul($real_price, bcdiv($user_group->discount, '100', 4), 4); - $append_description = ' (折扣 '.$user_group->discount.'%)'; + $append_description = ' (折扣 ' . $user_group->discount . '%)'; } } @@ -223,7 +223,7 @@ public function cost(string $amount = null, $auto = true): bool $month = now()->month; - $month_cache_key = 'user_'.$this->user_id.'_month_'.$month.'_hosts_balances'; + $month_cache_key = 'user_' . $this->user_id . '_month_' . $month . '_hosts_balances'; $hosts_balances = Cache::get($month_cache_key, []); // 统计 Host 消耗的 Balance @@ -277,7 +277,7 @@ public function addLog(string $amount = '0'): bool $current_month = now()->month; $current_year = now()->year; - $cache_key = 'module_earning_'.$this->module_id; + $cache_key = 'module_earning_' . $this->module_id; // 应支付的提成 $commission = config('settings.billing.commission'); @@ -292,7 +292,7 @@ public function addLog(string $amount = '0'): bool $earnings = Cache::get($cache_key, []); - if (! isset($earnings[$current_year])) { + if (!isset($earnings[$current_year])) { $earnings[$current_year] = []; } diff --git a/app/Models/PersonalAccessToken.php b/app/Models/PersonalAccessToken.php index f1ab141..f75407a 100644 --- a/app/Models/PersonalAccessToken.php +++ b/app/Models/PersonalAccessToken.php @@ -16,14 +16,15 @@ class PersonalAccessToken extends SanctumPersonalAccessToken * the last_used_at column that has changed. It prevents extra DB writes * since we aren't going to use that column for anything. * - * @param array $options + * @param array $options + * * @return bool */ public function save(array $options = []): bool { $changes = $this->getDirty(); // Check for 2 changed values because one is always the updated_at column - if (! array_key_exists('last_used_at', $changes) || count($changes) > 2) { + if (!array_key_exists('last_used_at', $changes) || count($changes) > 2) { parent::save(); } diff --git a/app/Models/Task.php b/app/Models/Task.php index 7366f1a..3540d45 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -4,11 +4,11 @@ use App\Events\Users; use App\Exceptions\CommonException; -use function auth; -use function broadcast; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Ramsey\Uuid\Uuid; +use function auth; +use function broadcast; class Task extends Model { @@ -42,7 +42,7 @@ protected static function boot() } // host_id 和 user_id 至少存在一个 - if (! $model->host_id && ! $model->user_id) { + if (!$model->host_id && !$model->user_id) { throw new CommonException('host_id 和 user_id 至少存在一个'); } diff --git a/app/Models/User.php b/app/Models/User.php index e7cdac7..fde75f3 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -132,11 +132,11 @@ private function getBirthdayFromIdCard(): string $idCard = $this->id_card; $bir = substr($idCard, 6, 8); - $year = (int) substr($bir, 0, 4); - $month = (int) substr($bir, 4, 2); - $day = (int) substr($bir, 6, 2); + $year = (int)substr($bir, 0, 4); + $month = (int)substr($bir, 4, 2); + $day = (int)substr($bir, 6, 2); - return $year.'-'.$month.'-'.$day; + return $year . '-' . $month . '-' . $day; } public function hasBalance(string $amount = '0.01'): bool @@ -198,10 +198,11 @@ public function startTransfer(self $to, string $amount, string|null $description /** * 扣除费用 * - * @param string|null $amount - * @param string $description - * @param bool $fail - * @param array $options + * @param string|null $amount + * @param string $description + * @param bool $fail + * @param array $options + * * @return string */ public function reduce(string|null $amount = '0', string $description = '消费', bool $fail = false, array $options = []): string @@ -210,7 +211,7 @@ public function reduce(string|null $amount = '0', string $description = '消费' return $this->balance; } - Cache::lock('user_balance_'.$this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) { + Cache::lock('user_balance_' . $this->id, 10)->block(10, function () use ($amount, $fail, $description, $options) { $this->refresh(); if ($this->balance < $amount) { @@ -243,10 +244,11 @@ public function reduce(string|null $amount = '0', string $description = '消费' /** * 增加余额 * - * @param string|null $amount - * @param string $payment - * @param string $description - * @param array $options + * @param string|null $amount + * @param string $payment + * @param string $description + * @param array $options + * * @return string */ public function charge(string|null $amount = '0', string $payment = 'console', string $description = '充值', array $options = []): string @@ -255,7 +257,7 @@ public function charge(string|null $amount = '0', string $payment = 'console', s return $this->balance; } - Cache::lock('user_balance_'.$this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) { + Cache::lock('user_balance_' . $this->id, 10)->block(10, function () use ($amount, $description, $payment, $options) { $this->refresh(); $this->balance = bcadd($this->balance, $amount, 4); $this->save(); diff --git a/app/Models/UserGroup.php b/app/Models/UserGroup.php index 9355848..4ffbc83 100644 --- a/app/Models/UserGroup.php +++ b/app/Models/UserGroup.php @@ -32,9 +32,10 @@ public function users(): HasMany /** * 设置临时用户组 * - * @param User $user - * @param UserGroup $group - * @param Carbon $expired_at + * @param User $user + * @param UserGroup $group + * @param Carbon $expired_at + * * @return User */ public function setTempGroup(User $user, self $group, Carbon $expired_at): User diff --git a/app/Models/WorkOrder/Reply.php b/app/Models/WorkOrder/Reply.php index 7d0bc02..a552314 100644 --- a/app/Models/WorkOrder/Reply.php +++ b/app/Models/WorkOrder/Reply.php @@ -49,16 +49,16 @@ protected static function boot() if (auth('admin')->check()) { $model->role = 'admin'; $model->workOrder->status = 'replied'; - } elseif (auth('sanctum')->check()) { + } else if (auth('sanctum')->check()) { $model->user_id = auth('sanctum')->id(); $model->role = 'user'; $model->workOrder->status = 'user_replied'; - } elseif (auth('module')->check()) { + } else if (auth('module')->check()) { $model->user_id = null; $model->role = 'module'; $model->workOrder->status = 'replied'; - // broadcast(new Users($model->user_id, 'work-order.replied', $model->workOrder)); + // broadcast(new Users($model->user_id, 'work-order.replied', $model->workOrder)); } else { $model->role = 'guest'; } diff --git a/app/Models/WorkOrder/WorkOrder.php b/app/Models/WorkOrder/WorkOrder.php index fa7f1c2..b2031db 100644 --- a/app/Models/WorkOrder/WorkOrder.php +++ b/app/Models/WorkOrder/WorkOrder.php @@ -55,12 +55,12 @@ protected static function boot() $model->user_id = auth()->id(); if ($model->host_id) { - if (! $model->user_id == $model->host->user_id) { + if (!$model->user_id == $model->host->user_id) { throw new CommonException('user_id not match host user_id'); } } } else { - if (! $model->user_id) { + if (!$model->user_id) { throw new CommonException('user_id is required'); } } @@ -136,19 +136,9 @@ public function isClosed(): bool return $this->status === 'closed'; } - public function isWaitingForResponse(): bool - { - return $this->status === 'replied' || $this->status === 'user_replied'; - } - - public function isPlatform(): bool - { - return $this->module_id === null && $this->host_id === null; - } - public function markAsRead(): bool { - if (! $this->isWaitingForResponse()) { + if (!$this->isWaitingForResponse()) { return false; } @@ -163,6 +153,11 @@ public function markAsRead(): bool return true; } + public function isWaitingForResponse(): bool + { + return $this->status === 'replied' || $this->status === 'user_replied'; + } + /** * @throws CommonException */ @@ -181,6 +176,11 @@ public function safeDelete(): bool return true; } + public function isPlatform(): bool + { + return $this->module_id === null && $this->host_id === null; + } + public function routeNotificationForMail(): array { $user = $this->user; diff --git a/app/Notifications/Channels/WeComChannel.php b/app/Notifications/Channels/WeComChannel.php index aece92a..fc780e0 100644 --- a/app/Notifications/Channels/WeComChannel.php +++ b/app/Notifications/Channels/WeComChannel.php @@ -14,26 +14,27 @@ class WeComChannel extends Notification /** * Send the given notification. * - * @param mixed $notifiable - * @param Notification $notification + * @param mixed $notifiable + * @param Notification $notification + * * @return void */ public function send(mixed $notifiable, Notification $notification): void { $data = $notification->toWeCom($notifiable); - if (! $data) { + if (!$data) { return; } $view = $data['view']; $key = $data['wecom_key'] ?? null; - if (! $key) { + if (!$key) { $key = config('settings.wecom.robot_hook.default'); } - $resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='.$key, [ + $resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $key, [ 'msgtype' => 'markdown', 'markdown' => [ 'content' => view($view, [ @@ -42,7 +43,7 @@ public function send(mixed $notifiable, Notification $notification): void ], ]); - if (! $resp->successful()) { + if (!$resp->successful()) { Log::error('企业微信机器人发送失败', $data['data']); } } diff --git a/app/Notifications/Channels/WebChannel.php b/app/Notifications/Channels/WebChannel.php index a8fdebf..7ee8a46 100644 --- a/app/Notifications/Channels/WebChannel.php +++ b/app/Notifications/Channels/WebChannel.php @@ -14,15 +14,16 @@ class WebChannel extends Notification /** * Send the given notification. * - * @param mixed $notifiable - * @param Notification $notification + * @param mixed $notifiable + * @param Notification $notification + * * @return void */ public function send(mixed $notifiable, Notification $notification): void { $data = $notification->toArray($notifiable); - if (! $data) { + if (!$data) { return; } diff --git a/app/Notifications/User/TodayIsUserBirthday.php b/app/Notifications/User/TodayIsUserBirthday.php index da9cac2..8f514b9 100644 --- a/app/Notifications/User/TodayIsUserBirthday.php +++ b/app/Notifications/User/TodayIsUserBirthday.php @@ -84,7 +84,7 @@ public function toMail(): MailMessage $email->line('生日快乐🎂') ->line('在生日当天,我们还为您提供了专属用户组,您可以前往仪表盘查看。') ->action('前往仪表盘', $url) - ->line('感谢您继续使用 '.config('app.display_name').'。'); + ->line('感谢您继续使用 ' . config('app.display_name') . '。'); return $email; } diff --git a/app/Notifications/WorkOrder/WorkOrder.php b/app/Notifications/WorkOrder/WorkOrder.php index 5482a29..c751765 100644 --- a/app/Notifications/WorkOrder/WorkOrder.php +++ b/app/Notifications/WorkOrder/WorkOrder.php @@ -30,7 +30,8 @@ public function __construct(WorkOrderModel $work_order) * Get the notification's delivery channels. * * - * @param WorkOrderModel $workOrder + * @param WorkOrderModel $workOrder + * * @return array */ public function via(WorkOrderModel $workOrder): array @@ -48,13 +49,14 @@ public function via(WorkOrderModel $workOrder): array * Get the mail representation of the notification. * * - * @param WorkOrderModel $workOrder + * @param WorkOrderModel $workOrder + * * @return MailMessage */ public function toMail(WorkOrderModel $workOrder): MailMessage { return (new MailMessage) - ->subject('工单: '.$workOrder->title.' 状态更新。') + ->subject('工单: ' . $workOrder->title . ' 状态更新。') ->line('我们查阅了您的工单并做出了相应处理。') ->line('请前往我们的仪表盘继续跟进问题。'); } @@ -63,14 +65,15 @@ public function toMail(WorkOrderModel $workOrder): MailMessage * Get the array representation of the notification. * * - * @param WorkOrderModel $workOrder + * @param WorkOrderModel $workOrder + * * @return array */ public function toArray(WorkOrderModel $workOrder): array { $array = $workOrder->toArray(); - $array['event'] = 'work-order.'.$workOrder->status; + $array['event'] = 'work-order.' . $workOrder->status; return $array; } diff --git a/app/Policies/WorkOrder/WorkOrderPolicy.php b/app/Policies/WorkOrder/WorkOrderPolicy.php index 779d1b6..3f45dda 100644 --- a/app/Policies/WorkOrder/WorkOrderPolicy.php +++ b/app/Policies/WorkOrder/WorkOrderPolicy.php @@ -15,8 +15,9 @@ class WorkOrderPolicy /** * Determine whether the user can view the model. * - * @param User|Module $user - * @param WorkOrder $workOrder + * @param User|Module $user + * @param WorkOrder $workOrder + * * @return Response|bool */ public function view(User|Module $user, WorkOrder $workOrder): Response|bool @@ -31,8 +32,9 @@ public function view(User|Module $user, WorkOrder $workOrder): Response|bool /** * Determine whether the user can update the model. * - * @param User|Module $user - * @param WorkOrder $workOrder + * @param User|Module $user + * @param WorkOrder $workOrder + * * @return Response|bool */ public function update(User|Module $user, WorkOrder $workOrder): Response|bool @@ -47,8 +49,9 @@ public function update(User|Module $user, WorkOrder $workOrder): Response|bool /** * Determine whether the user can delete the model. * - * @param User|Module $user - * @param WorkOrder $workOrder + * @param User|Module $user + * @param WorkOrder $workOrder + * * @return Response|bool */ public function delete(User|Module $user, WorkOrder $workOrder): Response|bool diff --git a/app/Support/ClusterSupport.php b/app/Support/ClusterSupport.php index cb679c4..ac5bbbe 100644 --- a/app/Support/ClusterSupport.php +++ b/app/Support/ClusterSupport.php @@ -60,13 +60,14 @@ public static function registerThisNode($report = true): void public static function hset($key, $value, $data = []): void { /** @noinspection PhpUndefinedMethodInspection */ - Redis::hset(self::$prefix.$key, $value, json_encode($data)); + Redis::hset(self::$prefix . $key, $value, json_encode($data)); } /** - * @param string|array $events 事件名称 - * @param $callback callable 回调函数,接收一个参数,为事件数据。 - * @param $ignore_self bool 是否忽略此节点的消息。 + * @param string|array $events 事件名称 + * @param $callback callable 回调函数,接收一个参数,为事件数据。 + * @param $ignore_self bool 是否忽略此节点的消息。 + * * @return void */ public static function listen(string|array $events, callable $callback, bool $ignore_self = true): void @@ -96,13 +97,13 @@ public static function listen(string|array $events, callable $callback, bool $ig public static function get($key, $default = null): string|array|null { /** @noinspection PhpUndefinedMethodInspection */ - return Redis::get(self::$prefix.$key, $default); + return Redis::get(self::$prefix . $key, $default); } public static function forget($key): void { /** @noinspection PhpUndefinedMethodInspection */ - Redis::forget(self::$prefix.$key); + Redis::forget(self::$prefix . $key); } // forever @@ -114,13 +115,13 @@ public static function forever($key, $value): void public static function set($key, $value, $ttl = null): void { /** @noinspection PhpUndefinedMethodInspection */ - Redis::set(self::$prefix.$key, $value, $ttl); + Redis::set(self::$prefix . $key, $value, $ttl); } public static function hget($key, $hashKey, $default = []): string|array|null { /** @noinspection PhpUndefinedMethodInspection */ - $value = Redis::hget(self::$prefix.$key, $hashKey); + $value = Redis::hget(self::$prefix . $key, $hashKey); return $value ?: $default; } @@ -147,7 +148,7 @@ public static function nodes($hide_ip = false): array public static function hgetAll($hashKey, $default = []): array { /** @noinspection PhpUndefinedMethodInspection */ - $value = Redis::hgetall(self::$prefix.$hashKey); + $value = Redis::hgetall(self::$prefix . $hashKey); return $value ?: $default; } diff --git a/app/Support/EmqxSupport.php b/app/Support/EmqxSupport.php index b43a357..ca88482 100644 --- a/app/Support/EmqxSupport.php +++ b/app/Support/EmqxSupport.php @@ -26,7 +26,7 @@ public function kickClient($client_id = null, $username = null, bool $like_usern } if ($client_id) { - $this->api()->delete('/clients/'.$client_id); + $this->api()->delete('/clients/' . $client_id); } if ($username) { @@ -44,7 +44,7 @@ public function api(): PendingRequest */ public function client(string $client_id) { - $response = $this->api()->get('clients/'.$client_id); + $response = $this->api()->get('clients/' . $client_id); if ($response->successful()) { return $response->json(); @@ -89,7 +89,7 @@ public function clients($params = []) $response = $this->api()->get('clients', $params); } /** @noinspection PhpRedundantCatchClauseInspection */ catch (ConnectionException $e) { Log::error('emqx connect failed.', [$e]); - throw new EmqxSupportException('EMQX API 无法连接。'.$e->getMessage()); + throw new EmqxSupportException('EMQX API 无法连接。' . $e->getMessage()); } if ($response->successful()) { diff --git a/app/Support/RealNameSupport.php b/app/Support/RealNameSupport.php index 106e5cf..acad1b0 100644 --- a/app/Support/RealNameSupport.php +++ b/app/Support/RealNameSupport.php @@ -25,7 +25,7 @@ public function __construct() $this->app_code = config('settings.supports.real_name.code'); $this->http = Http::withHeaders([ - 'Authorization' => 'APPCODE '.$this->app_code, + 'Authorization' => 'APPCODE ' . $this->app_code, 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8', 'Accept' => 'application/json', ])->baseUrl($this->url); @@ -45,7 +45,7 @@ public function create($user_id, $name, $id_card): string { $id = Str::random(32); - Cache::remember('real_name:'.$id, 600, function () use ($user_id, $name, $id_card) { + Cache::remember('real_name:' . $id, 600, function () use ($user_id, $name, $id_card) { return [ 'user_id' => $user_id, 'name' => $name, @@ -65,9 +65,9 @@ public function create($user_id, $name, $id_card): string */ private function submit(string $id): string { - $real_name = Cache::get('real_name:'.$id); + $real_name = Cache::get('real_name:' . $id); - if (! $real_name) { + if (!$real_name) { abort(404, '找不到实名认证请求'); } @@ -75,7 +75,7 @@ private function submit(string $id): string 'bizNo' => $id, 'idNumber' => $real_name['id_card'], 'idName' => $real_name['name'], - 'pageTitle' => config('app.display_name').' 实名认证', + 'pageTitle' => config('app.display_name') . ' 实名认证', 'notifyUrl' => route('public.real-name.notify'), 'procedureType' => 'video', 'txtBgColor' => '#cccccc', @@ -90,7 +90,7 @@ private function submit(string $id): string $resp = $this->http->asForm()->post('/edis_ctid_id_name_video_ocr_h5', $data)->json(); - if (! $resp || $resp['code'] !== '0000') { + if (!$resp || $resp['code'] !== '0000') { throw new CommonException('调用远程服务器时出现了问题,请检查身份证号码是否正确。'); } @@ -100,7 +100,8 @@ private function submit(string $id): string /** * 验证实名认证请求 * - * @param array $request + * @param array $request + * * @return array|bool */ public function verify(array $request): array|bool @@ -111,7 +112,7 @@ public function verify(array $request): array|bool $verify = $this->verifyIfSuccess($request['data'], $request['sign']); - if (! $verify) { + if (!$verify) { Log::debug('实名认证签名验证失败', $request); return false; @@ -121,9 +122,9 @@ public function verify(array $request): array|bool return false; } - $return = Cache::get('real_name:'.$data['bizNo'], false); + $return = Cache::get('real_name:' . $data['bizNo'], false); - Cache::forget('real_name:'.$data['bizNo']); + Cache::forget('real_name:' . $data['bizNo']); return $return; } @@ -140,7 +141,7 @@ private function verifyIfSuccess(string $request, string $sign): bool $public_key = openssl_pkey_get_public($public_key); - if (! $public_key) { + if (!$public_key) { abort(500, '公钥错误'); } @@ -155,6 +156,6 @@ public function getBirthday(string $id_card): string $month = substr($id_card, 10, 2); $day = substr($id_card, 12, 2); - return $year.'-'.$month.'-'.$day; + return $year . '-' . $month . '-' . $day; } }