all(); } public function enablePlugin(string $key): void { try { app(PluginManager::class)->enable($key); Notification::make()->title('已启用:'.$key)->success()->send(); } catch (\Throwable $e) { Notification::make()->title('启用失败')->body($e->getMessage())->danger()->send(); } } public function disablePlugin(string $key): void { try { app(PluginManager::class)->disable($key); Notification::make()->title('已停用:'.$key)->warning()->send(); } catch (\Throwable $e) { Notification::make()->title('停用失败')->body($e->getMessage())->danger()->send(); } } public function uninstallPlugin(string $key): void { try { app(PackageInstaller::class)->uninstallPlugin($key); Notification::make()->title('已卸载:'.$key)->success()->send(); } catch (\Throwable $e) { Notification::make()->title('卸载失败')->body($e->getMessage())->danger()->send(); } } public function uploadZip(): void { $this->validate([ 'zip' => ['required', 'file', 'mimes:zip'], ]); try { $result = app(PackageInstaller::class)->installZip($this->zip->getRealPath()); Notification::make() ->title('安装成功:'.($result['type'] === 'plugin' ? '插件' : '主题').' '.$result['key']) ->success() ->send(); } catch (\Throwable $e) { Notification::make()->title('安装失败')->body($e->getMessage())->danger()->send(); } $this->zip = null; } public function loadMarket(): void { try { $items = app(MarketplaceClient::class)->items(); $this->marketItems = array_values(array_filter( $items, fn (array $item) => ($item['type'] ?? 'plugin') === 'plugin' )); Notification::make()->title('市场已刷新:'.count($this->marketItems).' 个插件')->success()->send(); } catch (\Throwable $e) { Notification::make()->title('市场加载失败')->body($e->getMessage())->danger()->send(); } } public function installFromMarket(string $index): void { $item = $this->marketItems[(int) $index] ?? null; if (! $item) { return; } try { // 付费商品需先购买 app(MarketPurchaseService::class)->assertCanInstall($item); $result = app(PackageInstaller::class)->installFromMarket($item); Notification::make()->title('安装成功:'.$result['key'])->success()->send(); } catch (\Throwable $e) { Notification::make()->title('安装失败')->body($e->getMessage())->danger()->send(); } } public function purchaseMarketItem(string $index) { $item = $this->marketItems[(int) $index] ?? null; if (! $item) { return; } try { $payment = app(MarketPurchaseService::class)->purchase($item); if (! $payment) { Notification::make()->title('该商品已购买')->info()->send(); return; } return redirect()->route('pay.checkout', $payment); } catch (\Throwable $e) { Notification::make()->title('购买失败')->body($e->getMessage())->danger()->send(); } } public function isMarketPurchased(string $index): bool { $item = $this->marketItems[(int) $index] ?? null; if (! $item) { return false; } return app(MarketPurchaseService::class)->isPurchased( app(MarketPurchaseService::class)->itemKey($item), app(MarketPurchaseService::class)->itemType($item) ); } public function getMarketConfiguredProperty(): bool { return (bool) config('market.url'); } }