ice_gametopset.go
4.32 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
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
package sdkdb
import (
"errors"
"fmt"
"log"
"github.com/astaxie/beego/orm"
)
type IceGameTopSet struct {
GTID string `orm:"size(36);pk;unique"`
GID string `orm:"size(36);unique"`
TOPTYPE string `orm:"size(1);unique"`
GTNAME string `orm:"size(255)"`
SORCETYPE string `orm:"size(1)"`
SORCESUB string `orm:"size(1)"`
SORCEORDER string `orm:"size(1)"`
}
func (self *IceGameTopSet) String() string {
return fmt.Sprintf("GTID[%s] GID[%s] TOPTYPE[%s] GTNAME[%s] SORCETYPE[%s] SORCESUB[%s] SORCEORDER[%s]", self.GTID, self.GID, self.TOPTYPE, self.GTNAME, self.SORCETYPE, self.SORCESUB, self.SORCEORDER)
}
func IceGameTopSetInit() {
// 注册模型
orm.RegisterModel(new(IceGameTopSet))
}
/**
* 查询所有数据
*/
func IceGameTopSetQueryTotal() (iceGameTopSets []*IceGameTopSet, err error) {
o := orm.NewOrm()
var datalist []orm.Params
_, err = o.Raw("SELECT * FROM ice_gametopset").Values(&datalist)
iceGameTopSets = []*IceGameTopSet{}
for _, data := range datalist {
igt := new(IceGameTopSet)
igt.GTID = data["GTID"].(string)
igt.GID = data["GID"].(string)
igt.TOPTYPE = data["TOPTYPE"].(string)
igt.GTNAME = data["GTNAME"].(string)
igt.SORCETYPE = data["SORCETYPE"].(string)
igt.SORCESUB = data["SORCESUB"].(string)
igt.SORCEORDER = data["SORCEORDER"].(string)
iceGameTopSets = append(iceGameTopSets, igt)
}
return
}
/**
* 查询一条数据
*/
func IceGameTopSetQueryOne(gtid string, gid string, toptype string) (iceGameTopSet *IceGameTopSet, num int64, err error) {
o := orm.NewOrm()
var datalist []orm.Params
num, err = o.Raw("SELECT * FROM ice_gametopset where gtid=? and gid=? ", gtid, gid).Values(&datalist)
if num != 0 {
iceGameTopSet = new(IceGameTopSet)
iceGameTopSet.GTID = datalist[0]["GTID"].(string)
iceGameTopSet.GID = datalist[0]["GID"].(string)
iceGameTopSet.TOPTYPE = datalist[0]["TOPTYPE"].(string)
iceGameTopSet.GTNAME = datalist[0]["GTNAME"].(string)
iceGameTopSet.SORCETYPE = datalist[0]["SORCETYPE"].(string)
iceGameTopSet.SORCESUB = datalist[0]["SORCESUB"].(string)
iceGameTopSet.SORCEORDER = datalist[0]["SORCEORDER"].(string)
}
return
}
/**
* 查询一个排行榜ID的所有排行类型
*/
func IceGameTopSetQueryToptype(gtid string, gid string) (topTypes []string, err error) {
o := orm.NewOrm()
var datalist []orm.Params
_, err = o.Raw("SELECT toptype FROM ice_gametopset where gtid=? and gid=?", gtid, gid).Values(&datalist)
topTypes = []string{}
for _, data := range datalist {
topType := data["toptype"].(string)
topTypes = append(topTypes, topType)
}
return
}
func IceGameTopSetQuerySortType(gtid string, gid string) (sortType string, err error) {
o := orm.NewOrm()
var datalist []orm.Params
_, err = o.Raw("select sorceorder from ice_gametopset where gid=? and gtid=?", gid, gtid).Values(&datalist)
if len(datalist) == 0 {
err = errors.New("gamename or gametopname not exist")
return
}
sortType = datalist[0]["sorceorder"].(string)
return
}
func IceGameTopSetQuery(gtid string, gid string) (iceGameTopSets []*IceGameTopSet, err error) {
o := orm.NewOrm()
var datalist []orm.Params
_, err = o.Raw("SELECT GTID,GID,TOPTYPE,GTNAME,SORCETYPE,SORCESUB,SORCEORDER FROM ice_gametopset where gtid=? and gid=?", gtid, gid).Values(&datalist)
iceGameTopSets = []*IceGameTopSet{}
for _, data := range datalist {
igts := new(IceGameTopSet)
igts.GTID = data["GTID"].(string)
igts.GID = data["GID"].(string)
igts.TOPTYPE = data["TOPTYPE"].(string)
igts.GTNAME = data["GTNAME"].(string)
igts.SORCETYPE = data["SORCETYPE"].(string)
igts.SORCESUB = data["SORCESUB"].(string)
igts.SORCEORDER = data["SORCEORDER"].(string)
iceGameTopSets = append(iceGameTopSets, igts)
}
return
}
/**
* 创建排行榜
*/
func IceGameTopSetInsert(gtid string, gid string, toptype string, gtname string, sorcetype string, sorcesub string, sorceorder string) (err error) {
_, num, err := IceGameTopSetQueryOne(gtid, gid, toptype)
if num == 0 {
myorm, _ := DBBegin()
res, err := myorm.Raw("insert into ice_gametopset(gtid,gid,toptype,gtname,sorcetype,sorcesub,sorceorder) values(?,?,?,?,?,?,?)", gtid, gid, toptype, gtname, sorcetype, sorcesub, sorceorder).Exec()
if err == nil {
num, _ := res.RowsAffected()
log.Printf("mysql row affected nums[%d]", num)
}
DBCommit(myorm)
} else {
err = errors.New("排行榜已存在")
}
return
}