diff --git a/beike/Plugin/Manager.php b/beike/Plugin/Manager.php index bee1f006..af3f2f79 100644 --- a/beike/Plugin/Manager.php +++ b/beike/Plugin/Manager.php @@ -16,6 +16,7 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Http\UploadedFile; use Illuminate\Support\Arr; use Illuminate\Support\Collection; +use Illuminate\Support\Str; use ZanySoft\Zip\Zip; class Manager @@ -113,6 +114,7 @@ class Manager */ public function getPlugin($code): ?Plugin { + $code = Str::snake($code); $plugins = $this->getPlugins(); return $plugins[$code] ?? null; diff --git a/beike/Repositories/PluginRepo.php b/beike/Repositories/PluginRepo.php index a911c75d..6447c4db 100644 --- a/beike/Repositories/PluginRepo.php +++ b/beike/Repositories/PluginRepo.php @@ -17,6 +17,7 @@ use Beike\Shop\Services\TotalServices\ShippingService; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\File; +use Illuminate\Support\Str; class PluginRepo { @@ -113,6 +114,20 @@ class PluginRepo } } + /** + * Get plugin by code + * + * @param $code + * @return mixed + */ + public static function getPlugin($code): mixed + { + $code = Str::camel($code); + $plugins = self::getPluginsByCode(); + + return $plugins->get($code); + } + /** * 判断插件是否安装 * @@ -126,6 +141,19 @@ class PluginRepo return $plugins->has($code); } + /** + * 判断插件是否安装 + * + * @param $code + * @return bool + */ + public static function enabled($code): bool + { + $code = Str::camel($code); + + return SettingRepo::getPluginStatus($code); + } + /** * 获取所有已安装插件列表 * @@ -144,7 +172,7 @@ class PluginRepo * 获取所有已安装插件 * @return Plugin[]|Collection */ - public static function getPluginsByCode() + public static function getPluginsByCode(): Collection|array { $allPlugins = self::allPlugins(); diff --git a/beike/Shop/Http/Controllers/HomeController.php b/beike/Shop/Http/Controllers/HomeController.php index cdedbd07..657f51da 100644 --- a/beike/Shop/Http/Controllers/HomeController.php +++ b/beike/Shop/Http/Controllers/HomeController.php @@ -29,6 +29,15 @@ class HomeController extends Controller $viewPath = "design.{$code}"; } + $paths = explode('::', $viewPath); + if (count($paths) == 2) { + $pluginCode = $paths[0]; + $plugin = app('plugin')->getPlugin($pluginCode); + if (! $plugin || ! $plugin->getEnabled()) { + continue; + } + } + if (view()->exists($viewPath) && $moduleId) { $moduleItems[] = [ 'code' => $code,