lottery.go 948 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. model "go-common/app/admin/main/growup/model/income"
  7. "go-common/library/log"
  8. "go-common/library/xstr"
  9. )
  10. func (s *Service) lotteryStatis(c context.Context, categoryID []int64, from, to time.Time, groupType int) (data interface{}, err error) {
  11. query := ""
  12. if len(categoryID) != 0 {
  13. query = fmt.Sprintf("tag_id in (%s)", xstr.JoinInts(categoryID))
  14. }
  15. avs, err := s.GetArchiveIncome(c, _lottery, query, from.Format(_layout), to.Format(_layout))
  16. if err != nil {
  17. log.Error("s.GetArchiveIncome error(%v)")
  18. return
  19. }
  20. avsMap := make(map[string]*model.ArchiveStatis)
  21. for _, av := range avs {
  22. date := formatDateByGroup(av.Date.Time(), groupType)
  23. if val, ok := avsMap[date]; ok {
  24. val.Income += av.Income
  25. val.Avs++
  26. } else {
  27. avsMap[date] = &model.ArchiveStatis{
  28. Income: av.Income,
  29. Avs: 1,
  30. }
  31. }
  32. }
  33. data = parseArchiveStatis(avsMap, from, to, groupType)
  34. return
  35. }