/
tbl_bonus_pair.go
205 lines (189 loc) · 7.52 KB
/
tbl_bonus_pair.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package models
import (
"net/http"
"time"
"github.com/jinzhu/gorm"
"github.com/yapkah/go-api/pkg/e"
)
// TblBonusPair struct
type TblBonusPair struct {
TBnsFr string `json:"t_bns_fr"`
TBnsTo string `json:"t_bns_to"`
TMemberId int `json:"t_member_id"`
TMemberLot int `json:"t_member_lot"`
TPairGroup int `json:"t_pair_group"`
TRankEff string `json:"t_rank_eff"`
TStatus string `json:"t_status"`
ILft int `json:"i_lft"`
IRgt int `json:"i_rgt"`
ILvl int `json:"i_lvl"`
FBBf1 float64 `json:"f_b_bf_1"`
FBBf2 float64 `json:"f_b_bf_2"`
FBBf3 float64 `json:"f_b_bf_3"`
FBBf4 float64 `json:"f_b_bf_4"`
FBBf5 float64 `json:"f_b_bf_5"`
FBBf6 float64 `json:"f_b_bf_6"`
FBCur1 float64 `json:"f_b_cur_1"`
FBCur2 float64 `json:"f_b_cur_2"`
FBCur3 float64 `json:"f_b_cur_3"`
FBCur4 float64 `json:"f_b_cur_4"`
FBCur5 float64 `json:"f_b_cur_5"`
FBCur6 float64 `json:"f_b_cur_6"`
FBTot1 float64 `json:"f_b_tot_1"`
FBTot2 float64 `json:"f_b_tot_2"`
FBTot3 float64 `json:"f_b_tot_3"`
FBTot4 float64 `json:"f_b_tot_4"`
FBTot5 float64 `json:"f_b_tot_5"`
FBTot6 float64 `json:"f_b_tot_6"`
FBAcc float64 `json:"f_b_acc"`
FBFlush1 float64 `json:"f_b_flush_1"`
FBFlush2 float64 `json:"f_b_flush_2"`
FBFlush3 float64 `json:"f_b_flush_3"`
FBFlush4 float64 `json:"f_b_flush_4"`
FBFlush5 float64 `json:"f_b_flush_5"`
FBFlush6 float64 `json:"f_b_flush_6"`
FBCF1 float64 `json:"f_b_cf_1"`
FBCF2 float64 `json:"f_b_cf_2"`
FBCF3 float64 `json:"f_b_cf_3"`
FBCF4 float64 `json:"f_b_cf_4"`
FBCF5 float64 `json:"f_b_cf_5"`
FBCF6 float64 `json:"f_b_cf_6"`
FBMatch float64 `json:"f_b_match"`
FBMatch2 float64 `json:"f_b_match_2"`
FBMatch3 float64 `json:"f_b_match_3"`
IBPair int `json:"i_b_pair"`
IBPair2 int `json:"i_b_pair_2"`
IBPair3 int `json:"i_b_pair_3"`
IBPairAcc int `json:"i_b_pair_acc"`
IBPairAcc2 int `json:"i_b_pair_acc_2"`
IBPairAcc3 int `json:"i_b_pair_acc_3"`
FBPairPerc float64 `json:"f_b_pair_perc"`
FBPairPerc2 float64 `json:"f_b_pair_perc_2"`
FBPairPerc3 float64 `json:"f_b_pair_perc_3"`
FBnsPair float64 `json:"f_bns_pair"`
FBnsPair2 float64 `json:"f_bns_pair_2"`
FBnsPair3 float64 `json:"f_bns_pair_3"`
FBns float64 `json:"f_bns"`
BCap int `json:"b_cap"`
BLatest int `json:"b_latest"`
DtCreated time.Time `json:"dt_created"`
}
type TblBonusPairResult struct {
TBnsFr string `json:"t_bns_fr"`
TBnsTo string `json:"t_bns_to"`
TMemberId int `json:"t_member_id"`
Username string `json:"username"`
TMemberLot int `json:"t_member_lot"`
TPairGroup int `json:"t_pair_group"`
TRankEff string `json:"t_rank_eff"`
TStatus string `json:"t_status"`
ILft int `json:"i_lft"`
IRgt int `json:"i_rgt"`
ILvl int `json:"i_lvl"`
FBBf1 float64 `json:"f_b_bf_1"`
FBBf2 float64 `json:"f_b_bf_2"`
FBBf3 float64 `json:"f_b_bf_3"`
FBBf4 float64 `json:"f_b_bf_4"`
FBBf5 float64 `json:"f_b_bf_5"`
FBBf6 float64 `json:"f_b_bf_6"`
FBCur1 float64 `json:"f_b_cur_1"`
FBCur2 float64 `json:"f_b_cur_2"`
FBCur3 float64 `json:"f_b_cur_3"`
FBCur4 float64 `json:"f_b_cur_4"`
FBCur5 float64 `json:"f_b_cur_5"`
FBCur6 float64 `json:"f_b_cur_6"`
FBTot1 float64 `json:"f_b_tot_1"`
FBTot2 float64 `json:"f_b_tot_2"`
FBTot3 float64 `json:"f_b_tot_3"`
FBTot4 float64 `json:"f_b_tot_4"`
FBTot5 float64 `json:"f_b_tot_5"`
FBTot6 float64 `json:"f_b_tot_6"`
FBAcc float64 `json:"f_b_acc"`
FBFlush1 float64 `json:"f_b_flush_1"`
FBFlush2 float64 `json:"f_b_flush_2"`
FBFlush3 float64 `json:"f_b_flush_3"`
FBFlush4 float64 `json:"f_b_flush_4"`
FBFlush5 float64 `json:"f_b_flush_5"`
FBFlush6 float64 `json:"f_b_flush_6"`
Fbcf1 float64 `json:"f_b_cf_1"`
Fbcf2 float64 `json:"f_b_cf_2"`
Fbcf3 float64 `json:"f_b_cf_3"`
Fbcf4 float64 `json:"f_b_cf_4"`
Fbcf5 float64 `json:"f_b_cf_5"`
Fbcf6 float64 `json:"f_b_cf_6"`
FBMatch float64 `json:"f_b_match"`
FBMatch2 float64 `json:"f_b_match_2"`
FBMatch3 float64 `json:"f_b_match_3"`
IBPair int `json:"i_b_pair"`
IBPair2 int `json:"i_b_pair_2"`
IBPair3 int `json:"i_b_pair_3"`
IBPairAcc int `json:"i_b_pair_acc"`
IBPairAcc2 int `json:"i_b_pair_acc_2"`
IBPairAcc3 int `json:"i_b_pair_acc_3"`
FBPairPerc float64 `json:"f_b_pair_perc"`
FBPairPerc2 float64 `json:"f_b_pair_perc_2"`
FBPairPerc3 float64 `json:"f_b_pair_perc_3"`
FBnsPair float64 `json:"f_bns_pair"`
FBnsPair2 float64 `json:"f_bns_pair_2"`
FBnsPair3 float64 `json:"f_bns_pair_3"`
FBns float64 `json:"f_bns"`
BCap int `json:"b_cap"`
BLatest int `json:"b_latest"`
DtCreated time.Time `json:"dt_created"`
TotalPerLeg1 float64 `json:"total_per_leg1"`
TotalPerLeg2 float64 `json:"total_per_leg2"`
TotalPerLeg3 float64 `json:"total_per_leg2"`
TotalPerLeg4 float64 `json:"total_per_leg4"`
TotalPerLeg12 float64 `json:"total_per_leg12"`
TotalPerLeg34 float64 `json:"total_per_leg34"`
Leg1 float64 `json:"leg1"`
Leg2 float64 `json:"leg2"`
Leg3 float64 `json:"leg3"`
Leg4 float64 `json:"leg4"`
Leg12 float64 `json:"leg12"`
Leg34 float64 `json:"leg34"`
}
//get Pair bonus by memid
func GetPairBonusByMemberId(mem_id int, dateFrom string, dateTo string) ([]*TblBonusPairResult, error) {
var (
rwd []*TblBonusPairResult
)
query := db.Table("tbl_bonus_pair as a").
Select("a.*,b.nick_name as username,a.dt_created,a.f_b_cur_1 as total_per_leg1,a.f_b_cur_2 as total_per_leg2,a.f_b_cur_3 as total_per_leg3,a.f_b_cur_4 as total_per_leg4,a.f_b_cur_5 as total_per_leg12,a.f_b_cur_6 as total_per_leg34,a.f_b_cf_1 as leg1,a.f_b_cf_2 as leg2,a.f_b_cf_3 as leg3,a.f_b_cf_4 as leg4,a.f_b_cf_5 as leg12,a.f_b_cf_6 as leg34").
Joins("JOIN ent_member as b ON a.t_member_id = b.id")
if mem_id != 0 {
query = query.Where("a.t_member_id = ?", mem_id)
}
if dateFrom != "" {
query = query.Where("a.t_bns_fr >= ?", dateFrom)
}
if dateTo != "" {
query = query.Where("a.t_bns_fr <= ?", dateTo)
}
err := query.Order("a.t_bns_fr desc").Find(&rwd).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, &e.CustomError{HTTPCode: http.StatusInternalServerError, Code: e.ERROR, Msg: err.Error(), Data: err}
}
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return rwd, nil
}
// GetTblBonusPairFn get tbl_bonus_pair data with dynamic condition
func GetTblBonusPairFn(arrCond []WhereCondFn, debug bool) ([]*TblBonusPair, error) {
var result []*TblBonusPair
tx := db.Table("tbl_bonus_pair")
if len(arrCond) > 0 {
for _, v := range arrCond {
tx = tx.Where(v.Condition, v.CondValue)
}
}
if debug {
tx = tx.Debug()
}
err := tx.Find(&result).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, &e.CustomError{HTTPCode: http.StatusInternalServerError, Code: e.ERROR, Msg: err.Error(), Data: err}
}
return result, nil
}