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
package yz
import (
"context"
"encoding/json"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/util/gconv"
)
type goodsJD struct {
}
var Goods = goodsJD{}
type UpdateGoodsReq struct {
Param UpdateGoodsParam `json:"param"`
}
type UpdateGoodsParam struct {
ItemId int `json:"item_id"`
//NodeKdtId int `json:"node_kdt_id"`
ItemDeliveryParam ItemDeliveryParam `json:"item_delivery_param"`
ItemWeight int `json:"item_weight"`
ItemNo string `json:"item_no"`
SkuList []SkuListUpdate `json:"sku_list"`
Desc string `json:"desc"`
ImageIds []int64 `json:"image_ids"`
SkuValueProps []SkuValueProps `json:"sku_value_props"`
ItemType int `json:"item_type"`
ItemPriceParam ItemPriceParam `json:"item_price_param"`
Title string `json:"title"`
IsDisplay int `json:"is_display"`
Quantity int `json:"quantity"`
HideStock int `json:"hide_stock"`
}
type SkuListUpdate struct {
//SkuProps []SkuProps `json:"sku_props"`
Price int `json:"price"`
MaxGuidePrice int `json:"max_guide_price"`
CostPrice int `json:"cost_price"`
SkuNo string `json:"sku_no"`
StockNum int `json:"stock_num"`
SkuId int64 `json:"sku_id"`
}
type AddGoodsReq struct {
Param AddGoodsParam `json:"param"`
}
type ItemDeliveryParam struct {
Postage int `json:"postage"`
DeliverySetting DeliverySetting `json:"delivery_setting"`
}
type DeliverySetting struct {
Express bool `json:"express"`
}
type SkuList struct {
SkuProps []SkuProps `json:"sku_props"`
Price int `json:"price"`
MaxGuidePrice int `json:"max_guide_price"`
CostPrice int `json:"cost_price"`
SkuNo string `json:"sku_no"`
StockNum int `json:"stock_num"`
}
type SkuProps struct {
PropValueName string `json:"prop_value_name"`
PropName string `json:"prop_name"`
PropNameId int `json:"prop_name_id"`
PropValueId int `json:"prop_value_id"`
}
type SkuValueProps struct {
Name string `json:"name"`
ImgId int `json:"img_id"`
Id int `json:"id"`
}
type ItemPriceParam struct {
Origin string `json:"origin"`
CostPrice int `json:"cost_price"`
Price int `json:"price"`
}
type AddGoodsParam struct {
ItemId int `json:"item_id"`
//NodeKdtId int `json:"node_kdt_id"`
ItemDeliveryParam ItemDeliveryParam `json:"item_delivery_param"`
ItemWeight int `json:"item_weight"`
ItemNo string `json:"item_no"`
SkuList []SkuList `json:"sku_list"`
Desc string `json:"desc"`
ImageIds []int64 `json:"image_ids"`
SkuValueProps []SkuValueProps `json:"sku_value_props"`
ItemType int `json:"item_type"`
ItemPriceParam ItemPriceParam `json:"item_price_param"`
Title string `json:"title"`
IsDisplay int `json:"is_display"`
Quantity int `json:"quantity"`
HideStock int `json:"hide_stock"`
}
type AddGoodsRes struct {
CommonRes
Data struct {
ItemId int `json:"item_id"`
Alias string `json:"alias"`
} `json:"data"`
}
type UplpadImgReq struct {
Image string `json:"image"`
}
type FindGoodsDataReq struct {
ItemId int `json:"item_id"`
}
type FindGoodsDataRes struct {
CommonRes
Data GoodsData `json:"data"`
}
type GoodsData struct {
SkuList []SkuListData `json:"sku_list"`
}
type SkuListData struct {
SkuId int64 `json:"sku_id"`
SkuNo string `json:"sku_no"`
}
// type UplpadImgRes struct {
// CommonRes
// Data struct {
// ImageId int64 `json:"image_id"`
// } `json:"data"`
// }
type UplpadImgRes struct {
CommonRes
Data struct {
KdtId int `json:"kdt_id"`
ImageUrl string `json:"image_url"`
Width int `json:"width"`
ImageId int64 `json:"image_id"`
Height int `json:"height"`
} `json:"data"`
}
// 添加商品
func (*goodsJD) AddGoods(ctx context.Context, req *AddGoodsReq) (res *AddGoodsRes, err error) {
method := "youzan.item.add/1.0.1"
param := gconv.Map(req)
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
// 编辑商品
func (*goodsJD) UpdateGoods(ctx context.Context, req *UpdateGoodsReq) (res *AddGoodsRes, err error) {
method := "youzan.item.incremental.update/1.0.1"
param := gconv.Map(req)
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
// 图片上传
func (*goodsJD) UploadImg(ctx context.Context, req *UplpadImgReq) (res *UplpadImgRes, err error) {
method := "youzan.materials.storage.platform.img.upload/3.0.0"
//param := gconv.Map(req)
//param = map[string]interface{}{
// "image" : req.Image,
//}
result, err := server.requestApiImg(ctx, method, req.Image)
if err != nil {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
// 商品详情
func (*goodsJD) FindGoodsData(ctx context.Context, req *FindGoodsDataReq) (res *FindGoodsDataRes, err error) {
method := "youzan.item.detail.get/1.0.0"
param := gconv.Map(req)
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
//type UpDateStockReq struct {
// Quantity string `json:"quantity"`
// ItemId string `json:"item_id"`
// SkuId string `json:"sku_id"`
// Type string `json:"type"`
//}
//type UpDateStockRes struct {
// Code int `json:"code"`
// Data struct {
// IsSuccess bool `json:"is_success"`
// } `json:"data"`
// Success bool `json:"success"`
// Message string `json:"message"`
//}
//// 图片上传
//func (*goodsJD) UpDateStock(ctx context.Context, req *UpDateStockReq) (res *UpDateStockRes, err error) {
// method := "youzan.item.quantity.update/3.0.0"
// param := gconv.Map(req)
// result, err := server.requestApi(ctx, method, param)
// if err != nil {
// return
// }
// err = json.Unmarshal([]byte(result), &res)
// return
//}1