pluginService = $pluginService; } public function handle(): int { $pluginCode = $this->option('plugin'); if ($pluginCode) { $this->checkPlugin($pluginCode); } else { $this->info('检测所有插件更新...'); PrintPlugin::where('status', '!=', 'inactive')->each(function ($plugin) { $this->checkPlugin($plugin->code); }); } $this->info('检测完成'); return 0; } protected function checkPlugin(string $code): void { $this->info("检测插件: {$code}"); $result = $this->pluginService->checkUpdates($code); if ($result) { $this->warn("发现新版本: {$result['old_version']} -> {$result['new_version']}"); // 通知需要更新的用户 $usersToNotify = $this->pluginService->getUsersNeedingUpdate($code); foreach ($usersToNotify as $userInfo) { $this->notifyUser($userInfo); } $this->info("已通知 {$usersToNotify->count() ?? count($usersToNotify)} 个用户"); } else { $this->info("{$code}: 无更新"); } } protected function notifyUser(array $userInfo): void { // 记录通知日志 Log::channel('print_plugin')->info('插件更新通知', [ 'user_id' => $userInfo['user_id'], 'device_id' => $userInfo['device_id'], 'current_version' => $userInfo['current_version'], 'latest_version' => $userInfo['latest_version'], 'time' => now()->toIso8601String(), ]); // TODO: 发送邮件/短信通知 // 可以通过 Notification 发送 } }