商品管理接口文档
一、添加商品接口
1. 接口名称
添加商品
2. 接口描述
用于商家添加新商品到系统中,包括商品基本信息、规格、图片等内容。
3. 接口路径
http://ip:port/app/product.saveProduct
4. 请求方法
POST
5. 请求头
参数名称 |
必填 |
类型 |
描述 |
Authorization |
是 |
String |
用户认证token |
store-id |
是 |
String |
商户ID |
user-id |
是 |
String |
操作人ID |
6. 请求参数
6.1 请求体参数
必填参数:
参数名称 |
必填 |
类型 |
描述 |
prodName |
是 |
String |
商品名称 |
keyword |
是 |
String |
商品关键词,多个用分号(;)分隔 |
categoryId |
是 |
String |
商品分类ID |
unitName |
是 |
String |
商品单位 |
sort |
是 |
Integer |
排序值 |
isPostage |
是 |
String |
是否包邮(T/F) |
coverPhoto |
是 |
String |
商品封面图片URL |
content |
是 |
String |
商品详情描述 |
carouselFigurePhoto |
是 |
JSONArray |
商品轮播图URL数组 |
productSpecs |
是 |
JSONArray |
商品规格数组 |
可选参数:
参数名称 |
必填 |
类型 |
描述 |
shopId |
否 |
String |
店铺ID |
hktIds |
否 |
JSONArray |
家政服务类型ID数组 |
6.2 商品规格参数(productSpecs数组中的对象)
参数名称 |
必填 |
类型 |
描述 |
specName |
是 |
String |
规格名称 |
costPrice |
是 |
String |
成本价 |
originalPrice |
是 |
String |
原价 |
price |
是 |
String |
售价 |
stock |
是 |
String |
库存数量 |
isDefault |
是 |
String |
是否默认规格(T/F) |
deduction |
否 |
String |
抵扣金额,默认0.00 |
7. 返回值
7.1 返回值结构
参数名称 |
类型 |
描述 |
code |
String |
返回码(0成功) |
msg |
String |
返回信息 |
data |
Object |
返回数据 |
8. 示例请求
{
"prodName": "测试商品",
"keyword": "测试;商品",
"categoryId": "123456",
"unitName": "件",
"sort": 1,
"isPostage": "T",
"coverPhoto": "http://example.com/cover.jpg",
"content": "商品详细描述内容",
"carouselFigurePhoto": [
"http://example.com/image1.jpg",
"http://example.com/image2.jpg"
],
"productSpecs": [
{
"specName": "规格1",
"costPrice": "10.00",
"originalPrice": "20.00",
"price": "15.00",
"stock": "100",
"isDefault": "T",
"deduction": "0.00"
},
{
"specName": "规格2",
"costPrice": "15.00",
"originalPrice": "25.00",
"price": "20.00",
"stock": "50",
"isDefault": "F"
}
],
"shopId": "1001",
"hktIds": ["2001", "2002"]
}
9. 示例响应
{
"code": "0",
"msg": "保存成功",
"data": null
}
10. 错误码
错误码 |
描述 |
0 |
成功 |
非0 |
失败,具体错误信息见msg字段 |
11. 业务逻辑说明
- 验证请求参数完整性
- 验证店铺是否审核通过
- 保存商品基本信息
- 处理商品关键词
- 保存商品图片(封面和轮播图)
- 保存商品规格信息
- 保存商品详情
- 如果有初始库存,生成入库单
- 处理家政服务类型关联(如果有)
- 返回操作结果
12. 数据库操作
- 插入商品基本信息(product表)
- 插入商品关键词(product_serv_keyword表)
- 插入商品图片关联(file_rel表)
- 插入商品规格(product_spec_value表)
- 插入商品详情(product_detail表)
- 插入入库单(inout_order表)
- 插入入库单明细(inout_order_product表)
- 插入家政服务类型关联(product_h5_menu表)