mall-goods.go
900 Bytes
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
package models
import (
"database/sql"
"errors"
db "client/icesimba.mall/database"
)
type MallGoods struct {
GoodsInMall []Goods `json:"goods" form:"goods"`
}
func (in *MallGoods) QueryGoodsByMallId(mallId, gameId string) (out MallGoods, err error) {
if mallId == "" || gameId == "" {
err = errors.New("参数错误")
return
}
sqlQu := "select goodsid from ice_mall_gom INNER JOIN ice_mall where ID=MALLID and `CODE`=? AND GAMEID=?"
rows, err := db.SqlDB.Query(sqlQu, mallId, gameId)
if err != nil {
return
}
for rows.Next() {
var goodsId sql.NullString
goods := Goods{}
_ = rows.Scan(
&goodsId,
)
if goodsId.Valid {
goods, err = goods.QueryGoodsByGoodsId(goodsId.String)
}
if err != nil {
err = nil
continue
}
out.GoodsInMall = append(out.GoodsInMall, goods)
}
if len(out.GoodsInMall) <= 0 {
err = errors.New("商城没有商品")
}
return
}