Skip to content

管理折扣

折扣是商家为订单或商品提供优惠的一种营销工具。通过折扣,商家可以吸引顾客、提高转化率,同时也可针对特定客户群体制定促销策略。折扣可分为产品折扣、订单折扣和运费折扣,并支持固定金额或百分比优惠。折扣既可以通过折扣码的方式触发,也可以设置为自动生效。

可以通过 Genstore API 来管理折扣,创建与订单或商品相关的折扣,或为特定客户群体设定折扣。

前置准备

API 总览

以下是与折扣管理相关的主要 API 接口:

API Endpoint功能描述
/api/202412/discounts创建新折扣
/api/202412/discounts/{discountId}获取/更新/删除指定折扣(根据 HTTP 方法区分)
/api/202412/discounts/{discountId}/status变更指定折扣状态

业务场景:新建折扣

您可以使用 新建折扣 接口来创建折扣,创建折扣之前,开发者需要了解折扣的一些基本概念,包括折扣类型、折扣额配置、折扣生成类型以及适用客户范围。创建折扣时,系统将根据传入的配置生成一条新的折扣记录,供商家在订单或商品层面使用。

  • 折扣类型:
    • PRODUCT_DISCOUNT - 产品折扣;
    • ORDER_DISCOUNT - 订单折扣;
    • SHIPPING_DISCOUNT - 运费折扣。
  • 折扣额配置:
    • FIXED_AMOUNT_OFF - 固定金额优惠;
    • PERCENTAGE - 按百分比优惠。
  • 折扣生成类型:
    • CODE_DISCOUNT - 使用折扣码;
    • AUTOMATIC_DISCOUNT - 自动生效。
  • 适用人群:
    • ALL - 所有客户;
    • SEGMENT - 指定客群。

示例:创建折扣

请求

POST /api/202412/discounts

json
curl -X POST \ 
"https://{shop}.genmystore.com/api/202412/discounts" \ 
-H "X-Genstore-Access-Token: {access_token}" \ 
-H "Content-Type: application/json" \ 
-d '{
	"discount":{
		"promotionType":{
			"categoryType":"PRODUCT_DISCOUNT",
			"generateType":{
				"discountCode":"71NLIYCH",
				"generateDiscountType":"CODE_DISCOUNT"
			},
			"discountType":"PRICE_REDUCTION"
		},
		"discounts":{
			"discountValueType":"FIXED_AMOUNT_OFF",
			"value":"10"
		},
		"name":"My Discount Simple",
		"usageSetting":{
			"combinations":[
				"PRODUCT",
				"ORDER"
			],
			"customerOneUse":"false",
			"customerScopeType":"ALL",
			"discountCodeUseCount":"11",
			"segments":[
				{
					"id":"1"
				}
			]
		},
		"startTime":"2024-11-11T10:05:19.421Z",
		"trigger":{
			"buyConditionValue":"10",
			"scopeType":"SPECIFIC_PRODUCTS",
			"freeShippingLimit":"12.6",
			"collectionList":[
				{
					"id":"123"
				}
			],
			"freeShippingCountryList":[
				"OA",
				"CN"
			],
			"buyConditionType":"MINIMUM_NO",
			"productList":[
				{
					"discountProductSkuLists":[
						{
							"id":"107362071756584"
						}
					],
					"id":"102744478756584"
				}
			]
		},
		"endTime":"2024-11-11T10:05:19.421Z",
		"appHandle":"myAppHandle"
	}
}'

业务场景:更新折扣

业务场景说明

当商家需要调整或更新现有折扣方案时,可调用 更新折扣接口。更新操作允许修改折扣的基本信息、优惠规则以及适用范围等配置。

示例:更新折扣

请求

PUT /api/202412/{discountId}

json
curl -X PUT \ 
"https://{shop}.genmystore.com/api/202412/discounts/{discountId}" \ 
-H "X-Genstore-Access-Token: {access_token}" \ 
-H "Content-Type: application/json" \ 
-d '{
	"discount":{
		"promotionType":{
			"categoryType":"PRODUCT_DISCOUNT",
			"generateType":{
				"discountCode":"71NLIYCH",
				"generateDiscountType":"CODE_DISCOUNT"
			},
			"discountType":"PRICE_REDUCTION"
		},
		"discounts":{
			"discountValueType":"FIXED_AMOUNT_OFF",
			"value":"10"
		},
		"name":"My Discount Simple",
		"usageSetting":{
			"combinations":[
				"PRODUCT",
				"ORDER"
			],
			"customerOneUse":"false",
			"customerScopeType":"ALL",
			"discountCodeUseCount":"11",
			"segments":[
				{
					"id":"123"
				}
			]
		},
		"startTime":"2024-11-11T10:05:19.421Z",
		"trigger":{
			"buyConditionValue":"10",
			"scopeType":"SPECIFIC_PRODUCTS",
			"freeShippingLimit":"12.6",
			"collectionList":[
				{
					"id":"123"
				}
			],
			"freeShippingCountryList":[
				"OA",
				"CN"
			],
			"buyConditionType":"MINIMUM_NO",
			"productList":[
				{
					"discountProductSkuLists":[
						{
							"id":"107362071756584"
						}
					],
					"name":"shoes",
					"id":"102744478756584"
				}
			]
		},
		"endTime":"2024-11-11T10:05:19.421Z",
		"discountId":"21003695070100"
	}
}'

业务场景:更新折扣状态

业务场景说明

当商家需要使某个折扣生效或失效时,可调用 更新折扣状态接口,将折扣状态调整为 ACTIVE(生效)或 INACTIVE(失效)。

示例:变更折扣状态

请求

PUT /api/202412/{discountId}/status

json
curl -X PUT \ 
"https://{shop}.genmystore.com/api/202412/discounts/{discountId}/status" \ 
-H "X-Genstore-Access-Token: {access_token}" \ 
-H "Content-Type: application/json" \ 
-d '{
	"discount":{
		"operateType":"INACTIVE"
	}
}'

Webhook

业务场景说明

为实现折扣的实时自动化管理,建议订阅以下 Webhook 事件,以便在折扣创建、更新或删除时及时获取通知,从而触发相应的业务处理。

Webhook 主题描述
discounts/create折扣创建
discounts/update折扣更新
discounts/delete折扣删除