func GetUserDailyReports(c wine.Context) { start := c.Params().GetStr("start") end := c.Params().GetStr("end") var st time.Time var et time.Time var e error if st, e = time.Parse("2006-01-02", start); e != nil { ResponseError(c, ErrParm) return } if et, e = time.Parse("2006-01-02", end); e != nil { ResponseError(c, ErrParm) return } userId := c.Params().GetInt64("user_id") user, _ := dao.GetUser(userId) if user == nil { ResponseError(c, ErrParm) return } var reports []*models.DailyReport stt := st.Unix() ett := et.Unix() for t := stt; t <= ett; t += 24 * 3600 { d := time.Unix(t, 0).Format("2006-01-02") r, _ := dao.GetUserDailyReport(userId, d) if r == nil { r = new(models.DailyReport) r.ModifiedAt = time.Now().Unix() } r.User = user r.UserId = userId r.Date = d reports = append(reports, r) } ResponseData(c, gox.M{"reports": reports, "user": user}) }
func GetDailyReports(c wine.Context) { date := c.Params().GetStr("date") users, e := dao.GetAllUsers() if e != nil { ResponseError(c, ErrServer) return } reports := make([]*models.DailyReport, len(users)) for i, u := range users { r, _ := dao.GetUserDailyReport(u.Id, date) if r == nil { r = new(models.DailyReport) r.ModifiedAt = time.Now().Unix() } r.User = u r.UserId = u.Id reports[i] = r } ResponseData(c, gox.M{"reports": reports}) }