This commit is contained in:
zhang zhuo 2025-12-29 10:21:31 +08:00
parent 37a72de735
commit ba4ec748de
5 changed files with 56 additions and 12 deletions

View File

@ -30,12 +30,12 @@ abstract class Base extends AbstractController
/** /**
* Author: cfn <cfn@leapy.cn> * Author: cfn <cfn@leapy.cn>
* @param array|string $msg * @param array|string $msg
* @param LengthAwarePaginatorInterface|Collection|array|null $data * @param mixed $data
* @param null $count * @param null $count
* @param null $summary * @param null $summary
* @return ResponseInterface * @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)) { if (!is_string($msg)) {
$data = $msg; $data = $msg;
@ -54,12 +54,12 @@ abstract class Base extends AbstractController
/** /**
* Author: cfn <cfn@leapy.cn> * Author: cfn <cfn@leapy.cn>
* @param array|string $msg * @param array|string $msg
* @param LengthAwarePaginatorInterface|array|null $data * @param mixed $data
* @param null $count * @param null $count
* @param null $summary * @param null $summary
* @return ResponseInterface * @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)) { if (!is_string($msg)) {
$data = $msg; $data = $msg;
@ -96,7 +96,7 @@ abstract class Base extends AbstractController
* @param array|null $summary * @param array|null $summary
* @return ResponseInterface * @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"); $body = compact("code", "msg", "data", "count", "summary");
if ($count === null) unset($body['count']); if ($count === null) unset($body['count']);

View File

@ -41,12 +41,14 @@ use App\Utils\Param;
use App\Utils\RedisInfoHelper; use App\Utils\RedisInfoHelper;
use App\Utils\Str; use App\Utils\Str;
use App\Utils\SystemHelper; use App\Utils\SystemHelper;
use Hyperf\DbConnection\Db;
use Hyperf\Filesystem\FilesystemFactory; use Hyperf\Filesystem\FilesystemFactory;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping; use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping; use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping; use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping; use Hyperf\HttpServer\Annotation\PutMapping;
use function Hyperf\Translation\__;
#[Controller(prefix: "admin")] #[Controller(prefix: "admin")]
class System extends Base class System extends Base
@ -845,4 +847,39 @@ class System extends Base
$param['account_id'] = $this->accountId(); $param['account_id'] = $this->accountId();
return $this->toAjax(amModel::clearAll($param)); 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'));
}
} }

11
app/Utils/helpers.php Normal file
View File

@ -0,0 +1,11 @@
<?php
function sysConfig($key)
{
if (is_array($key)) {
return \App\Model\SystemConfig::whereIn('config_key', $key)->pluck('config_value', 'config_key') ?? [];
}
if (is_string($key)) {
return \App\Model\SystemConfig::where('config_key', $key)->value('config_value') ?? null;
}
}

View File

@ -1,6 +0,0 @@
<?php
function sysConfig($key)
{
return \App\Model\SystemConfig::where('config_key', $key)->value('config_value') ?? null;
}

View File

@ -60,7 +60,9 @@
"psr-4": { "psr-4": {
"App\\": "app/" "App\\": "app/"
}, },
"files": [] "files": [
"app/Utils/helpers.php"
]
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"prefer-stable": true, "prefer-stable": true,