You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.1 KiB
58 lines
2.1 KiB
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\facade\Filesystem;
|
|
use app\model\ConfigModel;
|
|
|
|
class Config extends AdminBaseController
|
|
{
|
|
|
|
public function setConfig()
|
|
{
|
|
try {
|
|
$param = $this->request->param();
|
|
if (empty($param['name'])) return json(['code' => '1', 'message' => '参数错误', 'data' => []]);
|
|
$name = $param['name'];
|
|
$type = $param['type'] ?? 'string';
|
|
$value = $param['value'] ?? '';
|
|
$tip = $param['tip'] ?? '';
|
|
|
|
$insertData = [
|
|
'name' => $name,
|
|
'group' => 'config',
|
|
'title' => $name,
|
|
'tip' => $tip,
|
|
'type' => $type,
|
|
'value' => $value,
|
|
];
|
|
|
|
$config = ConfigModel::where('name', $name)->find();
|
|
if (empty($config)) {
|
|
$bool = ConfigModel::insert($insertData);
|
|
if (!$bool) return json(['code' => '100500', 'message' => '设置失败', 'data' => []]);
|
|
} else {
|
|
$bool = ConfigModel::where('name', $name)->update($insertData);
|
|
if (!$bool) return json(['code' => '100500', 'message' => '设置失败', 'data' => []]);
|
|
}
|
|
|
|
return json(['code' => '0', 'message' => 'Request successful', 'data' => []]);
|
|
} catch (\Exception $exception) {
|
|
return json(['code' => '100500', 'message' => '系统繁忙', 'data' => [$exception->getMessage()]]);
|
|
}
|
|
}
|
|
|
|
public function getConfig()
|
|
{
|
|
try {
|
|
$param = $this->request->param();
|
|
if (empty($param['name'])) return json(['code' => '1', 'message' => '参数错误', 'data' => []]);
|
|
$name = $param['name'];
|
|
$value = ConfigModel::where('name', $name)->value('value');
|
|
|
|
return json(['code' => '0', 'message' => 'Request successful', 'data' => ['value' => $value]]);
|
|
} catch (\Exception $exception) {
|
|
return json(['code' => '100500', 'message' => '系统繁忙', 'data' => [$exception->getMessage()]]);
|
|
}
|
|
}
|
|
}
|