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
package ali
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
type goodsAli struct {
}
var Goods = goodsAli{}
type GoodsListReq struct {
Biztype string `json:"biztype,omitempty"` //经营模式 【1:生产加工,2:经销批发,3:招商代理,4:商业服务】
BuyerProtection string `json:"buyerProtection,omitempty"` //买家保障,多个值用逗号分割;【qtbh:7天包换;swtbh:15天包换】
City string `json:"city,omitempty"` //所在地区- 市 示例:杭州
DeliveryTimeType string `json:"deliveryTimeType,omitempty"` //发货时间;【1:24小时发货;2:48小时发货;3:72小时发货】
DescendOrder bool `json:"descendOrder,omitempty"` //是否倒序;【正序: false;倒序:true】
HolidayTagId string `json:"holidayTagId,omitempty"` //商品售卖类型筛选;枚举,多个值用分号分割;免费赊账:50000114
KeyWords string `json:"keyWords,omitempty"` //搜索关键词
Page int `json:"page"` //页码
PageSize int `json:"pageSize"` //页面数量;最大20
OfferIds string `json:"offerIds,omitempty"` //ID
CategoryId string `json:"postCategoryId,omitempty"` //分类ID
SortType string `json:"sortType,omitempty"` //排序字段
AccessToken string `json:"access_token"`
}
type GoodsListRes struct {
Result struct {
CommonRes
TotalCount int `json:"totalCount"` //总数
Result []struct {
Title string `json:"title"` //商品标题
ImgURL string `json:"imgUrl"` //商品首图
OfferID int64 `json:"offerId"` //商品id
SoldOut int `json:"soldOut"` //销量
Enable bool `json:"enable"` //是否有效
Profit string `json:"profit"` //利润空间; - :表示无 示例 300%-500%
CurrentPrice float64 `json:"currentPrice"` //分销价
OfferTags []string `json:"offerTags"` //标签数组
} `json:"result"`
} `json:"result"`
}
type GoodsInfoRes struct {
CommonRes
BizGroupInfos []struct {
Support bool `json:"support"`
Description string `json:"description"`
Code string `json:"code"`
} `json:"bizGroupInfos"`
ProductInfo struct {
ProductID int64 `json:"productID"`
SupplierLoginId string `json:"SupplierLoginId"`
MainVedio string `json:"MainVedio"`
CategoryID int `json:"categoryID"`
Subject string `json:"subject"`
Description string `json:"description"`
PictureAuth bool `json:"pictureAuth"`
IntelligentInfo IntelligentInfo `json:"intelligentInfo"` //商品算法智能改写信息,包含算法优化后的商品标题和图片信息,未改写的则直接返回原标题和原图片
Image struct {
Images []string `json:"images"`
} `json:"image"`
SkuInfos []struct {
Attributes []struct {
AttributeID int `json:"attributeID"`
AttributeValue string `json:"attributeValue"`
SkuImageURL string `json:"skuImageUrl"`
AttributeName string `json:"attributeName"`
} `json:"attributes"`
CargoNumber string `json:"cargoNumber"`
AmountOnSale int `json:"amountOnSale"`
Price float64 `json:"price"`
SkuID int64 `json:"skuId"`
SpecID string `json:"specId"`
ConsignPrice float64 `json:"consignPrice"`
Retailprice float64 `json:"retailprice"`
ChannelPrice float64 `json:"channelPrice"`
} `json:"skuInfos"`
SaleInfo struct {
SupportOnlineTrade bool `json:"supportOnlineTrade"`
MixWholeSale bool `json:"mixWholeSale"`
PriceAuth bool `json:"priceAuth"`
PriceRanges []struct {
StartQuantity int `json:"startQuantity"`
Price float64 `json:"price"`
} `json:"priceRanges"`
AmountOnSale float64 `json:"amountOnSale"`
Unit string `json:"unit"`
MinOrderQuantity int `json:"minOrderQuantity"`
QuoteType int `json:"quoteType"`
Retailprice float64 `json:"retailprice"`
ConsignPrice float64 `json:"consignPrice"`
ChannelPrice float64 `json:"channelPrice"`
} `json:"saleInfo"`
ShippingInfo struct {
FreightTemplateID int `json:"freightTemplateID"`
UnitWeight float64 `json:"unitWeight"`
SendGoodsAddressID int `json:"sendGoodsAddressId"`
SendGoodsAddressText string `json:"sendGoodsAddressText"`
FreightTemplate []struct {
AddressCodeText string `json:"addressCodeText"`
FromAreaCode string `json:"fromAreaCode"`
ID int `json:"id"`
ExpressSubTemplate struct {
SubTemplateDTO struct {
ChargeType int `json:"chargeType"`
IsSysTemplate bool `json:"isSysTemplate"`
ServiceType int `json:"serviceType"`
Type int `json:"type"`
} `json:"subTemplateDTO"`
RateList []struct {
IsSysRate bool `json:"isSysRate"`
ToAreaCodeText string `json:"toAreaCodeText"`
RateDTO struct {
FirstUnit int `json:"firstUnit"`
FirstUnitFee int `json:"firstUnitFee"`
NextUnit int `json:"nextUnit"`
NextUnitFee int `json:"nextUnitFee"`
} `json:"rateDTO"`
} `json:"rateList"`
} `json:"expressSubTemplate"`
LogisticsSubTemplate struct {
SubTemplateDTO struct {
ChargeType int `json:"chargeType"`
IsSysTemplate bool `json:"isSysTemplate"`
ServiceType int `json:"serviceType"`
Type int `json:"type"`
} `json:"subTemplateDTO"`
} `json:"logisticsSubTemplate"`
} `json:"freightTemplate"`
ChannelPriceFreePostage bool `json:"channelPriceFreePostage"`
ChannelPriceExcludeAreaCodes []struct {
Code string `json:"code"`
Name string `json:"name"`
} `json:"channelPriceExcludeAreaCodes"`
} `json:"shippingInfo"`
QualityLevel int `json:"qualityLevel"`
SupplierLoginID string `json:"supplierLoginId"`
CategoryName string `json:"categoryName"`
ReferencePrice string `json:"referencePrice"`
Attributes []struct {
AttributeID int `json:"attributeID"`
AttributeName string `json:"attributeName"`
Value string `json:"value"`
IsCustom bool `json:"isCustom"`
} `json:"attributes"`
Status string `json:"status"`
} `json:"productInfo"`
}
type IntelligentInfo struct {
Title string `json:"title"` //算法优化后的商品标题
Images []string `json:"images"` //主图列表,使用相对路径,需要增加域名:https://cbu01.alicdn.com/
SkuImages []struct { //算法优化后的规格图片
SkuId int64 `json:"skuId"` //规格ID
ImageUrl string `json:"imageUrl"` //图片
} `json:"skuImages"`
DescriptionImages []string `json:"descriptionImages"` //算法优化后的详情图片
}
type GoodsFollowRes struct {
Code int `json:"code"`
Message int `json:"message"`
}
type GoodsGroupReq struct {
PageNo int64 `json:"pageNo"`
PageSize int64 `json:"pageSize"`
AccessToken string `json:"access_token"`
}
type GoodsGroupRes struct {
Result struct {
Result []struct {
CreateTime string `json:"createTime"`
FeedCount int `json:"feedCount"`
ID int `json:"id"`
Title string `json:"title"`
} `json:"result"`
CommonRes
} `json:"result"`
}
type GoodsCategoryReq struct {
CategoryID int64 `json:"categoryID"`
AccessToken string `json:"access_token"`
}
type GoodsCategoryRes struct {
Succes string `json:"succes"`
CategoryInfo []struct {
CategoryID int `json:"categoryID"`
Name string `json:"name"`
IsLeaf bool `json:"isLeaf"`
ParentIDs []int `json:"parentIDs"`
MinOrderQuantity int `json:"minOrderQuantity"`
FeatureInfos []struct {
Key string `json:"key"`
Value string `json:"value"`
Status int `json:"status"`
Hierarchy bool `json:"hierarchy"`
} `json:"featureInfos"`
CategoryType string `json:"categoryType"`
IsSupportProcessing bool `json:"isSupportProcessing"`
} `json:"categoryInfo"`
}
//List 查询商品列表
func (goodsAli) List(ctx context.Context, req *GoodsListReq) (res *GoodsListRes, err error) {
method := "com.alibaba.p4p/alibaba.cps.op.searchCybOffers"
req.AccessToken = server.AccessToken
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
func (goodsAli) Info(ctx context.Context, req interface{}) (res *GoodsInfoRes, err error) {
method := "com.alibaba.product/alibaba.cpsMedia.productInfo"
request := g.Map{
"offerId": gconv.Int64(req),
"needCpsSuggestPrice": true,
"needIntelligentInfo": true,
"access_token": server.AccessToken,
}
result, err := server.Post(ctx, method, request)
_ = gjson.New(result).Scan(&res)
return
}
//Follow 关注商品
func (goodsAli) Follow(ctx context.Context, GoodsID string) (res *GoodsFollowRes, err error) {
method := "com.alibaba.product/alibaba.product.follow"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"productId": GoodsID,
})
_ = gjson.New(result).Scan(&res)
return
}
//UnFollow 解除关注商品
func (goodsAli) UnFollow(ctx context.Context, GoodsID string) (res *GoodsFollowRes, err error) {
method := "com.alibaba.product/alibaba.product.unfollow.crossborder"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"productId": GoodsID,
})
_ = gjson.New(result).Scan(&res)
return
}
//Group 获取我的选品库列表
func (goodsAli) Group(ctx context.Context, req *GoodsGroupReq) (res *GoodsGroupRes, err error) {
method := "com.alibaba.p4p/alibaba.cps.op.listCybUserGroup"
req.AccessToken = server.AccessToken
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}
func (goodsAli) Category(ctx context.Context, CategoryID interface{}) (res *GoodsCategoryRes, err error) {
method := "com.alibaba.product/alibaba.category.get"
var req = &GoodsCategoryReq{
CategoryID: gconv.Int64(CategoryID),
AccessToken: server.AccessToken,
}
result, err := server.Post(ctx, method, gconv.Map(req))
_ = gjson.New(result).Scan(&res)
return
}