mall.go
3.39 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package models
import (
"database/sql"
"errors"
//"fmt"
//"icesimba.mall/utils"
db "client/icesimba.mall/database"
)
type Mall struct {
Id string
Code string
Desc string
Name string
Icon string
GameId string
}
type MallOut struct {
Id string `json:"id"`
Desc string `json:"desc"`
Name string `json:"name"`
Icon string `json:"icon"`
}
type Malls struct {
Mallout []MallOut `json:"malls"`
}
type mallDb struct {
MallId sql.NullString
MallDesc sql.NullString
MallName sql.NullString
MallIcon sql.NullString
}
func (in *Mall) QueryMallsByGameId() (out Malls, err error) {
if in.GameId == "" {
err = errors.New("参数错误")
return
}
sqlQu := "select code,description,name,icon from ice_mall where gameid=?"
rows, err := db.SqlDB.Query(sqlQu, in.GameId)
if err != nil {
err = nil
return
}
for rows.Next() {
malldb := mallDb{}
mall := MallOut{}
err = rows.Scan(
&malldb.MallId,
&malldb.MallDesc,
&malldb.MallName,
&malldb.MallIcon,
)
if err != nil {
continue
}
if malldb.MallId.Valid {
mall.Id = malldb.MallId.String
}
if malldb.MallDesc.Valid {
mall.Desc = malldb.MallDesc.String
}
if malldb.MallName.Valid {
mall.Name = malldb.MallName.String
}
if malldb.MallIcon.Valid {
mall.Icon = malldb.MallIcon.String
}
out.Mallout = append(out.Mallout, mall)
}
return
}
func (in *Mall) QueryMallByMallCode() (code int, out Mall, err error) {
if in.Code == "" {
code = 400
err = errors.New("参数错误")
return
}
sqlQu := "select code,description,name,icon from ice_mall where code=? and gameid=?"
row := db.SqlDB.QueryRow(sqlQu, in.Code, in.GameId)
malldb := mallDb{}
err = row.Scan(
&malldb.MallId,
&malldb.MallDesc,
&malldb.MallName,
&malldb.MallIcon,
)
if err != nil {
code = 400
err = errors.New("数据不存在")
return
}
if malldb.MallId.Valid {
out.Id = malldb.MallId.String
}
if malldb.MallDesc.Valid {
out.Desc = malldb.MallDesc.String
}
if malldb.MallName.Valid {
out.Name = malldb.MallName.String
}
if malldb.MallIcon.Valid {
out.Icon = malldb.MallIcon.String
}
out.GameId = in.GameId
code = 200
return
}
/*
创建或者更新设置商城
@param gameid 游戏Id
@param code 游戏定义的商城code
*/
//func (in *Mall) InsertOrUpdateMall() (code int, err error) {
// if in.GameId == "" || in.Code == "" {
// code = 400
// err = errors.New("参数错误")
// return
// }
// _, _, err = in.QueryMallByMallCode()
// if err != nil {
// code, err = in.CreateNewMall()
// } else {
// code, err = in.UpdateMall()
// }
// return
//}
//func (in *Mall) CreateNewMall() (code int, err error) {
// id := utils.GetUuid()
// sqlIn := "insert into ice_mall(id, code, desc, name, icon, gameid) values(?, ?, ?, ?, ?, ?)"
// _, err = db.SqlDB.Exec(
// sqlIn,
// id,
// in.Code,
// in.Desc,
// in.Name,
// in.Icon,
// in.GameId,
// )
// if err != nil {
// err = errors.New("创建商城失败")
// code = 400
// fmt.Println(err)
// return
// }
// code = 200
// return
//}
//func (in *Mall) UpdateMall() (code int, err error) {
// sqlUp := "update ice_mall set desc=?, name=?, icon=? where code=? and gameid=? "
// stmt, err := db.SqlDB.Prepare(sqlUp)
// defer stmt.Close()
// _, err = stmt.Exec(
// in.Desc,
// in.Name,
// in.Icon,
// in.Code,
// in.GameId,
// )
// if err != nil {
// code = 400
// err = errors.New("更新商城数据失败")
// return
// }
// code = 200
// return
//}