goods-prop.go
1.12 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
package models
import (
"database/sql"
"errors"
db "client/icesimba.mall/database"
)
type GoodsProp struct {
Props []PropIn `json:"props"`
}
type PropIn struct {
Id string `json:"id"`
Count int64 `json:"count"`
}
func (in *GoodsProp) QueryProsByGoodsId(goodsId, gameId string) (out GoodsProp, err error) {
if goodsId == "" || gameId == "" {
err = errors.New("参数错误")
return
}
var goid sql.NullString
sqlQu0 := "SELECT id FROM ice_mall_goods WHERE `CODE`=? AND GAMEID=? limit 1"
err = db.SqlDB.QueryRow(sqlQu0, goodsId, gameId).Scan(
&goid,
)
if err != nil || !goid.Valid {
err = errors.New("请求错误")
return
}
sqlQu := "select `CODE`,PROPCOUNT from ice_mall_gop INNER JOIN ice_prop on ice_mall_gop.PROPID=ice_prop.ID AND GOODSID=?"
rows, err := db.SqlDB.Query(sqlQu, goid.String)
if err != nil {
return
}
for rows.Next() {
var (
id sql.NullString
count sql.NullInt64
)
propIn := PropIn{}
rows.Scan(
&id,
&count,
)
if id.Valid {
propIn.Id = id.String
}
if count.Valid {
propIn.Count = count.Int64
}
out.Props = append(out.Props, propIn)
}
return
}