first commit

This commit is contained in:
2025-03-17 10:56:09 +08:00
parent b65a5fd005
commit afec54dafe
6918 changed files with 1199199 additions and 0 deletions

View File

@@ -0,0 +1,117 @@
<?php
/*
* description
* authorwh
* 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客户端离线
* authorwh
*/
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',
]
]
* authorwh
*/
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;
}
}