-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgoods.barcode.go
185 lines (162 loc) · 6.39 KB
/
goods.barcode.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
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
package temu
import (
"context"
"fmt"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/hiscaler/temu-go/entity"
"github.com/hiscaler/temu-go/helpers"
"github.com/hiscaler/temu-go/normal"
"github.com/hiscaler/temu-go/validators/is"
"gopkg.in/guregu/null.v4"
"time"
)
// 商品条码服务
type goodsBarcodeService service
type NormalGoodsBarcodeQueryParams struct {
normal.ParameterWithPager
ProductSkuIdList []int64 `json:"productSkuIdList,omitempty"` // 货品 sku id 列表
SkcExtCode string `json:"skcExtCode,omitempty"` // skc 货号
ProductSkcIdList []int64 `json:"productSkcIdList,omitempty"` // 货品 skc id 列表
SkuExtCode string `json:"skuExtCode,omitempty"` // sku 货号
LabelCode int `json:"labelCode,omitempty"` // 标签条码
}
func (m NormalGoodsBarcodeQueryParams) validate() error {
return nil
}
// NormalGoods 商品条码查询v2(bg.goods.labelv2.get)
// https://seller.kuajingmaihuo.com/sop/view/889973754324016047#5LRokG
func (s goodsBarcodeService) NormalGoods(ctx context.Context, params NormalGoodsBarcodeQueryParams) (items []entity.GoodsLabel, err error) {
params.TidyPager()
if err = params.validate(); err != nil {
return items, invalidInput(err)
}
var result = struct {
normal.Response
Result struct {
LabelCodePageResult struct {
TotalCount int `json:"totalCount"` // 总数
Data []entity.GoodsLabel `json:"data"` // 结果列表
} `json:"labelCodePageResult"`
} `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetBody(params).
SetResult(&result).
Post("bg.goods.labelv2.get")
if err = recheckError(resp, result.Response, err); err != nil {
return
}
return result.Result.LabelCodePageResult.Data, nil
}
// 定制商品条码查询(bg.goods.custom.label.get)
type CustomGoodsBarcodeQueryParams struct {
NormalGoodsBarcodeQueryParams
ProductSkuIdList []int64 `json:"productSkuIdList,omitempty"` // 货品 SKU ID 列表
SkcExtCode string `json:"skcExtCode,omitempty"` // SKC 货号
ProductSkcIdList []int64 `json:"productSkcIdList,omitempty"` // 货品 SKC ID 列表
SkuExtCode string `json:"skuExtCode,omitempty"` // SKU 货号
LabelCode int64 `json:"labelCode,omitempty"` // 标签条码
PersonalProductSkuIdList []int64 `json:"personalProductSkuIdList,omitempty"` // 定制品 SKU ID
CreateTimeStart string `json:"createTimeStart,omitempty"` // 定制品创建时间,支持毫秒时间戳
CreateTimeEnd string `json:"createTimeEnd,omitempty"` // 定制品创建时间,支持毫秒时间戳
}
func (m CustomGoodsBarcodeQueryParams) validate() error {
return validation.ValidateStruct(&m,
validation.Field(&m.CreateTimeStart,
validation.When(m.CreateTimeStart != "" || m.CreateTimeEnd != "", validation.By(is.TimeRange(m.CreateTimeStart, m.CreateTimeEnd, time.DateTime))),
),
)
}
// CustomGoods 定制商品条码查询(bg.goods.custom.label.get)
// https://seller.kuajingmaihuo.com/sop/view/889973754324016047#Hc5wmR
func (s goodsBarcodeService) CustomGoods(ctx context.Context, params CustomGoodsBarcodeQueryParams) (items []entity.CustomGoodsLabel, err error) {
params.TidyPager()
if err = params.validate(); err != nil {
return items, invalidInput(err)
}
if params.CreateTimeStart != "" && params.CreateTimeEnd != "" {
if start, end, e := helpers.StrTime2UnixMilli(params.CreateTimeStart, params.CreateTimeEnd); e == nil {
params.CreateTimeStart = start
params.CreateTimeEnd = end
}
}
var result = struct {
normal.Response
Result struct {
PersonalLabelCodePageResult struct {
TotalCount int `json:"totalCount"` // 总数
Data []entity.CustomGoodsLabel `json:"data"` // 结果列表
} `json:"personalLabelCodePageResult"`
} `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetBody(params).
SetResult(&result).
Post("bg.goods.custom.label.get")
if err = recheckError(resp, result.Response, err); err != nil {
return
}
return result.Result.PersonalLabelCodePageResult.Data, nil
}
// 查询箱唛(bg.logistics.boxmarkinfo.get)
type BoxMarkBarcodeQueryParams struct {
normal.Parameter
ReturnDataKey null.Bool `json:"return_data_key"` // 是否以打印页面url返回,如果入参是,则不返回参数信息,返回dataKey,通过拼接https://openapi.kuajingmaihuo.com/tool/print?dataKey={返回的dataKey},访问组装的url即可打印,打印的条码按照入参参数所得结果进行打印
DeliveryOrderSnList []string `json:"deliveryOrderSnList"` // 发货单对象列表
}
func (m BoxMarkBarcodeQueryParams) validate() error {
return validation.ValidateStruct(&m,
validation.Field(&m.DeliveryOrderSnList,
validation.Required.Error("发货单对象列表不能为空"),
validation.Each(validation.By(is.ShipOrderNumber())),
),
)
}
// BoxMarkPrintUrl 箱唛打印地址
func (s goodsBarcodeService) BoxMarkPrintUrl(ctx context.Context, shipOrderNumbers ...string) (dataKey string, err error) {
params := BoxMarkBarcodeQueryParams{
ReturnDataKey: null.BoolFrom(true),
DeliveryOrderSnList: shipOrderNumbers,
}
if err = params.validate(); err != nil {
return "", invalidInput(err)
}
var result = struct {
normal.Response
Result string `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetBody(params).
SetResult(&result).
Post("bg.logistics.boxmarkinfo.get")
if err = recheckError(resp, result.Response, err); err != nil {
return
}
return fmt.Sprintf("https://openapi.kuajingmaihuo.com/tool/print?dataKey=%s", result.Result), nil
}
// BoxMark 箱唛信息
func (s goodsBarcodeService) BoxMark(ctx context.Context, shipOrderNumbers ...string) (items []entity.BoxMarkInfo, err error) {
params := BoxMarkBarcodeQueryParams{
ReturnDataKey: null.BoolFrom(false),
DeliveryOrderSnList: shipOrderNumbers,
}
if err = params.validate(); err != nil {
return items, invalidInput(err)
}
var result = struct {
normal.Response
Result []entity.BoxMarkInfo `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetBody(params).
SetResult(&result).
Post("bg.logistics.boxmarkinfo.get")
if err = recheckError(resp, result.Response, err); err != nil {
return
}
return result.Result, nil
}