From 9aeb30dfb2d9ea5561b553694b358c4f395b1486 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Wed, 30 Oct 2024 16:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/hdl/hdl_settle_center.go | 116 +++++++++++++++++++++++++++++++++++ app/router/router.go | 5 +- app/svc/svc_data_center.go | 109 +++++++++++++++++++++++++++++--- app/svc/svc_index.go | 42 +++++++++++-- go.mod | 3 +- 5 files changed, 258 insertions(+), 17 deletions(-) diff --git a/app/hdl/hdl_settle_center.go b/app/hdl/hdl_settle_center.go index 46d5559..003fcea 100644 --- a/app/hdl/hdl_settle_center.go +++ b/app/hdl/hdl_settle_center.go @@ -5,7 +5,19 @@ import ( "applet/app/lib/validate" "applet/app/md" "applet/app/svc" + "applet/app/utils" + db "code.fnuoos.com/zhimeng/model.git/src" + "code.fnuoos.com/zhimeng/model.git/src/super/implement" + "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" + "strings" + "time" ) // SettleCenterMediumList @@ -128,3 +140,107 @@ func SettleCenterInvoiceSave(c *gin.Context) { } svc.SettleCenterInvoiceSave(c, req) } +func SettleCenterSettleFileDown(c *gin.Context) { + path := "/data/advertisement-pdf" + id := c.Query("id") + engine := db.Db + NewMediumSettlementDb := implement.NewAgentSettlementDb(engine) + data, _ := NewMediumSettlementDb.GetAgentSettlementById(utils.StrToInt(id)) + NewMediumListDb := implement.NewAgentListDb(engine) + medium, _ := NewMediumListDb.GetAgentList(data.AgentId) + // 创建一个新的PDF文件 + pdf := gofpdf.New("P", "mm", "A4", "") + // 添加一页 + pdf.AddPage() + // 设置文本颜色(参数为RGB值) + pdf.SetTextColor(0, 0, 0) + // 换行 + pdf.Ln(-1) + // 引入中文字体,需要相应的字体文件 + + pdf.AddUTF8Font("SourceHanSansCN-Light", "", path+"/_0000000000_2024103011290507244911708.ttf") + // 引入中文字体后设置中文字体和字号 + left := 15.0 + pdf.Image(path+"/_0000000000_2024103011210157735330925.png", left, 25, 50, 15, false, "PNG", 0, "") + pdf.SetFont("SourceHanSansCN-Light", "", 10) + pdf.Text(130, 40, "杭州激活鸟网络科技有限公司") + //// 生成EAN-13条形码 + num := "jihuoniao-Ads-agent-" + time.Now().Format("20060102") + "-" + utils.IntToStr(data.Id) + cs, _ := code128.Encode(num) + // 创建一个要输出数据的文件 + + file, _ := os.Create(path + "/" + num + ".jpg") + defer file.Close() + // 设置图片像素大小 + qrCode, _ := barcode.Scale(cs, 350, 100) + // 将code128的条形码编码为png图片 + jpeg.Encode(file, qrCode, nil) + pdf.Image(path+"/"+num+".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, "结 算 单 号 : "+num) + pdf.Text(left, 115, "制 表 日 期 : "+time.Now().Format("2006/01/02")) + date := "" + if data.StartDate != "0000-00-00" && data.StartDate != "" { + date = strings.ReplaceAll(data.StartDate, "-", ".") + } + if data.EndDate != "0000-00-00" && data.EndDate != "" { + date += " - " + strings.ReplaceAll(data.EndDate, "-", ".") + } + pdf.Text(left, 125, "结 算 日 期 : "+date) + pdf.Text(left, 135, "客 户 名 称 : "+medium.CompanyName) + // 定义表格内容 + pdf.SetFont("SourceHanSansCN-Light", "", 12) + table := []string{ + "业务类型", "基础收益(元)", "其他调整(元)", "实际结算总计(元)", + "广告合作", utils.Float64ToStr(float64(data.BasicIncome) / 100), utils.Float64ToStr(float64(data.OtherIncome) / 100), utils.Float64ToStr(float64(data.BasicIncome+data.OtherIncome) / 100), + } + // 定义表格列数 + 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, utils.Float64ToStr(float64(data.BasicIncome+data.OtherIncome)/100)) + 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 := medium.CompanyName + "(" + strings.ReplaceAll(date, " ", "") + ")结算单.pdf" + err := pdf.OutputFileAndClose(path + "/" + 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(path + "/" + pdfName) + os.Remove(path + "/" + pdfName) + file.Close() + err = os.Remove(path + "/" + num + ".jpg") + fmt.Println(err) + return +} diff --git a/app/router/router.go b/app/router/router.go index abac72f..7011ba3 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -51,8 +51,9 @@ func Init() *gin.Engine { func route(r *gin.RouterGroup) { r.GET("/test", hdl.Demo) - r.POST("/qiniuyun/callback", hdl.FileImgCallback) //七牛云回调 - r.Use(mw.DB) // 以下接口需要用到数据库 + r.POST("/qiniuyun/callback", hdl.FileImgCallback) //七牛云回调 + r.GET("/settle/file/down", hdl.SettleCenterSettleFileDown) //结算中心-结算报表-结算单下载 + r.Use(mw.DB) // 以下接口需要用到数据库 { r.GET("/base", hdl.LoginBase) r.POST("/login", hdl.Login) diff --git a/app/svc/svc_data_center.go b/app/svc/svc_data_center.go index 4215dc7..6d5a155 100644 --- a/app/svc/svc_data_center.go +++ b/app/svc/svc_data_center.go @@ -27,9 +27,27 @@ func DataCenterRecordTotal(c *gin.Context, req md.DataCenterTableReq) md.DataCen where %s ` mediumId := GetAgentMediumId(c) - where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")" + ex := strings.Split(mediumId, ",") + str := "" + for _, v := range ex { + if str == "" { + str += "'" + v + "'" + } else { + str += ",'" + v + "'" + } + } + where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + str + ")" if req.AppId != "" || req.Platform != "" { - where += " and app_id in('" + appId + "')" + ex1 := strings.Split(appId, ",") + str1 := "" + for _, v := range ex1 { + if str1 == "" { + str1 += "'" + v + "'" + } else { + str1 += ",'" + v + "'" + } + } + where += " and app_id in('" + str1 + "')" } if req.AdType != "" { where += " and ad_slot='" + req.AdType + "'" @@ -166,7 +184,16 @@ func DataCenterCommissionRecordTotal(c *gin.Context, req md.DataCenterTableReq) mediumId := GetAgentMediumId(c) where := "is_generate_report=1 and uuid=" + c.GetString("mid") if req.AppId != "" || req.Platform != "" { - where += " and app_id in('" + appId + "')" + ex1 := strings.Split(appId, ",") + str1 := "" + for _, v := range ex1 { + if str1 == "" { + str1 += "'" + v + "'" + } else { + str1 += ",'" + v + "'" + } + } + where += " and app_id in('" + str1 + "')" } if req.AdType != "" { where += " and ad_slot='" + req.AdType + "'" @@ -177,7 +204,16 @@ func DataCenterCommissionRecordTotal(c *gin.Context, req md.DataCenterTableReq) if req.EndDate != "" { where += " and date<='" + req.EndDate + "'" } - whereMedium := where + " and medium_id in(" + mediumId + ")" + ex := strings.Split(mediumId, ",") + str := "" + for _, v := range ex { + if str == "" { + str += "'" + v + "'" + } else { + str += ",'" + v + "'" + } + } + whereMedium := where + " and medium_id in(" + str + ")" sql = fmt.Sprintf(sql, whereMedium) nativeString, _ := db.QueryNativeString(db.Db, sql) res := md.DataCenterCommissionTotalData{} @@ -400,9 +436,27 @@ func comm(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string where %s %s ` mediumId := GetAgentMediumId(c) - where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")" + ex := strings.Split(mediumId, ",") + str := "" + for _, v := range ex { + if str == "" { + str += "'" + v + "'" + } else { + str += ",'" + v + "'" + } + } + where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + str + ")" if req.AppId != "" || req.Platform != "" { - where += " and app_id in('" + appId + "')" + ex1 := strings.Split(appId, ",") + str1 := "" + for _, v := range ex1 { + if str1 == "" { + str1 += "'" + v + "'" + } else { + str1 += ",'" + v + "'" + } + } + where += " and app_id in('" + str1 + "')" } if req.AdType != "" { where += " and ad_slot='" + req.AdType + "'" @@ -448,7 +502,16 @@ func commAgentProfit(c *gin.Context, isTotal int, req md.DataCenterProfitRecordR user := GetUser(c) where := "g.is_generate_report=1 and gf.uuid=" + c.GetString("mid") + " and gf.agent_id =" + utils.IntToStr(user.AgentId) if req.AppId != "" || req.Platform != "" { - where += " and gf.app_id in('" + appId + "')" + ex1 := strings.Split(appId, ",") + str1 := "" + for _, v := range ex1 { + if str1 == "" { + str1 += "'" + v + "'" + } else { + str1 += ",'" + v + "'" + } + } + where += " and gf.app_id in('" + str1 + "')" } if req.StartDate != "" { where += " and gf.date >= '" + req.StartDate + "'" @@ -498,9 +561,27 @@ func commAgent(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[s where %s %s ` mediumId := GetAgentMediumId(c) - where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")" + ex := strings.Split(mediumId, ",") + str := "" + for _, v := range ex { + if str == "" { + str += "'" + v + "'" + } else { + str += ",'" + v + "'" + } + } + where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + str + ")" if req.AppId != "" || req.Platform != "" { - where += " and app_id in('" + appId + "')" + ex1 := strings.Split(appId, ",") + str1 := "" + for _, v := range ex1 { + if str1 == "" { + str1 += "'" + v + "'" + } else { + str1 += ",'" + v + "'" + } + } + where += " and app_id in('" + str1 + "')" } if req.AdType != "" { where += " and ad_slot='" + req.AdType + "'" @@ -544,7 +625,15 @@ func commAgent(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[s where %s ` user := GetUser(c) - whereAgent := "is_generate_report=1 and original_data_id in(" + strings.Join(ids, ",") + ") and agent_id=" + utils.IntToStr(user.AgentId) + str1 := "" + for _, v := range ids { + if str1 == "" { + str1 += "'" + v + "'" + } else { + str1 += ",'" + v + "'" + } + } + whereAgent := "is_generate_report=1 and original_data_id in(" + str1 + ") and agent_id=" + utils.IntToStr(user.AgentId) sqlAgent = fmt.Sprintf(sqlAgent, whereAgent) nativeStringAgent, _ := db.QueryNativeString(db.Db, sqlAgent) agentMap := make(map[string]map[string]string) diff --git a/app/svc/svc_index.go b/app/svc/svc_index.go index 2d58712..b43037f 100644 --- a/app/svc/svc_index.go +++ b/app/svc/svc_index.go @@ -141,7 +141,16 @@ func commTotal(c *gin.Context, startDate, endDate string) []map[string]string { where %s ` mediumId := GetAgentMediumId(c) - where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")" + ex := strings.Split(mediumId, ",") + str := "" + for _, v := range ex { + if str == "" { + str += "'" + v + "'" + } else { + str += ",'" + v + "'" + } + } + where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + str + ")" if startDate != "" { where += " and date>='" + startDate + "'" } @@ -199,7 +208,16 @@ func commTotalByApp(c *gin.Context, req md.IndexAppListReq, appId []string) []ma where %s group by app_id order by %s,id asc limit 20 ` mediumId := GetAgentMediumId(c) - where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")" + ex := strings.Split(mediumId, ",") + str := "" + for _, v := range ex { + if str == "" { + str += "'" + v + "'" + } else { + str += ",'" + v + "'" + } + } + where := "is_generate_report=1 and uuid=" + c.GetString("mid") + " and medium_id in(" + str + ")" if req.StartDate != "" { where += " and date>='" + req.StartDate + "'" } @@ -207,7 +225,15 @@ func commTotalByApp(c *gin.Context, req md.IndexAppListReq, appId []string) []ma where += " and date<='" + req.EndDate + "'" } if len(appId) > 0 { - where += " and app_id in('" + strings.Join(appId, ",") + "')" + str1 := "" + for _, v := range appId { + if str1 == "" { + str1 += "'" + v + "'" + } else { + str1 += ",'" + v + "'" + } + } + where += " and app_id in('" + str1 + "')" } if req.Sort == "" { req.Sort = "media_revenue desc" @@ -278,7 +304,15 @@ func commTotalByDate(c *gin.Context, startDate, endDate string, appId []string) where += " and date<='" + endDate + "'" } if len(appId) > 0 { - where += " and app_id in('" + strings.Join(appId, ",") + "')" + str1 := "" + for _, v := range appId { + if str1 == "" { + str1 += "'" + v + "'" + } else { + str1 += ",'" + v + "'" + } + } + where += " and app_id in('" + str1 + "')" } sql = fmt.Sprintf(sql, where) nativeString, err := db.QueryNativeString(db.Db, sql) diff --git a/go.mod b/go.mod index c69bb44..e7b56b5 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( ) require ( - code.fnuoos.com/zhimeng/model.git v0.0.3-0.20241009095023-24f5079bb959 + code.fnuoos.com/zhimeng/model.git v0.0.3-0.20241030074222-64103a1c8c40 github.com/360EntSecGroup-Skylar/excelize v1.4.1 ) @@ -70,6 +70,7 @@ 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/kennygrant/sanitize v1.2.4 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/leodido/go-urn v1.2.1 // indirect