ice_reward_user.go 1.83 KB
package sdkdb

import (
	"log"
	"strconv"

	"client/icesimba.mall/utils"

	"github.com/astaxie/beego/orm"
)

type IceRewardUser struct {
	UserID    string `orm:pk;unique` // 用户ID
	RewardID  string `orm:unique`    // 奖励ID
	IsPost    int64  // 是否发放(0 未发放 1 已发放)
	IsGet     int64  // 是否领取(0 未领取 1 已领取)
	StartTime int64  // 开始时间
	EndTime   int64  // 结束时间
}

type IceRewardContent struct {
	Name  string //奖励名字
	Count int    //奖励数量
}

func IceRewardUserInit() {
	// 注册模型
	orm.RegisterModel(new(IceRewardContent))
}

func IceRewardUserSendReward(uid string, rewardid string, ispost int64, isget int64, starttime int64, endtime int64, rank int, title string, content string, gtname string) (err error) {
	myorm, _ := DBBegin()
	o := orm.NewOrm()
	var datalist []orm.Params
	sqlstr := `select a.COUNT,b.NAME from ice_reward_prop a,ice_prop b where a.PROPID = b.ID and a.REWARDID =?`
	_, err = o.Raw(sqlstr, rewardid).Values(&datalist)
	if err != nil {
		return
	}
	rankString := strconv.Itoa(rank)
	infoTitle := "你在" + gtname + "中获得了第" + rankString + "名"
	infoContent := gtname + "奖励【排名】" + rankString + "【奖励】"
	for _, v := range datalist {
		infoContent = infoContent + v["NAME"].(string) + "x" + v["COUNT"].(string) + "  "
	}
	sqlstr = "insert into ice_reward_user (userid,rewardid,ispost,isget,starttime,endtime,ruid,title,content) values(?,?,?,?,?,?,?,?,?)"
	res, err := myorm.Raw(sqlstr, uid, rewardid, ispost, isget, starttime, endtime, utils.GetUuid(), infoTitle, infoContent).Exec()
	if err != nil {
		log.Printf("IceRewardUserSendReward err[%v]", err)
	}
	log.Printf("IceRewardUserSendReward res[%v] err[%v]", res, err)

	num, _ := res.RowsAffected()
	log.Printf("IceRewardUserSendReward affected nums[%d]", num)

	DBCommit(myorm)
	return
}