first commit
This commit is contained in:
174
digital_doctor/application/api/controller/Usersty.php
Normal file
174
digital_doctor/application/api/controller/Usersty.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/3/26} {20:55}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\TychatLogic;
|
||||
use app\api\logic\UserOfflinePrizeLogic;
|
||||
use app\common\model\TabConf;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use wanghua\general_utility_tools_php\gpt\chat\ChatGPT;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\SundryConfig;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
use wanghua\general_utility_tools_php\wechat\UserAuth;
|
||||
|
||||
|
||||
/**
|
||||
* 听译-用户
|
||||
* Class Users
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Usersty extends BaseHttpApi
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* desc:听译-授权,登录
|
||||
*
|
||||
* /api/Usersty/login
|
||||
*
|
||||
* 参数:clientid 客户端标识
|
||||
* username 用户名
|
||||
* password 密码
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function login()
|
||||
{
|
||||
return Mmodel::catchJson(function (){
|
||||
$clientid = input('clientid');
|
||||
if(empty($clientid)){
|
||||
return Tools::set_fail('clientid error');
|
||||
}
|
||||
|
||||
$username = input('username');
|
||||
if(empty($username)){
|
||||
return Tools::set_fail('参数错误:1');
|
||||
}
|
||||
$password = input('password');
|
||||
if(empty($password)){
|
||||
return Tools::set_fail('参数错误:2');
|
||||
}
|
||||
$user = Db::table('fa_hdrdoctorusers')
|
||||
->where('username',$username)
|
||||
->find();
|
||||
if(empty($user)){
|
||||
return Tools::set_fail('用户不存在');
|
||||
}
|
||||
if($password != $user['password']){
|
||||
return Tools::set_fail('密码错误');
|
||||
}
|
||||
|
||||
//session('api_user_info',$user);
|
||||
|
||||
unset($user['password']);
|
||||
|
||||
//未登录
|
||||
$expires = 7*86400+time();
|
||||
$ticketstr = md5($user['username']);
|
||||
//修改有效期
|
||||
Db::table('fa_hdrdoctorusers')
|
||||
->data([
|
||||
'qa_chat_ticket'=>$ticketstr,
|
||||
'ticket'=>$ticketstr,
|
||||
'expires'=>$expires,//7天
|
||||
])
|
||||
->where('username',$username)
|
||||
->update();
|
||||
unset($user['qa_chat_ticket']);
|
||||
|
||||
return Tools::set_ok('登录成功',['ticket'=>$ticketstr,'user'=>$user]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* desc: 绑定设备(选择角色时调用)
|
||||
*
|
||||
* api/Usersty/bindDevice
|
||||
*
|
||||
* 参数:username
|
||||
* clientid
|
||||
* type 用户类型:user=用户,doc=医生
|
||||
*/
|
||||
//function bindDevice(){
|
||||
// return Mmodel::catchJson(function (){
|
||||
// //绑定设备
|
||||
// $devidata = [
|
||||
// 'username'=>input('username'),
|
||||
// 'clientid'=>input('clientid'),
|
||||
// 'type'=>input('type'),
|
||||
// 'login_time'=>Tools::get_now_date(),
|
||||
// ];
|
||||
// Mmodel::existsUpdateInsert('fa_device',[
|
||||
// 'username'=>input('username'),
|
||||
// 'clientid'=>input('clientid'),
|
||||
// ],$devidata);
|
||||
// return Tools::set_ok('绑定成功');
|
||||
// });
|
||||
//}
|
||||
|
||||
/**
|
||||
* 医生问诊提示
|
||||
*
|
||||
* 请求类型:post
|
||||
* 请求地址:/api/Usersty/getTips
|
||||
* 参数:
|
||||
* hdruserbaseinfo_id 基本信息id
|
||||
*/
|
||||
function getTips(){
|
||||
return Mmodel::catchJson(function (){
|
||||
|
||||
$config = config('ai_doctor_tips_config');
|
||||
|
||||
//$hdruserbaseinfo_id = input('hdruserbaseinfo_id');
|
||||
//if(empty($hdruserbaseinfo_id)){
|
||||
// return Tools::set_fail('hdruserbaseinfo_id参数错误');
|
||||
//}
|
||||
$reportid = input('reportid');
|
||||
if(empty($reportid)){
|
||||
return Tools::set_fail('reportid参数错误');
|
||||
}
|
||||
|
||||
|
||||
//$content = [
|
||||
// ["role" => "user", "content" => '']
|
||||
//];
|
||||
$chatobj = new ChatGPT();
|
||||
$chatobj->url = $config['base_url'];
|
||||
$chatobj->model = '';
|
||||
$chatobj->apiKey = $config['APIKey'];
|
||||
|
||||
$answer_json_arr = [];
|
||||
|
||||
//查询病历报告
|
||||
$report = Db::table(TabConf::$fa_tt_medical_report)
|
||||
//->where('hdruserbaseinfo_id',$hdruserbaseinfo_id)
|
||||
//->order('id desc')
|
||||
->where('id',$reportid)
|
||||
->find();
|
||||
if(empty($report)){
|
||||
return Tools::set_fail('暂无病历报告');
|
||||
}
|
||||
$config = [
|
||||
'stream'=>false,
|
||||
];
|
||||
$question = $report['report_content'];//input('question','');
|
||||
|
||||
$chatobj->returnAnswer($question,$config,$answer_json_arr);
|
||||
Tools::log_to_write_txt(['医生问诊提示,gpt请求参数'=>$chatobj->post_msg_body]);
|
||||
Tools::log_to_write_txt(['医生问诊提示,gpt回复'=>$answer_json_arr]);
|
||||
|
||||
return Tools::set_ok('ok',['tips'=>$answer_json_arr]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user