diff --git a/digital_doctor/application/api/controller/HealthInsights.php b/digital_doctor/application/api/controller/HealthInsights.php index 076855b..ff240be 100644 --- a/digital_doctor/application/api/controller/HealthInsights.php +++ b/digital_doctor/application/api/controller/HealthInsights.php @@ -9,6 +9,9 @@ namespace app\api\controller; +use app\api\logic\TychatLogic; +use wanghua\general_utility_tools_php\Mmodel; + /** * 健康洞察 * @@ -19,4 +22,19 @@ class HealthInsights { + /** + * desc:健康洞察 + * + * 实时输出 + * + * /api/HealthInsights/getHealthInsight + * + * author:wh + */ + function getHealthInsight(){ + return Mmodel::catchJson(function (){ + $obj = new TychatLogic(); + $obj->getHealthInsight(); + }); + } } \ No newline at end of file diff --git a/digital_doctor/application/api/controller/Reportty.php b/digital_doctor/application/api/controller/Reportty.php index cef127e..88138fd 100644 --- a/digital_doctor/application/api/controller/Reportty.php +++ b/digital_doctor/application/api/controller/Reportty.php @@ -50,12 +50,17 @@ class Reportty return json(Tools::set_fail('ticket必须')); } - $user = Db::table('fa_users')->where('ticket',$ticket)->find(); + $user = Db::table('fa_ty_users')->where('ticket',$ticket)->find(); if(empty($user)){ return json(Tools::set_fail('用户不存在')); } - $his_record = Db::table('fa_ty_chathistory')->where('username',$user['username'])->order('id asc')->select(); + $day3 = date('Y-m-d 00:00:00',strtotime('-3 day')); + $his_record = Db::table('fa_ty_chathistory') + //->where('username',$user['username']) + ->order('id asc') + ->where('createtime','>',$day3)//3天之内 + ->select(); $config = [ 'stream'=>false, ]; @@ -76,7 +81,7 @@ class Reportty $data = [ 'doctor'=>$user['username'], //病人 - 'username'=>Db::table('fa_users')->where('doctor',$user['username'])->value('username'), + 'username'=>Db::table('fa_ty_users')->where('doctor',$user['username'])->value('username'), 'report_content'=>$choice['message']['content'], ]; Db::table('fa_ty_medical_report')->insert($data); @@ -141,7 +146,7 @@ class Reportty //if(empty($ticket)){ // return Tools::set_fail('ticket必须'); //} - //$user = Db::table('fa_users')->where('ticket',$ticket)->find(); + //$user = Db::table('fa_ty_users')->where('ticket',$ticket)->find(); //修改基本信息 $data = [ //'username'=>$user['username'],//医生 @@ -158,7 +163,7 @@ class Reportty 'diagnosis'=>input('diagnosis',''),//诊断 'treatment'=>input('treatment',''),//医嘱 ]; - Mmodel::existsUpdateInsert('fa_userbaseinfo',[ + Mmodel::existsUpdateInsert('fa_ty_userbaseinfo',[ 'username'=>input('username',''), 'name'=>input('name',''), ],$data); diff --git a/digital_doctor/application/api/controller/Tychat.php b/digital_doctor/application/api/controller/Tychat.php new file mode 100644 index 0000000..c00abe3 --- /dev/null +++ b/digital_doctor/application/api/controller/Tychat.php @@ -0,0 +1,24 @@ +where('openid',input('openid')); @@ -74,7 +74,7 @@ class Users extends BaseHttpApi return json(Tools::set_res(234,'用户不存在')); } //更新用户最后登录时间 - Db::table('fa_users') + Db::table('fa_ty_users') ->data(['last_login_time'=>Tools::get_now_date()]) ->where('id',$data['id']) ->update(); diff --git a/digital_doctor/application/api/logic/EnemyLogic.php b/digital_doctor/application/api/logic/EnemyLogic.php deleted file mode 100644 index 999beb1..0000000 --- a/digital_doctor/application/api/logic/EnemyLogic.php +++ /dev/null @@ -1,36 +0,0 @@ -where('openid',api_user_openid()) - ->setInc('enemy',$enemy_num);//累加击杀敌人数量 - return Tools::set_ok(); - }); - } -} \ No newline at end of file diff --git a/digital_doctor/application/api/logic/TychatLogic.php b/digital_doctor/application/api/logic/TychatLogic.php new file mode 100644 index 0000000..23b8529 --- /dev/null +++ b/digital_doctor/application/api/logic/TychatLogic.php @@ -0,0 +1,102 @@ +'TychatLogic/saveChatHistory', + 'items'=>[ + 'content'=>'挑剔内容', + 'username'=>'用户名', + ] + ]; + * author:wh + * @param $client_id + * @param $data + */ + function saveChatHistory($client_id,$res){ + $items = $res['items']; + $data = [ + 'username'=>$items['username'], + 'chat_msg'=>$items['content'], + ]; + Db::table('fa_ty_chathistory')->insert($data); + + //这里做健康小洞察 + //$this->getHealthInsight(); + + $json = BaseWssApi::json_wss('ok','保存成功'); + Gateway::sendToClient($client_id, $json); + } + + /** + * desc:健康洞察 + * author:wh + */ + function getHealthInsight(){ + $config = config('ai_health_insight_config'); + + $question = '';//input('question',''); + + $chatobj = new ChatGPT(); + $chatobj->url = $config['base_url']; + $chatobj->model = ''; + $chatobj->apiKey = $config['APIKey']; + + $answer_json_arr = []; + + $ticket = input('ticket'); + if(empty($ticket)){ + return json(Tools::set_fail('ticket必须')); + } + $user = Db::table('fa_ty_users')->where('ticket',$ticket)->find(); + if(empty($user)){ + return json(Tools::set_fail('用户不存在')); + } + $day3 = date('Y-m-d 00:00:00',strtotime('-3 day')); + $his_record = Db::table('fa_ty_chathistory') + //->where('username',$user['username']) + ->order('id asc') + ->where('createtime','>',$day3)//3天之内 + ->select(); + + $config = [ + 'stream'=>false, + ]; + $content = [ + //["role" => "user", "content" => ''] + ]; + foreach ($his_record as $item){ + $content[] = ["role" => "user", "content" => $item['chat_msg']]; + } + $chatobj->setBefore($content); + + $chatobj->chat($question,$config,$answer_json_arr); + } +} \ No newline at end of file diff --git a/digital_doctor/application/api/logic/UserOfflinePrizeLogic.php b/digital_doctor/application/api/logic/UserOfflinePrizeLogic.php deleted file mode 100644 index b920a87..0000000 --- a/digital_doctor/application/api/logic/UserOfflinePrizeLogic.php +++ /dev/null @@ -1,69 +0,0 @@ -where('openid',$openid) - ->order('id asc') - ->find(); - } - /** - * desc:用户上线时写入奖品(存在则num加1) - * author:wh - */ - static function insertPrize($openid,$gameprop_id,$num){ - // - $prize = Db::table(TabConf::$fa_user_offline_prize) - ->where('openid',$openid) - ->where('gameprop_id',$gameprop_id) - ->find(); - if($prize){ - Db::table(TabConf::$fa_user_offline_prize) - ->where('id',$prize['id']) - ->setInc('num',$num); - }else{ - Db::table(TabConf::$fa_user_offline_prize) - ->insert([ - 'openid'=>$openid, - 'gameprop_id'=>$gameprop_id, - 'num'=>$num - ]); - } - } - - /** - * desc:领取后删除 - * author:wh - * @param $openid - */ - static function deletedPrize($openid){ - Db::table(TabConf::$fa_user_offline_prize) - ->where('openid',$openid) - ->delete(); - } -} \ No newline at end of file diff --git a/digital_doctor/application/common/model/TabConf.php b/digital_doctor/application/common/model/TabConf.php index db24ced..31c3344 100644 --- a/digital_doctor/application/common/model/TabConf.php +++ b/digital_doctor/application/common/model/TabConf.php @@ -136,7 +136,7 @@ class TabConf /** * 用户表 */ - static $fa_users = 'fa_users'; + static $fa_users = 'fa_ty_users'; /** diff --git a/digital_doctor/application/index/logic/events/Events.php b/digital_doctor/application/index/logic/events/Events.php index 4d34b3f..8ce88f7 100644 --- a/digital_doctor/application/index/logic/events/Events.php +++ b/digital_doctor/application/index/logic/events/Events.php @@ -4,10 +4,10 @@ namespace app\index\logic\events; use app\api\controller\BaseWssApi; use app\api\logic\AudioRevertLogic; +use app\api\logic\BaseLogic; use app\api\logic\PartnerOfflineLogic; use app\api\logic\UserLogic; use app\api\logic\WssMessageLogic; -use app\index\logic\Baselogic; use GatewayWorker\Lib\Gateway; use IFlytek\Xfyun\Speech\LfasrClient; use think\Db; @@ -111,29 +111,31 @@ class Events extends \think\worker\Events { Tools::log_to_write_txt(['客户端发来数据(Gateway进程收到数据).client_id:'.$client_id,$data]); //$res = Tools::set_ok('ok',['client_id'=>$client_id,'msg'=>'你发来的消息我接收到了:',$client_id=>$data]); - //Gateway::sendToClient($client_id,json_encode($res,JSON_UNESCAPED_UNICODE)); + Gateway::sendToClient($client_id,json_encode($res,JSON_UNESCAPED_UNICODE)); - if(empty($data)){ - $json = BaseWssApi::json_wss('error','消息为空'); - - Gateway::sendToClient($client_id, $json); - return ; - } - //解析消息 - $xunfei_record_config = config('xunfei_record_config'); - $appId = $xunfei_record_config['appid']; - $secretKey = $xunfei_record_config['secretKey']; - - //解析action - // 处理接收到的语音数据 - // 这里需要将二进制数据转换为讯飞API所需的格式 - // 以下代码仅为示例,具体实现需要根据讯飞API文档进行调整 - $lfasrClient = new LfasrClient($appId, $secretKey); - $lfasrClient->sendBinaryData($data, function ($result) use ($client_id) { - // 处理讯飞API返回的实时转写结果 - // 将结果发送回客户端 - Gateway::sendToClient($client_id, json_encode(['type' => 'transcription', 'data' => $result])); - }); + //if(empty($data)){ + // $json = BaseWssApi::json_wss('error','消息为空'); + // + // Gateway::sendToClient($client_id, $json); + // return ; + //} + ////解析消息 + //$xunfei_record_config = config('xunfei_record_config'); + //$appId = $xunfei_record_config['appid']; + //$secretKey = $xunfei_record_config['secretKey']; + // + ////解析action + //// 处理接收到的语音数据 + //// 这里需要将二进制数据转换为讯飞API所需的格式 + //// 以下代码仅为示例,具体实现需要根据讯飞API文档进行调整 + //$lfasrClient = new LfasrClient($appId, $secretKey); + //$lfasrClient->sendBinaryData($data, function ($result) use ($client_id) { + // // 处理讯飞API返回的实时转写结果 + // // 将结果发送回客户端 + // Gateway::sendToClient($client_id, json_encode(['type' => 'transcription', 'data' => $result])); + //}); + $obj = new BaseLogic(); + $obj->domsg($client_id,$data); } diff --git a/digital_doctor/config/app.php b/digital_doctor/config/app.php index 852ba44..6711ecf 100644 --- a/digital_doctor/config/app.php +++ b/digital_doctor/config/app.php @@ -192,11 +192,17 @@ return [ ], ], + //听译-报告生成接口 'ai_listen_report_config'=>[ - 'base_url'=>'https://serverfastgpt.excn.top/api/v1/chat/completions', - 'APIKey'=>'fastgpt-e5wq9u6phvyfq4znrXfOuTHKHQHGjpcVBYay602ai5zv4HeOJRMDwT3ptm6', + 'base_url'=>'https://serverfastgpt.excn.top/api/v1/chat/completions', + 'APIKey'=>'fastgpt-e5wq9u6phvyfq4znrXfOuTHKHQHGjpcVBYay602ai5zv4HeOJRMDwT3ptm6', ], - //讯飞录音接口 + //听译-健康小洞察 + 'ai_health_insight_config'=>[ + 'base_url'=>'https://serverfastgpt.excn.top/api/v1/chat/completions', + 'APIKey'=>'fastgpt-tZKZGcsdkzAMPuKlRtI5HDtupY83wwQQigGuPjKqqElFPeD9cYku1w1OzXY', + ], + //听译-讯飞录音接口 'xunfei_record_config'=>[ //优一 'appid'=>'de02dasd', diff --git a/digital_doctor_admin/vendor/wanghua/general-utility-tools-php/src/api/BaseUserLogic.php b/digital_doctor_admin/vendor/wanghua/general-utility-tools-php/src/api/BaseUserLogic.php index 14455b4..7e21765 100644 --- a/digital_doctor_admin/vendor/wanghua/general-utility-tools-php/src/api/BaseUserLogic.php +++ b/digital_doctor_admin/vendor/wanghua/general-utility-tools-php/src/api/BaseUserLogic.php @@ -15,7 +15,7 @@ use wanghua\general_utility_tools_php\tool\Tools; class BaseUserLogic { - public $user_table = 'fa_users'; + public $user_table = 'fa_ty_users'; /** * desc:【通用】用户登录逻辑