# Khuyến mãi

> Base URL: `https://pos.pages.fm/api/v1`. Xác thực bằng tham số truy vấn `api_key`.

## Danh sách khuyến mãi

`GET /shops/{SHOP_ID}/promotion_advance`

Lấy danh sách khuyến mãi

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |
| `page` | query | integer |  | Số trang |
| `page_size` | query | integer |  | Kích thước trang |
| `textSearch` | query | string |  | Tìm kiếm |

### Phản hồi

- `200` Success (object)

```json
{
  "success": true,
  "data": [
    {
      "id": "260a0d45-ba88-457b-8b31-afa3fda0ce0e",
      "display_id": 50,
      "name": "km 345",
      "type": "discount_by_product",
      "start_time": "2022-03-10T05:04:11Z",
      "end_time": "2022-03-11T05:04:13Z",
      "warehouse_ids": [],
      "customer_tags": [],
      "order_sources": [],
      "group_name": "Nhóm 1",
      "is_activated": true,
      "is_variation": true,
      "is_used": null,
      "is_free_shipping": false,
      "is_discount_in_birthday_customer": false,
      "coupon_info": {
        "discount": 0,
        "is_percent": false
      },
      "promo_code_info": {
        "discount": 0,
        "is_percent": false,
        "max_discount_by_percent": 0
      },
      "discount_by_quantity": 1,
      "items": [
        {
          "id": "bd11e48a-6fec-4e3a-a1b7-8ef834a98dae",
          "promotion_advance_id": "260a0d45-ba88-457b-8b31-afa3fda0ce0e",
          "shop_id": 3,
          "product_id": null,
          "variation_id": "2f3aea54-5c0c-44db-9f9b-2c987c298795",
          "category_id": null,
          "product": null,
          "variation": {
            "id": "2f3aea54-5c0c-44db-9f9b-2c987c298795",
            "display_id": "SB21-M-DEN",
            "product_id": "d6d13d0b-320e-4651-a368-de2c9e30ae66",
            "retail_price": 250000,
            "retail_price_after_discount": 238000
          },
          "level_info": [
            {
              "discount": 30000,
              "is_percent": false,
              "from_quantity": 1,
              "to_quantity": 4
            }
          ],
          "fixed_prices": 0,
          "coupon_item_info": {
            "discount": 0,
            "is_percent": false
          },
          "limited_quantity": 0,
          "limited_quantity_used": 0,
          "attachment_product_info": [],
          "discount_info_by_attachment_product": null
        }
      ],
      "bonus_items": [],
      "total_quantity_bonus": 0,
      "arr_level_promotion": [],
      "level_order_prices": [],
      "priority_level": null,
      "type_employee": "all",
      "post_ids": [],
      "shop_id": 3,
      "creator_id": "4eab0efc-2994-4b96-acf0-e4c847668555",
      "inserted_at": "2022-03-10T05:04:33Z",
      "updated_at": "2022-04-08T08:14:58Z"
    }
  ]
}
```

## Tạo khuyến mãi

`POST /shops/{SHOP_ID}/promotion_advance`

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |

### Nội dung yêu cầu

Thông tin yêu cầu chứa thông tin khuyến mãi cần tạo

- `promotion_advance` (object, required): 
  - `name` (string, required): Tên khuyến mãi
  - `start_time` (integer): Thời điểm bắt đầu
  - `end_time` (integer): Thời điểm kết thúc
  - `warehouse_ids` (string[]): Danh sách mã kho
  - `customer_tags` (string[]): Thẻ khách hàng
  - `order_sources` (object[]): Nguồn đơn hàng
  - `type` (string, required): Loại khuyến mãi Values: `discount_by_product`, `discount_by_order_price`, `fixed_prices`, `coupon`, `double_reward_point`, `discount_by_coupon_id`, `discount_by_attachment_products`.
  - `group_name` (string): Nhóm khuyến mãi
  - `is_activated` (boolean): Đã kích hoạt
  - `is_variation` (boolean): Là mẫu mã
  - `coupon_info` (object): Thông tin coupon
  - `promo_code_info` (object): Thông tin mã khuyến mãi
  - `items` (object[]): Danh sách sản phẩm khuyến mãi
  - `is_free_shipping` (boolean): Miễn phí vận chuyển
  - `discount_by_quantity` (integer): Giảm giá theo số lượng
  - `bonus_items` (object[]): Sản phẩm tặng kèm
  - `is_discount_in_birthday_customer` (boolean): Giảm giá khách hàng sinh nhật
  - `arr_level_promotion` (object[]): Mức độ khuyến mãi
  - `total_quantity_bonus` (integer): Tổng số lượng tặng
  - `priority_level` (integer): Mức độ ưu tiên
  - `type_employee` (string): Loại nhân viên
  - `free_products` (object[]): Sản phẩm tặng kèm

```json
{
  "promotion_advance": {
    "name": "string",
    "type": "discount_by_product"
  }
}
```

### Phản hồi

- `200` Success (object)

```json
{
  "success": true
}
```

## Cập nhật khuyến mãi

`PUT /shops/{SHOP_ID}/promotion_advance/{PROMOTION_ID}`

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |
| `PROMOTION_ID` | path | string | yes | Mã khuyến mãi |

### Nội dung yêu cầu

Thông tin yêu cầu chứa thông tin khuyến mãi cần cập nhật

- `promotion_advance` (Promotion, required): 
  - `id` (string): Mã khuyến mãi
  - `display_id` (string): Mã hiển thị khuyến mãi
  - `name` (string): Tên khuyến mãi
  - `type` (string): Loại khuyến mãi
  - `start_time` (string (date-time)): Thời điểm bắt đầu
  - `end_time` (string (date-time)): Thời điểm kết thúc
  - `warehouse_ids` (string[]): Danh sách mã kho
  - `customer_tags` (string[]): Thẻ khách hàng
  - `order_sources` (object[]): Nguồn đơn hàng
  - `group_name` (string): Nhóm khuyến mãi
  - `is_activated` (boolean): Đã kích hoạt
  - `is_variation` (boolean): Khuyến mãi theo mẫu mã
  - `is_used` (boolean): Đã sử dụng
  - `is_free_shipping` (boolean): Miễn phí vận chuyển
  - `is_discount_in_birthday_customer` (boolean): Khuyến mãi cho sinh nhật
  - `coupon_info` (object): Thông tin phiếu giảm giá
  - `promo_code_info` (object): Thông tin mã khuyến mãi
  - `discount_by_quantity` (integer): Số lượng giảm giá
  - `items` (object[]): Danh sách sản phẩm/mẫu mã áp dụng khuyến mãi
  - `bonus_items` (object[]): Sản phẩm tặng thêm
  - `total_quantity_bonus` (integer): Tổng số lượng khuyến mãi
  - `arr_level_promotion` (object[]): Mức độ khuyến mãi
  - `level_order_prices` (object[]): Mức khuyến mãi đơn hàng
  - `priority_level` (integer): Mức độ ưu tiên
  - `type_employee` (string): Phân loại nhân viên
  - `post_ids` (string[]): Mã bài viết
  - `shop_id` (integer): Mã shop
  - `creator_id` (string): Mã người tạo
  - `inserted_at` (string (date-time)): Thời điểm tạo
  - `updated_at` (string (date-time)): Thời điểm cập nhật

```json
{
  "promotion_advance": {
    "id": "string",
    "display_id": "string",
    "name": "string",
    "type": "string",
    "start_time": "2026-01-01T00:00:00Z",
    "end_time": "2026-01-01T00:00:00Z"
  }
}
```

### Phản hồi

- `200` Success (object)

```json
{
  "success": true
}
```

## Kích hoạt/Vô hiệu hóa/Xóa khuyến mãi

`POST /shops/{SHOP_ID}/promotion_advance/delete_multi`

Kích hoạt, vô hiệu hóa hoặc xóa nhiều khuyến mãi

### Tham số

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Mã shop |

### Nội dung yêu cầu

Thông tin yêu cầu chứa danh sách mã khuyến mãi cần xóa

- `ids` (string[], required): Danh sách mã khuyến mãi
- `type_action` (string, required): Loại hành động Values: `DEACTIVE_PROMOTIONS` Vô hiệu hóa khuyến mãi, `ACTIVE_PROMOTIONS` Kích hoạt khuyến mãi, `DELETE_PROMOTIONS` Xóa khuyến mãi.

```json
{
  "ids": [
    "0fe988a1-26a5-4772-b4b6-a9c17c9f40cd"
  ],
  "type_action": "DEACTIVE_PROMOTIONS"
}
```

### Phản hồi

- `200` Success (object)

```json
{
  "success": true
}
```
