fixed active

This commit is contained in:
Edward Yang 2022-06-30 16:42:55 +08:00
parent f5efcc1b8d
commit b82df7984c
3 changed files with 44 additions and 18 deletions

View File

@ -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([

View File

@ -0,0 +1,41 @@
<?php
/**
* SettingRepo.php
*
* @copyright 2022 opencart.cn - All Rights Reserved
* @link http://www.guangdawangluo.com
* @author Edward Yang <yangjin@opencart.cn>
* @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');
}
}

View File

@ -33,11 +33,5 @@ return [
'type' => 'select',
'option' => ['China', 'USA'],
'required' => true,
],
[
'name' => 'active',
'label' => '是否开启',
'type' => 'bool',
'required' => true,
]
];