當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Account.LastTaskRecord方法代碼示例

本文整理匯總了Golang中github.com/ginuerzh/sports/models.Account.LastTaskRecord方法的典型用法代碼示例。如果您正苦於以下問題:Golang Account.LastTaskRecord方法的具體用法?Golang Account.LastTaskRecord怎麽用?Golang Account.LastTaskRecord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ginuerzh/sports/models.Account的用法示例。


在下文中一共展示了Account.LastTaskRecord方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getTasksHandler

func getTasksHandler(r *http.Request, w http.ResponseWriter, user *models.Account) {

	/*
		tasklist := user.Tasks

		week := len(tasklist.Completed) / 7
		if week > 0 && len(tasklist.Completed)%7 == 0 &&
			tasklist.Last.After(now.BeginningOfWeek()) {
			week -= 1
		}
		list := make([]models.Task, 7)
		if week*7+7 <= len(models.Tasks)+1 {
			copy(list, models.Tasks[week*7:week*7+7])
		}
		for i, _ := range list {
			list[i].Status = tasklist.TaskStatus(list[i].Id)
			if list[i].Type == models.TaskGame && list[i].Status == "FINISH" {
				rec := &models.Record{Uid: user.Id}
				rec.FindByTask(list[i].Id)
				if rec.Game != nil {
					list[i].Desc = fmt.Sprintf("你在%s遊戲中得了%d分",
						rec.Game.Name, rec.Game.Score)
				}
			}
		}
	*/
	count, _ := user.TaskRecordCount("", models.StatusFinish)
	week := count / 7

	var target, actual int

	last, _ := user.LastTaskRecord()
	// all weekly tasks are completed
	if week > 0 && count%7 == 0 && last.AuthTime.After(now.BeginningOfWeek()) {
		week -= 1
	}
	//log.Println("week", week)
	tasks := make([]models.Task, 7)
	if week*7+7 <= len(models.Tasks) {
		copy(tasks, models.Tasks[week*7:week*7+7])
	}

	for i, task := range tasks {
		tasks[i].Status = models.StatusNormal
		record := &models.Record{Uid: user.Id}

		if find, _ := record.FindByTask(task.Id); find {
			tasks[i].Status = record.Status
		}
		if task.Type == models.TaskGame && task.Status == models.StatusFinish &&
			record.Game != nil {
			tasks[i].Result = fmt.Sprintf("你在%s遊戲中得了%d分",
				record.Game.Name, record.Game.Score)
		}
		if task.Type == models.TaskRunning {
			target += task.Distance
			if tasks[i].Status == models.StatusFinish && record.Sport != nil {
				actual += record.Sport.Distance
			}
		}
	}
	//log.Println(tasks)
	//random := rand.New(rand.NewSource(time.Now().Unix()))
	respData := map[string]interface{}{
		"week_id":              week + 1,
		"task_list":            tasks,
		"task_target_distance": target,
		"task_actual_distance": actual,
		//"week_desc": tips[random.Int()%len(tips)],
	}

	writeResponse(r.RequestURI, w, respData, nil)
}
開發者ID:shevilangle,項目名稱:sports,代碼行數:73,代碼來源:task.go


注:本文中的github.com/ginuerzh/sports/models.Account.LastTaskRecord方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。