sellplan.go
1.08 KB
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
package models
import (
"database/sql"
"errors"
db "client/icesimba.ad/database"
)
type SellPlan struct {
AdId string
GameId string
PositionId string
Percent float64
}
type sellPlan struct {
AdId sql.NullString
GameId sql.NullString
PositionId sql.NullString
Percent sql.NullFloat64
}
func (sell *SellPlan) QueryAdIdByPositionId() (out []SellPlan, err error) {
sqlQu := "SELECT ad_id,persent FROM ice_ad_sellplan WHERE position_id=? AND position_app_id =?"
rows, err := db.SqlDB.Query(
sqlQu,
sell.PositionId,
sell.GameId,
)
if err != nil {
return
}
sellNull := sellPlan{}
for rows.Next() {
err = rows.Scan(
&sellNull.AdId,
&sellNull.Percent,
)
if err != nil {
continue
}
if sellNull.AdId.Valid {
sell.AdId = sellNull.AdId.String
}
if sellNull.Percent.Valid {
sell.Percent = sellNull.Percent.Float64
}
out = append(out, *sell)
}
return
}
func SellsFilter(sells []SellPlan) (sell SellPlan, err error) {
if len(sells) <= 0 {
err = errors.New("this position is no ads")
} else {
sell = sells[0]
}
return
}