278 lines
8.3 KiB
PHP
278 lines
8.3 KiB
PHP
<?php
|
||
/*
|
||
* description:
|
||
* author:wh
|
||
* email:
|
||
* createTime:{2024/3/26} {20:55}
|
||
*/
|
||
|
||
namespace app\api\controller;
|
||
|
||
|
||
use app\api\logic\TtchatLogic;
|
||
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\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 Userstt
|
||
* @package app\api\controller
|
||
*/
|
||
class Userstt extends BaseHttpApi
|
||
{
|
||
/**
|
||
* desc:疼痛科-根据id查询用户
|
||
* api/Userstt/getUserById
|
||
* 参数:
|
||
* dataid 用户id
|
||
* author:wh
|
||
*/
|
||
function getUserById(){
|
||
return Mmodel::catchJson(function (){
|
||
$dataid = input('dataid');
|
||
if(empty($dataid)){
|
||
return Tools::set_fail('参数错误');
|
||
}
|
||
$data = Db::table('fa_hdrdoctorusers')
|
||
->where('id',$dataid)
|
||
->find();
|
||
return Tools::set_res(200,'查询成功',$data);
|
||
});
|
||
}
|
||
|
||
|
||
/**
|
||
* desc:疼痛科-授权,登录
|
||
*
|
||
* /api/Userstt/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([
|
||
'ticket'=>$ticketstr,
|
||
'expires'=>$expires,//7天
|
||
//'clientid'=>$clientid,
|
||
])
|
||
->where('username',$username)
|
||
->update();
|
||
return Tools::set_ok('登录成功',['ticket'=>$ticketstr,'username'=>$username,'user'=>$user]);
|
||
});
|
||
}
|
||
|
||
/**
|
||
* desc:疼痛科-保存聊天记录
|
||
*
|
||
* api/Userstt/saveChatHistory
|
||
*
|
||
* author:wh
|
||
*/
|
||
function saveChatHistory(){
|
||
return Mmodel::catchJson(function (){
|
||
$obj = new TtchatLogic();
|
||
$chat_content = input('chat_content');
|
||
if(empty($chat_content)){
|
||
return Tools::set_fail('参数错误');
|
||
}
|
||
$res = $obj->saveChatHistory($chat_content);
|
||
return Tools::set_ok('ok',$res);
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 疼痛科-修改基本信息
|
||
* api/Userstt/editBaseinfo
|
||
* 参数:ticket
|
||
*
|
||
name 病人姓名
|
||
gender 病人性别
|
||
age 病人年龄
|
||
edu 教育程度
|
||
caree职业及年限r_year
|
||
power体力要求
|
||
satisfaction 经济满意度
|
||
old_car过往职业及年限eer_year
|
||
support 社会支持度
|
||
marriage 婚姻状况
|
||
live 居住情况
|
||
home 家庭关系
|
||
addres地址s
|
||
phone 联系方式
|
||
wechat_no微信号
|
||
*/
|
||
function editBaseinfo(){
|
||
return Mmodel::catchJson(function (){
|
||
$ticket = input('ticket');
|
||
if(empty($ticket)){
|
||
return Tools::set_fail('ticket必须');
|
||
}
|
||
$user = Db::table('fa_hdrdoctorusers')->where('ticket',$ticket)->find();
|
||
if(empty($user)){
|
||
return Tools::set_fail('ticket错误');
|
||
}
|
||
//修改基本信息
|
||
$data = [
|
||
'doctor'=>$user['username'],//医生
|
||
'name'=>input('name',''),//病人姓名
|
||
'gender'=>input('gender',''),//病人性别
|
||
'age'=>input('age',''),//病人年龄
|
||
'edu'=>input('edu',''),//教育程度
|
||
'career_year'=>input('career_year',''),//职业及年限
|
||
'power'=>input('power',''),//体力要求
|
||
'satisfaction'=>input('satisfaction',''),//经济满意度
|
||
'old_career_year'=>input('old_career_year',''),//过往职业及年限
|
||
'support'=>input('support',''),//社会支持度
|
||
'marriage'=>input('marriage',''),//婚姻状况
|
||
'live'=>input('live',''),//居住情况
|
||
'home'=>input('home',''),//家庭关系
|
||
'address'=>input('address',''),//地址
|
||
'phone'=>input('phone',''),//联系方式
|
||
'wechat_no'=>input('wechat_no',''),//微信号
|
||
|
||
];
|
||
Mmodel::existsUpdateInsert('fa_tt_userbaseinfo',[
|
||
'username'=>$user['username'],
|
||
'name'=>input('name',''),
|
||
],$data);
|
||
|
||
return Tools::set_ok();
|
||
});
|
||
}
|
||
|
||
/**
|
||
* desc:提交自由问答记录(后台需要单独列出来,对话时前端缓存在本地,对话结束提交)
|
||
*
|
||
* 参数:
|
||
* ticket 对话票据(结束问诊时重新生成)
|
||
* username 用户名
|
||
* content 对话内容,格式:
|
||
* content = [
|
||
["role" => "user", "content" => '1'],
|
||
["role" => "user", "content" => '2'],
|
||
["role" => "user", "content" => '3'],
|
||
];
|
||
*
|
||
* api/Userstt/subFreeQuestionAnswerRecord
|
||
*
|
||
* author:wh
|
||
*/
|
||
function subFreeQuestionAnswerRecord(){
|
||
return Mmodel::catchJson(function (){
|
||
$ticket = input('ticket');
|
||
if(empty($ticket)){
|
||
return Tools::set_fail('ticket必须');
|
||
}
|
||
$content = input('content');
|
||
if(empty($content)){
|
||
return Tools::set_fail('content对话内容必须');
|
||
}
|
||
$username = input('username');
|
||
if(empty($username)){
|
||
return Tools::set_fail('username必须');
|
||
}
|
||
|
||
$this->setTtFreeChatHistory($content,$username,$ticket);
|
||
|
||
return Tools::set_ok();
|
||
});
|
||
}
|
||
|
||
/**
|
||
* desc:保存疼痛科自由对话聊天记录
|
||
* author:wh
|
||
* @param $sub_content
|
||
*/
|
||
private function setTtFreeChatHistory($sub_content,$username,$ticket){
|
||
//$content = [
|
||
// //["role" => "user", "content" => '']
|
||
//];
|
||
$data = [];
|
||
foreach ($sub_content as $item){
|
||
$content = explode(':',$item['content']);
|
||
$d = [
|
||
'username'=>$username,
|
||
'type'=>empty($content[0])?'':$content[0],
|
||
'chat_msg'=>$item['content'],
|
||
'ticket'=>$ticket,
|
||
];
|
||
$data[] = $d;
|
||
}
|
||
Db::table(TabConf::$fa_tt_free_chathistory)->insertAll($data);
|
||
}
|
||
|
||
/**
|
||
* 诊断完成
|
||
* api/Userstt/diagFinish
|
||
* 参数:report_id 报告id
|
||
*/
|
||
function diagFinish(){
|
||
return Mmodel::catchJson(function (){
|
||
$report_id = input('report_id');
|
||
if(empty($report_id)){
|
||
return Tools::set_fail('参数错误');
|
||
}
|
||
//查询报告
|
||
$report = Db::table(TabConf::$fa_tt_medical_report)->where('id',$report_id)->find();
|
||
if(empty($report)){
|
||
return Tools::set_fail('报告不存在');
|
||
}
|
||
|
||
if($report['status']==2){
|
||
return Tools::set_fail('报告已诊断完成,请勿重复提交');
|
||
}
|
||
|
||
$res = Db::table(TabConf::$fa_tt_medical_report)->where('id',$report_id)->update(['status'=>2]);
|
||
return Tools::set_ok('ok',$res);
|
||
});
|
||
}
|
||
} |