-
Notifications
You must be signed in to change notification settings - Fork 3
/
ship.order.receive.address.go
60 lines (53 loc) · 1.82 KB
/
ship.order.receive.address.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
package temu
import (
"context"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/hiscaler/temu-go/entity"
"github.com/hiscaler/temu-go/normal"
"github.com/hiscaler/temu-go/validators/is"
"strings"
)
// 大仓收货地址
type shipOrderReceiveAddressService service
// Query 查询大仓收货地址 V2
// https://seller.kuajingmaihuo.com/sop/view/889973754324016047#chUUk1
func (s shipOrderReceiveAddressService) Query(ctx context.Context, purchaseOrderNumbers ...string) (items []entity.ShipOrderReceiveAddress, err error) {
err = validation.Validate(purchaseOrderNumbers,
validation.Required.Error("备货单号不能为空"),
validation.Each(validation.By(is.PurchaseOrderNumber())),
)
if err != nil {
return items, invalidInput(err)
}
var result = struct {
normal.Response
Result struct {
SubPurchaseReceiveAddressGroups []entity.ShipOrderReceiveAddress `json:"subPurchaseReceiveAddressGroups"` // 子采购单收货地址分组信息列表
} `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetBody(map[string][]string{"subPurchaseOrderSnList": purchaseOrderNumbers}).
SetResult(&result).
Post("bg.shiporder.receiveaddressv2.get")
if err = recheckError(resp, result.Response, err); err != nil {
return
}
return result.Result.SubPurchaseReceiveAddressGroups, nil
}
// One [WIP] 查询单个备货单收货地址
func (s shipOrderReceiveAddressService) One(ctx context.Context, purchaseOrderNumber string) (item entity.ShipOrderReceiveAddress, err error) {
items, err := s.Query(ctx, purchaseOrderNumber)
if err != nil {
return
}
purchaseOrderNumber = strings.ToLower(purchaseOrderNumber)
for _, d := range items {
for _, sn := range d.SubPurchaseOrderSnList {
if strings.ToLower(sn) == purchaseOrderNumber {
return d, nil
}
}
}
return item, ErrNotFound
}