**版本：202701**

# 更新自动折扣

**PUT** `/openapi/2027-01/discounts/automatic/:id`

通过 ID 更新指定的自动折扣活动。

## 请求

**Path参数**

- `id` string (required)

  折扣 ID

**application/json**

**请求体 | 示例**

**请求体 (required)**

- `discount` object (required)

  折扣信息

  - `discount_info` object

    折扣信息

    - `discount_name` string

      折扣名称
    - `display_name` string

      店铺前台展示名称
    - `starts_at` int32

      开始时间
    - `ends_at` int32

      结束时间。-1 表示折扣永久有效
  - `entitled_customer` object

    授权顾客

    - `customer_ids` string[]

      顾客 ID 列表
    - `customer_segment_ids` string[]

      顾客分组 ID 列表
  - `entitled_product` object

    授权商品

    - `product_ids` string[]

      商品 ID 列表
    - `variant_ids` string[]

      规格 ID 列表
    - `collection_ids` string[]

      集合 ID 列表
    - `sort` object

      排序配置

      - `by` string

        商品排序字段
      - `direction` string

        排序方向，如 asc（升序）或 desc（降序）
    - `selection` string

      商品范围选择策略：

      *   `entitled`: 仅包含指定商品
      *   `exclude`: 排除指定商品
      *   `all`: 包含所有商品（默认）
    - `sku_extends` object

      各规格的扩展设置，以规格 ID 为键

      - `property name*` SkuExtendReq

        - `obtain_value` string

          领取值
        - `min_purchase_qty` uint32

          最小购买数量
        - `seq` uint32

          序列号
        - `virtual_sales` int32

          虚拟销量
        - `follow_stock` string

          活动库存是否跟随商品库存：

          *   `product`: 同商品库存
          *   `discount`: 使用活动库存
        - `stock` int32

          库存数量
        - `collection_id` string

          集合 ID
  - `discount_rule` object

    折扣规则

    - `limit_max_discount` int32

      折扣最大使用次数，-1 表示不限
    - `limit_user_discount` int32

      每位顾客最大使用次数，-1 表示不限
    - `limit_order_discount` int32

      每笔订单最大使用次数，-1 表示不限
    - `limit_user_product_type` string

      每用户商品数量限制策略：

      *   `no_limit`: 不限制商品购买次数
      *   `customer_all_product`: 按顾客/折扣汇总所有参与规格的购买次数
      *   `customer_product`: 按顾客/折扣/商品限制购买次数
      *   `customer_variant`: 按顾客/折扣/规格限制购买次数
    - `limit_user_product_discount` int32

      每用户每商品折扣上限
    - `price_rule` string

      折扣计算的基准价格：

      *   `price`: 使用销售价
      *   `compare_at_price`: 使用划线价/原价
    - `product_discount_order` string

      折扣应用时的商品排序策略：

      *   `desc`: 按商品价格从高到低应用
      *   `asc`: 按商品价格从低到高应用
    - `virtual_sales` int32

      虚拟销量
    - `stock` int32

      库存数量
    - `follow_stock` string

      活动库存是否跟随商品库存：

      *   `product`: 同商品库存
      *   `discount`: 设置活动库存
    - `discount_combines` string[]

      可叠加的折扣类别：

      *   `product`: 可与商品折扣叠加
      *   `order`: 可与订单折扣叠加
      *   `shipping`: 可与运费折扣叠加
    - `mn_discount_scope` string

      多层折扣评估的范围策略：

      *   `highest`: 仅应用匹配到的最高档折扣
      *   `all`: 应用所有匹配的折扣层级
      *   `highest_all`: 应用所有匹配层级，超出最高档的数量按最高档优惠计算
  - `discount_layer` object

    折扣层级

    - `condition_type` string

      条件类型：

      *   `no_condition`: 无条件
      *   `purchase_quantity`: 满件数
      *   `purchase_amount`: 满金额
    - `obtain_type` string

      优惠类型：

      *   `no_discount`: 无优惠
      *   `free_acquisition`: 免费领取
      *   `percent`: 百分比折扣
      *   `fixed_price_reduction`: 固定金额减免
      *   `fixed_price`: 固定最终价格
      *   `fixed_quantity`: 固定数量赠送
      *   `product_price_reduction`: 商品级别价格减免
    - `layers` object[]

      层级列表

      *   Array \[

      - `condition_value` string

        条件值
      - `obtain_value` string

        领取值
      - `obtain_count` uint32

        领取数量
      *   \]

```json
{
  "discount": {
    "discount_info": {
      "discount_name": "string",
      "display_name": "string",
      "starts_at": 0,
      "ends_at": 0
    },
    "entitled_customer": {
      "customer_ids": [
        "string"
      ],
      "customer_segment_ids": [
        "string"
      ]
    },
    "entitled_product": {
      "product_ids": [
        "string"
      ],
      "variant_ids": [
        "string"
      ],
      "collection_ids": [
        "string"
      ],
      "sort": {
        "by": "string",
        "direction": "string"
      },
      "selection": "string",
      "sku_extends": {}
    },
    "discount_rule": {
      "limit_max_discount": 0,
      "limit_user_discount": 0,
      "limit_order_discount": 0,
      "limit_user_product_type": "string",
      "limit_user_product_discount": 0,
      "price_rule": "string",
      "product_discount_order": "string",
      "virtual_sales": 0,
      "stock": 0,
      "follow_stock": "string",
      "discount_combines": [
        "string"
      ],
      "mn_discount_scope": "string"
    },
    "discount_layer": {
      "condition_type": "string",
      "obtain_type": "string",
      "layers": [
        {
          "condition_value": "string",
          "obtain_value": "string",
          "obtain_count": 0
        }
      ]
    }
  }
}
```

## 响应

**200**

OK

**application/json**

**数据结构 | 示例**

**数据结构**

- `code` string

  错误码
- `message` string

  错误信息
- `data` object

  - `discount` object

    折扣信息

    - `discount_info` object

      折扣信息

      - `id` string

        折扣 ID
      - `discount_name` string

        折扣名称
      - `display_name` string

        店铺前台展示名称
      - `discount_target` string

        折扣目标类别：

        *   `product`: 商品折扣
        *   `order`: 订单折扣
        *   `shipping`: 运费折扣
      - `category` string

        折扣分类（顶层折扣类型）：

        *   `buy_one_get_one`: 买一赠一
        *   `buy_x_get_y`: 买 X 赠 Y
        *   `bundle`: 捆绑折扣
        *   `rebate`: 满减折扣
        *   `m_n_discount`: M 换 N 折扣
        *   `flash_sale`: 限时特卖
        *   `code`: 折扣码
        *   `coupon_old`: 旧版优惠券
        *   `plugin_old`: 旧版插件折扣
        *   `rebate_old`: 旧版满减
        *   `cycle_subscribe_old`: 旧版周期订购
      - `discount_type` string

        折扣类型：

        *   `rebate_cta_otr`: 满额固定减免
        *   `rebate_ctq_otr`: 满量固定减免
        *   `rebate_cta_otp`: 满额百分比折扣
        *   `rebate_ctq_otp`: 满量百分比折扣
        *   `m_n_discount`: M 换 N 折扣
        *   `flashsale`: 限时特卖折扣
        *   `code_percent`: 折扣码百分比折扣
        *   `code_fix_price_reduction`: 折扣码固定减免
        *   `code_bxgy`: 折扣码买 X 赠 Y
        *   `code_free_shipping`: 折扣码免运费
      - `discount_method` string

        折扣方式：

        *   `automatic`: 自动应用
        *   `discount_code`: 折扣码触发
      - `discount_code` string

        折扣码
      - `discount_codes` string[]

        该折扣下的所有折扣码列表
      - `starts_date` string

        开始日期
      - `ends_date` string

        结束日期
      - `starts_at` int32

        开始时间
      - `ends_at` int32

        结束时间
      - `created_at` string

        创建时间（ISO-8601 格式）
      - `updated_at` string

        最后更新时间（ISO-8601 格式）
      - `is_old_discount` boolean

        是否为旧版折扣
      - `progress` string

        当前进度状态：

        *   `ongoing`: 进行中
        *   `not_started`: 未开始
        *   `finished`: 已结束
        *   `paused`: 已暂停
      - `enable_all_customer` boolean

        是否对所有顾客启用
      - `is_show_admin` string

        是否在管理后台显示
      - `time_used` int32

        已使用次数
    - `entitled_customer` object

      授权顾客

      - `customer_ids` string[]

        顾客 ID 列表
      - `customer_segment_ids` string[]

        顾客分组 ID 列表
    - `entitled_product` object

      授权商品

      - `product_ids` string[]

        商品 ID 列表
      - `variant_ids` string[]

        规格 ID 列表
      - `collection_ids` string[]

        集合 ID 列表
      - `sort` object

        排序配置

        - `by` string

          排序字段
        - `direction` string

          排序方向
        - `before` string

          时间排序起始值（单位：秒），用于兼容旧版限时特卖
      - `selection` string

        商品范围选择策略：

        *   `entitled`: 仅包含授权商品
        *   `exclude`: 排除授权商品
        *   `all`: 包含全部商品
      - `sku_extends` object

        规格扩展配置，以规格 ID 为键

        - `property name*` SkuExtendResp

          - `obtain_value` string

            领取值
          - `min_purchase_qty` uint32

            最小购买数量
          - `seq` uint32

            序列号
          - `virtual_sales` int32

            虚拟销量
          - `follow_stock` string

            活动库存是否跟随商品库存：

            *   `product`: 同商品库存
            *   `discount`: 设置活动库存
          - `stock` int32

            库存数量
          - `collection_id` string

            集合 ID
    - `obtain_product` object

      领取商品

      - `product_ids` string[]

        商品 ID 列表
      - `variant_ids` string[]

        规格 ID 列表
      - `collection_ids` string[]

        集合 ID 列表
      - `sort` object

        排序配置

        - `by` string

          排序字段
        - `direction` string

          排序方向
        - `before` string

          时间排序起始值（单位：秒），用于兼容旧版限时特卖
      - `selection` string

        商品范围选择策略：

        *   `entitled`: 仅包含授权商品
        *   `exclude`: 排除授权商品
        *   `all`: 包含全部商品
      - `sku_extends` object

        规格扩展配置，以规格 ID 为键

        - `property name*` SkuExtendResp

          - `obtain_value` string

            领取值
          - `min_purchase_qty` uint32

            最小购买数量
          - `seq` uint32

            序列号
          - `virtual_sales` int32

            虚拟销量
          - `follow_stock` string

            活动库存是否跟随商品库存：

            *   `product`: 同商品库存
            *   `discount`: 设置活动库存
          - `stock` int32

            库存数量
          - `collection_id` string

            集合 ID
    - `discount_rule` object

      折扣规则

      - `limit_max_discount` int32

        折扣最大使用次数，-1 表示不限
      - `limit_user_discount` int32

        每位顾客最大使用次数，-1 表示不限
      - `limit_order_discount` int32

        每笔订单最大使用次数，-1 表示不限
      - `limit_user_product_type` string

        每用户商品类型折扣上限：

        *   `no_limit`: 不限制商品购买量
        *   `customer_all_product`: 每用户每折扣，所有符合条件的规格累计
        *   `customer_product`: 每用户每折扣每商品
        *   `customer_variant`: 每用户每折扣每规格
      - `limit_user_product_discount` int32

        每用户每商品折扣上限
      - `stock` int32

        库存数量
      - `follow_stock` string

        活动库存是否跟随商品库存：

        *   `product`: 同商品库存
        *   `discount`: 设置活动库存
      - `virtual_sales` int32

        虚拟销量
      - `price_rule` string

        价格规则：

        *   `price`: 使用销售价格
        *   `compare_at_price`: 使用划线价/原始价格
      - `extends` string

        扩展列表
      - `product_discount_order` string

        商品折扣排序：

        *   `desc`: 按商品价格降序应用
        *   `asc`: 按商品价格升序应用
      - `discount_combines` string[]

        折扣叠加配置列表：

        *   `product`: 可与商品折扣叠加
        *   `order`: 可与订单折扣叠加
        *   `shipping`: 可与运费折扣叠加
      - `obtain_full` boolean

        是否已满额领取
      - `mn_discount_scope` string

        多层折扣评估的范围策略：

        *   `highest`: 仅应用最高匹配层
        *   `all`: 应用所有匹配层
        *   `highest_all`: 应用所有匹配层；超出最高层的数量按最高层优惠处理
      - `limit_code_max_discount` int32

        每个折扣码最大使用次数，-1 表示不限。仅适用于非自动折扣
      - `limit_code_user_discount` int32

        每位顾客每个折扣码最大使用次数，仅适用于非自动折扣
      - `enable_product_extends` boolean

        是否启用商品扩展信息
    - `discount_layer` object

      折扣层级

      - `condition_type` string

        条件类型：

        *   `no_condition`: 无条件限制
        *   `purchase_quantity`: 需满足购买数量
        *   `purchase_amount`: 需满足购买金额
      - `obtain_type` string

        领取类型：

        *   `no_discount`: 无折扣
        *   `free_acquisition`: 免费领取
        *   `percent`: 百分比折扣
        *   `fixed_price_reduction`: 固定金额减免
        *   `fixed_price`: 固定最终价格
        *   `fixed_quantity`: 固定数量领取
        *   `product_price_reduction`: 商品级价格减免
      - `layers` object[]

        层级列表

        *   Array \[

        - `condition_value` string

          条件值
        - `obtain_value` string

          领取值
        - `obtain_count` uint32

          领取数量
        *   \]
    - `discount_combine` object

      折扣叠加配置

      - `use_with_other` boolean

        是否可与其他折扣叠加
    - `entitled_area` object

      授权地区

      - `areas` object[]

        地区列表

        *   Array \[

        - `country_code` string

          国家代码（如 CN）
        - `province_codes` string[]

          省份代码列表
        *   \]

```json
{
  "code": "string",
  "message": "string",
  "data": {
    "discount": {
      "discount_info": {
        "id": "string",
        "discount_name": "string",
        "display_name": "string",
        "discount_target": "string",
        "category": "string",
        "discount_type": "string",
        "discount_method": "string",
        "discount_code": "string",
        "discount_codes": [
          "string"
        ],
        "starts_date": "string",
        "ends_date": "string",
        "starts_at": 0,
        "ends_at": 0,
        "created_at": "string",
        "updated_at": "string",
        "is_old_discount": true,
        "progress": "string",
        "enable_all_customer": true,
        "is_show_admin": "string",
        "time_used": 0
      },
      "entitled_customer": {
        "customer_ids": [
          "string"
        ],
        "customer_segment_ids": [
          "string"
        ]
      },
      "entitled_product": {
        "product_ids": [
          "string"
        ],
        "variant_ids": [
          "string"
        ],
        "collection_ids": [
          "string"
        ],
        "sort": {
          "by": "string",
          "direction": "string",
          "before": "string"
        },
        "selection": "string",
        "sku_extends": {}
      },
      "obtain_product": {
        "product_ids": [
          "string"
        ],
        "variant_ids": [
          "string"
        ],
        "collection_ids": [
          "string"
        ],
        "sort": {
          "by": "string",
          "direction": "string",
          "before": "string"
        },
        "selection": "string",
        "sku_extends": {}
      },
      "discount_rule": {
        "limit_max_discount": 0,
        "limit_user_discount": 0,
        "limit_order_discount": 0,
        "limit_user_product_type": "string",
        "limit_user_product_discount": 0,
        "stock": 0,
        "follow_stock": "string",
        "virtual_sales": 0,
        "price_rule": "string",
        "extends": "string",
        "product_discount_order": "string",
        "discount_combines": [
          "string"
        ],
        "obtain_full": true,
        "mn_discount_scope": "string",
        "limit_code_max_discount": 0,
        "limit_code_user_discount": 0,
        "enable_product_extends": true
      },
      "discount_layer": {
        "condition_type": "string",
        "obtain_type": "string",
        "layers": [
          {
            "condition_value": "string",
            "obtain_value": "string",
            "obtain_count": 0
          }
        ]
      },
      "discount_combine": {
        "use_with_other": true
      },
      "entitled_area": {
        "areas": [
          {
            "country_code": "string",
            "province_codes": [
              "string"
            ]
          }
        ]
      }
    }
  }
}
```
