Skip to content

Commit

Permalink
fix: unable to save admin billing settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Cat committed Jun 23, 2024
1 parent 7882cc9 commit f1d5f10
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions src/Controllers/Admin/Setting/BillingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct()
parent::__construct();
$this->update_field = Config::getItemListByClass('billing');
$this->settings = Config::getClass('billing');
unset($this->update_field['payment_gateway']);
}

/**
Expand Down Expand Up @@ -60,10 +61,7 @@ public function save(ServerRequest $request, Response $response, array $args): R
}
}

$gateway = (new Config())->where('item', 'payment_gateway')->first();
$gateway->value = json_encode($gateway_in_use);

if (! $gateway->save()) {
if (! Config::set('payment_gateway', $gateway_in_use)) {
return $response->withJson([
'ret' => 0,
'msg' => '保存支付网关时出错',
Expand Down Expand Up @@ -158,8 +156,6 @@ public function returnGatewaysList(): array

public function returnActiveGateways(): ?array
{
$payment_gateways = (new Config())->where('item', 'payment_gateway')->first();

return json_decode($payment_gateways->value);
return Config::obtain('payment_gateway');
}
}
8 changes: 5 additions & 3 deletions src/Models/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property string $value 配置值
* @property string $class 配置类别
* @property string $is_public 是否为公共参数
* @property string $type 配置值类型
* @property string $default 默认值
* @property string $mark 备注
*
Expand All @@ -22,13 +23,14 @@ final class Config extends Model
protected $connection = 'default';
protected $table = 'config';

public static function obtain($item): bool|int|string
public static function obtain($item): bool|int|array|string
{
$config = (new Config())->where('item', $item)->first();

return match ($config->type) {
'bool' => (bool) $config->value,
'int' => (int) $config->value,
'array' => json_decode($config->value),
default => (string) $config->value,
};
}
Expand Down Expand Up @@ -81,11 +83,11 @@ public static function getPublicConfig(): array
return $configs;
}

public static function set($item, $value): bool
public static function set(string $item, mixed $value): bool
{
$config = (new Config())->where('item', $item)->first();

if ($config->tpye === 'array') {
if ($config->type === 'array') {
$config->value = json_encode($value);
} else {
$config->value = $value;
Expand Down

0 comments on commit f1d5f10

Please sign in to comment.