| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package coupon
- import (
- "fmt"
- "sort"
- "time"
- "bet24.com/log"
- )
- var mgr *couponManager
- type couponManager struct {
- day_list map[string]*statInfo
- hour_list map[string][]*statInfo
- }
- func Run() {
- mgr = new(couponManager)
- mgr.day_list = make(map[string]*statInfo)
- mgr.hour_list = make(map[string][]*statInfo)
- }
- func (this *couponManager) dayStat(beginTime, endTime string) []*statInfo {
- var list []*statInfo
- end, _ := time.Parse(dateFormat, endTime)
- for begin, _ := time.Parse(dateFormat, beginTime); !begin.After(end); begin = begin.AddDate(0, 0, 1) {
- dateStr := begin.Format(dateFormat)
- key := fmt.Sprintf("%s", dateStr)
- v, ok := this.day_list[key]
- if ok {
- list = append(list, v)
- continue
- }
- for _, v := range statByDay(dateStr) {
- log.Debug("couponmgr.dayStat ==> %+v", v)
- if begin.Format(dateFormat) == time.Now().Format(dateFormat) {
- list = append(list, v)
- continue
- }
- key = fmt.Sprintf("%s", v.DateFlag)
- this.day_list[key] = v
- list = append(list, v)
- }
- }
- sort.SliceStable(list, func(i, j int) bool {
- return list[i].DateFlag > list[j].DateFlag
- })
- return list
- }
- func (this *couponManager) hourStat(beginTime, endTime string) []*statInfo {
- var list []*statInfo
- end, _ := time.Parse(dateFormat, endTime)
- for begin, _ := time.Parse(dateFormat, beginTime); !begin.After(end); begin = begin.AddDate(0, 0, 1) {
- dateStr := begin.Format(dateFormat)
- key := fmt.Sprintf("%s", dateStr)
- v, ok := this.hour_list[key]
- if ok {
- list = append(list, v...)
- continue
- }
- for _, v := range statByHour(dateStr) {
- log.Debug("couponmgr.hourStat ==> %+v", v)
- if begin.Format(dateFormat) == time.Now().Format(dateFormat) {
- list = append(list, v)
- continue
- }
- key = fmt.Sprintf("%s", v.DateFlag)
- this.hour_list[key] = append(this.hour_list[key], v)
- list = append(list, v)
- }
- }
- sort.SliceStable(list, func(i, j int) bool {
- return list[i].DateFlag > list[j].DateFlag
- })
- return list
- }
|