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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
type goods struct {
}
var Goods = goods{}
type GoodsListReq struct {
Q string `json:"q,omitempty"` //关键词
SessionId string `json:"sessionId,omitempty"` //长度不要超过32位,用来分页去重,当前请求只是翻页,则这个值不要改变
Sort string `json:"sort,omitempty"` //排序参数
// 价格降序:sort=price:des
//价格升序:sort=price:asc
//综合排序:sort=popular:des
//销量降序:sort=sales:des
//客户响应率倒序 sort=cst_reply_rate:des
//客户响应率正序 sort=cst_reply_rate:acs
//好评率倒序 sort=pos_review_all_rate_30d:des
//好评率正序 sort=pos_review_all_rate:acs
//退货率倒序 sort=tj_pinzhi_rfd_rate:des
//退货率正序 sort=tj_pinzhi_rfd_rate:acs
//发货时效倒序 sort=ship_ord_rate_7d_104:des
//发货时效正序 sort=ship_ord_rate_7d_104:acs
Price string `json:"price,omitempty"` //价格筛选
//89~248 从89元到248元
//89~ 大于89元
//~248 小于248元
Cate string `json:"cate,omitempty"` //一级类目筛选
S int `json:"s"` //默认0,不是页码,是每次查询的起始位置,相当于 页码x每页数量
N int `json:"n"` //默认20, 每页数量,建议值10,不宜过大
Feature string `json:"feature,omitempty"` //字符串,不是json 请求示例 :{\"poolId\":\"1001\"}
//目前支持的key
//精选商品池映射 poolId
//退货率 refundRateBegin
//退货率 refundRateEnd
//好评率 posReviewRateBegin
//好评率 posReviewRateEnd
//客服响应率 cstRateBegin
//客服响应率 cstRateEnd
//发货时效 shipRateBegin
//发货时效 shipRateEnd
}
type GoodsListRes struct {
Result struct {
Auctions []struct {
Category string `json:"category"`
CstRate string `json:"cstRate"`
LevelOneCat string `json:"levelOneCat"`
Nid string `json:"nid"`
PictUrl string `json:"pictUrl"`
PosReviewRate string `json:"posReviewRate"`
RefundRate string `json:"refundRate"`
ReservePrice string `json:"reservePrice"`
ShipIn24 string `json:"shipIn24"`
ShipRate string `json:"shipRate"`
TejiaTotalSoldQuantity string `json:"tejiaTotalSoldQuantity"`
Title string `json:"title"`
ZkFinalPrice string `json:"zkFinalPrice"`
} `json:"auctions"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
TotalCount int `json:"totalCount"`
} `json:"result"`
}
func (goods) List(ctx context.Context, req GoodsListReq) (res *GoodsListRes, err error) {
method := "tt.item.list.v2"
result, err := server.Get(ctx, method, g.Map{
"request": req,
})
_ = gjson.New(result).Scan(&res)
return
}
type GoodsDetailReq struct {
AppKey int `json:"appKey"`
ItemId string `json:"itemId"`
SkuId string `json:"skuId,omitempty"`
}
type GoodsDetailRes struct {
ErrorMessage string `json:"error_message"`
ErrorCode string `json:"error_code"`
DebugInfoMap struct {
TraceId string `json:"traceId"`
} `json:"debugInfoMap"`
EnterNewLink string `json:"enterNewLink"`
Item struct {
CategoryId []string `json:"categoryId"` //商品的类目列表,从一级类目开始
CategoryName []string `json:"categoryName"` //商品的类目标题
City string `json:"city"`
FastPostFee int `json:"fastPostFee"` //商品的快递费用
Images []string `json:"images"`
ItemId string `json:"itemId"` //商品id
ItemServices []struct {
ActionTitle string `json:"actionTitle,omitempty"`
ActionUrl string `json:"actionUrl,omitempty"`
Desc string `json:"desc"`
Title string `json:"title"`
} `json:"itemServices"`
MainPic string `json:"mainPic"`
OrdinaryPostFee int `json:"ordinaryPostFee"` //商品的平邮费用
Props []struct {
Content string `json:"content"`
Word string `json:"word"`
} `json:"props"`
Prov string `json:"prov"`
Receipt bool `json:"receipt"`
SoldQuantity int `json:"soldQuantity"` //商品的销量
Status int `json:"status"` //商品的状态 0,1正常,-1:用户删除,-2:用户下架,-3 小二下架,-4 小二删除,-5 从未上架,-9 CC
Title string `json:"title"` //商品的类目标题
} `json:"item"`
Seller struct { //商品的卖家信息
ShopName string `json:"shopName"` //店铺名称
SellerId string `json:"sellerId"`
} `json:"seller"`
SkuBase struct {
Props []struct {
Name string `json:"name"` //sku的属性名称
Pid string `json:"pid"` //sku的属性id
Values []struct {
Image string `json:"image"`
Name string `json:"name"` //sku的属性内容
Vid string `json:"vid"` //sku的属性内容id
} `json:"values"`
} `json:"props"`
Skus []struct {
PropPath string `json:"propPath"` //sku的属性路径
SkuId string `json:"skuId"`
} `json:"skus"`
} `json:"skuBase"`
SkuCore struct {
Sku2Info map[string]GoodsItem `json:"sku2info"`
} `json:"skuCore"`
}
type GoodsItem struct {
QuantityVague string `json:"quantityVague"` //模糊化库存,实际库存大于200时展示200,小于200时展示实际的值
OriginalPrice string `json:"originalPrice"` //特价,报名特价版的价格 单位:分
FinalPrice string `json:"finalPrice"`
TjbMarketPrice string `json:"tjbMarketPrice"` //市场价
PriceMoney string `json:"priceMoney"` //单品优惠价,参与活动后得价格
}
//Detail 详情
func (goods) Detail(ctx context.Context, GoodsID string) (res *GoodsDetailRes, err error) {
method := "tt.item.detail.v2"
var request = GoodsDetailReq{
AppKey: gconv.Int(server.AppKey),
ItemId: GoodsID,
SkuId: "",
}
result, err := server.Post(ctx, method, g.Map{
"parameters": request,
})
_ = gjson.New(result).Scan(&res)
return
}
type GoodsDescRes struct {
ErrorMessage string `json:"error_message"`
ErrorCode string `json:"error_code"`
Components *GoodsDescItem `json:"components"`
}
type GoodsDescJson struct {
ErrorMessage string `json:"error_message"`
ErrorCode string `json:"error_code"`
Components string `json:"components"`
}
type GoodsDescItem struct {
ComponentData struct {
DetailPic1 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_1"`
DetailPic10 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_10"`
DetailPic11 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_11"`
DetailPic12 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_12"`
DetailPic2 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_2"`
DetailPic3 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_3"`
DetailPic4 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_4"`
DetailPic5 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_5"`
DetailPic6 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_6"`
DetailPic7 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_7"`
DetailPic8 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_8"`
DetailPic9 struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_9"`
DetailPicTmallPriceDesc struct {
Actions []string `json:"actions"`
Children []interface{} `json:"children"`
Model struct {
LocateId string `json:"locateId"`
PicUrl string `json:"picUrl"`
} `json:"model"`
Styles struct {
Size struct {
Height string `json:"height"`
Width string `json:"width"`
} `json:"size"`
} `json:"styles"`
} `json:"detail_pic_tmallPriceDesc"`
} `json:"componentData"`
Layout []struct {
ID string `json:"ID"`
Key string `json:"key"`
} `json:"layout"`
}
//Desc 详情描述
func (goods) Desc(ctx context.Context, GoodsID string) (res *GoodsDescRes, err error) {
method := "tt.item.desc"
result, err := server.Get(ctx, method, g.Map{
"itemId": GoodsID,
})
var data *GoodsDescJson
err = gjson.New(result).Scan(&data)
if err != nil {
return
}
if data.ErrorCode != "" {
err = gjson.New(result).Scan(&res)
return
}
res = new(GoodsDescRes)
_ = gjson.New(data.Components).Scan(&res.Components)
return
}
type GoodsCategoryRes struct {
ErrorMessage string `json:"error_message"`
ErrorCode string `json:"error_code"`
CateNameLists []string `json:"cateNameLists"`
Code string `json:"code"`
ItemId string `json:"itemId"`
ItemName string `json:"itemName"`
Message string `json:"message"`
}
//Category 商品类目
func (goods) Category(ctx context.Context, GoodsID string) (res *GoodsCategoryRes, err error) {
method := "tt.item.cateInfo"
result, err := server.Get(ctx, method, g.Map{
"itemId": GoodsID,
})
_ = gjson.New(result).Scan(&res)
return
}