feat : config
This commit is contained in:
83
app/Service/Admin/System/ConfigService.php
Normal file
83
app/Service/Admin/System/ConfigService.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\System;
|
||||
|
||||
use App\Exception\AdminException;
|
||||
use App\Model\Config;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class ConfigService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 注入设置模型
|
||||
* @var Config
|
||||
*/
|
||||
#[Inject]
|
||||
protected Config $configModel;
|
||||
|
||||
/**
|
||||
* 修改配置
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$editKey = $this->request->input('key');
|
||||
$editValue = $this->request->input('value');
|
||||
|
||||
switch ($editKey)
|
||||
{
|
||||
case 'test':
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$res = (new Config)->where('key', $editKey)->update(['value' => $editValue]);
|
||||
|
||||
if (!$res) throw new AdminException('配置更新失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置模块
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigModule(): array
|
||||
{
|
||||
$res = $this->configModel->getTopConfigModule();
|
||||
|
||||
return $this->return->success('success', ['list' => $res]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigForm(): array
|
||||
{
|
||||
$list = $this->configModel->getConfigByPid($this->request->input('pid'));
|
||||
|
||||
foreach ($list as &$item) {
|
||||
switch ($item['type']) {
|
||||
case 2:
|
||||
$data = explode('|', $item['value']);
|
||||
$item['min'] = (int)$data[0];
|
||||
$item['max'] = (int)$data[1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user