chore(addon/aikefu): 更新获取配置及保存逻辑
This commit is contained in:
@@ -12,37 +12,31 @@ class Kefu extends BaseShop
|
||||
{
|
||||
/**
|
||||
* 智能客服配置页
|
||||
* @return \think\response\View
|
||||
* @return \think\response\View|\think\response\Json
|
||||
*/
|
||||
public function config()
|
||||
{
|
||||
$kefu_config_model = new KefuConfigModel();
|
||||
$config_info = $kefu_config_model->getConfigInfo([['site_id', '=', $this->site_id]]);
|
||||
|
||||
View::assign('config_info', $config_info);
|
||||
return View::fetch('kefu/config');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存智能客服配置
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function saveConfig()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
|
||||
$kefu_config_model = new KefuConfigModel();
|
||||
|
||||
$data = [
|
||||
'api_key' => $params['api_key'] ?? '',
|
||||
'base_url' => $params['base_url'] ?? 'https://api.dify.ai/v1',
|
||||
'chat_endpoint' => $params['chat_endpoint'] ?? '/chat-messages',
|
||||
'status' => $params['status'] ?? 0,
|
||||
];
|
||||
|
||||
$result = $kefu_config_model->setConfig($data, $this->site_id);
|
||||
|
||||
return $this->success($result);
|
||||
if ($this->request->isJson()) {
|
||||
// 保存配置
|
||||
$params = $this->request->post();
|
||||
|
||||
$data = [
|
||||
'api_key' => $params['api_key'] ?? '',
|
||||
'base_url' => $params['base_url'] ?? 'https://api.dify.ai/v1',
|
||||
'chat_endpoint' => $params['chat_endpoint'] ?? '/chat-messages',
|
||||
'status' => $params['status'] ?? 0,
|
||||
];
|
||||
|
||||
$result = $kefu_config_model->setConfig($data, $this->site_id);
|
||||
return $result;
|
||||
} else {
|
||||
// 获取配置
|
||||
$config_info = $kefu_config_model->getConfig($this->site_id);
|
||||
$this->assign('config_info', $config_info);
|
||||
return $this->fetch('kefu/config');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user