-
Notifications
You must be signed in to change notification settings - Fork 3
/
goods.certification.go
96 lines (84 loc) · 2.75 KB
/
goods.certification.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
package temu
import (
"context"
"errors"
"fmt"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/hiscaler/temu-go/entity"
"github.com/hiscaler/temu-go/normal"
)
// 商品资质服务
type goodsCertificationService service
type GoodsCertificationQueryParams struct {
CertTypeList []int `json:"certTypeList,omitempty"` // 资质类型 ID 列表
ProductId int64 `json:"productId"` // 货品 ID
Language string `json:"language,omitempty"` // 语言
}
func (m GoodsCertificationQueryParams) validate() error {
return validation.ValidateStruct(&m,
validation.Field(&m.CertTypeList,
validation.When(len(m.CertTypeList) != 0, validation.By(func(value interface{}) error {
types, ok := value.([]int)
if !ok {
return errors.New("无效的资质类型")
}
for _, typ := range types {
if typ < 0 || typ > 303 {
return fmt.Errorf("无效的资质类型 %d", typ)
}
}
return nil
}))),
validation.Field(&m.ProductId, validation.Required.Error("货品不能为空")),
)
}
// Query 批量查询货品资质信息
// https://seller.kuajingmaihuo.com/sop/view/649320516224723675#Oq8dC9
func (s goodsCertificationService) Query(ctx context.Context, params GoodsCertificationQueryParams) (certifications []entity.GoodsCertification, err error) {
if err = params.validate(); err != nil {
return certifications, invalidInput(err)
}
var result = struct {
normal.Response
Result struct {
ProductCertList []entity.GoodsCertification `json:"productCertList"`
} `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetBody(params).
SetResult(&result).
Post("bg.arbok.open.product.cert.query")
if err = recheckError(resp, result.Response, err); err != nil {
return
}
certifications = result.Result.ProductCertList
return
}
type GoodsCertificationNeedUploadItemRequest struct {
CertType int `json:"certType"` // 资质类型
ProductId int64 `json:"productId"` // 货品 ID
}
func (m GoodsCertificationNeedUploadItemRequest) validate() error {
return nil
}
func (s goodsCertificationService) QueryNeedUploadItems(ctx context.Context, request GoodsCertificationNeedUploadItemRequest) (items []entity.GoodsCertificationNeedUploadItem, err error) {
if err = request.validate(); err != nil {
return items, invalidInput(err)
}
var result = struct {
normal.Response
Result struct {
CertNeedUploadItems []entity.GoodsCertificationNeedUploadItem `json:"certNeedUploadItems"`
} `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetBody(request).
SetResult(&result).
Post("bg.arbok.open.cert.queryNeedUploadItems")
if err = recheckError(resp, result.Response, err); err != nil {
return
}
return result.Result.CertNeedUploadItems, nil
}