-
Notifications
You must be signed in to change notification settings - Fork 2
/
income_detail_model.go
90 lines (77 loc) · 2.48 KB
/
income_detail_model.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
package model
type IncomeDetailSection string
type IncomeDetailKey string
var TOTAL_SALES_SECTION IncomeDetailSection = "total_sales"
var (
TOTAL_PRICE_KEY IncomeDetailKey = "TOTAL_PRICE"
TOTAL_SHIPPING_FEE_KEY IncomeDetailKey = "TOTAL_SHIPPING_FEE"
CASHLESS_SHIPPING_FEE_KEY IncomeDetailKey = "CASHLESS_SHIPPING_FEE"
)
type SOMComponent struct {
Key IncomeDetailKey `json:"key"`
Label string `json:"label"`
SubLabel any `json:"sub_label"`
Value string `json:"value"`
ValueRaw int `json:"value_raw"`
Attributes any `json:"attributes"`
Type string `json:"type"`
Typename string `json:"__typename"`
}
type SomSection struct {
Key IncomeDetailSection `json:"key"`
Label string `json:"label"`
SubLabel any `json:"sub_label"`
Value string `json:"value"`
ValueRaw int `json:"value_raw"`
Attributes any `json:"attributes"`
Components []*SOMComponent `json:"components"`
Typename string `json:"__typename"`
}
type SOMSummary struct {
Key string `json:"key"`
Label string `json:"label"`
SubLabel any `json:"sub_label"`
Value string `json:"value"`
ValueRaw int `json:"value_raw"`
Attributes any `json:"attributes"`
State string `json:"state"`
Note string `json:"note"`
Typename string `json:"__typename"`
}
type GetSomIncomeDetail struct {
Title string `json:"title"`
Sections []*SomSection `json:"sections"`
Summary *SOMSummary `json:"summary"`
Typename string `json:"__typename"`
}
type SOMIncomeDetailRes struct {
Data struct {
GetSomIncomeDetail GetSomIncomeDetail `json:"get_som_income_detail"`
} `json:"data"`
}
func (d *SOMIncomeDetailRes) GetSection(key IncomeDetailSection) *SomSection {
for _, section := range d.Data.GetSomIncomeDetail.Sections {
if section.Key == key {
return section
}
}
return nil
}
func (d *SOMIncomeDetailRes) GetSectionComponent(sec IncomeDetailSection, key IncomeDetailKey) *SOMComponent {
section := d.GetSection(sec)
if section != nil {
for _, component := range section.Components {
if component.Key == key {
return component
}
}
}
return nil
}
func (d *SOMIncomeDetailRes) GetOngkir() int {
component := d.GetSectionComponent(TOTAL_SALES_SECTION, TOTAL_SHIPPING_FEE_KEY)
if component != nil {
return component.ValueRaw
}
return 0
}