From ba4ec748de66e9616cdbb1d1983462ea58aaa523 Mon Sep 17 00:00:00 2001 From: zhang zhuo Date: Mon, 29 Dec 2025 10:21:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/Admin/Base.php | 10 ++++----- app/Controller/Admin/System.php | 37 +++++++++++++++++++++++++++++++++ app/Utils/helpers.php | 11 ++++++++++ app/helpers.php | 6 ------ composer.json | 4 +++- 5 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 app/Utils/helpers.php delete mode 100644 app/helpers.php diff --git a/app/Controller/Admin/Base.php b/app/Controller/Admin/Base.php index ff38f07..c76a092 100644 --- a/app/Controller/Admin/Base.php +++ b/app/Controller/Admin/Base.php @@ -30,12 +30,12 @@ abstract class Base extends AbstractController /** * Author: cfn * @param array|string $msg - * @param LengthAwarePaginatorInterface|Collection|array|null $data + * @param mixed $data * @param null $count * @param null $summary * @return ResponseInterface */ - public function success(array|string $msg = "success", LengthAwarePaginatorInterface|Collection|array|null $data = null, $count = null, $summary = null) + public function success(array|string $msg = "success", mixed $data = null, $count = null, $summary = null) { if (!is_string($msg)) { $data = $msg; @@ -54,12 +54,12 @@ abstract class Base extends AbstractController /** * Author: cfn * @param array|string $msg - * @param LengthAwarePaginatorInterface|array|null $data + * @param mixed $data * @param null $count * @param null $summary * @return ResponseInterface */ - public function error(array|string $msg = "error", LengthAwarePaginatorInterface|array|null $data = null, $count = null, $summary = null) + public function error(array|string $msg = "error", mixed $data = null, $count = null, $summary = null) { if (!is_string($msg)) { $data = $msg; @@ -96,7 +96,7 @@ abstract class Base extends AbstractController * @param array|null $summary * @return ResponseInterface */ - protected function response(int $code, string $msg, array $data = null, int $count = null, array $summary = null): ResponseInterface + protected function response(int $code, string $msg, mixed $data = null, int $count = null, array $summary = null): ResponseInterface { $body = compact("code", "msg", "data", "count", "summary"); if ($count === null) unset($body['count']); diff --git a/app/Controller/Admin/System.php b/app/Controller/Admin/System.php index 44e4dcd..8fe57f6 100644 --- a/app/Controller/Admin/System.php +++ b/app/Controller/Admin/System.php @@ -41,12 +41,14 @@ use App\Utils\Param; use App\Utils\RedisInfoHelper; use App\Utils\Str; use App\Utils\SystemHelper; +use Hyperf\DbConnection\Db; use Hyperf\Filesystem\FilesystemFactory; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\DeleteMapping; use Hyperf\HttpServer\Annotation\GetMapping; use Hyperf\HttpServer\Annotation\PostMapping; use Hyperf\HttpServer\Annotation\PutMapping; +use function Hyperf\Translation\__; #[Controller(prefix: "admin")] class System extends Base @@ -845,4 +847,39 @@ class System extends Base $param['account_id'] = $this->accountId(); return $this->toAjax(amModel::clearAll($param)); } + + #[GetMapping(path: "config/index")] + #[Auth(auth: "config:index")] + public function configIndex() + { + $param = Param::only(['type']); + $data = sysConfig($param['type']); + return $this->success("success", $data); + } + + #[GetMapping(path: "config/multi")] + #[Auth(auth: "config:multi")] + public function sendMulti() + { + $param = Param::only(['keys']); + $data = sysConfig($param['keys']); + return $this->success("success", $data ? $data->toArray() : []); + } + + #[PostMapping(path: "config/save")] + #[Auth(auth: "config:save")] + public function configSave() + { + $param = $this->request->post(); + Db::beginTransaction(); + foreach ($param as $k => $v) { + $res = scModel::where("config_key", $k)->update(['config_value' => $v]); + if (!$res) { + Db::rollback(); + return $this->error(__('system.saveFail')); + } + } + Db::commit(); + return $this->success(__('system.saveSuccess')); + } } \ No newline at end of file diff --git a/app/Utils/helpers.php b/app/Utils/helpers.php new file mode 100644 index 0000000..059a38c --- /dev/null +++ b/app/Utils/helpers.php @@ -0,0 +1,11 @@ +pluck('config_value', 'config_key') ?? []; + } + if (is_string($key)) { + return \App\Model\SystemConfig::where('config_key', $key)->value('config_value') ?? null; + } +} \ No newline at end of file diff --git a/app/helpers.php b/app/helpers.php deleted file mode 100644 index d98b0e6..0000000 --- a/app/helpers.php +++ /dev/null @@ -1,6 +0,0 @@ -value('config_value') ?? null; -} \ No newline at end of file diff --git a/composer.json b/composer.json index 0247d62..c61864e 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,9 @@ "psr-4": { "App\\": "app/" }, - "files": [] + "files": [ + "app/Utils/helpers.php" + ] }, "minimum-stability": "dev", "prefer-stable": true,