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