add get more lottery func, chenge lottery act

This commit is contained in:
root committed 2018-10-09 23:45:45 +08:00
1 parent e0323e964f
commit 38bc2f7639
2 files changed
+37 -6

No files matched your search

+13 -2
View File
@@ -17,9 +17,20 @@ type Lottery struct {
// GetRandomLotteryByType -
func GetRandomLotteryByType(t string) (p *Lottery, err error) {
p = &Lottery{}
parr, err := GetRandomLotteryByTypeAndLimit(t, 1)
if err != nil {
return nil, err
}
if parr == nil {
return nil, nil
}
return parr[0], err
}
// GetRandomLotteryByTypeAndLimit -
func GetRandomLotteryByTypeAndLimit(t string, limit int) (p []*Lottery, err error) {
offset := rand.Intn(10)
err = x.Get(p, `select * from "public"."lottery" where "type" = $1 order by random() offset $2 limit 1`, t, offset)
err = x.Select(p, `select * from "public"."lottery" where "type" = $1 order by random() offset $2 limit $3`, t, offset, limit)
if err == sql.ErrNoRows {
return nil, nil
}