@@ -0,0 +1,73 @@ | |||
package enum | |||
import "applet/app/md" | |||
type AdunitType string //广告单元类型 | |||
var AdTypeList = []md.SelectData{ | |||
{Name: "banner", Value: AdunitTypeForBanner}, | |||
{Name: "激励视频", Value: AdunitTypeForRewardVideo}, | |||
{Name: "插屏广告", Value: AdunitTypeForInterstitial}, | |||
{Name: "视频广告", Value: AdunitTypeForVideoFeeds}, | |||
//{Name: "视频贴片广告", Value: "5"}, | |||
} | |||
const ( | |||
AdunitTypeForBanner = "SLOT_ID_WEAPP_BANNER" | |||
AdunitTypeForRewardVideo = "SLOT_ID_WEAPP_REWARD_VIDEO" | |||
AdunitTypeForInterstitial = "SLOT_ID_WEAPP_INTERSTITIAL" | |||
AdunitTypeForVideoFeeds = "SLOT_ID_WEAPP_VIDEO_FEEDS" | |||
AdunitTypeForVideoBegin = "SLOT_ID_WEAPP_VIDEO_BEGIN" | |||
) | |||
func (gt AdunitType) String() string { | |||
switch gt { | |||
case AdunitTypeForBanner: | |||
return "小程序banner" | |||
case AdunitTypeForRewardVideo: | |||
return "小程序激励视频" | |||
case AdunitTypeForInterstitial: | |||
return "小程序插屏广告" | |||
case AdunitTypeForVideoFeeds: | |||
return "小程序视频广告" | |||
case AdunitTypeForVideoBegin: | |||
return "小程序视频贴片广告" | |||
default: | |||
return "未知" | |||
} | |||
} | |||
type AdunitStatus string //广告单元开关状态 | |||
const ( | |||
AdunitStatusForOn = "AD_UNIT_STATUS_ON" | |||
AdunitStatusForOff = "AD_UNIT_STATUS_OFF" | |||
) | |||
func (gt AdunitStatus) String() string { | |||
switch gt { | |||
case AdunitStatusForOn: | |||
return "开通" | |||
case AdunitStatusForOff: | |||
return "关闭" | |||
default: | |||
return "未知" | |||
} | |||
} | |||
type SetCoverAdposStatus int32 //广告单元开关状态 | |||
const ( | |||
SetCoverAdposStatusForOn = 1 | |||
SetCoverAdposStatusForOff = 4 | |||
) | |||
func (gt SetCoverAdposStatus) String() string { | |||
switch gt { | |||
case SetCoverAdposStatusForOn: | |||
return "开通" | |||
case SetCoverAdposStatusForOff: | |||
return "关闭" | |||
default: | |||
return "未知" | |||
} | |||
} |
@@ -199,3 +199,23 @@ func GenerateDataDetail(c *gin.Context) { | |||
} | |||
svc.DataCenterGenerateDataDetail(c, req) | |||
} | |||
func DataCenterSelectData(c *gin.Context) { | |||
svc.DataCenterSelectData(c) | |||
} | |||
func DataCenterTable(c *gin.Context) { | |||
var req md.DataCenterTableReq | |||
err := c.ShouldBindJSON(&req) | |||
if err != nil { | |||
err = validate.HandleValidateErr(err) | |||
err1 := err.(e.E) | |||
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 | |||
} |
@@ -8,6 +8,7 @@ type DataCenterGenerateDataReq struct { | |||
Platform string `json:"platform"` | |||
StartTime string `json:"start_time"` | |||
EndTime string `json:"end_time"` | |||
AppId string `json:"app_id"` | |||
} | |||
type DataCenterGenerateDataForOpenReq struct { | |||
@@ -7,6 +7,34 @@ var AdState = []SelectData{ | |||
{Name: "封禁中", Value: "3"}, | |||
} | |||
type DataCenterTableReq struct { | |||
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:"应用"` | |||
AdType string `json:"ad_type" example:"广告位类型"` | |||
} | |||
type DataCenterTableRes struct { | |||
List []DataCenterTableData `json:"list" ` | |||
} | |||
type DataCenterTableData struct { | |||
Date string `json:"date" example:"日期"` | |||
ExposureCount string `json:"exposure_count" example:"曝光量"` | |||
MediaRevenue string `json:"media_revenue" example:"预估收益"` | |||
Ecpm string `json:"ecpm" example:"ecpm"` | |||
} | |||
type DataCenterRecordReq struct { | |||
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:"应用"` | |||
AdType string `json:"ad_type" example:"广告位类型"` | |||
Limit string `json:"limit"` | |||
Page string `json:"page" ` | |||
Name string `json:"name"` | |||
} | |||
var AdPlatform = []SelectData{ | |||
{Name: "微信小程序", Value: "wx_applet"}, | |||
} | |||
@@ -20,6 +48,7 @@ type DataCenterOriginalDataReq struct { | |||
Platform string `json:"platform"` | |||
StartTime string `json:"start_time"` | |||
EndTime string `json:"end_time"` | |||
AppId string `json:"app_id"` | |||
} | |||
type DataCenterOriginalDataRes struct { | |||
@@ -257,6 +257,8 @@ func rDataCenter(r *gin.RouterGroup) { | |||
r.POST("/income/data/listForOpen", hdl.IncomeDataListForOpen) // 数据中心-收益报表(开放使用) | |||
r.POST("/income/data/list/output", hdl.IncomeDataListOutPut) // 数据中心-收益报表 | |||
r.POST("/income/data/detail", hdl.IncomeDataDetail) // 数据中心-收益报表-详情 | |||
r.GET("/income/data/select/data", hdl.DataCenterSelectData) //数据中心-收益报表-筛选条件 | |||
r.POST("/income/data/table", hdl.DataCenterTable) //数据中心-收益报表-数据图表 | |||
} | |||
@@ -2,6 +2,7 @@ package svc | |||
import ( | |||
"applet/app/e" | |||
"applet/app/enum" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
@@ -12,6 +13,8 @@ import ( | |||
"errors" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"github.com/jinzhu/copier" | |||
"time" | |||
) | |||
func DataCenterIncomeDataListForOpen(c *gin.Context, req md.DataCenterGenerateDataForOpenReq) md.DataCenterIncomeDataRes { | |||
@@ -64,7 +67,7 @@ func DataCenterIncomeDataList(c *gin.Context, req md.DataCenterGenerateDataReq) | |||
engine := db.Db | |||
NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine) | |||
user := GetUser(c) | |||
appId := GetAppletId(c, req.Name, req.Platform) | |||
appId := GetAppletId(c, req.Name, req.Platform, req.AppId) | |||
mediumId := GetMediumIdStr(c, user.AdmId, "", "") | |||
slotId := GetSlotId(c, req.State) | |||
MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMedium(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) | |||
@@ -113,7 +116,7 @@ func DataCenterIncomeDataListOutput(c *gin.Context, req md.DataCenterGenerateDat | |||
engine := db.Db | |||
NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine) | |||
user := GetUser(c) | |||
appId := GetAppletId(c, req.Name, req.Platform) | |||
appId := GetAppletId(c, req.Name, req.Platform, req.AppId) | |||
mediumId := GetMediumIdStr(c, user.AdmId, "", "") | |||
slotId := GetSlotId(c, req.State) | |||
req.Limit = "3000" | |||
@@ -246,7 +249,7 @@ func DataCenterGenerateDataList(c *gin.Context, req md.DataCenterGenerateDataReq | |||
engine := db.Db | |||
NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine) | |||
user := GetUser(c) | |||
appId := GetAppletId(c, req.Name, req.Platform) | |||
appId := GetAppletId(c, req.Name, req.Platform, req.AppId) | |||
mediumId := GetMediumIdStr(c, user.AdmId, "", "") | |||
slotId := GetSlotId(c, req.State) | |||
MediumList, total, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataList(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) | |||
@@ -399,3 +402,116 @@ func DataCenterGenerateDataDoing(c *gin.Context, req md.DataCenterGenerateDataCo | |||
} | |||
return nil | |||
} | |||
func DataCenterSelectData(c *gin.Context) { | |||
NewAppletApplicationDb := implement2.NewAppletApplicationDb(MasterDb(c)) | |||
appList, _ := NewAppletApplicationDb.FindAllAppletApplicationList() | |||
appMap := make(map[string][]map[string]interface{}) | |||
user := GetUser(c) | |||
NewAdminBindMediumDb := implement2.NewAdminBindMediumDb(MasterDb(c)) | |||
list := NewAdminBindMediumDb.FindAll(user.AdmId) | |||
ids := make([]string, 0) | |||
for _, v := range list { | |||
ids = append(ids, utils.IntToStr(v.MediumId)) | |||
} | |||
for _, v := range appList { | |||
if utils.InArr(utils.IntToStr(v.MediumId), ids) == false { | |||
continue | |||
} | |||
_, ok := appMap[v.Platform] | |||
if ok == false { | |||
appMap[v.Platform] = make([]map[string]interface{}, 0) | |||
} | |||
tmp := map[string]interface{}{ | |||
"name": v.Name, | |||
"app_id": v.AppId, | |||
"ad_type": enum.AdTypeList, | |||
} | |||
appMap[v.Platform] = append(appMap[v.Platform], tmp) | |||
} | |||
platform := []map[string]interface{}{ | |||
{ | |||
"name": "微信小程序", | |||
"platform": "wx_applet", | |||
"app_list": appMap["wx_applet"], | |||
}, | |||
} | |||
e.OutSuc(c, platform, nil) | |||
return | |||
} | |||
func DataCenterTable(c *gin.Context, req md.DataCenterTableReq) md.DataCenterTableRes { | |||
var req1 md.DataCenterRecordReq | |||
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"], | |||
ExposureCount: v["exposure_count"], | |||
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{ | |||
List: list, | |||
} | |||
return res | |||
} | |||
func comm(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string]string, int64) { | |||
appId := GetAppletId(c, req.Name, req.Platform, req.AppId) | |||
sql := ` | |||
SELECT | |||
%s | |||
FROM generate_wx_ad_data | |||
where %s %s | |||
` | |||
where := "is_generate_report=1 and uuid=" + c.GetString("mid") | |||
if req.AppId != "" || req.Platform != "" { | |||
where += " and app_id in('" + appId + "')" | |||
} | |||
if req.AdType != "" { | |||
where += " and ad_slot='" + req.AdType + "'" | |||
} | |||
if req.StartDate != "" { | |||
where += " and date>='" + req.StartDate + "'" | |||
} | |||
if req.EndDate != "" { | |||
where += " and date<='" + req.EndDate + "'" | |||
} | |||
field := `*` | |||
start := (utils.StrToInt(req.Page) - 1) * utils.StrToInt(req.Limit) | |||
groupBy := " order by date desc,id desc" | |||
if req.Page != "" { | |||
groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit | |||
} else { | |||
groupBy = " order by date asc,id asc" | |||
} | |||
sql1 := fmt.Sprintf(sql, field, where, groupBy) | |||
nativeString, _ := db.QueryNativeString(db.Db, sql1) | |||
var total int64 = 0 | |||
if isTotal == 1 { | |||
sqlTotal := fmt.Sprintf(sql, "COUNT(*) as count ", where, "") | |||
nativeStringTotal, _ := db.QueryNativeString(db.Db, sqlTotal) | |||
for _, v := range nativeStringTotal { | |||
total = utils.StrToInt64(v["count"]) | |||
} | |||
} | |||
return nativeString, total | |||
} |
@@ -22,7 +22,7 @@ func DataCenterOriginalDataList(c *gin.Context, req md.DataCenterOriginalDataReq | |||
engine := db.Db | |||
NewOriginalWxAdDataDb := implement.NewOriginalWxAdDataDb(engine) | |||
user := GetUser(c) | |||
appId := GetAppletIdByAdminId(c, user.AdmId, req.Name, req.Platform) | |||
appId := GetAppletIdByAdminId(c, user.AdmId, req.Name, req.Platform, req.AppId) | |||
slotId := GetSlotId(c, req.State) | |||
MediumList, total, _ := NewOriginalWxAdDataDb.FindOriginalWxAdDataList(c.GetString("mid"), appId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) | |||
data := make([]md.DataCenterOriginalDataData, 0) | |||
@@ -357,11 +357,14 @@ func OriginalDataOneApplicationTotal(c *gin.Context, req md.DataCenterOriginalDa | |||
} | |||
// 应用 | |||
func GetAppletId(c *gin.Context, name, platform string) string { | |||
mediumId := "" | |||
func GetAppletId(c *gin.Context, name, platform, appId string) string { | |||
appIds := "" | |||
sess := MasterDb(c).Where("1=1") | |||
var ids = make([]string, 0) | |||
if name != "" || platform != "" || appId != "" { | |||
ids = []string{"-1"} | |||
} | |||
if name != "" || platform != "" { | |||
ids := []string{"-1"} | |||
var tmp []model2.AppletApplication | |||
if name != "" { | |||
sess.And("name like ? ", "%"+name+"%") | |||
@@ -373,12 +376,18 @@ func GetAppletId(c *gin.Context, name, platform string) string { | |||
for _, v := range tmp { | |||
ids = append(ids, v.AppId) | |||
} | |||
mediumId = strings.Join(ids, ",") | |||
appIds = strings.Join(ids, ",") | |||
} | |||
return mediumId | |||
if appId != "" { | |||
ids = []string{appId} | |||
} | |||
if name != "" || appId != "" || platform != "" { | |||
appIds = strings.Join(ids, ",") | |||
} | |||
return appIds | |||
} | |||
func GetAppletIdByAdminId(c *gin.Context, admId int, name, platform string) string { | |||
appId := GetAppletId(c, name, platform) | |||
func GetAppletIdByAdminId(c *gin.Context, admId int, name, platform, appIdStr string) string { | |||
appId := GetAppletId(c, name, platform, appIdStr) | |||
appIds := []string{"-1"} | |||
NewAdminBindMediumDb := implement2.NewAdminBindMediumDb(MasterDb(c)) | |||
list := NewAdminBindMediumDb.FindAll(admId) | |||
@@ -38,6 +38,7 @@ require ( | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240830072333-a1980ffb256e | |||
code.fnuoos.com/zhimeng/model.git v0.0.3-0.20241028073907-ef7ecbd0db8d | |||
github.com/360EntSecGroup-Skylar/excelize v1.4.1 | |||
github.com/gin-contrib/cors v1.7.2 | |||
github.com/jinzhu/copier v0.4.0 | |||
) | |||
@@ -48,11 +49,9 @@ require ( | |||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect | |||
github.com/bytedance/sonic v1.11.6 // indirect | |||
github.com/bytedance/sonic/loader v0.1.1 // indirect | |||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | |||
github.com/cloudwego/base64x v0.1.4 // indirect | |||
github.com/cloudwego/iasm v0.2.0 // indirect | |||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect | |||
github.com/gin-contrib/cors v1.7.2 // indirect | |||
github.com/gin-contrib/sse v0.1.0 // indirect | |||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | |||
github.com/go-openapi/jsonreference v0.19.6 // indirect | |||