Пример #1
0
 /**
  * Check the connect client whether has the VIP helpdesk
  * @param array $client
  * @param MongoId $accountId
  * @return mixed
  */
 public static function hasVIPDesk($client, $accountId)
 {
     // Check the client from 'website' or 'WeConnect'
     if (!empty($client['originId'])) {
         $member = Member::findOne(['openId' => $client['originId']]);
         if (!empty($member) && !empty($member->tags)) {
             $client['tags'] = $member->tags;
             $helpdesks = self::getByAccountAndTags($member->tags, $accountId);
             if (!empty($helpdesks)) {
                 $maxClient = HelpDeskSetting::getMaxClientCount($accountId);
                 $availableDeskIds = [];
                 foreach ($helpdesks as $helpdesk) {
                     $helpdesk = $helpdesk->toArray();
                     if ($helpdesk['isOnline'] && $helpdesk['clientCount'] < $maxClient) {
                         $availableDeskIds[] = new \MongoId($helpdesk['id']);
                     }
                 }
                 if (!empty($availableDeskIds)) {
                     $lastChatConversation = ChatConversation::find()->where(['desk.id' => ['$in' => $availableDeskIds]])->orderBy(['lastChatTime' => SORT_DESC])->one();
                     $targetDeskId = null;
                     if (!empty($lastChatConversation)) {
                         $targetDeskId = (string) $lastChatConversation->desk['id'];
                     } else {
                         $targetDeskId = (string) $availableDeskIds[0];
                     }
                     return $targetDeskId;
                 }
             }
         }
     }
     return false;
 }