1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package jingdong
import (
"context"
"encoding/json"
"github.com/gogf/gf/container/garray"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
type goodsJD struct {
}
var Goods = goodsJD{}
type CheckSaleRes struct {
*CommonRes
Result []struct {
SkuId int `json:"skuid"` //商品编号
Name string `json:"name"` //商品名称
SaleState int `json:"saleState"` //是否可售 1:是,0:否
IsCanVAT int `json:"isCanVAT"` //是否可开增票,1:支持,0:不支持
Is7ToReturn int `json:"is7ToReturn"` //是否支持7天退货,1:是,0:不支持
} `json:"result"`
}
type CheckOnSaleRes struct {
*CommonRes
Result []struct {
Sku int `json:"sku"` //商品编号
State int `json:"state"` //1:上架,0:下架
} `json:"result"`
}
type GetStockMidRes struct {
*CommonRes
Result string `json:"result"`
}
type GetStockRes struct {
*CommonRes
Result []struct {
SkuID int `json:"skuId"` //商品编号
AreaID string `json:"areaId"` //入参时传入的区域码area。因京东目前是3、4级地址均支持,存在areaId在传入的3级地址后填充4级地址“_0“后返回的情况。
StockStateID int `json:"stockStateId"` //存状态编号。 参考枚举值: 33,39,40,36,34,99
StockStateDesc string `json:"StockStateDesc"` /*库存状态描述。以下为stockStateId不同时,此字段不同的返回值:
33 有货 现货-下单立即发货
39 有货 在途-正在内部配货,预计2~6天到达本仓库
40 有货 可配货-下单后从有货仓库配货
36 预订
34 无货
99 无货开预定*/
} `json:"result"`
}
type CheckAreaMidRes struct {
*CommonRes
Result string `json:"result"`
}
type CheckAreaLimitRes struct {
*CommonRes
Result []struct {
SkuID int `json:"skuId"` //商品编码
IsAreaRestrict bool `json:"isAreaRestrict"` //true 代表区域受限 false 区域不受限
} `json:"result"`
}
type GetProductsPriceRes struct {
*CommonRes
Result []struct {
SkuID int `json:"skuId"` //商品编码
Price float64 `json:"price"` //京东销售价
JdPrice float64 `json:"jdPrice"` //京东价
MarketPrice float64 `json:"marketPrice"` //京东的前台划线价
} `json:"result"`
}
type GetDetailRes struct {
*CommonRes
Result struct {
SaleUnit string `json:"saleUnit"` //售卖单位
Weight string `json:"weight"` //重量
ProductArea string `json:"productArea"` //产地
WareQD string `json:"wareQD"` //包装清单
ImagePath string `json:"imagePath"` //主图
State int `json:"state"` //状态
Sku int `json:"sku"` //商品编号
BrandName string `json:"brandName"` //品牌名称
Category string `json:"category"` //分类 示例"670;729;4837"
Name string `json:"name"` //商品名称
Introduction string `json:"introduction"` //商品详情页大字段
IsFactoryShip string `json:"isFactoryShip"` //1 厂商直送;0 非厂商直送
IsSelf int `json:"isSelf"` //是否自营
LowestBuy interface{} `json:"LowestBuy"` //商品最低起购量
Wxintroduction string `json:"wxintroduction"` //微信小程序商品详情大字段,仅提供图片地址
} `json:"result"`
}
type GetCategoryRes struct {
*CommonRes //异常代码(3422:获取分类列表信息失败;3423:分类列表不存在;1003:参数值不正确;5001:服务异常,请稍后重试;)
Result struct {
TotalRows int `json:"totalRows"`
PageNo int `json:"pageNo"`
PageSize int `json:"pageSize"`
Categorys []struct {
CatId int `json:"catId"` //分类ID
ParentId int `json:"parentId"` //父分类ID
Name string `json:"name"` //分类名称
CatClass int `json:"catClass"` //0:一级分类;1:二级分类;2:三级分类;
State int `json:"state"`
} `json:"categorys"`
} `json:"result"`
}
type GetSkuImageRes struct {
*CommonRes //异常代码(0010:返回数据为空;1001:参数为空;1003:参数值不正确/sku数量过多,目前最大支持100个商品)
Result map[string][]struct {
Id int `json:"id"` //编号
SkuId int `json:"skuId"` //商品编号
Path string `json:"path"` //图片路径
} `json:"result"`
}
type GetSimilarSkuRes struct {
*CommonRes
Result []struct {
Dim int `json:"dim"` //维度
SaleName string `json:"saleName"` //销售名称
SaleAttrList []struct { //商品销售标签 销售属性下可能只有一个标签,此种场景可以选择显示销售名称和标签,也可以不显示
ImagePath string `json:"imagePath"` //标签图片地址
SaleValue string `json:"saleValue"` //标签名称
SkuIds []int `json:"skuIds"` //当前标签下的同类商品skuId
} `json:"saleAttrList"` //
} `json:"result"`
}
// CheckSale 商品可售验证接口
func (*goodsJD) CheckSale(ctx context.Context, req *garray.Array) (res *CheckSaleRes, err error) {
method := "product/check"
param := g.Map{
"skuIds": req.Join(","),
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
// CheckOnSale 查询商品上下架状态
func (*goodsJD) CheckOnSale(ctx context.Context, req *garray.Array) (res *CheckOnSaleRes, err error) {
method := "product/skuState"
param := g.Map{
"sku": req.Join(","),
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
//GetStock 查询商品库存
func (*goodsJD) GetStock(ctx context.Context, req []*SkuNums, area string) (res *GetStockRes, err error) {
method := "stock/getNewStockById"
param := g.Map{
"skuNums": gjson.New(req).MustToJsonString(),
"area": area,
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
var middle *GetStockMidRes
err = gjson.New(result).Scan(&middle)
if err != nil {
return
}
err = gjson.New(middle.CommonRes).Scan(&res)
if err != nil {
return
}
err = gjson.New(middle.Result).Scan(&res.Result)
return
}
// CheckAreaLimit 查询商品区域购买限制
func (*goodsJD) CheckAreaLimit(ctx context.Context, skuIds *garray.Array, provinceID, cityID, countyID, townID interface{}) (res *CheckAreaLimitRes, err error) {
method := "product/checkAreaLimit"
param := g.Map{
"skuIds": skuIds.Join(","),
"province": gconv.String(provinceID),
"city": gconv.String(cityID),
"county": gconv.String(countyID),
"town": gconv.String(townID),
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
var middle *CheckAreaMidRes
err = gjson.New(result).Scan(&middle)
if err != nil {
return
}
err = gjson.New(middle.CommonRes).Scan(&res)
if err != nil {
return
}
err = gjson.New(middle.Result).Scan(&res.Result)
return
}
//GetProductsPrice 查询商品价格
func (*goodsJD) GetProductsPrice(ctx context.Context, skus *garray.Array) (res *GetProductsPriceRes, err error) {
method := "price/getSellPrice"
param := g.Map{
"sku": skus.Join(","),
"queryExts": "marketPrice",
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
//GetDetail 查询商品详情
func (*goodsJD) GetDetail(ctx context.Context, skus *garray.Array) (res *GetDetailRes, err error) {
method := "product/getDetail"
param := g.Map{
"sku": skus.Join(","),
"queryExts": "spuId,pName,isFactoryShip,isSelf,LowestBuy,wxintroduction",
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
//GetCategory 查询分类列表
func (*goodsJD) GetCategory(ctx context.Context, pageNo, pageSize interface{}) (res *GetCategoryRes, err error) {
method := "product/getCategorys"
param := g.Map{
"pageNo": gconv.String(pageNo),
"pageSize": gconv.String(pageSize),
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
//GetSkuImage 查询商品图片
func (*goodsJD) GetSkuImage(ctx context.Context, skus *garray.Array) (res *GetSkuImageRes, err error) {
method := "product/skuImage"
param := g.Map{
"sku": skus.Join(","),
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
//GetSimilarSku 查询同类商品
func (*goodsJD) GetSimilarSku(ctx context.Context, skus interface{}) (res *GetSimilarSkuRes, err error) {
method := "product/getSimilarSku"
param := g.Map{
"skuId": skus,
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}