> ## Documentation Index
> Fetch the complete documentation index at: https://apidocs.erlcrussia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Операции с бизнесами

> Управление бизнесами, сотрудниками, товарами и финансами.

Доступные действия:
- `request` - создать заявку на бизнес (userId, username, name, form, channelId).
- `approve` - одобрить заявку (requestId, approverId, +поля бизнеса).
- `cancelRequest` - отменить/удалить пендинг заявку (requestId).
- `create` - прямое создание бизнеса (businessData).
- `delete` - удалить бизнес (businessId).
- `addMoney` - добавить деньги в бизнес (businessId, amount).
- `removeMoney` - забрать деньги из бизнеса (businessId, amount).
- `withdraw` - вывести деньги бизнеса пользователю (businessId, amount, targetUserId).
- `transfer` - перевод между бизнесами (fromBusinessId, toBusinessId, amount, reason, authorId).
- `addEmployee` - добавить сотрудника (businessId, userId, username, position).
- `removeEmployee` - уволить сотрудника (businessId, userId).
- `addProduct` - добавить товар (businessName, item).
- `removeProduct` - удалить товар (businessName, itemName).
- `buyProduct` - купить товар у бизнеса (userId, businessName, itemName, quantity).
- `returnMoney` - вернуть деньги по транзакции (businessId, transactionId).




## OpenAPI

````yaml ru/openapi/ru-economy-v2-openapi.yaml POST /moscowroleplay/civops/businesses
openapi: 3.1.0
info:
  title: ER:LC Россия API V2 - Moscow RolePlay API Экономики V2
  version: 2.0.0
servers:
  - url: https://api.erlcrussia.xyz/v2
    description: ER:LC Россия API V2
security: []
tags:
  - name: Moscow RolePlay API Экономики V2
    description: Эндпоинты для управления экономикой и CivOps системой.
paths:
  /moscowroleplay/civops/businesses:
    post:
      tags:
        - Moscow RolePlay API Экономики V2
      summary: Операции с бизнесами
      description: >
        Управление бизнесами, сотрудниками, товарами и финансами.


        Доступные действия:

        - `request` - создать заявку на бизнес (userId, username, name, form,
        channelId).

        - `approve` - одобрить заявку (requestId, approverId, +поля бизнеса).

        - `cancelRequest` - отменить/удалить пендинг заявку (requestId).

        - `create` - прямое создание бизнеса (businessData).

        - `delete` - удалить бизнес (businessId).

        - `addMoney` - добавить деньги в бизнес (businessId, amount).

        - `removeMoney` - забрать деньги из бизнеса (businessId, amount).

        - `withdraw` - вывести деньги бизнеса пользователю (businessId, amount,
        targetUserId).

        - `transfer` - перевод между бизнесами (fromBusinessId, toBusinessId,
        amount, reason, authorId).

        - `addEmployee` - добавить сотрудника (businessId, userId, username,
        position).

        - `removeEmployee` - уволить сотрудника (businessId, userId).

        - `addProduct` - добавить товар (businessName, item).

        - `removeProduct` - удалить товар (businessName, itemName).

        - `buyProduct` - купить товар у бизнеса (userId, businessName, itemName,
        quantity).

        - `returnMoney` - вернуть деньги по транзакции (businessId,
        transactionId).
      parameters:
        - name: action
          in: query
          description: Тип операции.
          required: true
          schema:
            type: string
            enum:
              - request
              - approve
              - cancelRequest
              - create
              - delete
              - addMoney
              - removeMoney
              - withdraw
              - transfer
              - addEmployee
              - removeEmployee
              - addProduct
              - removeProduct
              - buyProduct
              - returnMoney
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
            examples:
              request:
                summary: Создать заявку на бизнес (этап 1)
                value:
                  userId: '760966468715937814'
                  username: ttunku_pal
                  name: Roma Aeterna
                  form: ООО
                  channelId: '1432651696210841760'
              cancelRequest:
                summary: Отменить pending заявку на бизнес (удалить из ожидания)
                value:
                  requestId: req_abc123
              approve:
                summary: Подтвердить заявку и создать бизнес (этап 2)
                value:
                  requestId: req_abc123
                  approverId: '1133665013794607114'
                  guildId: '1133665013794607114'
                  ownerId: '760966468715937814'
                  ownerName: ttunku_pal
                  channelId: '1432651696210841760'
                  channelName: roma-aeterna
                  roleId: '1432651691987304522'
                  roleName: Roma Aeterna
                  employeeRoleId: '1432651694289846302'
                  employeeRoleName: Сотрудник Бизнеса Roma Aeterna
                  description: >-
                    В «Roma Aeterna» мы верим, что лучшие беседы рождаются за
                    вкусной едой.
                  address: 2221 Southern Avenue
                  createChannel: true
                  createRoles: true
              delete:
                summary: Удалить бизнес со всеми Discord объектами
                value:
                  businessId: UCEW29
                  guildId: '1133665013794607114'
              create:
                summary: Прямое создание бизнеса
                value:
                  businessData:
                    name: Roma Aeterna
                    owner_id: '760966468715937814'
                    form: ООО
              addMoney:
                summary: Добавить деньги в бизнес
                value:
                  businessId: UCEW29
                  amount: 5000
              removeMoney:
                summary: Снять деньги с бизнеса
                value:
                  businessId: UCEW29
                  amount: 5000
              withdraw:
                summary: Вывести деньги с бизнеса на счет пользователя
                value:
                  businessId: UCEW29
                  amount: 1000
                  targetUserId: '1133665013794607114'
              transfer:
                summary: Перевод между бизнесами
                value:
                  fromBusinessId: UCEW29
                  toBusinessId: RAWDB4
                  amount: 5000
                  reason: Оплата услуг
                  authorId: '1133665013794607114'
              addEmployee:
                summary: Добавить сотрудника в бизнес
                value:
                  businessId: UCEW29
                  userId: '1335499851273601029'
                  username: ytkaytkovich_16555
                  position: Сотрудник
                  guildId: '1133665013794607114'
              removeEmployee:
                summary: Удалить сотрудника из бизнеса
                value:
                  businessId: UCEW29
                  userId: '1335499851273601029'
                  guildId: '1133665013794607114'
              addProduct:
                summary: Добавить товар в магазин бизнеса
                value:
                  businessName: Roma Aeterna
                  item:
                    name: ☕ 1. Noctis Amor
                    price_buy: 250
                    description: >-
                      («Любовь ночи») Густой эспрессо с ванильной пенкой и
                      каплей карамели.
                    quantity: 100
              removeProduct:
                summary: Удалить товар из магазина бизнеса
                value:
                  businessName: Roma Aeterna
                  itemName: ☕ 1. Noctis Amor
              buyProduct:
                summary: Купить товар у бизнеса
                value:
                  userId: '1133665013794607114'
                  businessName: Roma Aeterna
                  itemName: ☕ 1. Noctis Amor
                  quantity: 1
              returnMoney:
                summary: Вернуть деньги по транзакции (возврат товара)
                value:
                  businessId: UCEW29
                  transactionId: txn_20241201_xyz789
      responses:
        '200':
          description: Операция успешно выполнена.
          content:
            application/json:
              schema:
                type: object
              examples:
                request:
                  summary: Заявка создана.
                  value:
                    success: true
                    requestId: req_123
                    status: pending
                    message: Request created, awaiting approval
                approve:
                  summary: Бизнес одобрен и создан.
                  value:
                    success: true
                    businessId: UCEW29
                    name: Roma Aeterna
                    status: active
                    owner_id: '760966468715937814'
                    owner_name: ttunku_pal
                cancelRequest:
                  summary: Заявка отменена.
                  value:
                    success: true
                    requestId: req_abc123
                    action: cancelled
                    removedFromMemory: true
                    removedFromDB: false
                    message: Pending request has been cancelled and removed
                buyProduct:
                  summary: Товар куплен.
                  value:
                    success: true
                    userId: '1133665013794607114'
                    businessName: Roma Aeterna
                    item: ☕ 1. Noctis Amor
                    quantity: 1
                    totalPrice: 250
        '400':
          description: >-
            Ошибка запроса (отсутствуют обязательные поля или неизвестный
            action).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/UnauthorizedMissingOrInvalidToken'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - MRPAPIKey: []
components:
  schemas:
    ErrorResponse:
      type: object
      description: Стандартный формат ошибки.
      required:
        - code
        - message
      properties:
        code:
          type: integer
          description: Код ошибки API.
          example: 5007
        message:
          type: string
          description: Сообщение/идентификатор ошибки.
          example: Missing Token
    UnauthorizedError:
      type: object
      description: Ошибка аутентификации (отсутствует или неверный токен).
      required:
        - code
        - message
      properties:
        code:
          type: integer
          example: 5007
        message:
          type: string
          example: Missing Token
    ForbiddenError:
      type: object
      description: Ошибка доступа (запрещено).
      required:
        - code
        - message
      properties:
        code:
          type: integer
          example: 5009
        message:
          type: string
          example: Forbidden
    RateLimitError:
      type: object
      description: Ошибка превышения лимита запросов.
      required:
        - code
        - message
      properties:
        code:
          type: integer
          example: 6021
        message:
          type: string
          example: Rate Limit Exceeded
        retry_after:
          type: integer
          description: Время до сброса лимита в секундах.
          example: 30
    EconomyApiError:
      type: object
      description: Ошибка API Экономики.
      required:
        - code
        - message
      properties:
        code:
          type: integer
          example: 6010
        message:
          type: string
          example: Business not found
  responses:
    UnauthorizedMissingOrInvalidToken:
      description: Ошибка аутентификации.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UnauthorizedError'
          examples:
            Missing Token:
              summary: Нет токена.
              value:
                code: 5007
                message: Missing Token
            Invalid Token:
              summary: Неверный или деактивированный токен.
              value:
                code: 5008
                message: Invalid Token
            Invalid Master Key:
              summary: Неверный мастер-ключ.
              value:
                code: 5006
                message: Invalid Master Key
    Forbidden:
      description: Доступ запрещён.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ForbiddenError'
          examples:
            Forbidden:
              summary: Нет прав доступа к эндпоинту.
              value:
                code: 5009
                message: Forbidden
            Api Version Forbidden:
              summary: Доступ к этой версии API запрещён.
              value:
                code: 5010
                message: Api Version Forbidden
            Query Param Forbidden:
              summary: Query-параметр запрещён.
              value:
                code: 5011
                message: Query Param Forbidden
    TooManyRequests:
      description: Превышено количество запросов.
      headers:
        X-RateLimit-Limit:
          description: Максимум запросов в минуту.
          schema:
            type: integer
            example: 60
        X-RateLimit-Remaining:
          description: Оставшееся количество запросов.
          schema:
            type: integer
            example: 0
        Retry-After:
          description: Секунд до сброса лимита.
          schema:
            type: integer
            example: 30
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitError'
          examples:
            Rate Limit Exceeded:
              summary: Превышение лимита запросов.
              value:
                code: 6021
                message: Rate Limit Exceeded
                retry_after: 30
    InternalServerError:
      description: Внутренняя ошибка сервера.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/EconomyApiError'
          examples:
            Internal Server Error Occurred:
              summary: Ошибка API экономики.
              value:
                code: 6005
                message: Internal Server Error Occurred.
  securitySchemes:
    MRPAPIKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        API ключ для доступа к эндпоинтам Гражданских Операций.

        Передается в заголовке `Authorization: Bearer <ключ>`.

        ОБЯЗАТЕЛЕН ДЛЯ ВСЕХ ЭНДПОИНТОВ ГРАЖДАНСКИХ ОПЕРАЦИЙ (кроме /health).

````