forked from go-http/feidee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
116 lines (99 loc) · 2.57 KB
/
report.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package feidee
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"time"
)
//对账报表
type CompareInfo struct {
Balance float32 //当前余额
DayBalance float32 //当日余额(当日收入-当日支出)
Money struct {
Claims float32
Income float32
In float32 //流入
Debet float32
Out float32 //留出
Payout float32
}
Date DateInfo
}
//报表页响应
type CompareReportResponse struct {
PageInfo
List []CompareInfo
}
//获取所有对账报表
func (cli *Client) CompareReport(accountId int, begin, end time.Time) ([]CompareInfo, error) {
pageCount := 1
list := []CompareInfo{}
for page := 1; page <= pageCount; page += 1 {
info, err := cli.CompareReportByPage(accountId, begin, end, page)
if err != nil {
return nil, err
}
pageCount = info.PageCount
list = append(list, info.List...)
}
return list, nil
}
//获取单页对账报表
func (cli *Client) CompareReportByPage(accountId int, begin, end time.Time, page int) (CompareReportResponse, error) {
data := url.Values{}
data.Set("m", "compare")
data.Set("page", strconv.Itoa(page))
data.Set("cardId", strconv.Itoa(accountId))
data.Set("endDate", end.Format("2006.01.02"))
data.Set("beginDate", begin.Format("2006.01.02"))
resp, err := cli.PostForm(BaseUrl+"/report.rmi", data)
if err != nil {
return CompareReportResponse{}, fmt.Errorf("请求出错: %s", err)
}
defer resp.Body.Close()
var respInfo CompareReportResponse
err = json.NewDecoder(resp.Body).Decode(&respInfo)
if err != nil {
return CompareReportResponse{}, fmt.Errorf("读取出错: %s", err)
}
return respInfo, nil
}
//日常收支报表
type DailyReportList []struct {
IdName
Total float32
List []struct {
IdName
Amount float32
} `json:"c"`
}
type DailyReport struct {
InAmount float32
OutAmount float32
Symbol string
MaxIn float32 `json:"maxI"`
MaxOut float32 `json:"maxO"`
InList DailyReportList `json:"inlst"`
OutList DailyReportList `json:"outlst"`
}
//日常收支报表
func (cli *Client) DailyReport(begin, end time.Time, params url.Values) (DailyReport, error) {
if params == nil {
params = url.Values{}
}
params.Set("m", "daily")
params.Set("endDate", end.Format("2006.01.02"))
params.Set("beginDate", begin.Format("2006.01.02"))
resp, err := cli.PostForm(BaseUrl+"/report.rmi", params)
if err != nil {
return DailyReport{}, fmt.Errorf("请求出错: %s", err)
}
defer resp.Body.Close()
var respInfo DailyReport
err = json.NewDecoder(resp.Body).Decode(&respInfo)
if err != nil {
return DailyReport{}, fmt.Errorf("读取出错: %s", err)
}
return respInfo, nil
}