调整消息推送“

This commit is contained in:
mzl
2025-10-12 08:59:39 +00:00
parent 9dcba987ef
commit 72e2b46f60
3 changed files with 49 additions and 14 deletions
+47 -8
View File
@@ -122,14 +122,6 @@ class WsEvents
'system.auth',
['uid' => $user->uid]
));
// 初始化推送
$wdata = [
'is_first' => true,
'event' => 'approval.todo.counts',
'user_id' => $user->uid
];
\Webman\RedisQueue\Redis::send('ws-msg', $wdata);
} catch (\Throwable $th) {
flg('[x] [TOKEN认证] TOKEN认证失败:'.$th->getMessage(), false);
Gateway::sendToClient($client_id, WsResponse::error(
@@ -164,6 +156,18 @@ class WsEvents
}
public function systemConnect(?string $traceId)
{
$num = (new \app\common\utils\approval\service\ApprovalFlowService())->getInitTodoCount($_SESSION['uid']);
$this->todoCounts($_SESSION['uid'], $num);
Gateway::sendToClient($this->clientId, WsResponse::success(
'system.connect.receive',
['time' => time()],
$traceId
));
}
// ================= 消息通知事件 =================
/**
* 管理端主动推送通知
@@ -255,6 +259,7 @@ class WsEvents
/*
init.pull
approval.todo.counts 审批待办数量
*/
@@ -269,4 +274,38 @@ class WsEvents
default => throw new \InvalidArgumentException('UID must be integer or string'),
};
}
// ================= 临时业务处理 =================
public function todoCounts(int $userId, int $num = 0)
{
$ly = [
1 => 186,
3 => 226,
];
if ($num === 0) {
$num = (new \app\common\utils\approval\service\ApprovalFlowService())->getInitTodoCount($userId);
}
$systemIds = \app\common\model\UserSystems::where('user_id', $userId)->pluck('system_id')->toArray();
if (count($systemIds) > 0) {
foreach ($systemIds as $systemId) {
if (isset($ly[$systemId])) {
$chain = \app\common\service\MenuBadgeService::buildBadgeChain(menuId: $ly[$systemId], leafCount: $num);
$this->pushWebsocket('approval.todo.counts', $userId, $chain);
}
}
}
}
}