chore(addon/aikefu): 更新获取配置及保存逻辑

This commit is contained in:
2025-12-06 11:59:53 +08:00
parent cdcd9eeffa
commit fc5615a9c7
3 changed files with 321 additions and 61 deletions

View File

@@ -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');
}
}
/**

View File

@@ -59,43 +59,43 @@
form.render();
/**
* 监听提交
*/
form.on('submit(save)', function(data) {
if (repeat_flag) return false;
repeat_flag = true;
$.ajax({
url: ns.url("aikefu://shop/kefu/saveConfig"),
type: 'POST',
data: data.field,
dataType: 'json',
success: function(res) {
repeat_flag = false;
if (res.code === 0) {
layer.confirm('保存成功', {
title: '操作提示',
btn: ['返回列表', '继续编辑'],
yes: function(index, layero) {
location.reload();
layer.close(index);
},
btn2: function(index, layero) {
layer.close(index);
}
});
} else {
layer.msg(res.message, {icon: 2});
* 监听提交
*/
form.on('submit(save)', function(data) {
if (repeat_flag) return false;
repeat_flag = true;
$.ajax({
url: ns.url("aikefu://shop/kefu/config"),
type: 'POST',
data: data.field,
dataType: 'json',
success: function(res) {
repeat_flag = false;
if (res.code === 0) {
layer.confirm('保存成功', {
title: '操作提示',
btn: ['返回列表', '继续编辑'],
yes: function(index, layero) {
location.reload();
layer.close(index);
},
btn2: function(index, layero) {
layer.close(index);
}
});
} else {
layer.msg(res.message, {icon: 2});
}
},
error: function() {
repeat_flag = false;
layer.msg('请求失败,请稍后重试', {icon: 2});
}
},
error: function() {
repeat_flag = false;
layer.msg('请求失败,请稍后重试', {icon: 2});
}
});
return false;
});
return false;
});
});
function back() {