优惠券-创建
接口信息
- 接口地址:
{your-site-url}/api/skill/coupon/create
- 基础 URL:
{your-site-url} 需替换为你自己的独立站 URL 地址,如 https://your-domain.com/apimanager666
- 请求方式:
POST
- 说明: 此接口用于创建一张新的优惠券。
认证
请求头中需要携带 skill-access-token:
| Header |
值 |
skill-access-token |
{your-skill-access-token} (请替换为你自己的 token) |
请求参数 (JSON Body)
基本信息
| 字段 |
类型 |
必填 |
说明 |
title |
string |
是 |
优惠券标题 |
code |
string |
是 |
优惠券码 |
status |
int |
是 |
状态。1 = 激活,2 = 关闭 |
is_campaign |
int |
是 |
是否与其他活动优惠叠加使用。1 = 是,2 = 否 |
starts_at |
string |
是 |
生效时间,格式 YYYY-MM-DD HH:mm:ss |
ends_at |
string |
是 |
结束时间,格式 YYYY-MM-DD HH:mm:ss。空字符串或 0 表示不限时 |
折扣设置
| 字段 |
类型 |
必填 |
说明 |
value_type |
int |
是 |
折扣类型。1 = 固定金额(fixed_amount),2 = 百分比(percentage) |
value |
number |
是 |
折扣值。value_type=1 时为固定金额,value_type=2 时为百分比数值 |
usage_limit |
int |
是 |
优惠券可被使用的总次数。0 表示无限制 |
usage_count_per_customer |
int |
是 |
每个顾客使用该优惠券的最大次数。0 表示无限制 |
适用商品
| 字段 |
类型 |
必填 |
说明 |
product_selection_type |
int |
是 |
适用商品选择类型。1 = 全部商品,2 = 指定商品,3 = 指定商品专辑(collection) |
entitled_product_ids |
Array[Object] |
否 |
适用商品列表,product_selection_type=2 时有效。每项包含 product_id 和 variant_ids。variant_ids 有值代表该商品下的指定变体,为空数组则代表该商品的所有变体 |
entitled_collection_ids |
Array |
否 |
适用商品专辑 ID 列表,product_selection_type=3 时有效 |
最低使用条件
| 字段 |
类型 |
必填 |
说明 |
minimum_requirements_type |
int |
是 |
最低要求类型。1 = 无限制,2 = 最低购买金额,3 = 最低购买数量 |
prerequisite_subtotal |
number/string |
否 |
最低购买金额,minimum_requirements_type=2 时有效。类型为 float,订单商品小计金额必须 ≥ 此值 |
prerequisite_quantity |
int/string |
否 |
最低购买数量,minimum_requirements_type=3 时有效。类型为 int,订单商品总数量必须 ≥ 此值 |
展示设置
| 字段 |
类型 |
必填 |
说明 |
product_sort |
int |
是 |
商品排序。1 = A-Z,2 = Z-A,3 = 价格从低到高,4 = 价格从高到低,5 = 按销量从高到低,6 = 按实际销量从高到低 |
banner_image |
string |
否 |
Banner 图片路径(相对路径) |
banner_show_type |
int |
是 |
Banner 展示类型。1 = 铺满全屏,2 = 两边留白 |
is_product_page_show |
int |
是 |
是否在产品页面展示。1 = 展示,2 = 不展示 |
product_image_height_type |
string |
否 |
产品图片高度。auto = 自适应,big = 大,medium = 中,small = 小 |
copywriting - 文案/UI配色
| 字段 |
类型 |
说明 |
copywriting.color |
string |
配色方案名,如 blue |
copywriting.timeType |
int |
时间显示类型 |
copywriting.backgroundLeft |
string |
背景色左(rgba) |
copywriting.backgroundRight |
string |
背景色右(rgba) |
copywriting.fontTip |
string |
提示文字颜色(rgba) |
copywriting.timeBg |
string |
时间背景色(rgba) |
copywriting.timeFont |
string |
时间文字颜色(rgba) |
copywriting.couponBg |
string |
优惠券背景色(rgba) |
copywriting.couponFont |
string |
优惠券文字颜色(rgba) |
copywriting.couponBtLeft |
string |
按钮左渐变色(rgba) |
copywriting.couponBtRight |
string |
按钮右渐变色(rgba) |
copywriting.couponBtFont |
string |
按钮文字颜色(rgba) |
copywriting.copyColor |
string |
复制按钮颜色(rgba) |
请求示例
cURL
curl --location --request POST '{your-site-url}/api/skill/coupon/create' \
--header 'skill-access-token: {your-skill-access-token}' \
--header 'Content-Type: application/json' \
--data-raw '{
"is_campaign": 1,
"status": 1,
"title": "terry coupon",
"code": "LX4ABQ14",
"value_type": 1,
"value": 10,
"usage_count_per_customer": 0,
"usage_limit": 0,
"starts_at": "2026-06-03 20:50:03",
"ends_at": "",
"product_selection_type": 2,
"entitled_product_ids": [
{"product_id": 7042, "variant_ids": []},
{"product_id": 7041, "variant_ids": []}
],
"entitled_collection_ids": [],
"minimum_requirements_type": 2,
"prerequisite_subtotal": 50,
"prerequisite_quantity": "",
"product_sort": 1,
"banner_image": "/product/15/image/2026/05/29/430015af6d7473355e7180b97741e443.png",
"banner_show_type": 1,
"is_product_page_show": 1,
"product_image_height_type": "auto",
"copywriting": {
"color": "blue",
"timeType": 1,
"backgroundLeft": "rgba(255,72,72,100)",
"backgroundRight": "rgba(255,13,125,100)",
"fontTip": "rgba(255,255,255,100)",
"timeBg": "rgba(255,243,203,100)",
"timeFont": "rgba(0,0,0,100)",
"couponBg": "rgba(255,248,227,100)",
"couponFont": "rgba(233,5,73,100)",
"couponBtLeft": "rgba(255,139,2,100)",
"couponBtRight": "rgba(255,109,4,100)",
"couponBtFont": "rgba(255,255,255,100)",
"copyColor": "rgba(255,109,4,100)"
}
}'
返回结果
code 为 200 表示调用成功;code 不为 200 表示调用失败。
成功响应
{
"code": 200,
"data": {
"shop_id": 15,
"status": 1,
"title": "terry coupon",
"code": "LX4ABQ14",
"value_type": 1,
"value": 10,
"product_image_height_type": "auto",
"usage_count_per_customer": 0,
"starts_at": "2026-06-03 20:50:03",
"ends_at": 0,
"product_selection_type": 2,
"is_campaign": 1,
"product_sort": 1,
"banner_image": "/product/15/image/2026/05/29/430015af6d7473355e7180b97741e443.png",
"banner_show_type": 1,
"copywriting": { ... },
"is_product_page_show": 1,
"usage_limit": 0,
"entitled_product_ids": [
{"product_id": 7042, "variant_ids": []},
{"product_id": 7041, "variant_ids": []}
],
"entitled_collection_ids": [],
"minimum_requirements_type": 2,
"prerequisite_subtotal": 50,
"prerequisite_quantity": 0,
"created_at": "2026-06-03 20:51:44",
"updated_at": "2026-06-03 20:51:44",
"id": 70
},
"message": "success"
}
返回字段说明
| 字段 |
类型 |
说明 |
code |
Number |
状态码,200 表示成功 |
message |
String |
执行结果的文字描述 |
data |
Object |
创建的优惠券完整信息,字段与请求参数对应 |
data.id |
int |
新创建的优惠券 ID |
data.created_at |
string |
创建时间 |
data.updated_at |
string |
更新时间 |
注意事项
banner_image 完整图片url,或者相对路径。如果是相对路径,需要先通过 得到网站基础URL 获取 attachment_url,然后拼接得到完整 URL:attachment_url + banner_image
ends_at 为空字符串时表示不限时,返回时值为 0
entitled_product_ids 中 variant_ids 为空数组时表示该商品的全部变体适用
copywriting 为前台 UI 配色配置,可根据主题自定义颜色值