/** * HelpDesk offline * @param string $deskId * @param MongoId $accountId * @param Object $extra * @return array */ public static function leave($deskId, $accountId, $extra) { $cache = Yii::$app->cache; //remove it from conversation caches $conversations = $cache->get('conversations' . $accountId); unset($conversations[$deskId]); $cache->set('conversations' . $accountId, $conversations); //remove it from online caches self::cacheOnlineDesks($deskId, (string) $accountId, ChatConversation::EVENT_USER_REMOVED); //remove the helpdesk ping time $onlineHelpDesks = $cache->get(HelpDesk::CACHE_PREFIX_HELPDESK_PING . $accountId); unset($onlineHelpDesks[$deskId]); $cache->set(HelpDesk::CACHE_PREFIX_HELPDESK_PING . $accountId, $onlineHelpDesks); //get the conversation records in db according to the deskId $conversationInstances = ChatConversation::findOpenByDeskId(new \MongoId($deskId), $accountId); foreach ($conversationInstances as $conversationInstance) { $clientTemp = $conversationInstance->client; $desk = $conversationInstance->desk; //trigger deskLeft event $data = ['conversationId' => (string) $conversationInstance['_id'], 'desk' => $desk, 'client' => $clientTemp, 'extra' => $extra, 'sentTime' => TimeUtil::msTime()]; $channels = [ChatConversation::getChannelName($deskId, $clientTemp['openId'])]; Yii::$app->tuisongbao->triggerEvent(ChatConversation::EVENT_DESK_LEFT, $data, $channels); //set the status of the chatConversation to "closed" ChatConversation::closeById($conversationInstance['_id']); HelpDesk::sendSystemReplyByType($clientTemp, $accountId, isset($extra['type']) ? $extra['type'] : HelpDeskSetting::REPLY_CLOSE); } //flush the client count in db helpDesk::flushClientCount(new \MongoId($deskId)); LogUtil::info(['event' => 'deskLeft', 'deskId' => $deskId], 'helpdesk'); return ['status' => 'ok']; }