|
|
@@ -0,0 +1,271 @@
|
|
|
+package cow_point_task
|
|
|
+
|
|
|
+import (
|
|
|
+ "d5c-statement-api/models"
|
|
|
+ "github.com/astaxie/beego"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type GamePrizeDailyController struct {
|
|
|
+ beego.Controller
|
|
|
+}
|
|
|
+
|
|
|
+// @Title Get
|
|
|
+// @Description 获取养牛平台的抽奖奖品配置列表
|
|
|
+// @Param Authorization header string true "格式: Token XXXXXX"
|
|
|
+// @Param query_date query string false "query_date"
|
|
|
+// @Success 200 {object} Ret
|
|
|
+// @router /prize/config [get]
|
|
|
+func (self *GamePrizeDailyController) PrizeDrawConfig() {
|
|
|
+ c := "type_cow" //养牛平台
|
|
|
+ list := models.GetPrizeDrawList(c)
|
|
|
+ self.Data["json"] = list
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title Get
|
|
|
+// @Description 输入某个日期(默认是今天及其前6天),查询输入日期及其前6天的统计数据
|
|
|
+// @Param Authorization header string true "格式: Token XXXXXX"
|
|
|
+// @Param query_date query string false "query_date"
|
|
|
+// @Success 200 {object} Ret
|
|
|
+// @router /daily_prize/seven [get]
|
|
|
+func (self *GamePrizeDailyController) RecordDailyCountSeven() {
|
|
|
+ query_date := self.GetString("query_date")
|
|
|
+ s := strings.Split(query_date, "-")
|
|
|
+
|
|
|
+ type CountList struct {
|
|
|
+ ConfigId int64 `json:"config_id"` //配置ID
|
|
|
+ ConfigName string `json:"config_name"` //配置名称
|
|
|
+ CountData []*models.DayItem `json:"count_data"` //统计数据
|
|
|
+ CountDay []int64 `json:"count_day"` //按天的统计数据
|
|
|
+ }
|
|
|
+ type Ret struct {
|
|
|
+ Days []string `json:"days"` //最近7天
|
|
|
+ PrizeConfig []*CountList `json:"prize_config"` //按照奖品配置列表进行统计
|
|
|
+ }
|
|
|
+
|
|
|
+ now := time.Now() //2006-01-02 15:04:05
|
|
|
+ startTime := now.AddDate(0, 0, -6)
|
|
|
+ nextTime := now.AddDate(0, 0, 1)
|
|
|
+
|
|
|
+ start := time.Date(startTime.Year(), startTime.Month(), startTime.Day(), 0, 0, 0, 0, time.Local)
|
|
|
+ end := time.Date(nextTime.Year(), nextTime.Month(), nextTime.Day(), 0, 0, 0, 0, time.Local)
|
|
|
+
|
|
|
+ if len(s) == 3 {
|
|
|
+ //2006-01-02 00:00:00
|
|
|
+ query_date_tmp, _ := time.Parse("2006-01-02", query_date)
|
|
|
+ queryDateTmp := time.Date(query_date_tmp.Year(), query_date_tmp.Month(), query_date_tmp.Day(), 0, 0, 0, 0, time.Local)
|
|
|
+
|
|
|
+ start = queryDateTmp.AddDate(0, 0, -6) //前6天
|
|
|
+ beego.BeeLogger.Warn("start:%s", start)
|
|
|
+
|
|
|
+ end = queryDateTmp.AddDate(0, 0, 1)
|
|
|
+ beego.BeeLogger.Warn("end:%s", end)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ c := "type_cow" //养牛平台
|
|
|
+ pConfigList := models.GetPrizeDrawList(c)
|
|
|
+ var prizeDataList []*CountList
|
|
|
+ for _, item := range pConfigList {
|
|
|
+ countOne := new(CountList)
|
|
|
+ list := models.GameRecordCountByTime(item.Id, start, end)
|
|
|
+ countOne.ConfigId = item.Id
|
|
|
+ countOne.ConfigName = item.Name
|
|
|
+ countOne.CountData = list
|
|
|
+
|
|
|
+ var dayCountData []int64
|
|
|
+ for i := 0; i < 7; i++ {
|
|
|
+ md := start.AddDate(0, 0, i).Format("20060102")
|
|
|
+ mdInt, _ := strconv.ParseInt(md, 0, 64)
|
|
|
+ dayCashOrderCount := models.CashDayItemListAndReturnItemCount(mdInt, list)
|
|
|
+ dayCountData = append(dayCountData, dayCashOrderCount)
|
|
|
+ }
|
|
|
+ countOne.CountDay = dayCountData
|
|
|
+
|
|
|
+ prizeDataList = append(prizeDataList, countOne)
|
|
|
+ }
|
|
|
+
|
|
|
+ var days []string
|
|
|
+ for i := 0; i < 7; i++ {
|
|
|
+ day := start.AddDate(0, 0, i).Format("01-02")
|
|
|
+ days = append(days, day)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.Data["json"] = &Ret{Days: days, PrizeConfig: prizeDataList}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title Get
|
|
|
+// @Description 输入某个日期,获得天天抽奖的:每日参与总人数、每日饲料消耗总数
|
|
|
+// @Param Authorization header string true "格式: Token XXXXXX"
|
|
|
+// @Param query_date query string false "query_date"
|
|
|
+// @Success 200 {object} Ret
|
|
|
+// @router /daily_prize/countuser [get]
|
|
|
+func (self *GamePrizeDailyController) RecordCountUserOneDay() {
|
|
|
+ query_date := self.GetString("query_date")
|
|
|
+ s := strings.Split(query_date, "-")
|
|
|
+
|
|
|
+ type Ret struct {
|
|
|
+ Day string `json:"day"` //日期
|
|
|
+ CountUser int64 `json:"count_user"` //参与总人数
|
|
|
+ CountFeed int64 `json:"count_feed"` //饲料消耗总数
|
|
|
+ }
|
|
|
+
|
|
|
+ now := time.Now() //2006-01-02 15:04:05
|
|
|
+
|
|
|
+ start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
|
|
|
+ end := start.AddDate(0, 0, 1)
|
|
|
+
|
|
|
+ if len(s) == 3 {
|
|
|
+ //2006-01-02 00:00:00
|
|
|
+ query_date_tmp, _ := time.Parse("2006-01-02", query_date)
|
|
|
+ queryDateTmp := time.Date(query_date_tmp.Year(), query_date_tmp.Month(), query_date_tmp.Day(), 0, 0, 0, 0, time.Local)
|
|
|
+
|
|
|
+ start = queryDateTmp
|
|
|
+ beego.BeeLogger.Warn("start:%s", start)
|
|
|
+
|
|
|
+ end = queryDateTmp.AddDate(0, 0, 1)
|
|
|
+ beego.BeeLogger.Warn("end:%s", end)
|
|
|
+ }
|
|
|
+
|
|
|
+ countUser := models.GameRecordUserCountByTime(-1, start, end)
|
|
|
+ countFeed := models.GameRecordFeedReduceCountByTime(start, end)
|
|
|
+
|
|
|
+ var days []string
|
|
|
+ for i := 0; i < 7; i++ {
|
|
|
+ day := start.AddDate(0, 0, i).Format("01-02")
|
|
|
+ days = append(days, day)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.Data["json"] = &Ret{Day: start.Format("2006-01-02"), CountUser: countUser, CountFeed: countFeed}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title Get
|
|
|
+// @Description 按月统计数据 - 六个月的数据
|
|
|
+// @Param Authorization header string true "格式: Token XXXXXX"
|
|
|
+// @Param query_date query string false "query_date"
|
|
|
+// @Success 200 {object} Ret
|
|
|
+// @router /month_prize/count [get]
|
|
|
+func (self *GamePrizeDailyController) RecordCountHalfYear() {
|
|
|
+ query_date := self.GetString("query_date")
|
|
|
+ s := strings.Split(query_date, "-")
|
|
|
+
|
|
|
+ type CountList struct {
|
|
|
+ ConfigId int64 `json:"config_id"` //配置ID
|
|
|
+ ConfigName string `json:"config_name"` //配置名称
|
|
|
+ CountData []*models.MonthItem `json:"count_data"` //统计数据
|
|
|
+ CountDay []int64 `json:"count_day"` //按月的统计数据
|
|
|
+ }
|
|
|
+ type Ret struct {
|
|
|
+ Months []string `json:"days"` //最近六个月
|
|
|
+ PrizeConfig []*CountList `json:"prize_config"` //按照奖品配置列表进行统计
|
|
|
+ }
|
|
|
+
|
|
|
+ now := time.Now() //2006-01-02 15:04:05
|
|
|
+ startTime := now.AddDate(0, -5, 0)
|
|
|
+ nextTime := now.AddDate(0, 1, 0)
|
|
|
+
|
|
|
+ start := time.Date(startTime.Year(), startTime.Month(), startTime.Day(), 0, 0, 0, 0, time.Local)
|
|
|
+ end := time.Date(nextTime.Year(), nextTime.Month(), nextTime.Day(), 0, 0, 0, 0, time.Local)
|
|
|
+
|
|
|
+ query_date_tmp := now
|
|
|
+ if len(s) == 3 {
|
|
|
+ query_date_tmp, _ = time.Parse("2006-01-02", query_date)
|
|
|
+ queryDate := time.Date(query_date_tmp.Year(), query_date_tmp.Month(), 1, 0, 0, 0, 0, time.Local)
|
|
|
+ start = queryDate.AddDate(0, -5, 0)
|
|
|
+ end = queryDate.AddDate(0, 1, 0)
|
|
|
+ }
|
|
|
+ if len(s) == 2 {
|
|
|
+ query_date_tmp, _ = time.Parse("2006-01", query_date)
|
|
|
+ queryDate := time.Date(query_date_tmp.Year(), query_date_tmp.Month(), 1, 0, 0, 0, 0, time.Local)
|
|
|
+ start = queryDate.AddDate(0, -5, 0)
|
|
|
+ end = queryDate.AddDate(0, 1, 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ c := "type_cow" //养牛平台
|
|
|
+ pConfigList := models.GetPrizeDrawList(c)
|
|
|
+ var prizeDataList []*CountList
|
|
|
+ for _, item := range pConfigList {
|
|
|
+ countOne := new(CountList)
|
|
|
+ list := models.GameRecordCountByMonth(item.Id, start, end)
|
|
|
+ countOne.ConfigId = item.Id
|
|
|
+ countOne.ConfigName = item.Name
|
|
|
+ countOne.CountData = list
|
|
|
+
|
|
|
+ var dayCountData []int64
|
|
|
+ for i := 0; i < 6; i++ {
|
|
|
+ md := start.AddDate(0, i, 0).Format("200601")
|
|
|
+ mdInt, _ := strconv.ParseInt(md, 0, 64)
|
|
|
+ dayCashOrderCount := models.ContainsInMonthItemListAndReturnItemCount(mdInt, list)
|
|
|
+ dayCountData = append(dayCountData, dayCashOrderCount)
|
|
|
+ }
|
|
|
+ countOne.CountDay = dayCountData
|
|
|
+
|
|
|
+ prizeDataList = append(prizeDataList, countOne)
|
|
|
+ }
|
|
|
+
|
|
|
+ var days []string
|
|
|
+ for i := 0; i < 6; i++ {
|
|
|
+ day := start.AddDate(0, i, 0).Format("2006-01")
|
|
|
+ days = append(days, day)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.Data["json"] = &Ret{Months: days, PrizeConfig: prizeDataList}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|
|
|
+
|
|
|
+// @Title Get
|
|
|
+// @Description 按月统计数据,获得天天抽奖的:每月参与总人数、每月饲料消耗总数
|
|
|
+// @Param Authorization header string true "格式: Token XXXXXX"
|
|
|
+// @Param query_date query string false "query_date"
|
|
|
+// @Success 200 {object} Ret
|
|
|
+// @router /month_prize/countuser [get]
|
|
|
+func (self *GamePrizeDailyController) RecordCountUserOneMonth() {
|
|
|
+ query_date := self.GetString("query_date")
|
|
|
+ s := strings.Split(query_date, "-")
|
|
|
+
|
|
|
+ type Ret struct {
|
|
|
+ Month string `json:"month"` //日期
|
|
|
+ CountUser int64 `json:"count_user"` //参与总人数
|
|
|
+ CountFeed int64 `json:"count_feed"` //饲料消耗总数
|
|
|
+ }
|
|
|
+
|
|
|
+ now := time.Now() //2006-01-02 15:04:05
|
|
|
+
|
|
|
+ start := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.Local)
|
|
|
+ end := start.AddDate(0, 1, 0)
|
|
|
+
|
|
|
+ if len(s) == 3 {
|
|
|
+ //2006-01-02 00:00:00
|
|
|
+ query_date_tmp, _ := time.Parse("2006-01-02", query_date)
|
|
|
+ queryDateTmp := time.Date(query_date_tmp.Year(), query_date_tmp.Month(), 1, 0, 0, 0, 0, time.Local)
|
|
|
+
|
|
|
+ start = queryDateTmp
|
|
|
+ beego.BeeLogger.Warn("start:%s", start)
|
|
|
+
|
|
|
+ end = queryDateTmp.AddDate(0, 1, 0)
|
|
|
+ beego.BeeLogger.Warn("end:%s", end)
|
|
|
+ }
|
|
|
+ if len(s) == 2 {
|
|
|
+ query_date_tmp, _ := time.Parse("2006-01", query_date)
|
|
|
+ queryDate := time.Date(query_date_tmp.Year(), query_date_tmp.Month(), 1, 0, 0, 0, 0, time.Local)
|
|
|
+ start = queryDate
|
|
|
+ end = queryDate.AddDate(0, 1, 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ countUser := models.GameRecordUserCountByTime(-1, start, end)
|
|
|
+ countFeed := models.GameRecordFeedReduceCountByTime(start, end)
|
|
|
+
|
|
|
+ var days []string
|
|
|
+ for i := 0; i < 7; i++ {
|
|
|
+ day := start.AddDate(0, 0, i).Format("01-02")
|
|
|
+ days = append(days, day)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.Data["json"] = &Ret{Month: start.Format("2006-01"), CountUser: countUser, CountFeed: countFeed}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|