-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgoods.go
58 lines (47 loc) · 1.48 KB
/
goods.go
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
package pdd
import (
"encoding/json"
)
type GoodsAPI struct {
Context *Context
}
func NewGoodsAPI(cfg *Config) *GoodsAPI {
return &GoodsAPI{Context: NewContext(cfg)}
}
func newGoodsAPIWithContext(c *Context) *GoodsAPI {
return &GoodsAPI{Context: c}
}
type Category struct {
Level int `json:"level"` // 层级,1-一级,2-二级,3-三级,4-四级
CatId int `json:"cat_id"` //
ParentCatId int `json:"parent_cat_id"`
CatName string `json:"cat_name"`
}
func (g *GoodsAPI) GoodsCatGet(parentCatId int) (res []*Category, err error) {
params := NewParamsWithType(GoodsCatsGet)
params.Set("parent_cat_id", parentCatId)
r, err := Call(g.Context, params)
if err != nil {
return
}
bytes, err := GetResponseBytes(r, "goods_cats_get_response", "goods_cats_list")
json.Unmarshal(bytes, &res)
return
}
type Opt struct {
Level int `json:"level"` // 层级,1-一级,2-二级,3-三级,4-四级
ParentOptID int `json:"parent_opt_id"` // id 所属父 Id,其中,parent_id = 0 时为顶级节点
OptName string `json:"opt_name"` // 商品标签名
OptID int `json:"opt_id"` // 商品标签ID
}
func (g *GoodsAPI) GoodsOptGet(parentOptId int) (res []*Opt, err error) {
params := NewParamsWithType(GoodsOptGet)
params.Set("parent_opt_id", parentOptId)
r, err := Call(g.Context, params)
if err != nil {
return
}
bytes, err := GetResponseBytes(r, "goods_opt_get_response", "goods_opt_list")
json.Unmarshal(bytes, &res)
return
}