diff --git a/app/hdl/hdl_demo1.go b/app/hdl/hdl_demo1.go new file mode 100644 index 0000000..da0be88 --- /dev/null +++ b/app/hdl/hdl_demo1.go @@ -0,0 +1,96 @@ +package hdl + +import ( + "fmt" + "github.com/boombuler/barcode" + "github.com/boombuler/barcode/code128" + "github.com/gin-gonic/gin" + "github.com/jung-kurt/gofpdf" + "image/jpeg" + "net/url" + "os" +) + +func Demo1(c *gin.Context) { + // 创建一个新的PDF文件 + pdf := gofpdf.New("P", "mm", "A4", "") + // 添加一页 + pdf.AddPage() + // 设置文本颜色(参数为RGB值) + pdf.SetTextColor(0, 0, 0) + // 换行 + pdf.Ln(-1) + // 引入中文字体,需要相应的字体文件 + pdf.AddUTF8Font("SourceHanSansCN-Light", "", "./static/SourceHanSansCN-Light.ttf") + // 引入中文字体后设置中文字体和字号 + left := 15.0 + pdf.Image("./static/图片1.png", left, 25, 50, 15, false, "PNG", 0, "") + pdf.SetFont("SourceHanSansCN-Light", "", 10) + pdf.Text(130, 40, "杭州激活鸟网络科技有限公司") + //// 生成EAN-13条形码 + cs, _ := code128.Encode("jihuoniao-Ads-20240913-7653481486") + // 创建一个要输出数据的文件 + file, _ := os.Create("./static/1.jpg") + defer file.Close() + // 设置图片像素大小 + qrCode, _ := barcode.Scale(cs, 350, 100) + // 将code128的条形码编码为png图片 + jpeg.Encode(file, qrCode, nil) + pdf.Image("./static/1.jpg", left, 50, 170, 30, false, "JPEG", 0, "") + pdf.SetFont("SourceHanSansCN-Light", "", 28) + pdf.Text(left, 95, "激活鸟 · 变现中心结算对账单") + pdf.SetFont("SourceHanSansCN-Light", "", 12) + pdf.Text(left, 105, "结 算 单 号 : jihuoniao-Ads-20240913-7653481486") + pdf.Text(left, 115, "制 表 日 期 : 2024/10/29") + pdf.Text(left, 125, "结 算 日 期 : 2024.08.01 - 2024.08.31") + pdf.Text(left, 135, "客 户 名 称 : 天津公交易通科技有限公司") + // 定义表格内容 + pdf.SetFont("SourceHanSansCN-Light", "", 12) + table := []string{ + "业务类型", "基础收益(元)", "其他调整(元)", "实际结算总计(元)", + "广告合作", "1", "2", "3", + } + // 定义表格列数 + col := 4 + // 定义单元格位置 + cellWidth := 10.0 * 4 + cellHeight := 8.0 + x := left + y := 140.0 + for i := 0; i < len(table); { + pdf.SetXY(x, y) + if i == col { + cellHeight = 13 + } + for j := 0; j < col; j++ { + if i < len(table) { + // 循环绘制单元格并输入内容 + pdf.CellFormat(cellWidth, cellHeight, table[i], "1", 0, "C", false, 0, "") + } + i++ + } + y = y + cellHeight + } + pdf.SetFont("SourceHanSansCN-Light", "", 12) + pdf.Text(100, 170, "实际结算总计(元):") + pdf.Text(160, 170, "63531.08") + pdf.Text(210/2-20, 190, "数据确认回执栏") + pdf.Line(left, 193, 180, 194) + pdf.Text(left, 200, "数据确认") + pdf.Text(left, 210, "公司(盖章或手印):") + pdf.Text(left, 220, "授权人代表签字:") + pdf.Text(left, 230, "日期:") + + // 保存PDF文件 + pdfName := "hello.pdf" + err := pdf.OutputFileAndClose("./static/" + pdfName) + if err != nil { + fmt.Println(err) + return + } + c.Header("Content-Type", "application/octet-stream") + c.Header("Content-Disposition", "attachment; filename="+url.QueryEscape(pdfName)) + c.Header("Content-Transfer-Encoding", "binary") + c.File("./static/" + pdfName) + return +} diff --git a/app/router/router.go b/app/router/router.go index 5362cf9..b2c5be7 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -72,6 +72,7 @@ func Init() *gin.Engine { func route(r *gin.RouterGroup) { r.GET("/test", hdl.Demo) + r.GET("/test1", hdl.Demo1) r.GET("/getAuthToken", hdl.GetAuthToken) r.GET("/authorize", hdl.AppletAuthorize) diff --git a/app/svc/svc_data_center_generate_data.go b/app/svc/svc_data_center_generate_data.go index 0c87d32..6c585b4 100644 --- a/app/svc/svc_data_center_generate_data.go +++ b/app/svc/svc_data_center_generate_data.go @@ -2,7 +2,6 @@ package svc import ( "applet/app/e" - "applet/app/enum" "applet/app/md" "applet/app/utils" "applet/app/utils/cache" @@ -425,10 +424,22 @@ func DataCenterSelectData(c *gin.Context) { if ok == false { appMap[v.Platform] = make([]map[string]interface{}, 0) } + NewAppletApplicationAdSpaceListDb := implement2.NewAppletApplicationAdSpaceListDb(MasterDb(c)) + adList, _ := NewAppletApplicationAdSpaceListDb.FindAppletApplicationAdSpaceListByAppidIds(v.AppId) + adData := make([]md.SelectData, 0) + if adList != nil { + for _, v1 := range *adList { + tmp1 := md.SelectData{ + Name: v1.Name, + Value: v1.AdId, + } + adData = append(adData, tmp1) + } + } tmp := map[string]interface{}{ "name": v.Name, "app_id": v.AppId, - "ad_type": enum.AdTypeList, + "ad_type": adData, } appMap[v.Platform] = append(appMap[v.Platform], tmp) } @@ -454,7 +465,7 @@ func DataCenterTable(c *gin.Context, req md.DataCenterTableReq) md.DataCenterTab Date: v["date"], ExposureCount: v["exposure_count"], MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100), - Ecpm: v["ecpm"], + Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100), } tmpMap[v["date"]] = tmp } @@ -513,8 +524,7 @@ func comm(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string where += " and app_id in(" + str + ")" } if req.AdType != "" { - adType, _ := GetSlotIds(c, req.AdType) - where += " and slot_id in(" + adType + ")" + where += " and slot_id in('" + req.AdType + "')" } if req.StartDate != "" { where += " and date>='" + req.StartDate + "'" @@ -528,9 +538,9 @@ func comm(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string if req.Page != "" { groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit } else { - groupBy = " order by date asc,id asc" + field = "SUM(ecpm) AS ecpm,SUM(media_revenue) AS media_revenue,SUM(exposure_count) AS exposure_count,date" + groupBy = " group by date order by date asc,id asc" } - sql1 := fmt.Sprintf(sql, field, where, groupBy) nativeString, _ := db.QueryNativeString(db.Db, sql1) diff --git a/app/svc/svc_data_center_original_data.go b/app/svc/svc_data_center_original_data.go index c572d6d..3b09ee9 100644 --- a/app/svc/svc_data_center_original_data.go +++ b/app/svc/svc_data_center_original_data.go @@ -430,6 +430,16 @@ func GetSlotId(c *gin.Context, state string) string { return mediumId } func GetSlotIds(c *gin.Context, adType string) (string, string) { + adId := "" + adIds := "" + if adType != "" { + adId = "'" + adType + "'" + ids := []string{adType} + adIds = strings.Join(ids, ",") + } + return adId, adIds +} +func GetSlotIds1(c *gin.Context, adType string) (string, string) { adId := "" adIds := "" if adType != "" { diff --git a/go.mod b/go.mod index dacd484..7a927d3 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ go 1.18 require ( github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 - github.com/boombuler/barcode v1.0.1 github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/forgoer/openssl v0.0.0-20201023062029-c3112b0c8700 @@ -36,10 +35,12 @@ require ( 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.20241029093801-ac7d9e08df0e + code.fnuoos.com/zhimeng/model.git v0.0.3-0.20241030025944-2a0971f8eb9d github.com/360EntSecGroup-Skylar/excelize v1.4.1 github.com/gin-contrib/cors v1.7.2 github.com/jinzhu/copier v0.4.0 + github.com/signintech/gopdf v0.28.0 + github.com/tealeg/xlsx v1.0.5 ) require ( @@ -47,6 +48,7 @@ require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/boombuler/barcode v1.0.2 // indirect github.com/bytedance/sonic v1.11.6 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cloudwego/base64x v0.1.4 // indirect @@ -59,6 +61,7 @@ require ( github.com/go-openapi/swag v0.19.15 // indirect github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/goccy/go-json v0.10.2 // indirect + github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/gookit/color v1.3.8 // indirect github.com/gorilla/context v1.1.1 // indirect @@ -66,7 +69,9 @@ require ( github.com/gorilla/sessions v1.2.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/jung-kurt/gofpdf v1.16.2 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/ledongthuc/pdf v0.0.0-20240201131950-da5b75280b06 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -74,6 +79,7 @@ require ( 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.2.1 // indirect + github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/streadway/amqp v1.0.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect @@ -83,6 +89,7 @@ require ( go.uber.org/multierr v1.6.0 // indirect golang.org/x/arch v0.7.0 // indirect golang.org/x/crypto v0.22.0 // indirect + golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a // indirect golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sync v0.1.0 // indirect