Refactor ChatConnect and related classes to use dynamic typing for properties and method parameters. Update event handling to use a consistent naming convention for emitted events. Adjust WebSocket message handling methods to accept event arrays instead of specific data structures. Update configuration for Swoole to increase ping intervals and timeouts.
This commit is contained in:
@@ -19,7 +19,7 @@ class SessionService
|
||||
private const CONN_USER_PREFIX = 'cs:conn:user:';
|
||||
private const CONN_AGENT_PREFIX = 'cs:conn:agent:';
|
||||
|
||||
private AssignService $assignService;
|
||||
private $assignService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ class SessionService
|
||||
* @param int $source 来源 1=PC 2=Game 3=Portal
|
||||
* @return array 会话数据
|
||||
*/
|
||||
public function createSession(int $userId, int $source): array
|
||||
public function createSession($userId, $source)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
@@ -70,7 +70,7 @@ class SessionService
|
||||
/**
|
||||
* 获取用户活跃会话
|
||||
*/
|
||||
public function getActiveSession(int $userId): ?array
|
||||
public function getActiveSession($userId)
|
||||
{
|
||||
return ChatSession::getActiveByUserId($userId);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class SessionService
|
||||
/**
|
||||
* 获取会话详情(含用户信息)
|
||||
*/
|
||||
public function getSessionDetail(int $sessionId): ?array
|
||||
public function getSessionDetail($sessionId)
|
||||
{
|
||||
$session = ChatSession::find($sessionId);
|
||||
if (!$session) {
|
||||
@@ -105,7 +105,7 @@ class SessionService
|
||||
/**
|
||||
* 结束会话
|
||||
*/
|
||||
public function endSession(int $sessionId, int $operatorId): bool
|
||||
public function endSession($sessionId, $operatorId)
|
||||
{
|
||||
$session = ChatSession::find($sessionId);
|
||||
if (!$session) {
|
||||
@@ -141,7 +141,7 @@ class SessionService
|
||||
/**
|
||||
* 转接会话
|
||||
*/
|
||||
public function transferSession(int $sessionId, int $newAdminId): bool
|
||||
public function transferSession($sessionId, $newAdminId)
|
||||
{
|
||||
$session = ChatSession::find($sessionId);
|
||||
if (!$session || $session['status'] !== ChatSession::STATUS_ACTIVE) {
|
||||
@@ -175,7 +175,7 @@ class SessionService
|
||||
/**
|
||||
* 会话评价
|
||||
*/
|
||||
public function rateSession(int $sessionId, int $rating, ?string $content = null): bool
|
||||
public function rateSession($sessionId, $rating, $content = null)
|
||||
{
|
||||
$session = ChatSession::find($sessionId);
|
||||
if (!$session) {
|
||||
@@ -197,7 +197,7 @@ class SessionService
|
||||
/**
|
||||
* 注册用户连接
|
||||
*/
|
||||
public function registerUserConnection(int $userId, int $fd): void
|
||||
public function registerUserConnection($userId, $fd)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->setex(self::CONN_USER_PREFIX . $userId, 60, $fd);
|
||||
@@ -206,7 +206,7 @@ class SessionService
|
||||
/**
|
||||
* 注册客服连接
|
||||
*/
|
||||
public function registerAgentConnection(int $adminId, int $fd): void
|
||||
public function registerAgentConnection($adminId, $fd)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->setex(self::CONN_AGENT_PREFIX . $adminId, 60, $fd);
|
||||
@@ -215,7 +215,7 @@ class SessionService
|
||||
/**
|
||||
* 刷新用户连接TTL
|
||||
*/
|
||||
public function refreshUserConnection(int $userId): void
|
||||
public function refreshUserConnection($userId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->expire(self::CONN_USER_PREFIX . $userId, 60);
|
||||
@@ -224,7 +224,7 @@ class SessionService
|
||||
/**
|
||||
* 刷新客服连接TTL
|
||||
*/
|
||||
public function refreshAgentConnection(int $adminId): void
|
||||
public function refreshAgentConnection($adminId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->expire(self::CONN_AGENT_PREFIX . $adminId, 60);
|
||||
@@ -233,7 +233,7 @@ class SessionService
|
||||
/**
|
||||
* 获取用户连接FD
|
||||
*/
|
||||
public function getUserFd(int $userId): ?int
|
||||
public function getUserFd($userId): ?int
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$fd = $redis->get(self::CONN_USER_PREFIX . $userId);
|
||||
@@ -243,7 +243,7 @@ class SessionService
|
||||
/**
|
||||
* 获取客服连接FD
|
||||
*/
|
||||
public function getAgentFd(int $adminId): ?int
|
||||
public function getAgentFd($adminId): ?int
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$fd = $redis->get(self::CONN_AGENT_PREFIX . $adminId);
|
||||
@@ -253,7 +253,7 @@ class SessionService
|
||||
/**
|
||||
* 清理用户连接
|
||||
*/
|
||||
public function clearUserConnection(int $userId): void
|
||||
public function clearUserConnection($userId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->del(self::CONN_USER_PREFIX . $userId);
|
||||
@@ -262,7 +262,7 @@ class SessionService
|
||||
/**
|
||||
* 清理客服连接
|
||||
*/
|
||||
public function clearAgentConnection(int $adminId): void
|
||||
public function clearAgentConnection($adminId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->del(self::CONN_AGENT_PREFIX . $adminId);
|
||||
@@ -271,7 +271,7 @@ class SessionService
|
||||
/**
|
||||
* 获取客服会话列表
|
||||
*/
|
||||
public function getAgentSessions(int $adminId): array
|
||||
public function getAgentSessions($adminId)
|
||||
{
|
||||
$sessions = ChatSession::getActiveByAdminId($adminId);
|
||||
|
||||
@@ -297,7 +297,7 @@ class SessionService
|
||||
/**
|
||||
* 获取待分配会话列表
|
||||
*/
|
||||
public function getPendingSessions(): array
|
||||
public function getPendingSessions()
|
||||
{
|
||||
$sessions = ChatSession::where('status', ChatSession::STATUS_PENDING)
|
||||
->order('create_time', 'asc')
|
||||
@@ -319,7 +319,7 @@ class SessionService
|
||||
/**
|
||||
* 获取Redis实例
|
||||
*/
|
||||
private function getRedis(): \Redis
|
||||
private function getRedis()
|
||||
{
|
||||
return Cache::store('redis')->handler();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user