p2 project
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.

87 lines
2.9 KiB

5 months ago
<?php
namespace app\admin\controller;
4 months ago
use app\admin\service\ConfigService;
5 months ago
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()]]);
}
}
4 months ago
// 获取邮箱模板列表
public function emailTemplateList()
{
$returnData = (new ConfigService())->emailTemplateList($this->request->param());
return json($returnData);
}
// 编辑邮箱模板列表
public function editEmailTemplate()
{
$returnData = (new ConfigService())->editEmailTemplate($this->request->param());
return json($returnData);
}
// 短信模板列表
public function smsTemplateList()
{
$returnData = (new ConfigService())->smsTemplateList($this->request->param());
return json($returnData);
}
// 编辑邮短信板列表
public function editSmsTemplate()
{
$returnData = (new ConfigService())->editSmsTemplate($this->request->param());
return json($returnData);
}
5 months ago
}