/** * 获取用户中心信息 * @param int $user_id * @return array|int */ public function userCenter($user_id) { if (!is_numeric($user_id)) { return ErrorConstant::USER_ID_ERROR; } $user = UserModel::find()->select('name,icon_url,nick_name,gender,birthday,mobile')->asArray()->one(); if (empty($user)) { return ErrorConstant::USER_NOT_EXISTS; } return $user; }
/** * 获取验证码 * * @param int $user_id * @return mixed */ private function getInvitationCode($user_id) { $invitationCode = InvitationCode::findOne(['user_id' => $user_id]); if ($invitationCode === null) { $invitationCode = $this->addInvitationCode($user_id); } if ($invitationCode === null) { return ErrorConstant::CREATE_INVITATION_CODE_FAILED; } $_return['code'] = $invitationCode->invitation_code; $_return['registerNum'] = UserModel::find()->where(['invitation_code' => $invitationCode->invitation_code])->count(); return $_return; }
/** * 获取好友列表 * @param $user_id * @param int $page_index * @param int $page_count * @return array|int|\yii\db\ActiveRecord[] */ public function friendList($user_id, $page_index = self::DEFAULT_PAGE_INDEX, $page_count = self::DEFAULT_PAGE_COUNT) { if (!is_numeric($user_id)) { return ErrorConstant::PARAM_ERROR; } $page_index = is_numeric($page_index) ? $page_index : self::DEFAUT_PAGE_INDEX; $page_count = is_numeric($page_count) ? $page_count : self::DEFAUT_PAGE_COUNT; $_offset = ($page_index - 1) * $page_count; $_friend = FriendModel::find()->where(['originator' => $user_id, 'deleted' => FriendModel::IS_NOT_DELETED, 'status' => FriendModel::RELATION_STATUS_IS_FRIEND])->indexBy('friend_id')->asArray()->all(); $_originator = FriendModel::find()->where(['agree_id' => $user_id, 'deleted' => FriendModel::IS_NOT_DELETED, 'status' => FriendModel::RELATION_STATUS_IS_FRIEND])->asArray()->indexBy('originator')->all(); $_list_id = ArrayHelper::merge(ArrayHelper::getColumn($_friend, 'friend_id'), ArrayHelper::getColumn($_originator, 'originator')); $_friends = UserModel::find()->where(['in', 'id', $_list_id])->offset($_offset)->limit($page_count)->asArray()->all(); return $_friends; }
/** * 根据用户名名(手机号),密码查找用户 * @param string $user_name * @param string $password * @return array|null|\yii\db\ActiveRecord */ private function _findUser($user_name, $password) { return UserModel::find()->where('(name = :name OR mobile = :name) AND password = :password', ['name' => $user_name, 'password' => $password])->one(); }
/** * 获取演员评论信息 * @param $actor_id * @param $index * @param $count * @return array|int|\yii\mongodb\ActiveRecord */ public function commentList($actor_id, $index, $count) { if (!is_numeric($actor_id)) { return ErrorConstant::PARAM_ERROR; } $index = is_numeric($index) ? $index : self::PAGE_INDEX_DEFAULT; $count = is_numeric($count) ? $count : self::PAGE_COUNT_DEFAULT; $offset = ($index - 1) * $count; //判断演员是否存在 $actor = ActorModel::find()->where(['status' => ActorModel::ACTOR_STATUS_OK, 'id' => $actor_id])->asArray()->one(); if ($actor === []) { return ErrorConstant::ACTOR_NOT_EXISTS; } //获取评论列表 $commentList = ActorCommentModel::find()->where(['actor_id' => (int) $actor_id])->offset($offset)->limit($count)->asArray()->orderBy('create_time DESC')->all(); if ($commentList === []) { return $commentList; } $user_id = array_unique(array_merge(ArrayHelper::getColumn($commentList, 'user_id'), ArrayHelper::getColumn($commentList, 'target_user_id'))); //获取用户信息 $comment_user = UserModel::find()->where(['in', 'id', $user_id])->asArray()->all(); $comment_user = ArrayHelper::index($comment_user, 'id'); //获取用户评论的评论信息 $comment_id = array_unique(ArrayHelper::getColumn($commentList, 'target_comment_id')); $target_comment = ActorCommentModel::find()->where(['in', '_id', $comment_id])->asArray()->all(); $target_comment = ArrayHelper::index($target_comment, '_id'); foreach ($commentList as $key => $comment) { $commentList[$key]['user_name'] = $comment_user[$comment['user_id']]['nick_name']; $commentList[$key]['icon_url'] = $comment_user[$comment['user_id']]['icon_url']; if ($comment['target_comment_id'] >= 0) { $commentList[$key]['target_user_name'] = $comment_user[$comment['target_user_id']]['nick_name']; $commentList[$key]['target_user_icon_url'] = $comment_user[$comment['target_user_id']]['icon_url']; $commentList[$key]['target_comment_content'] = $target_comment[$comment['target_user_id']]['content']; } } return $commentList; }