本文整理匯總了Golang中github.com/ginuerzh/sports/models.Account.UpdateTask方法的典型用法代碼示例。如果您正苦於以下問題:Golang Account.UpdateTask方法的具體用法?Golang Account.UpdateTask怎麽用?Golang Account.UpdateTask使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ginuerzh/sports/models.Account
的用法示例。
在下文中一共展示了Account.UpdateTask方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newRecordHandler
//.........這裏部分代碼省略.........
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()
awards = Awards{
Physical: 30 + level,
Wealth: 30 * models.Satoshi,
Score: 30 + level,
}
GiveAwards(user, awards, redis)
redis.UpdateRecLB(user.Id, rec.Sport.Distance, int(rec.Sport.Duration))
rec.Coin = awards.Wealth
rec.Status = models.StatusFinish
}
*/
default:
log.Println("Unknown record type:", form.Record.Type)
}
// assign task id
if rec.Task == 0 {
rec.Task = rec.PubTime.Unix()
}
if err := rec.Save(); err != nil {
writeResponse(request.RequestURI, resp, nil, err)
return
}
if rec.Type == "run" {
article := &models.Article{
Author: user.Id,
PubTime: time.Now(),
Loc: user.Loc,
Record: rec.Id.Hex(),
Type: models.ArticleRecord,
}
if !form.Public {
article.Privilege = models.PrivPrivate
}
if err := article.Save(); err == nil {
redis.AddPost(user.Id, "", 1)
user.UpdateStat(models.StatArticles, 1)
}
}
if form.Task > 0 {
user.UpdateTask(int(form.Task), rec.Status)
/*
if rec.Status == models.StatusFinish {
// ws push
event := &models.Event{
Type: models.EventNotice,
Time: time.Now().Unix(),
Data: models.EventData{
Type: models.EventTaskDone,
To: user.Id,
Body: []models.MsgBody{
{Type: "task_id", Content: strconv.Itoa(int(form.Task))},
{Type: "literature_value", Content: strconv.FormatInt(awards.Literal, 10)},
{Type: "magic_value", Content: strconv.FormatInt(awards.Mental, 10)},
{Type: "coin_value", Content: strconv.FormatInt(awards.Wealth, 10)},
},
},
}
event.Save()
redis.PubMsg(event.Type, event.Data.To, event.Bytes())
}
*/
}
respData := map[string]interface{}{
"record_id": rec.Id.Hex(),
"ExpEffect": awards,
}
writeResponse(request.RequestURI, resp, respData, nil)
}
示例2: getTaskHandler
func getTaskHandler(r *http.Request, w http.ResponseWriter,
user *models.Account, p Parameter) {
form := p.(getTaskForm)
tid := user.Taskid
status := user.TaskStatus
if tid == 0 {
rec, _ := user.LastTaskRecord2()
tid = int(rec.Task + 1) // next task
status = rec.Status
if status == "" {
status = models.StatusNormal
}
user.UpdateTask(tid, status)
}
if status == "" {
status = models.StatusNormal
}
if form.Next {
if status == models.StatusFinish {
tid++
}
if status == models.StatusFinish || status == models.StatusUnFinish {
status = models.StatusNormal
}
user.UpdateTask(tid, status)
}
if tid > len(models.NewTasks) {
writeResponse(r.RequestURI, w, nil, nil)
}
task := models.NewTasks[tid-1]
task.Status = status
config := &models.Config{}
config.Find()
if task.Index < len(config.Videos) {
video := config.Videos[task.Index]
task.Video = video.Url
/*
if len(video.Desc) > 0 {
task.Desc = video.Desc
}
*/
}
var stat struct {
Distance int `json:"distance"`
Run int `json:"run"`
Article int `json:"article"`
Game int `json:"game"`
}
stat.Article, _ = user.TaskRecordCount("post", models.StatusFinish)
stat.Game, _ = user.TaskRecordCount("game", models.StatusFinish)
records, _ := user.TaskRecords("run")
stat.Run = len(records)
for i, _ := range records {
stat.Distance += records[i].Sport.Distance
}
respData := map[string]interface{}{
"task": task,
"stat": stat,
}
writeResponse(r.RequestURI, w, respData, nil)
}