/**
  * 获取验证码
  *
  * @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 string $user_id
  * @return array|int
  */
 public function account($user_id)
 {
     if (!is_numeric($user_id)) {
         return ErrorConstant::USER_ID_ERROR;
     }
     $user = UserModel::findOne($user_id);
     if ($user === null) {
         return ErrorConstant::USER_NOT_EXISTS;
     }
     $_userInfo = $user->toArray(['icon_url', 'nick_name']);
     //用户积分
     $_userInfo['score'] = 999;
     //是否有未读消息
     $_userInfo['unreadMessagee'] = true;
     return $_userInfo;
 }
示例#3
0
 /**
  * 根据用户名名(手机号),密码查找用户
  * @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();
 }
示例#4
0
 /**
  * 获取演员评论信息
  * @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;
 }
 /**
  * 解除好友关系
  * @param $user_id
  * @param $friend_id
  * @return int
  */
 public function releaseFriend($user_id, $friend_id)
 {
     if (!is_numeric($user_id) || !is_numeric($friend_id)) {
         return ErrorConstant::PARAM_ERROR;
     }
     if (UserModel::findOne($friend_id === null)) {
         return ErrorConstant::USER_NOT_EXISTS;
     }
     //判断是已经是好友关系
     $_relation = FriendModel::isFriend($user_id, $friend_id);
     if ($_relation === false) {
         return ErrorConstant::FRIEND_NOT_EXISTS;
     }
     switch ($_relation->status) {
         case FriendModel::RELATION_STATUS_IN_HAND:
             return ErrorConstant::FRIEND_IN_HAND;
         default:
             break;
     }
     $_relation->status = FriendModel::RELATION_STATUS_RELEASE;
     $_relation->release_time = \common\helpers\DateHelper::now();
     $_relation->deleted = FriendModel::IS_DELETED;
     if ($_relation->update() === false) {
         return ErrorConstant::RELEASE_FRIEND_FAILED;
     }
     $this->triggerFriendEvent(self::AFTER_RELEASE_FRIEND, $user_id, $friend_id);
     return true;
 }