|
|
@@ -0,0 +1,94 @@
|
|
|
+package fohow_fans_controller
|
|
|
+
|
|
|
+import (
|
|
|
+ "fohow-statement-api/models"
|
|
|
+ "github.com/astaxie/beego"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type FohowFansMonthGrouthController struct {
|
|
|
+ beego.Controller
|
|
|
+}
|
|
|
+
|
|
|
+// @Title Get
|
|
|
+// @Description 默认是当月及其前5月,输入某个日期,查询输入日期月份及其前5月的净增和新增数组
|
|
|
+// @Param Authorization header string true "格式: Token XXXXXX"
|
|
|
+// @Param query_date query string false "query_date"
|
|
|
+// @Success 200 {object} Ret
|
|
|
+// @router / [get]
|
|
|
+func (self *FohowFansMonthGrouthController) Get() {
|
|
|
+
|
|
|
+ query_date := self.GetString("query_date")
|
|
|
+ s := strings.Split(query_date, "-")
|
|
|
+ type Ret struct {
|
|
|
+ Months []string `json:"months"` //六个月
|
|
|
+ MonthNewFans []int64 `json:"month_new_fans"` //新增
|
|
|
+ //MonthNetFans []int64 `json:"month_net_fans"` //净增
|
|
|
+ }
|
|
|
+
|
|
|
+ now := time.Now() //2018-03-24 14:32:00
|
|
|
+ start := now
|
|
|
+ end := now
|
|
|
+
|
|
|
+ query_date_tmp := now
|
|
|
+ if len(s) == 3 {
|
|
|
+ //2018-02-09 00:00:00
|
|
|
+ query_date_tmp, _ = time.Parse("2006-01-02", query_date)
|
|
|
+ }
|
|
|
+ if len(s) == 2 {
|
|
|
+ //2018-02-01 00:00:00
|
|
|
+ query_date_tmp, _ = time.Parse("2006-01", query_date)
|
|
|
+ }
|
|
|
+
|
|
|
+ //2018-02-01 00:00:00
|
|
|
+ queryDate := time.Date(query_date_tmp.Year(), query_date_tmp.Month(), 1, 0, 0, 0, 0, time.Local)
|
|
|
+
|
|
|
+ start = queryDate.AddDate(0, -5, 0) //2018-09-01 00:00:00
|
|
|
+ beego.BeeLogger.Warn("start:%s", start)
|
|
|
+
|
|
|
+ end = queryDate.AddDate(0, 1, 0) //2018-03-01 00:00:00
|
|
|
+ beego.BeeLogger.Warn("end:%s", end)
|
|
|
+
|
|
|
+ xcxUserCountPerMonthList := models.GetAllXcxUserCountByMonth(start, end, true)
|
|
|
+ //unxcxUserCountPerMonthList := models.GetAllUnSubUserCountByMonth(start, end, true)
|
|
|
+
|
|
|
+ var months []string
|
|
|
+ var monthNewFans []int64
|
|
|
+ var monthNetFans []int64
|
|
|
+
|
|
|
+ for i := 0; i < 6; i++ {
|
|
|
+
|
|
|
+ month := start.AddDate(0, i, 0).Format("2006-01")
|
|
|
+ months = append(months, month)
|
|
|
+
|
|
|
+ ym := start.AddDate(0, i, 0).Format("200601")
|
|
|
+
|
|
|
+ ymInt, _ := strconv.ParseInt(ym, 0, 64)
|
|
|
+
|
|
|
+ sub := models.ContainsInMonthItemListAndReturnItemCount(ymInt, xcxUserCountPerMonthList)
|
|
|
+ beego.BeeLogger.Warn("sub:%d", sub)
|
|
|
+ //subOther := ContainsInMonthListAndReturn(ymInt, subOtherCountPerMonthList)
|
|
|
+ //beego.BeeLogger.Warn("subOther:%d",subOther)
|
|
|
+ unSub := int64(0)
|
|
|
+ beego.BeeLogger.Warn("unSub:%d", unSub)
|
|
|
+ //unSubOther := ContainsInMonthListAndReturn(ymInt, unSubOtherCountPerMonthList)
|
|
|
+ //beego.BeeLogger.Warn("unSubOther:%d",unSubOther)
|
|
|
+
|
|
|
+ //subOtherNet := subOther - unSubOther
|
|
|
+
|
|
|
+ dayNewF := sub
|
|
|
+ beego.BeeLogger.Warn("monthNewF:%d", dayNewF)
|
|
|
+
|
|
|
+ monthNewFans = append(monthNewFans, dayNewF)
|
|
|
+
|
|
|
+ dayNetF := sub - unSub
|
|
|
+ beego.BeeLogger.Warn("monthNetF:%d", dayNetF)
|
|
|
+
|
|
|
+ monthNetFans = append(monthNetFans, dayNetF)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.Data["json"] = &Ret{Months: months, MonthNewFans: monthNewFans}
|
|
|
+ self.ServeJSON()
|
|
|
+}
|