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:
@@ -31,7 +31,7 @@ class AssignService
|
||||
* @param int $sessionId 会话ID
|
||||
* @return int|null 分配的客服ID,null表示无可用客服
|
||||
*/
|
||||
public function assignSession(int $userId, int $sessionId): ?int
|
||||
public function assignSession($userId, $sessionId): ?int
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$lockKey = self::LOCK_PREFIX . $userId;
|
||||
@@ -85,7 +85,7 @@ class AssignService
|
||||
/**
|
||||
* 获取在线客服列表
|
||||
*/
|
||||
public function getOnlineAgents(): array
|
||||
public function getOnlineAgents()
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$enabledAdmins = ChatAdminStatus::getEnabledAdminIds();
|
||||
@@ -103,7 +103,7 @@ class AssignService
|
||||
/**
|
||||
* 选择会话数最少的客服
|
||||
*/
|
||||
public function selectLeastLoadAgent(array $onlineAgents): ?int
|
||||
public function selectLeastLoadAgent($onlineAgents): ?int
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$loads = [];
|
||||
@@ -129,7 +129,7 @@ class AssignService
|
||||
/**
|
||||
* 添加到离线队列 (按余额降序)
|
||||
*/
|
||||
public function addToOfflineQueue(int $userId, int $sessionId): void
|
||||
public function addToOfflineQueue($userId, $sessionId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
@@ -151,7 +151,7 @@ class AssignService
|
||||
/**
|
||||
* 客服上线时处理队列
|
||||
*/
|
||||
public function processOfflineQueue(int $adminId): array
|
||||
public function processOfflineQueue($adminId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$processed = [];
|
||||
@@ -190,7 +190,7 @@ class AssignService
|
||||
/**
|
||||
* 释放会话 (会话结束时调用)
|
||||
*/
|
||||
public function releaseSession(int $sessionId, int $adminId): void
|
||||
public function releaseSession($sessionId, $adminId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
@@ -207,7 +207,7 @@ class AssignService
|
||||
/**
|
||||
* 设置客服在线状态
|
||||
*/
|
||||
public function setAgentOnline(int $adminId): void
|
||||
public function setAgentOnline($adminId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->setex(self::ONLINE_PREFIX . $adminId, 60, '1');
|
||||
@@ -217,7 +217,7 @@ class AssignService
|
||||
/**
|
||||
* 刷新客服在线状态 (心跳续期)
|
||||
*/
|
||||
public function refreshAgentOnline(int $adminId): void
|
||||
public function refreshAgentOnline($adminId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->expire(self::ONLINE_PREFIX . $adminId, 60);
|
||||
@@ -226,7 +226,7 @@ class AssignService
|
||||
/**
|
||||
* 设置客服离线
|
||||
*/
|
||||
public function setAgentOffline(int $adminId): void
|
||||
public function setAgentOffline($adminId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->del(self::ONLINE_PREFIX . $adminId);
|
||||
@@ -236,7 +236,7 @@ class AssignService
|
||||
/**
|
||||
* 获取客服最大会话数
|
||||
*/
|
||||
private function getAgentMaxSessions(int $adminId): int
|
||||
private function getAgentMaxSessions($adminId)
|
||||
{
|
||||
$status = ChatAdminStatus::getByAdminId($adminId);
|
||||
return $status['max_sessions'] ?? self::MAX_SESSIONS;
|
||||
@@ -245,7 +245,7 @@ class AssignService
|
||||
/**
|
||||
* 获取用户已有会话的客服ID
|
||||
*/
|
||||
private function getExistingSessionAgent(int $userId): ?int
|
||||
private function getExistingSessionAgent($userId): ?int
|
||||
{
|
||||
$session = ChatSession::getActiveByUserId($userId);
|
||||
return $session['admin_id'] ?? null;
|
||||
@@ -254,7 +254,7 @@ class AssignService
|
||||
/**
|
||||
* 绑定会话到客服
|
||||
*/
|
||||
private function bindSessionToAgent(int $sessionId, int $adminId): void
|
||||
private function bindSessionToAgent($sessionId, $adminId)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
@@ -272,7 +272,7 @@ class AssignService
|
||||
/**
|
||||
* 释放分配锁
|
||||
*/
|
||||
private function releaseLock(string $key, string $value): void
|
||||
private function releaseLock($key, $value)
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
@@ -290,7 +290,7 @@ class AssignService
|
||||
/**
|
||||
* 获取Redis实例
|
||||
*/
|
||||
private function getRedis(): \Redis
|
||||
private function getRedis()
|
||||
{
|
||||
return Cache::store('redis')->handler();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user