public function actionIndex() { $accountId = $this->getAccountId(); $currentHelpdeskId = $this->getUserId(); $query = HelpDesk::find(); $clientOpenId = $this->getQuery('clientOpenId'); if ($orderBy = $this->getQuery('orderBy')) { if (StringUtil::isJson($orderBy)) { $orderBy = Json::decode($orderBy, true); foreach ($orderBy as $key => $value) { if ($value === 'asc' || $value === 'ASC') { $orderBy[$key] = SORT_ASC; } else { $orderBy[$key] = SORT_DESC; } } } else { $orderBy = [$orderBy => SORT_DESC]; } $query->orderBy($orderBy); } $allHelpdesks = $query->where(['accountId' => $accountId, 'isDeleted' => false, 'isActivated' => true, 'isEnabled' => true])->andWhere(['not in', '_id', [$currentHelpdeskId]])->orderBy(['clientCount' => SORT_ASC])->all(); $result = []; if ($allHelpdesks) { foreach ($allHelpdesks as $helpdesk) { array_push($result, $helpdesk->toArray()); } } $lastChatConversation = ChatConversation::getLastChatByClient($clientOpenId, $currentHelpdeskId, $accountId); if ($lastChatConversation) { $lastServeHelpdeskId = (string) $lastChatConversation->desk['id']; if (!empty($result)) { $allOnlineHelpdesks = []; foreach ($result as $index => $item) { if ($item['isOnline'] && $item['id'] === $lastServeHelpdeskId) { $item['isLastChat'] = true; array_unshift($allOnlineHelpdesks, $item); } else { if ($item['isOnline']) { array_push($allOnlineHelpdesks, $item); } } } $result = $allOnlineHelpdesks; } } return $result; }
/** * Get helpdesk list exculde tag name * @param String $tagName * @return array **/ public static function getExculdeTags($tags, $accountId) { if (is_string($tags)) { $tags = [$tags]; } $condition = ['tags' => ['$nin' => $tags], 'accountId' => $accountId, 'isDeleted' => self::NOT_DELETED]; return HelpDesk::find()->where($condition)->all(); }