almanac-reward.go 1.05 KB
package models

import (
	"database/sql"
	"fmt"

	db "client/icesimba.mail/database"
)

type AlmanacReward struct {
	ImgUrl string     `json:"almanac_url"`
	Props  []PropJson `json:"props"`
}

func QueryAlmanacReward(date string, gameId string) (out AlmanacReward, err error) {
	sqlQu := "select rewardid,imgurl from ice_reward_almanac where date=? and gameid=? limit 1"
	fmt.Printf("select rewardid,imgurl from ice_reward_almanac where date=%s and gameid=%s limit 1", date, gameId)
	var (
		rewardIdNull sql.NullString
		imgUrlNull   sql.NullString
	)
	err = db.SqlDB.QueryRow(sqlQu, date, gameId).Scan(
		&rewardIdNull,
		&imgUrlNull,
	)
	if err != nil {
		return
	}
	if imgUrlNull.Valid {
		checkstr := imgUrlNull.String[:4]
		if checkstr == "http" {
			out.ImgUrl = imgUrlNull.String
		} else {
			out.ImgUrl = "http://iceplayimage.icesimba.cn/" + imgUrlNull.String
		}
	}
	if rewardIdNull.Valid {
		rewardProp := RewardProp{
			RewardId: rewardIdNull.String,
		}
		props := Props{}
		props, err = rewardProp.QueryRewardProp()
		out.Props = props.PropOut
	}
	return
}