/**
  * Query user list
  *
  * <b>Request Type</b>: GET<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/channel/followers<br/><br/>
  * <b>Response Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for querying users by propertities.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     channelId: string, id of the channel<br/>
  *     tags: array, if more than one tag, implode by comma<br/>
  *     gender: MALE, FEMALE<br/>
  *     country: string<br/>
  *     province: string<br/>
  *     city: string<br/>
  *     subscribeTimeFrom: timestamp<br/>
  *     nickname: string<br/>
  *     per-page: int<br/>
  *     page: int<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     items: array, json array to queried channels detail information<br/>
  *     _meta: array, the pagination information.
  *     <br/><br/>
  *
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *  "items": [
  *      {
  *          "id": "548028238d7a9e9dc8397f8a",
  *          "accountId": "548024cfe4b0cea2642d3c78",
  *          "subscribed": true,
  *          "originId": "oYoUVt2zT6mtrFn9T0nlNWkzJbEo",
  *          "nickname": "hank",
  *          "gender": "Female",
  *          "language": "english",
  *          "city": "武汉",
  *          "province": "湖北",
  *          "country": "中国",
  *          "headerImgUrl": "http://ssp-stage.qiniudn.com/avatar/oib7yt7612cCWuzWj1J5r9kl8-VU.jpg",
  *          "subscribeTime": "2014-12-02 08:17:01",
  *          "unionId": "12.0",
  *          "massSendUsageCount": 4,
  *          "tags": [
  *              "高富帅",
  *              "白富美"
  *          ],
  *          "subscribeSource": "other",
  *          "firstSubscribeSource": "other",
  *          "firstSubscribeTime": "2014-12-02 08:17:01",
  *          "interactMessageCount": 1,
  *          "lastInteractMessageTime": null,
  *          "lastInteractEventTime": "2014-12-02 08:17:01",
  *          "createTime": "2014-12-02 08:17:01",
  *          "unsubscribeTime": null
  *      },
  *      {
  *          "id": "54803daf8d7a9e9dc8397f8b",
  *          "accountId": "548024cfe4b0cea2642d3c78",
  *          "subscribed": true,
  *          "originId": "oYoUVt2zT6mtrFn9T0nlNWkzJbEo",
  *          "nickname": "clark",
  *          "gender": "Female",
  *          "language": "english",
  *          "city": "青岛",
  *          "province": "山东",
  *          "country": "中国",
  *          "headerImgUrl": "http://ssp-stage.qiniudn.com/avatar/oib7yt7612cCWuzWj1J5r9kl8-VU.jpg",
  *          "subscribeTime": "2014-12-02 08:17:01",
  *          "unionId": "12.0",
  *          "massSendUsageCount": 4,
  *          "tags": [
  *              "高富帅",
  *              "白富美"
  *          ],
  *          "subscribeSource": "other",
  *          "firstSubscribeSource": "other",
  *          "firstSubscribeTime": "2014-12-02 08:17:01",
  *          "interactMessageCount": 1,
  *          "lastInteractMessageTime": null,
  *          "lastInteractEventTime": "2014-12-02 08:17:01",
  *          "createTime": "2014-12-02 08:17:01",
  *          "unsubscribeTime": null
  *      }
  *  ],
  *  "_meta": {
  *      "totalCount": 1,
  *      "pageCount": 1,
  *      "currentPage": 1,
  *      "perPage": 20
  *  }
  * }
  * </pre>
  */
 public function actionIndex()
 {
     $query = $this->getQuery();
     $accountId = $this->getAccountId();
     if (empty($query['channelId'])) {
         throw new BadRequestHttpException("Missing channel id");
     }
     $channelId = $query['channelId'];
     unset($query['channelId']);
     $query['pageSize'] = $query['per-page'];
     $query['pageNum'] = $query['page'];
     unset($query['per-page']);
     unset($query['page']);
     $raw = Yii::$app->weConnect->getFollowers($channelId, $query);
     if (array_key_exists('results', $raw)) {
         $openIds = ArrayHelper::getColumn($raw['results'], 'originId');
         $members = Member::getByOpenIds($accountId, $openIds);
         $openIdNameMap = $this->getOpenIdNameMap($members);
         foreach ($raw['results'] as &$result) {
             $result['name'] = empty($openIdNameMap[$result['originId']]) ? '' : $openIdNameMap[$result['originId']];
         }
         return ['items' => $raw['results'], '_meta' => ['totalCount' => $raw['totalAmount'], 'pageCount' => ceil($raw['totalAmount'] / $raw['pageSize']), 'currentPage' => $raw['pageNum'], 'perPage' => $raw['pageSize']]];
     } else {
         throw new ServerErrorHttpException(Yii::t('channel', 'api_data_exception'));
     }
 }