浏览代码

更新

master
huangjiajun 4 周前
父节点
当前提交
6031bf3608
共有 5 个文件被更改,包括 133 次插入6 次删除
  1. +12
    -0
      app/hdl/hdl_data_center_generate_data.go
  2. +7
    -6
      app/router/router.go
  3. +76
    -0
      app/svc/svc_data_center_generate_data.go
  4. +36
    -0
      app/utils/xls.go
  5. +2
    -0
      go.mod

+ 12
- 0
app/hdl/hdl_data_center_generate_data.go 查看文件

@@ -58,6 +58,18 @@ func IncomeDataList(c *gin.Context) {
e.OutSuc(c, res, nil)
return
}
func IncomeDataListOutPut(c *gin.Context) {
var req md.DataCenterGenerateDataReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
svc.DataCenterIncomeDataListOutput(c, req)

}

// IncomeDataDetail
// @Summary 收益报表-详情


+ 7
- 6
app/router/router.go 查看文件

@@ -228,12 +228,13 @@ func rDataCenter(r *gin.RouterGroup) {
r.POST("/original/data/one/application/doing", hdl.OriginalDataOneApplicationDoing) // 数据中心-原始数据-单个应用数据操作
r.GET("/original/data/one/application/state", hdl.OriginalDataOneApplicationState) // 数据中心-原始数据-单个应用数据操作后的完成状态

r.POST("/generate/data/list", hdl.GenerateDataList) // 数据中心-分成数据
r.POST("/generate/data/del", hdl.GenerateDataDel) // 数据中心-分成数据-删除
r.POST("/generate/data/detail", hdl.GenerateDataDetail) // 数据中心-分成数据-详情
r.POST("/generate/data/doing", hdl.GenerateDataDoing) // 数据中心-分成数据-报表生成操作
r.POST("/income/data/list", hdl.IncomeDataList) // 数据中心-收益报表
r.POST("/income/data/detail", hdl.IncomeDataDetail) // 数据中心-收益报表-详情
r.POST("/generate/data/list", hdl.GenerateDataList) // 数据中心-分成数据
r.POST("/generate/data/del", hdl.GenerateDataDel) // 数据中心-分成数据-删除
r.POST("/generate/data/detail", hdl.GenerateDataDetail) // 数据中心-分成数据-详情
r.POST("/generate/data/doing", hdl.GenerateDataDoing) // 数据中心-分成数据-报表生成操作
r.POST("/income/data/list", hdl.IncomeDataList) // 数据中心-收益报表
r.POST("/income/data/list/output", hdl.IncomeDataListOutPut) // 数据中心-收益报表
r.POST("/income/data/detail", hdl.IncomeDataDetail) // 数据中心-收益报表-详情

}



+ 76
- 0
app/svc/svc_data_center_generate_data.go 查看文件

@@ -62,6 +62,82 @@ func DataCenterIncomeDataList(c *gin.Context, req md.DataCenterGenerateDataReq)
}
return res
}
func DataCenterIncomeDataListOutput(c *gin.Context, req md.DataCenterGenerateDataReq) {
engine := db.Db
NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(engine)
user := GetUser(c)
appId := GetAppletId(c, req.Name, req.Platform)
mediumId := GetMediumIdStr(c, user.AdmId, "", "")
slotId := GetSlotId(c, req.State)
req.Limit = "3000"
MediumList, _, _ := NewGenerateWxAdDataDb.FindGenerateWxAdDataListMedium(c.GetString("mid"), appId, mediumId, slotId, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
data := map[string]string{
"A1": "名称",
"B1": "日期",
"C1": "广告位",
"D1": "曝光量",
"E1": "点击率(%)",
"F1": "点击量",
"G1": "结算平台",
"H1": "媒体-ECPM",
"I1": "媒体收益(元)",
"J1": "代理收益(元)",
"K1": "平台收益(元)",
}
name := "运营报表第" + req.Page + "页"

if len(MediumList) > 0 {
for k, v := range MediumList {
var tmp = md.DataCenterIncomeDataData{
AgreementSharing: utils.Float64ToStr(float64(v.AgreementSharing) / 100),
AgentRevenue: utils.Float64ToStr(float64(v.AgentRevenue) / 100),
Id: utils.IntToStr(v.Id),
ExposureCount: utils.IntToStr(v.ExposureCount),
ClickCount: utils.IntToStr(v.ClickCount),
ClickRate: v.ClickRate,
Ecpm: utils.Float64ToStr(utils.StrToFloat64(v.Ecpm) / 100),
Date: v.Date,
MediaRevenue: utils.Float64ToStr(float64(v.MediaRevenue) / 100),
SettleAmount: utils.Float64ToStr(float64(v.MediaRevenue+v.AgentRevenue+v.AgreementSharing) / 100),
}
tmpApplet := GetAppletInfo(c, v.AppId)
if tmpApplet["platform"] != "" {
tmp.Platform = tmpApplet["platform"]
}
if tmpApplet["name"] != "" {
tmp.Name = tmpApplet["name"]
}
tmpSlot := GetSlotInfo(c, v.SlotId)
if tmpSlot["state"] != "" {
tmp.State = tmpSlot["state"]
}
if tmpSlot["name"] != "" {
tmp.AdvName = tmpSlot["name"]
}
i := utils.IntToStr(k + 2)
data["A"+i] = tmp.Name
data["B"+i] = tmp.Date
data["C"+i] = tmp.AdvName
data["D"+i] = tmp.ExposureCount
data["E"+i] = tmp.ClickRate
data["F"+i] = tmp.ClickCount
data["G"+i] = tmp.Platform
data["H"+i] = tmp.Ecpm
data["I"+i] = tmp.MediaRevenue
data["J"+i] = tmp.AgentRevenue
data["K"+i] = tmp.AgreementSharing
}
}

file := utils.Output(c, name, data)
filename := name + ".xlsx"
r := map[string]string{
"file": file,
"filename": filename,
}
e.OutSuc(c, r, nil)
return
}
func DataCenterIncomeDataDetail(c *gin.Context, req md.DataCenterGenerateDataCommReq) {
NewGenerateWxAdDataDb := implement.NewGenerateWxAdDataDb(db.Db)
data, _ := NewGenerateWxAdDataDb.GetGenerateWxAdData(utils.StrToInt(req.Id))


+ 36
- 0
app/utils/xls.go 查看文件

@@ -0,0 +1,36 @@
package utils

import (
"bytes"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/gin-gonic/gin"
"io/ioutil"
)

func Output(c *gin.Context, name string, data map[string]string) string {
//创建excel文件
xlsx := excelize.NewFile()
//创建新表单
index := xlsx.NewSheet(name)
for k, v := range data {
//设置单元格的值
xlsx.SetCellValue(name, k, v)
}
//设置默认打开的表单
xlsx.SetActiveSheet(index)
////保存文件到指定路径
//err := xlsx.SaveAs("./" + name + ".xlsx")
//if err != nil {
// log.Fatal(err)
//}
//_ = file.Save(fileName)
c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name+".xlsx"))
c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
var buffer bytes.Buffer
_ = xlsx.Write(&buffer)
r := bytes.NewReader(buffer.Bytes())
fSrc, _ := ioutil.ReadAll(r)
str := "data:application/vnd.ms-excel;base64," + Base64RawStdEncode(string(fSrc))
return str
}

+ 2
- 0
go.mod 查看文件

@@ -37,6 +37,7 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
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.20241025040814-725e7331c9a8
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/jinzhu/copier v0.4.0
)

@@ -67,6 +68,7 @@ require (
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/streadway/amqp v1.0.0 // indirect


正在加载...
取消
保存