This commit is contained in:
2024-07-15 21:34:27 +08:00
parent 0f369cfae9
commit cb358bb9f0
11 changed files with 192 additions and 140 deletions

View File

@@ -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
*
* authorwh
*/
function getHealthInsight(){
return Mmodel::catchJson(function (){
$obj = new TychatLogic();
$obj->getHealthInsight();
});
}
}

View File

@@ -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);

View File

@@ -0,0 +1,24 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/15} {16:13}
*/
namespace app\api\controller;
/**
* 听译聊天
* Class Tychat
* @package app\api\controller
*/
class Tychat
{
function saveChat(){
return Mmodel::catchJson(function (){
});
}
}

View File

@@ -64,7 +64,7 @@ class Users extends BaseHttpApi
$model_obj = Db::table('fa_users');
$model_obj = Db::table('fa_ty_users');
if(input('openid')){
$model_obj->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();

View File

@@ -1,36 +0,0 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/6/18} {18:05}
*/
namespace app\api\logic;
use app\common\model\TabConf;
use think\Db;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\tool\Tools;
class EnemyLogic extends BaseLogic
{
/**
* desc累加击杀敌人数量
*
* 参数enemy_num
*
* authorwh
*/
function addKillEnemyNum(){
return Mmodel::catchJson(function (){
$enemy_num = input('enemy_num',1);
Db::table(TabConf::$fa_users)
->where('openid',api_user_openid())
->setInc('enemy',$enemy_num);//累加击杀敌人数量
return Tools::set_ok();
});
}
}

View File

@@ -0,0 +1,102 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/7/15} {16:14}
*/
namespace app\api\logic;
use app\api\controller\BaseWssApi;
use GatewayWorker\Lib\Gateway;
use think\Db;
use wanghua\general_utility_tools_php\gpt\chat\ChatGPT;
use wanghua\general_utility_tools_php\tool\Tools;
/**
* 听译聊天
* Class TychatLogic
* @package app\api\logic
*/
class TychatLogic extends BaseLogic
{
/**
* desc保存听译聊天记录
*
* action:TychatLogic/saveChatHistory
*
* 参数:
* [
'action'=>'TychatLogic/saveChatHistory',
'items'=>[
'content'=>'挑剔内容',
'username'=>'用户名',
]
];
* authorwh
* @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健康洞察
* authorwh
*/
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);
}
}

View File

@@ -1,69 +0,0 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/6/2} {10:51}
*/
namespace app\api\logic;
use app\common\model\TabConf;
use think\Db;
use wanghua\general_utility_tools_php\Mmodel;
/**
* 用户离线奖品表(用户上线时写入,领取后删除)
* Class UserOfflinePrizeLogic
* @package app\api\logic
*/
class UserOfflinePrizeLogic
{
/**
* desc查询最早的一条奖品数据
* authorwh
* @param $openid
*/
static function getFirstPrizeRecord($openid){
return Db::table(TabConf::$fa_user_offline_prize)
->where('openid',$openid)
->order('id asc')
->find();
}
/**
* desc用户上线时写入奖品(存在则num加1)
* authorwh
*/
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领取后删除
* authorwh
* @param $openid
*/
static function deletedPrize($openid){
Db::table(TabConf::$fa_user_offline_prize)
->where('openid',$openid)
->delete();
}
}

View File

@@ -136,7 +136,7 @@ class TabConf
/**
* 用户表
*/
static $fa_users = 'fa_users';
static $fa_users = 'fa_ty_users';
/**

View File

@@ -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);
}

View File

@@ -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',

View File

@@ -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【通用】用户登录逻辑