userid = $userid; $this->dialogMsgArray = $dialogMsgArray; } /** * @throws \Throwable */ public function start() { $userids = is_array($this->userid) ? $this->userid : [$this->userid]; $msgId = intval($this->dialogMsgArray['id']); $send = intval($this->dialogMsgArray['send']); if (empty($userids) || empty($msgId)) { return; } $pushIds = []; foreach ($userids AS $userid) { $msgRead = WebSocketDialogMsgRead::createInstance([ 'msg_id' => $msgId, 'userid' => $userid, ]); try { $msgRead->saveOrFail(); $pushIds[] = $userid; } catch (\Throwable $e) { // } } // 更新已发送数量 if ($send != count($pushIds)) { $send = WebSocketDialogMsgRead::whereMsgId($msgId)->count(); WebSocketDialogMsg::whereId($msgId)->update([ 'send' => $send ]); $this->dialogMsgArray['send'] = $send; } // 开始推送消息 if ($pushIds) { PushTask::push([ 'userid' => $pushIds, 'msg' => [ 'type' => 'dialog', 'data' => $this->dialogMsgArray, ] ]); } } }