|
|
@@ -216,3 +216,72 @@ func commTotalByApp(c *gin.Context, req md.IndexAppListReq, appId []string) []ma |
|
|
|
nativeString, _ := db.QueryNativeString(db.Db, sql) |
|
|
|
return nativeString |
|
|
|
} |
|
|
|
func BeforeSevenPoint(c *gin.Context, req md.IndexAppListTableReq) map[string][]string { |
|
|
|
|
|
|
|
start := utils.TimeStdParseUnix(req.StartDate + " 00:00:00") |
|
|
|
day := (utils.TimeStdParseUnix(req.EndDate+" 00:00:00")-start)/86400 + 1 |
|
|
|
first := start - day*86400*6 |
|
|
|
dayAll := (utils.TimeStdParseUnix(req.EndDate+" 00:00:00")-first)/86400 + 1 |
|
|
|
|
|
|
|
firstTime := time.Unix(first, 0).Format("2006-01-02") |
|
|
|
appData := make(map[string][]string) |
|
|
|
for _, v := range req.AppId { |
|
|
|
appData[v] = make([]string, dayAll/day+1, dayAll/day+1) |
|
|
|
} |
|
|
|
dateList := make(map[int]string) |
|
|
|
j := 1 |
|
|
|
for i := 0; i < int(dayAll); i++ { |
|
|
|
if i >= (j-1)*int(day) && i < j*int(day) { |
|
|
|
dateList[j-1] += "," + time.Unix(first+int64(i)*86400, 0).Format("2006-01-02") |
|
|
|
continue |
|
|
|
} |
|
|
|
j++ |
|
|
|
dateList[j-1] += "," + time.Unix(first+int64(i)*86400, 0).Format("2006-01-02") |
|
|
|
} |
|
|
|
if len(req.AppId) > 0 { |
|
|
|
date := commTotalByDate(c, firstTime, req.EndDate, req.AppId) |
|
|
|
for _, v := range date { |
|
|
|
for k1, v1 := range dateList { |
|
|
|
if strings.Contains(v1, v["date"]) { |
|
|
|
appData[v["app_id"]][k1] = utils.Float64ToStr(utils.StrToFloat64(appData[v["app_id"]][k1]) + utils.StrToFloat64(v["media_revenue"])/100) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for k, v := range appData { |
|
|
|
for k1, v1 := range v { |
|
|
|
if v1 == "" { |
|
|
|
appData[k][k1] = "0" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return appData |
|
|
|
} |
|
|
|
func commTotalByDate(c *gin.Context, startDate, endDate string, appId []string) []map[string]string { |
|
|
|
sql := ` |
|
|
|
SELECT |
|
|
|
app_id as app_id, |
|
|
|
date as date, |
|
|
|
SUM(exposure_count) as exposure_count, |
|
|
|
SUM(click_count) as click_count, |
|
|
|
SUM(click_count)/SUM(exposure_count)*100 as click_rate, |
|
|
|
SUM(ecpm) as ecpm, |
|
|
|
SUM(media_revenue) as media_revenue |
|
|
|
FROM generate_wx_ad_data |
|
|
|
where %s group by date,app_id |
|
|
|
` |
|
|
|
where := "uuid=" + c.GetString("mid") |
|
|
|
if startDate != "" { |
|
|
|
where += " and date>='" + startDate + "'" |
|
|
|
} |
|
|
|
if endDate != "" { |
|
|
|
where += " and date<='" + endDate + "'" |
|
|
|
} |
|
|
|
if len(appId) > 0 { |
|
|
|
where += " and app_id in('" + strings.Join(appId, ",") + "')" |
|
|
|
} |
|
|
|
sql = fmt.Sprintf(sql, where) |
|
|
|
nativeString, err := db.QueryNativeString(db.Db, sql) |
|
|
|
fmt.Println(err) |
|
|
|
return nativeString |
|
|
|
} |