-
Notifications
You must be signed in to change notification settings - Fork 3
/
getMemeberDiscount.go
executable file
·81 lines (65 loc) · 2.7 KB
/
getMemeberDiscount.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
package crm
import (
"github.com/XiBao/jos/api"
"github.com/XiBao/jos/sdk"
"github.com/XiBao/jos/sdk/request/crm"
)
type GetMemeberDiscountRequest struct {
api.BaseRequest
}
type GetMemeberDiscountResponse struct {
ErrorResp *api.ErrorResponnse `json:"error_response,omitempty" codec:"error_response,omitempty"`
Data *GetMemeberDiscountData `json:"jingdong_pop_crm_getMemeberDiscount_responce,omitempty" codec:"jingdong_pop_crm_getMemeberDiscount_responce,omitempty"`
}
func (r GetMemeberDiscountResponse) IsError() bool {
return r.ErrorResp != nil || r.Data == nil || r.Data.IsError()
}
func (r GetMemeberDiscountResponse) Error() string {
if r.ErrorResp != nil {
return r.ErrorResp.Error()
}
if r.Data != nil {
return r.Data.Error()
}
return "no result data"
}
type GetMemeberDiscountData struct {
ReturnType *GetMemeberDiscountReturnType `json:"returnType,omitempty" codec:"returnType,omitempty"`
}
func (r GetMemeberDiscountData) IsError() bool {
return r.ReturnType == nil || r.ReturnType.IsError()
}
func (r GetMemeberDiscountData) Error() string {
if r.ReturnType != nil {
return r.ReturnType.Error()
}
return "no result data"
}
type GetMemeberDiscountReturnType struct {
Desc string `json:"desc,omitempty" codec:"desc,omitempty"` //返回值code码
Code string `json:"code,omitempty" codec:"code,omitempty"` //返回值code码描述
Data []ShopRuleDiscountDTO `json:"data,omitempty" codec:"data,omitempty"` //折扣信息数组 返回值:code码为200时,可能为空;code码为400、500时,为空;
}
func (r GetMemeberDiscountReturnType) IsError() bool {
return r.Code != "200"
}
func (r GetMemeberDiscountReturnType) Error() string {
return sdk.ErrorString(r.Code, r.Desc)
}
type ShopRuleDiscountDTO struct {
CurGradeName string `json:"curGradeName,omitempty" codec:"curGradeName,omitempty"` //当前会员店铺等级名称
CurGrade string `json:"curGrade,omitempty" codec:"curGrade,omitempty"` // 当前会员店铺等级(1、2、3、4、5),最少1个等级,最多5个等级
VenderId uint64 `json:"venderId,omitempty" codec:"venderId,omitempty"` //商家Id
Discount string `json:"discount,omitempty" codec:"discount,omitempty"` //会员折扣(1-9.9),为空表示未设置折扣
}
// TODO 查询会员折扣信息
func GetMemeberDiscount(req *GetMemeberDiscountRequest) ([]ShopRuleDiscountDTO, error) {
client := sdk.NewClient(req.AnApiKey.Key, req.AnApiKey.Secret)
client.Debug = req.Debug
r := crm.NewGetMemeberDiscountRequest()
var response GetMemeberDiscountResponse
if err := client.Execute(r.Request, req.Session, &response); err != nil {
return nil, err
}
return response.Data.ReturnType.Data, nil
}