117 lines
3.7 KiB
PHP
117 lines
3.7 KiB
PHP
<?php
|
||
/*
|
||
* description:
|
||
* author:wh
|
||
* email:
|
||
* createTime:{2024/5/23} {18:01}
|
||
*/
|
||
|
||
namespace app\api\logic;
|
||
|
||
|
||
use app\api\controller\BaseWssApi;
|
||
use app\common\model\TabConf;
|
||
use GatewayWorker\Lib\Gateway;
|
||
use think\Db;
|
||
use wanghua\general_utility_tools_php\Mmodel;
|
||
use wanghua\general_utility_tools_php\tool\Tools;
|
||
|
||
/**
|
||
* Class TyuserLogic
|
||
* @package app\api\logic
|
||
*/
|
||
class TyuserLogic extends BaseLogic
|
||
{
|
||
|
||
/**
|
||
* desc:客户端离线
|
||
* author:wh
|
||
*/
|
||
function offline($client_id){
|
||
Mmodel::catchTrans(function () use ($client_id){
|
||
Tools::log_to_write_txt(['服务端收到客户端离线消息:client_id:' . $client_id]);
|
||
|
||
$user = Db::table(TabConf::$fa_device)
|
||
->where('clientid', $client_id)
|
||
->find();
|
||
if(empty($user)){
|
||
Tools::log_to_write_txt(['error:客户端离线,用户不存在:client_id:' . $client_id]);
|
||
return ;
|
||
}
|
||
|
||
Tools::log_to_write_txt(['设置离线时间:clientid:' . $client_id]);
|
||
//$username = $user['username'];
|
||
Db::table(TabConf::$fa_device)
|
||
->where('clientid', $client_id)
|
||
->delete();
|
||
//把ticket设置为空,标识离线(不能清,因为听译和数字人用的同一个账号,否则查不到账号信息)
|
||
//Db::table('fa_hdrdoctorusers')
|
||
// ->data([
|
||
// 'ticket'=>'',//修改为离线
|
||
// ])
|
||
// ->where('username',$username)
|
||
// ->update();
|
||
|
||
//在$client_id无效的情况下可能会抛出异常
|
||
//$json = BaseWssApi::wss_json('ok', '用户已离线');
|
||
//Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||
});
|
||
}
|
||
|
||
|
||
|
||
|
||
/**
|
||
* desc:登录选择角色时绑定设备关系
|
||
* 请求类型:wss
|
||
*请求参数:
|
||
* json消息格式:[
|
||
'action'=>'Tyuser/bindRelation',
|
||
'items'=>[
|
||
'username'=>'13333322323',
|
||
'ticket'=>'sadddddddddddddddddddddddddddd',
|
||
]
|
||
]
|
||
* author:wh
|
||
*/
|
||
function bindRelation($clientid,$data){
|
||
$action = 'Tyuser/bindRelation';
|
||
if(empty($data['items'])){
|
||
$json = Tools::wss_json($action,'items参数错误');
|
||
return Gateway::sendToClient($clientid, $json);
|
||
}
|
||
$items = $data['items'];
|
||
if(empty($items['username'])){
|
||
$json = Tools::wss_json($action,'username参数错误');
|
||
return Gateway::sendToClient($clientid, $json);
|
||
}
|
||
if(empty($items['ticket'])){
|
||
$json = Tools::wss_json($action,'ticket参数错误');
|
||
return Gateway::sendToClient($clientid, $json);
|
||
}
|
||
//验证clientid重复
|
||
$arr = Db::table(TabConf::$fa_device)
|
||
->where('clientid',$clientid)
|
||
->find();
|
||
if(!empty($arr)){
|
||
$json = Tools::wss_json($action,'clientid重复,请重新登录');
|
||
return Gateway::sendToClient($clientid, $json);
|
||
}
|
||
|
||
//先清除这个医生的其它设备(可能是之前绑定的设备,因为医患设备只能一对一),不能清除自己的设备
|
||
Db::table(TabConf::$fa_device)
|
||
->where('username',$items['username'])
|
||
->where('clientid','neq',$clientid)
|
||
->delete();
|
||
|
||
//绑定设备
|
||
Db::table(TabConf::$fa_device)
|
||
->insert([
|
||
'username'=>$items['username'],
|
||
'clientid'=>$clientid,
|
||
'ticket'=>$items['ticket'],//对话票据,根据票据分发消息
|
||
]);
|
||
|
||
return null;
|
||
}
|
||
} |