Parcourir la source

增加fohow user grouth 接口

abiao il y a 5 ans
Parent
commit
3d093e1bc1

+ 94 - 0
go/gopath/src/fohow-statement-api/controllers/fohow_fans_controller/fans_month_grouth.go

@@ -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()
+}

+ 1 - 1
go/gopath/src/fohow-statement-api/models/d5c_user.go

@@ -338,7 +338,7 @@ func GetFohowMonthNewOrderTotals(startTime, endTime string) (list []*MonthItem)
 		WHERE
 			date_add(created_at, INTERVAL 8 HOUR) < '%s'
 		AND date_add(created_at, INTERVAL 8 HOUR) >= '%s'
-		AND status in ('processing','dispatch','complete')
+		AND state in ('processing','dispatch','complete')
 		GROUP BY
 			ym
 		ORDER BY

+ 35 - 0
go/gopath/src/fohow-statement-api/models/d5c_wx_user.go

@@ -273,6 +273,41 @@ func GetSubUserCountByMonth(start, end time.Time) (monthFansList []*MonthItem) {
 	return monthFansList
 }
 
+//一段时间内,小程序的所有粉丝数据,分月
+func GetAllXcxUserCountByMonth(start, end time.Time, useCache bool) (monthFansList []*MonthItem) {
+	k := fmt.Sprintf("models.GetAllXcxUserCountByMonth(%s,%s)", start.Format("2006-01-02"), end.Format("2006-01-02"))
+	if useCache {
+		if s, ok := cache.Cache.Get(k).([]*MonthItem); ok {
+			return s
+		}
+	}
+	o := orm.NewOrm()
+	o.Using("fohow_data_source")
+	sql := `
+
+		SELECT
+			count(*) AS c,
+			DATE_ADD(created_at, INTERVAL 8 HOUR),'%s') AS ym,,
+			DATE_ADD(created_at, INTERVAL 8 HOUR),'%s') AS m
+		FROM
+			wx_users
+		WHERE
+			DATE_ADD(created_at, INTERVAL 8 HOUR) >= ?
+			AND DATE_ADD(created_at, INTERVAL 8 HOUR) < ?
+		group by ym;
+	`
+	sql = fmt.Sprintf(sql, "%Y%m", "%m", start.Format("2006-01-02"), end.Format("2006-01-02"))
+
+	_, err := o.Raw(sql).QueryRows(&monthFansList)
+
+	if err != nil {
+		beego.BeeLogger.Warn("models.GetAllXcxUserCountByMonth(%s,%s) err[%s]", start.Format("2006-01-02"), end.Format("2006-01-02"), err)
+		return nil
+	}
+	cache.Cache.Put(k, monthFansList, 2*time.Minute)
+	return monthFansList
+}
+
 //一段时间内,不分有没有渠道的所有粉丝取消关注数据,分月
 func GetAllUnSubUserCountByMonth(start, end time.Time, useCache bool) (monthFansList []*MonthItem) {
 	k := fmt.Sprintf("models.GetAllUnSubUserCountByMonth(%s,%s)", start.Format("2006-01-02"), end.Format("2006-01-02"))

+ 6 - 0
go/gopath/src/fohow-statement-api/routers/router.go

@@ -32,6 +32,7 @@ import (
 	"fohow-statement-api/controllers/d5c_train_controller"
 	"fohow-statement-api/controllers/d5c_user_controller"
 	"fohow-statement-api/controllers/d5c_zt_invest_controller"
+	"fohow-statement-api/controllers/fohow_fans_controller"
 	"fohow-statement-api/controllers/fohow_home_page_stat_controller"
 	"fohow-statement-api/controllers/fohow_user_controller"
 	"fohow-statement-api/controllers/rabbit_balance_consume_controller"
@@ -442,6 +443,11 @@ func init() {
 				&fohow_user_controller.FohowUserGrouthController{},
 			),
 		),
+		beego.NSNamespace("/fohow_fans_month_grouth",
+			beego.NSInclude(
+				&fohow_fans_controller.FohowFansMonthGrouthController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }