From 8572c5d25e952d872e6c271458d60a18f81b5d9f Mon Sep 17 00:00:00 2001 From: wh <382379437@qq.com> Date: Wed, 31 Jul 2024 12:26:31 +0800 Subject: [PATCH] fixed --- .../application/api/logic/TychatLogic.php | 53 +++++++++---------- .../application/api/logic/TyuserLogic.php | 8 +-- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/digital_doctor/application/api/logic/TychatLogic.php b/digital_doctor/application/api/logic/TychatLogic.php index 55675fe..1c38107 100644 --- a/digital_doctor/application/api/logic/TychatLogic.php +++ b/digital_doctor/application/api/logic/TychatLogic.php @@ -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); } } \ No newline at end of file diff --git a/digital_doctor/application/api/logic/TyuserLogic.php b/digital_doctor/application/api/logic/TyuserLogic.php index 091750a..034527e 100644 --- a/digital_doctor/application/api/logic/TyuserLogic.php +++ b/digital_doctor/application/api/logic/TyuserLogic.php @@ -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,