public function joinGroup(Group $group, GroupUser $model) { if ($resp = $this->checkGroupWithUser($group, $model)) { return $resp; } if (($result = $this->getGroupUserArray($model)) instanceof ApiResponse) { return $result; } if ($result) { if (Group::TYPE_CHATROOM == $group->type) { return new ApiResponse(Code::FAIL_GROUP_USER_ALREADY_MEMBER, 'you are one of them'); } else { ConvertUtil::arrayToObject($result, $model, ['id', 'gid', 'uid', 'permission', 'create_time', 'status', 'remark']); switch ($model->status) { case GroupUser::STATUS_REQUEST: return new ApiResponse(Code::FAIL_GROUP_USER_ALREADY_REQUEST, 'you have requested'); // if user be invited, and want to join this group, make user member // if user be invited, and want to join this group, make user member case GroupUser::STATUS_INVITED: return null; case GroupUser::STATUS_AGREE: return new ApiResponse(Code::FAIL_GROUP_USER_ALREADY_MEMBER, 'you are one of them'); // if i am refuse this guy, but he send again, get he the second chance // if i am refuse this guy, but he send again, get he the second chance case GroupUser::STATUS_REFUSED: $model->status = GroupUser::STATUS_REQUEST; if ($resp = $this->updateGroupUserStatus($model)) { return $resp; } JegarnUtil::sendGroupRequestNotification($group->uid, $model->uid, $group->id, $group->name); return null; default: /*case GroupUser::STATUS_UNSUBSCRIBE: case GroupUser::STATUS_BLACK:*/ return new ApiResponse(Code::FAIL_GROUP_USER_ALREADY_REFUSED, 'you have requested'); } } } else { if (Group::TYPE_CHATROOM == $group->type) { $model->status = GroupUser::STATUS_AGREE; $model->permission = GroupUser::PERMISSION_NORMAL; if ($resp = $this->addGroupUser($group, $model)) { return $resp; } JegarnUtil::joinChatroom($group->id, $model->uid); } else { $model->status = GroupUser::STATUS_REQUEST; $model->permission = GroupUser::PERMISSION_NORMAL; if ($resp = $this->addGroupUser($group, $model)) { return $resp; } JegarnUtil::sendGroupRequestNotification($group->uid, $model->uid, $group->id, $group->name); } } return null; }