goods-prop.go 1.12 KB
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
}