fixed
This commit is contained in:
@@ -10,6 +10,7 @@ namespace app\api\logic;
|
|||||||
|
|
||||||
|
|
||||||
use app\api\controller\BaseWssApi;
|
use app\api\controller\BaseWssApi;
|
||||||
|
use app\common\model\TabConf;
|
||||||
use GatewayWorker\Lib\Gateway;
|
use GatewayWorker\Lib\Gateway;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use wanghua\general_utility_tools_php\gpt\chat\ChatGPT;
|
use wanghua\general_utility_tools_php\gpt\chat\ChatGPT;
|
||||||
@@ -47,40 +48,38 @@ class TychatLogic extends BaseLogic
|
|||||||
if(empty($data['items']['type'])){
|
if(empty($data['items']['type'])){
|
||||||
$json = Tools::wss_json_fail($action, 'type参数错误,缺少角色类型:doc、user');
|
$json = Tools::wss_json_fail($action, 'type参数错误,缺少角色类型:doc、user');
|
||||||
return Gateway::sendToClient($client_id, $json);
|
return Gateway::sendToClient($client_id, $json);
|
||||||
|
|
||||||
}
|
}
|
||||||
$type = $data['items']['type'];//角色类型
|
if(empty($data['items']['ticket'])){
|
||||||
//if(empty($data['items']['username'])){
|
$json = Tools::wss_json_fail($action, 'ticket参数错误');
|
||||||
// $json = Tools::wss_json_fail($action, 'username参数错误');
|
|
||||||
// return Gateway::sendToClient($client_id, $json);
|
|
||||||
//}
|
|
||||||
$chat_msg = $data['items']['chat_msg'];
|
|
||||||
|
|
||||||
$user = Db::table('fa_device')
|
|
||||||
->where('clientid',$client_id)
|
|
||||||
->find();
|
|
||||||
Tools::log_to_write_txt(['保存历史记录,$user'=>$user]);
|
|
||||||
if(empty($user)){
|
|
||||||
$json = Tools::wss_json_fail($action, '用户不存在,请绑定设备');
|
|
||||||
return Gateway::sendToClient($client_id, $json);
|
return Gateway::sendToClient($client_id, $json);
|
||||||
}
|
}
|
||||||
$username = $user['username'];
|
$type = $data['items']['type'];//角色类型
|
||||||
//保存记录
|
$ticket = $data['items']['ticket'];//对话票据
|
||||||
$this->saveHistory($username,$chat_msg,$type);
|
$chat_msg = $data['items']['chat_msg'];//对话内容
|
||||||
|
|
||||||
|
|
||||||
//广播消息
|
//广播消息
|
||||||
//查询广播客户端id
|
//查询广播客户端id
|
||||||
$arr = Db::table('fa_device')
|
$arr = Db::table(TabConf::$fa_device)
|
||||||
->where('username',$username)
|
->where('say_ticket',$ticket)
|
||||||
->where('clientid','neq',$client_id)
|
->where('clientid','neq',$client_id)//不给自己发
|
||||||
->select();
|
->select();
|
||||||
|
if(empty($arr)){
|
||||||
|
$json = Tools::wss_json_fail($action, '未找到广播对象,请确认目标对象是否登录并绑定设备关系');
|
||||||
|
return Gateway::sendToClient($client_id, $json);
|
||||||
|
}
|
||||||
|
$username = $arr[0]['username'];
|
||||||
$clientid_arr = array_column($arr,'clientid');
|
$clientid_arr = array_column($arr,'clientid');
|
||||||
|
|
||||||
|
//保存记录
|
||||||
|
$this->saveHistory($username,$chat_msg,$type);
|
||||||
|
|
||||||
|
//向客户端发送消息
|
||||||
$json = Tools::wss_json_ok($action, $chat_msg);
|
$json = Tools::wss_json_ok($action, $chat_msg);
|
||||||
Gateway::sendToAll($json,null,[$client_id]);
|
Gateway::sendToAll($json,$clientid_arr);
|
||||||
|
|
||||||
//健康小洞察
|
//健康小洞察
|
||||||
$this->getHealthInsight2($client_id,$clientid_arr,$chat_msg);
|
$this->getHealthInsight2($clientid_arr,$chat_msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -130,7 +129,7 @@ class TychatLogic extends BaseLogic
|
|||||||
* ]
|
* ]
|
||||||
* author:wh
|
* author:wh
|
||||||
*/
|
*/
|
||||||
function getHealthInsight2($client_id,$clientid_arr,$chat_msg){
|
function getHealthInsight2($clientid_arr,$chat_msg){
|
||||||
Tools::log_to_write_txt(['健康洞察,入参'=>['域名'=>request()->controller().'/'.request()->action()]]);
|
Tools::log_to_write_txt(['健康洞察,入参'=>['域名'=>request()->controller().'/'.request()->action()]]);
|
||||||
$action = 'Tychat/getHealthInsight2';
|
$action = 'Tychat/getHealthInsight2';
|
||||||
|
|
||||||
@@ -155,11 +154,11 @@ class TychatLogic extends BaseLogic
|
|||||||
$chatobj->setBefore($content);
|
$chatobj->setBefore($content);
|
||||||
|
|
||||||
$chatobj->returnAnswer($question,$config,$answer_json_arr);
|
$chatobj->returnAnswer($question,$config,$answer_json_arr);
|
||||||
Tools::log_to_write_txt(['健康洞察,gpt请求参数'=>$chatobj->post_msg_body]);
|
//Tools::log_to_write_txt(['健康洞察,gpt请求参数'=>$chatobj->post_msg_body]);
|
||||||
//return json(Tools::set_ok('查询成功',$answer_json_arr));
|
////return json(Tools::set_ok('查询成功',$answer_json_arr));
|
||||||
Tools::log_to_write_txt(['健康洞察,出参'=>$answer_json_arr]);
|
//Tools::log_to_write_txt(['健康洞察,出参'=>$answer_json_arr]);
|
||||||
|
|
||||||
$json = Tools::wss_json_ok($action, 'ok',$answer_json_arr);
|
$json = Tools::wss_json_ok($action, 'ok',$answer_json_arr);
|
||||||
Gateway::sendToAll($json);
|
Gateway::sendToAll($json,$clientid_arr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ class TyuserLogic extends BaseLogic
|
|||||||
Mmodel::catchTrans(function () use ($client_id){
|
Mmodel::catchTrans(function () use ($client_id){
|
||||||
Tools::log_to_write_txt(['服务端收到客户端离线消息:client_id:' . $client_id]);
|
Tools::log_to_write_txt(['服务端收到客户端离线消息:client_id:' . $client_id]);
|
||||||
|
|
||||||
$user = Db::table('fa_device')
|
$user = Db::table(TabConf::$fa_device)
|
||||||
->where('clientid', $client_id)
|
->where('clientid', $client_id)
|
||||||
->find();
|
->find();
|
||||||
if(empty($user)){
|
if(empty($user)){
|
||||||
@@ -40,7 +40,7 @@ class TyuserLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tools::log_to_write_txt(['设置离线时间:clientid:' . $client_id]);
|
Tools::log_to_write_txt(['设置离线时间:clientid:' . $client_id]);
|
||||||
Db::table('fa_device')
|
Db::table(TabConf::$fa_device)
|
||||||
->where('clientid', $client_id)
|
->where('clientid', $client_id)
|
||||||
->delete();
|
->delete();
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ class TyuserLogic extends BaseLogic
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* desc:登录选择角色时绑定关系
|
* desc:登录选择角色时绑定设备关系
|
||||||
* 请求类型:wss
|
* 请求类型:wss
|
||||||
*请求参数:
|
*请求参数:
|
||||||
* json消息格式:[
|
* json消息格式:[
|
||||||
@@ -83,7 +83,7 @@ class TyuserLogic extends BaseLogic
|
|||||||
return Gateway::sendToClient($clientid, $json);
|
return Gateway::sendToClient($clientid, $json);
|
||||||
}
|
}
|
||||||
//绑定设备
|
//绑定设备
|
||||||
Db::table(TabConf::$fa_hdrdevice)
|
Db::table(TabConf::$fa_device)
|
||||||
->insert([
|
->insert([
|
||||||
'username'=>$items['username'],
|
'username'=>$items['username'],
|
||||||
'clientid'=>$clientid,
|
'clientid'=>$clientid,
|
||||||
|
|||||||
Reference in New Issue
Block a user