mall-goods.go 900 Bytes
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
}