reward-prop.go 2.17 KB
package models

import (
	"database/sql"

	db "client/icesimba.mail/database"
)

/*礼物设置表与礼物表的关系表*/
type RewardProp struct {
	RewardId string //礼物配置Id

	PropId []string //道具Id

	PropCount []int //道具数量
}

func (in *RewardProp) QueryRewardProp() (out Props, err error) {
	sqlQue := "select code,count from ice_reward_prop INNER JOIN ice_prop  on ice_reward_prop.PROPID=ice_prop.ID AND rewardid=?"
	rows, err := db.SqlDB.Query(sqlQue, in.RewardId)
	if err != nil {
		return
	}
	for rows.Next() {
		var (
			propid sql.NullString
			count  sql.NullInt64
		)
		prop := PropJson{}
		err = rows.Scan(
			&propid,
			&count,
		)
		if propid.Valid {
			prop.Id = propid.String
		}
		if count.Valid {
			prop.Count = count.Int64
		}
		if err == nil {
			out.PropOut = append(out.PropOut, prop)
		}
	}
	if err != nil {
		return
	}
	return
}

func QueryRPIcon(rewardId string) string {
	sqlQue := "select icon from ice_reward_prop INNER JOIN ice_prop  on ice_reward_prop.PROPID=ice_prop.ID AND rewardid=? limit 1"
	var icon sql.NullString
	db.SqlDB.QueryRow(sqlQue, rewardId).Scan(
		&icon,
	)
	if icon.Valid {
		checkstr := icon.String[:4]
		if checkstr == "http" {
			return icon.String
		}
		str := "http://iceplayimage.icesimba.cn/" + icon.String
		return str
	}
	return ""
}

//func (in *RewardUser) UpdateRewardUser() (out RewardUser, err error) {
//	sqlUp := "update ice_reward_user set ispost=?,isget=?,starttime=?,endtime=? where userid=? and rewardid=?"
//	stmt, err := db.SqlDB.Prepare(sqlUp)
//	defer stmt.Close()
//	rs, err := stmt.Exec(
//		in.IsPost[0],
//		in.IsGet[0],
//		in.StartTime[0],
//		in.EndTime[0],
//		in.UserId,
//		in.RewardId[0],
//	)
//	if err != nil {
//		err = errors.New("更新数据失败")
//		return
//	}
//	_, err = rs.RowsAffected()
//	return
//}

func (in *RewardProp) InsertGiftSetGift() (code int, out RewardProp, err error) {
	//	sqlIn := "insert into ice_giftset_gift(ggid,gsid,gid,num) VALUES (?, ?, ?, ?)"
	//	_, err = db.SqlDB.Exec(
	//		sqlIn,
	//		in.Id,
	//		in.RewardId,
	//		in.PropId,
	//		in.PropCount,
	//	)
	//	if err != nil {
	//		err = errors.New("插入数据失败")
	//		code = 400
	//		return
	//	}
	//	code = 200
	return
}