public function actionIndex() { $perPage = $this->getQuery('per-page', 20); $page = $this->getQuery('page', 1); $accountId = $this->getAccountId(); $account = Account::findByPk($accountId); $channels = Channel::getEnableChannelIds($accountId); $tags = empty($account->tags) ? [] : $account->tags; $tags = ArrayHelper::getColumn($tags, 'name', false); $totalCount = count($tags); rsort($tags); $tags = array_slice($tags, ($page - 1) * $perPage, $perPage); if (empty($tags)) { return ['items' => [], '_meta' => ['totalCount' => 0, 'pageCount' => 0, 'currentPage' => $page, 'perPage' => $perPage]]; } if (!defined('KLP') || !KLP) { if (!empty($channels)) { $followerTags = Yii::$app->weConnect->getTagStats($channels, $tags); } } $memberTags = Member::getTagStats($accountId, $tags, $channels); $memberTagMap = ArrayHelper::map($memberTags, '_id', 'count'); $items = []; foreach ($tags as $tag) { $items[] = ['name' => $tag, 'memberCount' => empty($memberTagMap[$tag]) ? 0 : $memberTagMap[$tag], 'followerCount' => empty($followerTags[$tag]) ? 0 : $followerTags[$tag]]; } $meta = ['totalCount' => $totalCount, 'pageCount' => ceil($totalCount / $perPage), 'currentPage' => $page, 'perPage' => $perPage]; return ['items' => $items, '_meta' => $meta]; }