代码提交
This commit is contained in:
@@ -62,7 +62,15 @@ class ConversationController extends BaseController
|
|||||||
try {
|
try {
|
||||||
$bot_id = input('bot_id','');
|
$bot_id = input('bot_id','');
|
||||||
if(empty($bot_id)){
|
if(empty($bot_id)){
|
||||||
return errorJson('智能体ID不能为空');
|
if($is_internal){
|
||||||
|
return json_encode([
|
||||||
|
'code' => 400,
|
||||||
|
'msg' => '智能体ID不能为空',
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}else{
|
||||||
|
return errorJson('智能体ID不能为空');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$page = input('page',1);
|
$page = input('page',1);
|
||||||
$limit = input('limit',20);
|
$limit = input('limit',20);
|
||||||
@@ -78,7 +86,15 @@ class ConversationController extends BaseController
|
|||||||
$result = json_decode($result, true);
|
$result = json_decode($result, true);
|
||||||
|
|
||||||
if ($result['code'] != 0) {
|
if ($result['code'] != 0) {
|
||||||
return errorJson($result['msg'], $result['code']);
|
if($is_internal){
|
||||||
|
return json_encode([
|
||||||
|
'code' => $result['code'],
|
||||||
|
'msg' => $result['msg'],
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}else{
|
||||||
|
return errorJson($result['msg'], $result['code']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理返回的数据并存入数据库
|
// 处理返回的数据并存入数据库
|
||||||
@@ -107,7 +123,15 @@ class ConversationController extends BaseController
|
|||||||
$companyId = $userInfo['companyId'];
|
$companyId = $userInfo['companyId'];
|
||||||
|
|
||||||
if(empty($bot_id)){
|
if(empty($bot_id)){
|
||||||
return errorJson('智能体ID不能为空');
|
if($is_internal){
|
||||||
|
return json_encode([
|
||||||
|
'code' => 400,
|
||||||
|
'msg' => '智能体ID不能为空',
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}else{
|
||||||
|
return errorJson('智能体ID不能为空');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建元数据和消息
|
// 构建元数据和消息
|
||||||
@@ -131,7 +155,15 @@ class ConversationController extends BaseController
|
|||||||
$result = $this->httpRequest($url, 'POST', json_encode($params,256), $this->headers);
|
$result = $this->httpRequest($url, 'POST', json_encode($params,256), $this->headers);
|
||||||
$result = json_decode($result, true);
|
$result = json_decode($result, true);
|
||||||
if ($result['code'] != 0) {
|
if ($result['code'] != 0) {
|
||||||
return errorJson($result['msg'], $result['code']);
|
if($is_internal){
|
||||||
|
return json_encode([
|
||||||
|
'code' => $result['code'],
|
||||||
|
'msg' => $result['msg'],
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}else{
|
||||||
|
return errorJson($result['msg'], $result['code']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取返回的对话数据并保存
|
// 获取返回的对话数据并保存
|
||||||
@@ -167,7 +199,15 @@ class ConversationController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return errorJson('创建对话失败:' . $e->getMessage());
|
if($is_internal){
|
||||||
|
return json_encode([
|
||||||
|
'code' => 500,
|
||||||
|
'msg' => '创建对话失败:' . $e->getMessage(),
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
}else{
|
||||||
|
return errorJson('创建对话失败:' . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class MessageController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function getMessages()
|
public function getMessages()
|
||||||
{
|
{
|
||||||
|
return successJson([], '获取成功');
|
||||||
try {
|
try {
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
$userInfo = request()->userInfo;
|
$userInfo = request()->userInfo;
|
||||||
@@ -37,12 +38,11 @@ class MessageController extends BaseController
|
|||||||
if (empty($conversation)) {
|
if (empty($conversation)) {
|
||||||
$conversationController = new ConversationController();
|
$conversationController = new ConversationController();
|
||||||
$result = $conversationController->create(true);
|
$result = $conversationController->create(true);
|
||||||
$result = json_decode($result, true);
|
$resultData = json_decode($result, true);
|
||||||
if ($result['code'] != 200) {
|
if ($resultData['code'] != 200) {
|
||||||
return errorJson('创建会话失败:' . $result['msg']);
|
return errorJson('创建会话失败:' . $resultData['msg']);
|
||||||
}
|
}
|
||||||
|
$conversation_id = $resultData['data']['id'];
|
||||||
$conversation_id = $result['data']['id'];
|
|
||||||
} else {
|
} else {
|
||||||
$conversation_id = $conversation['conversation_id'];
|
$conversation_id = $conversation['conversation_id'];
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,8 @@ class MessageController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 分页参数
|
// 分页参数
|
||||||
$page = input('page', 1);
|
$page = input('page', 1);
|
||||||
$limit = input('limit', 20);
|
$limit = input('limit', 20);
|
||||||
|
|||||||
Reference in New Issue
Block a user