ソースを参照

更新

master
huangjiajun 3ヶ月前
コミット
eadb631055
7個のファイルの変更141行の追加35行の削除
  1. +16
    -0
      app/hdl/hdl_data_center.go
  2. +8
    -1
      app/hdl/hdl_index.go
  3. +1
    -0
      app/hdl/hdl_login.go
  4. +3
    -3
      app/md/md_data_center.go
  5. +43
    -7
      app/svc/svc_data_center.go
  6. +66
    -20
      app/svc/svc_index.go
  7. +4
    -4
      app/utils/time.go

+ 16
- 0
app/hdl/hdl_data_center.go ファイルの表示

@@ -28,6 +28,10 @@ func DataCenterTable(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
res := svc.DataCenterTable(c, req)
e.OutSuc(c, res, nil)
return
@@ -53,6 +57,10 @@ func DataCenterRecordTotal(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
res := svc.DataCenterRecordTotal(c, req)
e.OutSuc(c, res, nil)
return
@@ -78,6 +86,10 @@ func DataCenterRecordList(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
res := svc.DataCenterRecordList(c, req)
e.OutSuc(c, res, nil)
return
@@ -103,6 +115,10 @@ func DataCenterRecordOutPut(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
svc.DataCenterRecordOutPut(c, req)
return
}


+ 8
- 1
app/hdl/hdl_index.go ファイルの表示

@@ -26,9 +26,16 @@ func Base(c *gin.Context) {
NewMediumListDb := implement.NewMediumListDb(db.Db)
data, _ := NewMediumListDb.GetMediumList(user.MediumId)
settleType := []string{"", "日结", "周结", "月结", "预付"}
name := user.Username
if data.CompanyName != "" {
name = data.CompanyName
}
if data.CompanyAbbreviation != "" {
name = data.CompanyAbbreviation
}
res := map[string]string{
"account_id": utils.IntToStr(user.MediumId),
"name": user.Username,
"name": name,
"account": user.Username,
"settle_type": utils.IntToStr(data.SettlementType),
"settle_type_str": settleType[data.SettlementType],


+ 1
- 0
app/hdl/hdl_login.go ファイルの表示

@@ -156,6 +156,7 @@ func Register(c *gin.Context) {
MediumId: utils.StrToInt(mediumId),
Kind: 1,
CompanyName: "",
SettlementType: 1,
CompanyAbbreviation: "",
UnifiedSocialCreditCode: "",
BusinessLicenseImgUrl: "",


+ 3
- 3
app/md/md_data_center.go ファイルの表示

@@ -1,7 +1,7 @@
package md

type DataCenterTableReq struct {
StartDate string `json:"start_date" example:"2024-08-30"`
StartDate string `json:"start_date" example:"2024-08-30 默认查昨天的 最近7天"`
EndDate string `json:"end_date" example:"2024-08-30"`
Platform string `json:"platform" example:"平台"`
AppId string `json:"app_id" example:"应用"`
@@ -9,7 +9,7 @@ type DataCenterTableReq struct {
}

type DataCenterRecordReq struct {
StartDate string `json:"start_date" example:"2024-08-30"`
StartDate string `json:"start_date" example:"2024-08-30 默认查昨天的 最近7天"`
EndDate string `json:"end_date" example:"2024-08-30"`
Platform string `json:"platform" example:"平台"`
AppId string `json:"app_id" example:"应用"`
@@ -18,7 +18,7 @@ type DataCenterRecordReq struct {
Page string `json:"page" `
}
type DataCenterRecordOutPutReq struct {
StartDate string `json:"start_date" example:"2024-08-30"`
StartDate string `json:"start_date" example:"2024-08-30 默认查昨天的 最近7天"`
EndDate string `json:"end_date" example:"2024-08-30"`
Platform string `json:"platform" example:"平台"`
AppId string `json:"app_id" example:"应用"`


+ 43
- 7
app/svc/svc_data_center.go ファイルの表示

@@ -12,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"strings"
"time"
)

func DataCenterTable(c *gin.Context, req md.DataCenterTableReq) md.DataCenterTableRes {
@@ -19,6 +20,7 @@ func DataCenterTable(c *gin.Context, req md.DataCenterTableReq) md.DataCenterTab
copier.Copy(&req1, &req)
nativeString, _ := comm(c, 0, req1)
list := make([]md.DataCenterTableData, 0)
tmpMap := make(map[string]md.DataCenterTableData)
for _, v := range nativeString {
tmp := md.DataCenterTableData{
Date: v["date"],
@@ -26,6 +28,20 @@ func DataCenterTable(c *gin.Context, req md.DataCenterTableReq) md.DataCenterTab
MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100),
Ecpm: v["ecpm"],
}
tmpMap[v["date"]] = tmp
}
day := (utils.TimeStdParseUnix(req.EndDate+" 00:00:00") - utils.TimeStdParseUnix(req.StartDate+" 00:00:00")) / 86400
for i := day; i >= 0; i-- {
date := utils.TimeStdParseUnix(req.EndDate+" 00:00:00") - i*86400
tmp, ok := tmpMap[time.Unix(date, 0).Format("2006-01-02")]
if ok == false {
tmp = md.DataCenterTableData{
Date: time.Unix(date, 0).Format("2006-01-02"),
ExposureCount: "0",
MediaRevenue: "0",
Ecpm: "0",
}
}
list = append(list, tmp)
}
res := md.DataCenterTableRes{
@@ -45,7 +61,8 @@ func DataCenterRecordTotal(c *gin.Context, req md.DataCenterTableReq) md.DataCen
FROM generate_wx_ad_data
where %s
`
where := "uuid=" + c.GetString("mid")
user := GetUser(c)
where := "uuid=" + c.GetString("mid") + " and medium_id=" + utils.IntToStr(user.MediumId)
if req.AppId != "" || req.Platform != "" {
where += " and app_id in(" + appId + ")"
}
@@ -70,7 +87,7 @@ func DataCenterRecordTotal(c *gin.Context, req md.DataCenterTableReq) md.DataCen
ExposureCount: v["exposure_count"],
MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100),
Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
ClickRate: utils.GetPrec(v["click_rate"], "2"),
ClickRate: utils.GetPrec(v["click_rate"], "2") + "%",
ClickCount: v["click_count"],
}
}
@@ -88,15 +105,21 @@ func DataCenterRecordList(c *gin.Context, req md.DataCenterRecordReq) md.DataCen
name = app.Name
platform = app.Platform
}
NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
adData, _ := NewAppletApplicationAdSpaceListDb.GetAppletApplicationAdSpaceListByAdId(v["slot_id"])
adName := enum.AdunitType(v["ad_slot"]).String()
if adData != nil {
adName = adData.Name
}
tmp := md.DataCenterTotalData{
Date: v["date"],
AppName: name,
PlatformName: md.AppletPlatformMap[platform],
AdvName: enum.AdunitType(v["ad_slot"]).String(),
AdvName: adName,
ExposureCount: v["exposure_count"],
MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100),
Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
ClickRate: v["click_rate"],
ClickRate: v["click_rate"] + "%",
ClickCount: v["click_count"],
}
list = append(list, tmp)
@@ -113,8 +136,10 @@ func DataCenterRecordOutPut(c *gin.Context, req md.DataCenterRecordOutPutReq) {
req.Limit = "10000"
nativeString, _ := comm(c, 0, req1)
appId := make([]string, 0)
adId := make([]string, 0)
for _, v := range nativeString {
appId = append(appId, v["app_id"])
adId = append(adId, v["slot_id"])
}
var app []model2.AppletApplication
appMap := make(map[string]model2.AppletApplication)
@@ -122,7 +147,13 @@ func DataCenterRecordOutPut(c *gin.Context, req md.DataCenterRecordOutPutReq) {
for _, v := range app {
appMap[v.AppId] = v
}
name := req.StartDate + "~" + req.EndDate + "-第" + req.Page + "页"
var ad []model2.AppletApplicationAdSpaceList
adMap := make(map[string]model2.AppletApplicationAdSpaceList)
MasterDb(c).In("ad_id=?", adId).Find(&adMap)
for _, v := range ad {
adMap[v.AdId] = v
}
name := req.StartDate + "~" + req.EndDate + "(第" + req.Page + "页 " + utils.IntToStr(len(nativeString)) + "条)"
//写入数据
data := map[string]string{
"A1": "日期",
@@ -139,7 +170,7 @@ func DataCenterRecordOutPut(c *gin.Context, req md.DataCenterRecordOutPutReq) {
data["A"+i] = v["date"]
data["B"+i] = appMap[v["app_id"]].Name
data["C"+i] = md.AppletPlatformMap[appMap[v["app_id"]].Platform]
data["D"+i] = enum.AdunitType(v["ad_slot"]).String()
data["D"+i] = adMap[v["slot_id"]].Name
data["E"+i] = v["exposure_count"]
data["F"+i] = v["click_count"]
data["G"+i] = utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100)
@@ -163,7 +194,8 @@ func comm(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string
FROM generate_wx_ad_data
where %s %s
`
where := "uuid=" + c.GetString("mid")
user := GetUser(c)
where := "uuid=" + c.GetString("mid") + " and medium_id=" + utils.IntToStr(user.MediumId)
if req.AppId != "" || req.Platform != "" {
where += " and app_id in(" + appId + ")"
}
@@ -202,7 +234,11 @@ func DataCenterSelectData(c *gin.Context) {
NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
appList, _ := NewAppletApplicationDb.FindAllAppletApplicationList()
appMap := make(map[string][]map[string]interface{})
user := GetUser(c)
for _, v := range appList {
if v.MediumId != user.MediumId {
continue
}
_, ok := appMap[v.Platform]
if ok == false {
appMap[v.Platform] = make([]map[string]interface{}, 0)


+ 66
- 20
app/svc/svc_index.go ファイルの表示

@@ -7,37 +7,85 @@ import (
db "code.fnuoos.com/zhimeng/model.git/src"
"fmt"
"github.com/gin-gonic/gin"
"strings"
"time"
)

func IndexTotal(c *gin.Context) {
//昨天
yesterday := utils.GetTimeRange("yesterday")
yesterdayTotal := commTotal(c, time.Unix(yesterday["start"], 0).Format("2006-01-02"), time.Unix(yesterday["end"]-3600, 0).Format("2006-01-02"))
//前天
beforeYesterDayTotal := commTotal(c, time.Unix(yesterday["start"]-86400, 0).Format("2006-01-02"), time.Unix(yesterday["start"]-3600, 0).Format("2006-01-02"))
//7天
withinSevenDays := utils.GetTimeRange("new_within_seven_days")
withinSevenDaysTotal := commTotal(c, time.Unix(withinSevenDays["start"], 0).Format("2006-01-02"), time.Unix(withinSevenDays["end"]-3600, 0).Format("2006-01-02"))
//7天前的 7天
beforeWithinSevenDaysTotal := commTotal(c, time.Unix(withinSevenDays["start"]-3600-7*86400, 0).Format("2006-01-02"), time.Unix(withinSevenDays["start"]-3600, 0).Format("2006-01-02"))
//本月
currentMonth := utils.GetTimeRange("current_month")
currentMonthTotal := commTotal(c, time.Unix(currentMonth["start"], 0).Format("2006-01-02"), time.Unix(currentMonth["end"]-3600, 0).Format("2006-01-02"))
//上月
lastMonth := utils.GetTimeRange("last_month")
lastMonthTotal := commTotal(c, time.Unix(lastMonth["start"], 0).Format("2006-01-02"), time.Unix(lastMonth["end"]-3600, 0).Format("2006-01-02"))
//上上月
beforeLastMonth := time.Unix(lastMonth["start"]-86400, 0)
beforeLastMonthStr := time.Date(beforeLastMonth.Year(), beforeLastMonth.Month(), 1, 0, 0, 0, 0, beforeLastMonth.Location())
beforeLastMonthTotal := commTotal(c, beforeLastMonthStr.Format("2006-01-02"), time.Unix(lastMonth["start"]-3600, 0).Format("2006-01-02"))
res := []md.IndexAppListDataList{
{Name: "昨日收益", Type: "yesterday", Bili: "-%", Value: utils.Float64ToStr(utils.StrToFloat64(yesterdayTotal[0]["media_revenue"]) / 100)},
{Name: "七日收益", Type: "within_seven_days", Bili: "-%", Value: utils.Float64ToStr(utils.StrToFloat64(withinSevenDaysTotal[0]["media_revenue"]) / 100)},
{Name: "本月收益", Type: "current_month", Bili: "-%", Value: utils.Float64ToStr(utils.StrToFloat64(currentMonthTotal[0]["media_revenue"]) / 100)},
{Name: "上月收益", Type: "last_month", Bili: "-%", Value: utils.Float64ToStr(utils.StrToFloat64(lastMonthTotal[0]["media_revenue"]) / 100)},
{Name: "昨日收益", Type: "yesterday", Bili: commBili(c, beforeYesterDayTotal, yesterdayTotal, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(yesterdayTotal[0]["media_revenue"]) / 100)},
{Name: "七日收益", Type: "within_seven_days", Bili: commBili(c, beforeWithinSevenDaysTotal, withinSevenDaysTotal, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(withinSevenDaysTotal[0]["media_revenue"]) / 100)},
{Name: "本月收益", Type: "current_month", Bili: commBili(c, lastMonthTotal, currentMonthTotal, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(currentMonthTotal[0]["media_revenue"]) / 100)},
{Name: "上月收益", Type: "last_month", Bili: commBili(c, beforeLastMonthTotal, lastMonthTotal, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(lastMonthTotal[0]["media_revenue"]) / 100)},
}
e.OutSuc(c, res, nil)
return
}
func commBili(c *gin.Context, before, after []map[string]string, types string) string {
bili := "-%"
if utils.StrToFloat64(before[0][types]) > 0 {
tmpDiff := utils.StrToFloat64(after[0][types]) - utils.StrToFloat64(before[0][types])
types1 := "+"
if tmpDiff < 0 {
types1 = ""
}
bili = types1 + utils.Float64ToStr(tmpDiff/utils.StrToFloat64(before[0][types])*100) + "%"
}
return bili
}
func IndexAppList(c *gin.Context, req md.IndexAppListReq) md.IndexAppListRes {
data := commTotalByApp(c, req)
appId := make([]string, 0)
data := commTotalByApp(c, req, appId)
for _, v := range data {
appId = append(appId, v["app_id"])
}
start := utils.TimeStdParseUnix(req.StartDate + " 00:00:00")
day := (utils.TimeStdParseUnix(req.EndDate+" 00:00:00") - start) / 86400
req.EndDate = time.Unix(start-1, 0).Format("2006-01-02")
req.StartDate = time.Unix(start-1-day*86400, 0).Format("2006-01-02")
dataLast := commTotalByApp(c, req, appId)
dataLastMap := make(map[string][]map[string]string)
for _, v := range dataLast {
dataLastMap[v["app_id"]] = make([]map[string]string, 0)
dataLastMap[v["app_id"]] = append(dataLastMap[v["app_id"]], v)
}
list := make([]md.IndexAppListData, 0)
for _, v := range data {
_, ok := dataLastMap[v["app_id"]]
if ok == false {
dataLastMap[v["app_id"]] = []map[string]string{
{"media_revenue": "0", "ecpm": "0", "exposure_count": "0", "click_count": "0", "click_rate": "0"},
}
}
tmpList := []map[string]string{
v,
}
dataList := []md.IndexAppListDataList{
{Name: "广告预估收益", Type: "media_revenue", Bili: "-%", Value: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100)},
{Name: "ECPM", Type: "ecpm", Bili: "-%", Value: v["ecpm"]},
{Name: "曝光量", Type: "exposure_count", Bili: "-%", Value: v["exposure_count"]},
{Name: "点击量", Type: "click_count", Bili: "-%", Value: v["click_count"]},
{Name: "点击率", Type: "click_rate", Bili: "-%", Value: utils.GetPrec(v["click_rate"], "2")},
{Name: "广告预估收益", Type: "media_revenue", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100)},
{Name: "ECPM", Type: "ecpm", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "ecpm"), Value: v["ecpm"]},
{Name: "曝光量", Type: "exposure_count", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "exposure_count"), Value: v["exposure_count"]},
{Name: "点击量", Type: "click_count", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "click_count"), Value: v["click_count"]},
{Name: "点击率", Type: "click_rate", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "click_rate"), Value: utils.GetPrec(v["click_rate"], "2") + "%"},
}
applet := GetAppletInfo(c, v["app_id"])
tmp := md.IndexAppListData{
@@ -69,7 +117,8 @@ func commTotal(c *gin.Context, startDate, endDate string) []map[string]string {
FROM generate_wx_ad_data
where %s
`
where := "uuid=" + c.GetString("mid")
user := GetUser(c)
where := "uuid=" + c.GetString("mid") + " and medium_id=" + utils.IntToStr(user.MediumId)
if startDate != "" {
where += " and date>='" + startDate + "'"
}
@@ -87,7 +136,7 @@ func commTotal(c *gin.Context, startDate, endDate string) []map[string]string {
}
return nativeString
}
func commTotalByApp(c *gin.Context, req md.IndexAppListReq) []map[string]string {
func commTotalByApp(c *gin.Context, req md.IndexAppListReq, appId []string) []map[string]string {
sql := `
SELECT
app_id as app_id,
@@ -99,24 +148,21 @@ func commTotalByApp(c *gin.Context, req md.IndexAppListReq) []map[string]string
FROM generate_wx_ad_data
where %s group by app_id order by %s,id asc limit 10
`
where := "uuid=" + c.GetString("mid")
user := GetUser(c)
where := "uuid=" + c.GetString("mid") + " and medium_id=" + utils.IntToStr(user.MediumId)
if req.StartDate != "" {
where += " and date>='" + req.StartDate + "'"
}
if req.EndDate != "" {
where += " and date<='" + req.EndDate + "'"
}
if len(appId) > 0 {
where += " and app_id in(" + strings.Join(appId, ",") + ")"
}
if req.Sort == "" {
req.Sort = "media_revenue desc"
}
sql = fmt.Sprintf(sql, where, req.Sort)
nativeString, _ := db.QueryNativeString(db.Db, sql)
if len(nativeString) == 0 {
nativeString = []map[string]string{
{
"media_revenue": "0",
},
}
}
return nativeString
}

+ 4
- 4
app/utils/time.go ファイルの表示

@@ -173,11 +173,11 @@ func GetTimeRange(s string) map[string]int64 {
// 今日 0点
etime = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
case "current_month":
stime = time.Date(t.Year(), t.Month(), 0, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month()+1, 0, 0, 0, 0, 0, t.Location())
stime = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month()+1, 1, 0, 0, 0, 0, t.Location())
case "last_month":
stime = time.Date(t.Year(), t.Month()-1, 0, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month(), 0, 0, 0, 0, 0, t.Location())
stime = time.Date(t.Year(), t.Month()-1, 1, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
}

return map[string]int64{


読み込み中…
キャンセル
保存