diff --git a/beike/Plugin/Plugin.php b/beike/Plugin/Plugin.php index d13c9c16..23690d9f 100644 --- a/beike/Plugin/Plugin.php +++ b/beike/Plugin/Plugin.php @@ -12,6 +12,7 @@ namespace Beike\Plugin; use Beike\Models\Setting; +use Beike\Repositories\SettingRepo; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Arr; use Illuminate\Support\Str; @@ -108,10 +109,8 @@ class Plugin implements Arrayable, \ArrayAccess */ public function getColumns(): array { - if (empty($this->columns)) { - return []; - } - $existValues = $this->getColumnsFromDb(); + $this->columns[] = SettingRepo::getPluginStatusColumn(); + $existValues = SettingRepo::getPluginColumns($this->code); foreach ($this->columns as &$column) { $dbColumn = $existValues[$column['name']] ?? null; if (empty($dbColumn)) { @@ -124,14 +123,6 @@ class Plugin implements Arrayable, \ArrayAccess } - private function getColumnsFromDb() - { - return Setting::query()->where('type', 'plugin') - ->where('space', $this->code) - ->get()->keyBy('name'); - } - - public function toArray(): array { return (array)array_merge([ diff --git a/beike/Repositories/SettingRepo.php b/beike/Repositories/SettingRepo.php new file mode 100644 index 00000000..4d68a6b6 --- /dev/null +++ b/beike/Repositories/SettingRepo.php @@ -0,0 +1,41 @@ + + * @created 2022-06-30 16:36:40 + * @modified 2022-06-30 16:36:40 + */ + +namespace Beike\Repositories; + +use Beike\Models\Setting; + +class SettingRepo +{ + /** + * 获取插件默认字段 + * + * @return array + */ + public static function getPluginStatusColumn(): array + { + return [ + 'name' => 'active', + 'label' => '是否开启', + 'type' => 'bool', + 'required' => true, + ]; + } + + public static function getPluginColumns($pluginCode) + { + return Setting::query() + ->where('type', 'plugin') + ->where('space', $pluginCode) + ->get() + ->keyBy('name'); + } +} diff --git a/plugins/BKStripe/columns.php b/plugins/BKStripe/columns.php index 2e3abf49..ced86714 100644 --- a/plugins/BKStripe/columns.php +++ b/plugins/BKStripe/columns.php @@ -33,11 +33,5 @@ return [ 'type' => 'select', 'option' => ['China', 'USA'], 'required' => true, - ], - [ - 'name' => 'active', - 'label' => '是否开启', - 'type' => 'bool', - 'required' => true, ] ];