-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement.go
91 lines (83 loc) · 2.05 KB
/
statement.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
package main
import (
"fmt"
"time"
)
// 适配器模式 https://juejin.cn/post/6972352388250206216
/**
* @Author: Jason Pang
* @Description: 对账单数据
*/
type StatementItem struct {
OrderId string //系统单号
TransactionId string //第三方交易号
Amount int64 //支付金额,单位:分
PaymentTime int64 //订单支付时间
}
/**
* @Author: Jason Pang
* @Description: 从第三方获取对账数据
*/
type StatementData interface {
GetStatementData(startTime int64, endTime int64) []*StatementItem
}
/**
* @Author: Jason Pang
* @Description: WX支付
*/
type WXStatementData struct {
}
func (w *WXStatementData) GetStatementData(startTime int64, endTime int64) []*StatementItem {
fmt.Println("从WX获取到的对账数据,支付时间需要格式化为时间戳")
return []*StatementItem{
{
OrderId: "WX订单222",
TransactionId: "WX支付单号",
Amount: 999,
PaymentTime: time.Date(2014, 1, 7, 5, 50, 4, 0, time.Local).Unix(),
},
}
}
/**
* @Author: Jason Pang
* @Description: ZFB支付
*/
type ZFBStatementData struct {
}
func (z *ZFBStatementData) GetStatementData(startTime int64, endTime int64) []*StatementItem {
fmt.Println("从ZFB获取到的对账数据,金额需要从元转化为分")
return []*StatementItem{
{
OrderId: "ZFB订单111",
TransactionId: "ZFB支付单号",
Amount: 99.9 * 100,
PaymentTime: 1389058332,
},
}
}
/**
* @Author: Jason Pang
* @Description: 对账函数
* @param list 从第三方获取的对账单
* @return bool
*/
func DoStatement(list []*StatementItem) bool {
fmt.Println("开始对账")
fmt.Println("从自身系统中获取指定时间内的支付单")
for _, item := range list {
fmt.Println(item.OrderId + " 与系统支付单进行对账")
}
fmt.Println("对账完成")
return true
}
func main() {
wx := &WXStatementData{}
zfb := &ZFBStatementData{}
stattementData := []StatementData{
wx,
zfb,
}
for _, s := range stattementData {
DoStatement(s.GetStatementData(1389058332, 1389098332))
}
}