-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjit.presale.rule.go
80 lines (70 loc) · 2.58 KB
/
jit.presale.rule.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
package temu
import (
"context"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/go-ozzo/ozzo-validation/v4/is"
"github.com/hiscaler/temu-go/entity"
"github.com/hiscaler/temu-go/normal"
)
type jitPresaleRuleService service
// Query jit预售规则查询接口(bg.virtualinventoryjit.rule.get)
// https://seller.kuajingmaihuo.com/sop/view/706628248275137588#9h0RVQ
// 全托管JIT开通:全托管的SKC开通JIT模式,需要签署对应协议之后才可添加虚拟库存
func (s jitPresaleRuleService) Query(ctx context.Context) (rule entity.JitPresaleRule, err error) {
var result = struct {
normal.Response
Result entity.JitPresaleRule `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetResult(&result).
Post("bg.virtualinventoryjit.rule.get")
if err = recheckError(resp, result.Response, err); err != nil {
return
}
return result.Result, nil
}
// Sign jit预售规则签署接口(bg.virtualinventoryjit.rule.sign)
// https://seller.kuajingmaihuo.com/sop/view/706628248275137588#q8IeTi
// - 全托管JIT开通:全托管的SKC开通JIT模式,需要签署对应协议之后才可添加虚拟库存
type JitPresaleRuleSignRequest struct {
ProductId int64 `json:"productId"` // 货品 id,货品需要处于 JI T开启状态,才能签署 JIT 协议
AgtVersion int `json:"agtVersion"` // JIT 预售协议版本号
ProductAgtType int `json:"productAgtType"` // 货品协议类型(1: JIT模式快速售卖协议)
Url string `json:"url"` // JIT 协议链接
}
func (m JitPresaleRuleSignRequest) validate() error {
return validation.ValidateStruct(&m,
validation.Field(&m.ProductId,
validation.Required.Error("无效的货品"),
),
validation.Field(&m.AgtVersion,
validation.Required.Error("无效的 JIT 预售协议版本号"),
),
validation.Field(&m.ProductAgtType,
validation.In(1).Error("无效的货品协议类型"),
),
validation.Field(&m.Url,
validation.Required.Error("JIT 协议链接不能为空"),
is.URL.Error("无效的 JIT 协议链接"),
),
)
}
func (s jitPresaleRuleService) Sign(ctx context.Context, request JitPresaleRuleSignRequest) (bool, error) {
if err := request.validate(); err != nil {
return false, invalidInput(err)
}
var result = struct {
normal.Response
Result any `json:"result"`
}{}
resp, err := s.httpClient.R().
SetContext(ctx).
SetBody(request).
SetResult(&result).
Post("bg.virtualinventoryjit.rule.sign")
if err = recheckError(resp, result.Response, err); err != nil {
return false, err
}
return true, nil
}