85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
<?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\ErrException;
|
|
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 ErrException('配置更新失败');
|
|
|
|
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
|
|
{
|
|
$pid = (int)$this->request->input('pid');
|
|
|
|
$list = $this->configModel->getConfigByPid($pid);
|
|
|
|
foreach ($list as &$item) {
|
|
switch ($item['input_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]);
|
|
}
|
|
} |