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) }