func (s *Service) getLastMonthStartEnd() (int64, int64) { now := time.Now() env := g.Cfg().GetString("bonus.env") var start, end time.Time if env == "dev" { // 測試環境就查本月的 start, end = helper.GetMonthStartEnd(now) } else { lastMonth := now.AddDate(0, -1, -now.Day()+1) start, end = helper.GetMonthStartEnd(lastMonth) } return start.Unix(), end.Unix() } // 獲取指定時間所在月的開始 結束時間 func GetMonthStartEnd(t time.Time) (time.Time, time.Time) { monthStartDay := t.AddDate(0, 0, -t.Day()+1) monthStartTime := time.Date(monthStartDay.Year(), monthStartDay.Month(), monthStartDay.Day(), 0, 0, 0, 0, t.Location()) monthEndDay := monthStartTime.AddDate(0, 1, -1) monthEndTime := time.Date(monthEndDay.Year(), monthEndDay.Month(), monthEndDay.Day(), 23, 59, 59, 0, t.Location()) return monthStartTime, monthEndTime }