本文整理匯總了Golang中github.com/ginuerzh/sports/models.Account.SetInfo方法的典型用法代碼示例。如果您正苦於以下問題:Golang Account.SetInfo方法的具體用法?Golang Account.SetInfo怎麽用?Golang Account.SetInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ginuerzh/sports/models.Account
的用法示例。
在下文中一共展示了Account.SetInfo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newRecordHandler
func newRecordHandler(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, user *models.Account, p Parameter) {
form := p.(newRecordForm)
rec := &models.Record{
Uid: user.Id,
Task: form.Task,
Type: form.Record.Type,
StartTime: time.Unix(form.Record.BeginTime, 0),
EndTime: time.Unix(form.Record.EndTime, 0),
PubTime: time.Now(),
}
awards := Awards{}
level := user.Level()
switch form.Record.Type {
case "post":
rec.Status = models.StatusFinish
if form.Task > 0 {
rec.Coin = (2 + level) * models.Satoshi
awards = Awards{
Score: 2 + level,
Literal: 2 + level,
Wealth: rec.Coin,
}
} else {
rec.Coin = 2 * models.Satoshi
awards = Awards{
Score: 2,
Literal: 2,
Wealth: rec.Coin,
}
}
GiveAwards(user, awards, redis)
redis.AddPost(user.Id, "", 1)
user.UpdateStat(models.StatArticles, 1)
case "game":
if form.Task > 0 {
awards = gameAwards(level, form.Record.GameScore, true)
//user.AddTask(models.Tasks[form.Task-1].Type, form.Task, nil)
rec.Status = models.StatusFinish
} else {
if form.Record.GameScore >= 100 &&
user.Stat != nil && user.Stat.LastGameTime < nowDate().Unix() {
awards = gameAwards(level, form.Record.GameScore, false)
}
user.UpdateStat(models.StatLastGameTime, time.Now().Unix())
}
GiveAwards(user, awards, redis)
rec.Game = &models.GameRecord{
Type: form.Record.GameType,
Name: form.Record.GameName,
Duration: form.Record.Duration,
Score: form.Record.GameScore,
Magic: int(awards.Mental),
}
rec.Coin = awards.Wealth
redis.AddGameTime(user.Id, int(form.Record.Duration))
user.UpdateStat(models.StatGameTime, form.Record.Duration)
redis.SetGameMaxScore(gameType(rec.Game.Type), user.Id, rec.Game.Score)
user.SetGameTime(gameType(rec.Game.Type), time.Now())
case "run":
if rec.Task > 0 {
rec.Delete()
}
rec.Sport = &models.SportRecord{
Source: form.Record.Source,
Duration: form.Record.Duration,
Distance: form.Record.Distance,
Weight: form.Record.Weight,
Mood: form.Record.Mood,
HeartRate: form.Record.HeartRate,
Pics: form.Record.Pics,
}
if rec.Sport.Weight == 0 {
rec.Sport.Weight = user.Weight
}
// update weight
if rec.Sport.Weight != user.Weight {
user.SetInfo(&models.SetInfo{Weight: rec.Sport.Weight})
}
if form.Record.Duration > 0 {
rec.Sport.Speed = float64(form.Record.Distance) / float64(form.Record.Duration)
}
rec.Status = models.StatusAuth
redis.AddRecord(user.Id, 1)
user.UpdateStat(models.StatRecords, 1)
/*
if len(form.Record.Source) > 0 {
level := user.Level()
//.........這裏部分代碼省略.........
示例2: setInfoHandler
func setInfoHandler(request *http.Request, resp http.ResponseWriter, redis *models.RedisLogger,
user *models.Account, p Parameter) {
form := p.(setInfoForm)
setinfo := &models.SetInfo{
Phone: form.UserInfo.Phone,
Nickname: form.UserInfo.Nickname,
Height: form.UserInfo.Height,
Weight: form.UserInfo.Weight,
Birth: form.UserInfo.Birth,
Gender: form.UserInfo.Gender,
Sign: form.UserInfo.Sign,
Emotion: form.UserInfo.Emotion,
Profession: form.UserInfo.Profession,
Hobby: form.UserInfo.Hobby,
Hometown: form.UserInfo.Hometown,
OftenAppear: form.UserInfo.OftenAppear,
CoverImage: form.UserInfo.CoverImage,
Setinfo: user.Setinfo,
SetinfoAll: user.SetinfoAll,
}
addr := &models.Address{
Country: form.UserInfo.Country,
Province: form.UserInfo.Province,
City: form.UserInfo.City,
Area: form.UserInfo.Area,
Desc: form.UserInfo.LocDesc,
}
if addr.String() != "" {
setinfo.Address = addr
}
if len(setinfo.Phone) > 0 && setinfo.Phone != user.Phone {
user.Phone = setinfo.Phone
//setinfo.Setinfo = false
if b, _ := user.Exists("phone"); b {
writeResponse(request.RequestURI, resp, nil,
errors.NewError(errors.UserExistError, "綁定失敗,當前手機號已綁定"))
return
}
}
if len(setinfo.Nickname) > 0 && setinfo.Nickname != user.Nickname {
u := &models.Account{}
if find, _ := u.FindByNickname(setinfo.Nickname); find {
writeResponse(request.RequestURI, resp, nil, errors.NewError(errors.UserExistError, "昵稱已被占用"))
return
}
}
awards := Awards{}
if !user.Setinfo || !user.SetinfoAll {
ratio := calcInfo(user, setinfo)
if ratio >= 80 && !user.Setinfo {
setinfo.Setinfo = true
awards.Wealth = 30 * models.Satoshi
awards.Score = 30
}
if ratio == 100 && !user.SetinfoAll {
setinfo.SetinfoAll = true
awards.Wealth = 50 * models.Satoshi
awards.Score = 50
}
}
if err := user.SetInfo(setinfo); err != nil {
writeResponse(request.RequestURI, resp, nil, err)
return
}
GiveAwards(user, awards, redis)
writeResponse(request.RequestURI, resp, map[string]interface{}{"ExpEffect": awards}, nil)
user.UpdateAction(ActInfo, nowDate())
//redis.SetOnlineUser(form.Token, user, false)
}