|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- package hdl
-
- import (
- "applet/app/e"
- "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
- // @Summary 媒体列表
- // @Tags 结算中心------嘉俊
- // @Description 结算中心-媒体列表
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.SettleCenterDataReq true "请求参数"
- // @Success 200 {object} md.SettleCenterDataRes "具体看返回内容 这是data里面的数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/settleCenter/medium/list [POST]
- func SettleCenterMediumList(c *gin.Context) {
- var req md.SettleCenterDataReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- res := svc.SettleCenterMediumList(c, req)
- e.OutSuc(c, res, nil)
- return
- }
-
- // SettleCenterMediumSave
- // @Summary 媒体修改结算方式
- // @Tags 结算中心------嘉俊
- // @Description 结算中心-媒体修改结算方式
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.SettleCenterDataSaveReq true "请求参数"
- // @Success 200 {string} "具体看返回内容 这是data里面的数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/settleCenter/medium/save [POST]
- func SettleCenterMediumSave(c *gin.Context) {
- var req md.SettleCenterDataSaveReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- svc.SettleCenterMediumSave(c, req)
- }
-
- // SettleCenterMediumDetail
- // @Summary 媒体详情
- // @Tags 结算中心------嘉俊
- // @Description 结算中心-媒体详情
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.SettleCenterDataDetailReq true "请求参数"
- // @Success 200 {object} md.SettleCenterDataDetailRes "具体看返回内容 这是data里面的数据"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/settleCenter/medium/detail [POST]
- func SettleCenterMediumDetail(c *gin.Context) {
- var req md.SettleCenterDataDetailReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- res := svc.SettleCenterMediumDetail(c, req)
- e.OutSuc(c, res, nil)
- return
- }
- func SettleCenterSettleFileDown(c *gin.Context) {
- path := "/data/advertisement-pdf"
- id := c.Query("id")
- engine := db.Db
- NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
- data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(id))
- NewMediumListDb := implement.NewMediumListDb(engine)
- medium, _ := NewMediumListDb.GetMediumList(data.MediumId)
- // 创建一个新的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-" + 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 := num + ".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
- }
- func AgentSettleCenterSettleFileDown(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 := num + ".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
- }
|