chore(addon/aikefu): 调整config的配置内容

This commit is contained in:
2025-12-06 13:25:15 +08:00
parent 0ff979917c
commit d8a0dd5d31
2 changed files with 70 additions and 64 deletions

View File

@@ -1,4 +1,9 @@
<?php <?php
/**
* 智能客服配置模型
* 用于存储和管理智能客服的配置信息
* 版本1.0.0
*/
namespace addon\aikefu\model; namespace addon\aikefu\model;

View File

@@ -1,4 +1,7 @@
<?php <?php
/**
* 智能客服控制器
*/
namespace addon\aikefu\shop\controller; namespace addon\aikefu\shop\controller;
@@ -8,6 +11,9 @@ use addon\aikefu\model\Message as KefuMessageModel;
use app\shop\controller\BaseShop; use app\shop\controller\BaseShop;
use think\facade\View; use think\facade\View;
/**
* 智能客服 控制器
*/
class Kefu extends BaseShop class Kefu extends BaseShop
{ {
/** /**
@@ -18,24 +24,24 @@ class Kefu extends BaseShop
{ {
$kefu_config_model = new KefuConfigModel(); $kefu_config_model = new KefuConfigModel();
if ($this->request->isJson()) { if (request()->isJson()) {
// 保存配置 $api_key = input("api_key", "");//Dify API密钥
$params = $this->request->post(); $base_url = input("base_url", "https://api.dify.ai/v1");//API基础地址
$chat_endpoint = input("chat_endpoint", "/chat-messages");//聊天接口端点
$status = input("status", 0);//状态
$data = [ $data = array(
'api_key' => $params['api_key'] ?? '', "api_key" => $api_key,
'base_url' => $params['base_url'] ?? 'https://api.dify.ai/v1', "base_url" => $base_url,
'chat_endpoint' => $params['chat_endpoint'] ?? '/chat-messages', "chat_endpoint" => $chat_endpoint,
'status' => $params['status'] ?? 0, "status" => $status
]; );
$result = $kefu_config_model->setConfig($data, $this->site_id, $this->app_module);
$result = $kefu_config_model->setConfig($data, $this->site_id);
return $result; return $result;
} else { } else {
// 获取配置
$config_info = $kefu_config_model->getConfig($this->site_id, $this->app_module)['data']['value'] ?? []; $config_info = $kefu_config_model->getConfig($this->site_id, $this->app_module)['data']['value'] ?? [];
$this->assign('config_info', $config_info); $this->assign("config_info", $config_info);
return $this->fetch('kefu/config'); return $this->fetch("kefu/config");
} }
} }
@@ -45,7 +51,7 @@ class Kefu extends BaseShop
*/ */
public function conversation() public function conversation()
{ {
return View::fetch('kefu/conversation'); return View::fetch("kefu/conversation");
} }
/** /**
@@ -54,11 +60,10 @@ class Kefu extends BaseShop
*/ */
public function getConversationList() public function getConversationList()
{ {
$params = $this->request->post(); $page = input("page", 1);
$page = $params['page'] ?? 1; $limit = input("limit", 10);
$limit = $params['limit'] ?? 10; $user_id = input("user_id", "");
$user_id = $params['user_id'] ?? ''; $status = input("status", "");
$status = $params['status'] ?? '';
$kefu_conversation_model = new KefuConversationModel(); $kefu_conversation_model = new KefuConversationModel();
$condition = [['site_id', '=', $this->site_id]]; $condition = [['site_id', '=', $this->site_id]];
@@ -82,8 +87,7 @@ class Kefu extends BaseShop
*/ */
public function getConversationInfo() public function getConversationInfo()
{ {
$params = $this->request->post(); $conversation_id = input("conversation_id", "");
$conversation_id = $params['conversation_id'] ?? '';
if (empty($conversation_id)) { if (empty($conversation_id)) {
return $this->error('会话ID不能为空'); return $this->error('会话ID不能为空');
@@ -108,8 +112,7 @@ class Kefu extends BaseShop
*/ */
public function endConversation() public function endConversation()
{ {
$params = $this->request->post(); $id = input("id", "");
$id = $params['id'] ?? '';
if (empty($id)) { if (empty($id)) {
return $this->error('会话ID不能为空'); return $this->error('会话ID不能为空');
@@ -133,8 +136,7 @@ class Kefu extends BaseShop
*/ */
public function deleteConversation() public function deleteConversation()
{ {
$params = $this->request->post(); $id = input("id", "");
$id = $params['id'] ?? '';
if (empty($id)) { if (empty($id)) {
return $this->error('会话ID不能为空'); return $this->error('会话ID不能为空');
@@ -183,9 +185,9 @@ class Kefu extends BaseShop
*/ */
public function message() public function message()
{ {
$conversation_id = $this->request->param('conversation_id') ?? ''; $conversation_id = input("conversation_id", "");
View::assign('conversation_id', $conversation_id); View::assign("conversation_id", $conversation_id);
return View::fetch('kefu/message'); return View::fetch("kefu/message");
} }
/** /**
@@ -194,10 +196,9 @@ class Kefu extends BaseShop
*/ */
public function getMessageList() public function getMessageList()
{ {
$params = $this->request->post(); $page = input("page", 1);
$page = $params['page'] ?? 1; $limit = input("limit", 50);
$limit = $params['limit'] ?? 50; $conversation_id = input("conversation_id", "");
$conversation_id = $params['conversation_id'] ?? '';
if (empty($conversation_id)) { if (empty($conversation_id)) {
return $this->error('会话ID不能为空'); return $this->error('会话ID不能为空');