first commit
This commit is contained in:
253
digital_doctor/application/api/controller/Usersh5.php
Normal file
253
digital_doctor/application/api/controller/Usersh5.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/8/10} {11:25}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
use app\api\logic\TtchatLogic;
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\Mmodel;
|
||||
use wanghua\general_utility_tools_php\Validate;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Usersh5 extends BaseHttpApi
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
//if(!self::checkLogin()){
|
||||
// echo json_encode(['code'=>591,'msg'=>'未登录']);exit;
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查登录
|
||||
*/
|
||||
static function checkLogin(){
|
||||
return Mmodel::catch(function (){
|
||||
$ticket = input('ticket');
|
||||
if(empty($ticket)){
|
||||
return false;//默认未登录
|
||||
}
|
||||
$user = Db::table(TabConf::$fa_hdrusersh5)->where('ticket',$ticket)->cache(300)->find();
|
||||
if(empty($user)){
|
||||
return false;//默认未登录
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:h5-授权,登录
|
||||
*
|
||||
* /api/Usersh5/login
|
||||
*
|
||||
* 参数:
|
||||
* username 用户名(手机号)
|
||||
* code 验证码
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function login()
|
||||
{
|
||||
return Mmodel::catchJson(function (){
|
||||
$doctor = input('doctor');
|
||||
if(empty($doctor)){
|
||||
return Tools::set_fail('doctor所属医生参数错误:1');
|
||||
}
|
||||
if(!Validate::is_mobile($doctor)){
|
||||
return Tools::set_fail('doctor医生手机号错误:2');
|
||||
}
|
||||
|
||||
$username = input('username');
|
||||
if(empty($username)){
|
||||
return Tools::set_fail('参数错误:1');
|
||||
}
|
||||
$code = input('code');//验证码
|
||||
if(empty($code)){
|
||||
return Tools::set_fail('验证码错误:2');
|
||||
}
|
||||
if(!Validate::is_mobile($username)){
|
||||
return Tools::set_fail('手机号错误:2');
|
||||
}
|
||||
|
||||
//校验验证码
|
||||
if(empty($code)){
|
||||
return Tools::set_fail('验证码错误:2');
|
||||
}
|
||||
//查询短信验证码
|
||||
$sms = Db::table(TabConf::$fa_sms)
|
||||
->where('mobile',$username)
|
||||
->where('code',$code)
|
||||
->order('id desc')
|
||||
->find();
|
||||
if(empty($sms)){
|
||||
return Tools::set_res(340,'验证码错误:3');
|
||||
}
|
||||
if($sms['event'] != 'login'){
|
||||
return Tools::set_fail('场景错误:4');
|
||||
}
|
||||
if($sms['times'] > 1){
|
||||
return Tools::set_fail('该验证码已失效:4');
|
||||
}
|
||||
|
||||
$user = Db::table(TabConf::$fa_hdrusersh5)
|
||||
->where('username',$username)
|
||||
->find();
|
||||
//返回票据
|
||||
$ticketstr = md5($username);
|
||||
$expires = 30*86400+time();//报告完成之后重新获取票据
|
||||
if(empty($user)){
|
||||
//注册
|
||||
$user = Db::table(TabConf::$fa_hdrusersh5)
|
||||
->data([
|
||||
'username'=>$username,
|
||||
'ticket'=>$ticketstr,
|
||||
'expires'=>$expires,
|
||||
'doctor'=>$doctor,
|
||||
'expire_time'=>date('Y-m-d H:i:s',$expires)
|
||||
])
|
||||
->insert();
|
||||
}
|
||||
//修改验证码验证次数
|
||||
Db::table(TabConf::$fa_sms)
|
||||
->where('id',$sms['id'])
|
||||
->setInc('times');
|
||||
|
||||
|
||||
$uniqueid = md5($ticketstr.$expires.Tools::rand_str(6));
|
||||
|
||||
//修改有效期
|
||||
Db::table(TabConf::$fa_hdrusersh5)
|
||||
->data([
|
||||
'ticket'=>$ticketstr,
|
||||
'expires'=>$expires,//7天
|
||||
'doctor'=>$doctor,//每次扫码更新医生
|
||||
'expire_time'=>date('Y-m-d H:i:s',$expires)
|
||||
])
|
||||
->where('username',$username)
|
||||
->update();
|
||||
|
||||
//查询最新的基本信息id
|
||||
$baseuserinfo_id = Db::table(TabConf::$fa_ty_userbaseinfo)
|
||||
->where('phone',$username)
|
||||
->order('id desc')
|
||||
->value('id');
|
||||
return Tools::set_ok('登录成功',[
|
||||
'ticket'=>$ticketstr,'uniqueid'=>$uniqueid,
|
||||
'username'=>$username,'user'=>$user,
|
||||
'baseuserinfo_id'=>$baseuserinfo_id
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:h5-根据id查询用户
|
||||
* api/Usersh5/getUserById
|
||||
* 参数:
|
||||
* dataid 用户id
|
||||
* author:wh
|
||||
*/
|
||||
function getUserById(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$dataid = input('dataid');
|
||||
if(empty($dataid)){
|
||||
return Tools::set_fail('参数错误');
|
||||
}
|
||||
$data = Db::table(TabConf::$fa_hdrusersh5)
|
||||
->where('id',$dataid)
|
||||
->find();
|
||||
return Tools::set_res(200,'查询成功',$data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* desc:h5-保存聊天记录
|
||||
*
|
||||
* api/Usersh5/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);
|
||||
// });
|
||||
//}
|
||||
|
||||
/**
|
||||
* h5-修改基本信息
|
||||
* api/Usersh5/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(TabConf::$fa_hdrusersh5)->where('ticket',$ticket)->find();
|
||||
// //if(empty($user)){
|
||||
// // return Tools::set_fail('ticket错误,未查询到用户');
|
||||
// //}
|
||||
// $userid = input('userid');
|
||||
// if(empty($userid)){
|
||||
// return Tools::set_fail('h5用户id必须');
|
||||
// }
|
||||
// //修改基本信息
|
||||
// $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(TabConf::$fa_ty_userbaseinfo,[
|
||||
// 'id'=>$userid,
|
||||
// ],$data);
|
||||
//
|
||||
// return Tools::set_ok();
|
||||
// });
|
||||
//}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user