广告平台(媒体使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

222 lines
7.6 KiB

  1. package hdl
  2. import (
  3. "applet/app/e"
  4. "applet/app/lib/validate"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. db "code.fnuoos.com/zhimeng/model.git/src"
  9. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  10. "fmt"
  11. "github.com/boombuler/barcode"
  12. "github.com/boombuler/barcode/code128"
  13. "github.com/gin-gonic/gin"
  14. "github.com/jung-kurt/gofpdf"
  15. "image/jpeg"
  16. "net/url"
  17. "os"
  18. "strings"
  19. "time"
  20. )
  21. // SettleCenterList
  22. // @Summary 结算报表
  23. // @Tags 结算中心------嘉俊
  24. // @Description 结算中心-结算报表
  25. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  26. // @Accept json
  27. // @Produce json
  28. // @Param args body md.SettleCenterDataReq true "请求参数"
  29. // @Success 200 {object} md.SettleCenterDataRes "具体看返回内容 这是data里面的数据"
  30. // @Failure 400 {object} md.Response "具体错误"
  31. // @Router /api/settleCenter/list [POST]
  32. func SettleCenterList(c *gin.Context) {
  33. var req md.SettleCenterDataReq
  34. err := c.ShouldBindJSON(&req)
  35. if err != nil {
  36. err = validate.HandleValidateErr(err)
  37. err1 := err.(e.E)
  38. e.OutErr(c, err1.Code, err1.Error())
  39. return
  40. }
  41. res := svc.SettleCenterList(c, req)
  42. e.OutSuc(c, res, nil)
  43. return
  44. }
  45. // SettleCenterDetail
  46. // @Summary 结算报表-详情
  47. // @Tags 结算中心------嘉俊
  48. // @Description 结算中心-结算报表-详情
  49. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  50. // @Accept json
  51. // @Produce json
  52. // @Param args body md.CommDetailReq true "请求参数"
  53. // @Success 200 {object} md.SettleCenterDataDetailRes "具体看返回内容 这是data里面的数据"
  54. // @Failure 400 {object} md.Response "具体错误"
  55. // @Router /api/settleCenter/detail [POST]
  56. func SettleCenterDetail(c *gin.Context) {
  57. var req md.CommDetailReq
  58. err := c.ShouldBindJSON(&req)
  59. if err != nil {
  60. err = validate.HandleValidateErr(err)
  61. err1 := err.(e.E)
  62. e.OutErr(c, err1.Code, err1.Error())
  63. return
  64. }
  65. res := svc.SettleCenterDetail(c, req)
  66. e.OutSuc(c, res, nil)
  67. return
  68. }
  69. // SettleCenterSettleFileSave
  70. // @Summary 媒体详情-结算单保存
  71. // @Tags 财务中心------嘉俊
  72. // @Description 财务中心-媒体详情-结算单保存
  73. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  74. // @Accept json
  75. // @Produce json
  76. // @Param args body md.SettleFileReq true "请求参数"
  77. // @Success 200 {string} "具体看返回内容 这是data里面的数据"
  78. // @Failure 400 {object} md.Response "具体错误"
  79. // @Router /api/settleCenter/settle/file/save [POST]
  80. func SettleCenterSettleFileSave(c *gin.Context) {
  81. var req md.SettleFileReq
  82. err := c.ShouldBindJSON(&req)
  83. if err != nil {
  84. err = validate.HandleValidateErr(err)
  85. err1 := err.(e.E)
  86. e.OutErr(c, err1.Code, err1.Error())
  87. return
  88. }
  89. svc.SettleCenterSettleFileSave(c, req)
  90. }
  91. // SettleCenterInvoiceSave
  92. // @Summary 媒体详情-发票上传
  93. // @Tags 财务中心------嘉俊
  94. // @Description 财务中心-媒体详情-发票上传
  95. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  96. // @Accept json
  97. // @Produce json
  98. // @Param args body md.InvoiceReq true "请求参数"
  99. // @Success 200 {string} "具体看返回内容 这是data里面的数据"
  100. // @Failure 400 {object} md.Response "具体错误"
  101. // @Router /api/settleCenter/invoice/save [POST]
  102. func SettleCenterInvoiceSave(c *gin.Context) {
  103. var req md.InvoiceReq
  104. err := c.ShouldBindJSON(&req)
  105. if err != nil {
  106. err = validate.HandleValidateErr(err)
  107. err1 := err.(e.E)
  108. e.OutErr(c, err1.Code, err1.Error())
  109. return
  110. }
  111. svc.SettleCenterInvoiceSave(c, req)
  112. }
  113. func SettleCenterSettleFileDown(c *gin.Context) {
  114. path := "/data/advertisement-pdf"
  115. id := c.Query("id")
  116. engine := db.Db
  117. NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
  118. data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(id))
  119. NewMediumListDb := implement.NewMediumListDb(engine)
  120. medium, _ := NewMediumListDb.GetMediumList(data.MediumId)
  121. // 创建一个新的PDF文件
  122. pdf := gofpdf.New("P", "mm", "A4", "")
  123. // 添加一页
  124. pdf.AddPage()
  125. // 设置文本颜色(参数为RGB值)
  126. pdf.SetTextColor(0, 0, 0)
  127. // 换行
  128. pdf.Ln(-1)
  129. // 引入中文字体,需要相应的字体文件
  130. pdf.AddUTF8Font("SourceHanSansCN-Light", "", path+"/_0000000000_2024103011290507244911708.ttf")
  131. // 引入中文字体后设置中文字体和字号
  132. left := 15.0
  133. pdf.Image(path+"/_0000000000_2024103011210157735330925.png", left, 25, 50, 15, false, "PNG", 0, "")
  134. pdf.SetFont("SourceHanSansCN-Light", "", 10)
  135. pdf.Text(130, 40, "杭州激活鸟网络科技有限公司")
  136. //// 生成EAN-13条形码
  137. num := "jihuoniao-Ads-" + time.Now().Format("20060102") + "-" + utils.IntToStr(data.Id)
  138. cs, _ := code128.Encode(num)
  139. // 创建一个要输出数据的文件
  140. file, _ := os.Create(path + "/" + num + ".jpg")
  141. defer file.Close()
  142. // 设置图片像素大小
  143. qrCode, _ := barcode.Scale(cs, 350, 100)
  144. // 将code128的条形码编码为png图片
  145. jpeg.Encode(file, qrCode, nil)
  146. pdf.Image(path+"/"+num+".jpg", left, 50, 170, 30, false, "JPEG", 0, "")
  147. pdf.SetFont("SourceHanSansCN-Light", "", 28)
  148. pdf.Text(left, 95, "激活鸟 · 变现中心结算对账单")
  149. pdf.SetFont("SourceHanSansCN-Light", "", 12)
  150. pdf.Text(left, 105, "结 算 单 号 : "+num)
  151. pdf.Text(left, 115, "制 表 日 期 : "+time.Now().Format("2006/01/02"))
  152. date := ""
  153. if data.StartDate != "0000-00-00" && data.StartDate != "" {
  154. date = strings.ReplaceAll(data.StartDate, "-", ".")
  155. }
  156. if data.EndDate != "0000-00-00" && data.EndDate != "" {
  157. date += " - " + strings.ReplaceAll(data.EndDate, "-", ".")
  158. }
  159. pdf.Text(left, 125, "结 算 日 期 : "+date)
  160. pdf.Text(left, 135, "客 户 名 称 : "+medium.CompanyName)
  161. // 定义表格内容
  162. pdf.SetFont("SourceHanSansCN-Light", "", 12)
  163. table := []string{
  164. "业务类型", "基础收益(元)", "其他调整(元)", "实际结算总计(元)",
  165. "广告合作", utils.Float64ToStr(float64(data.BasicIncome) / 100), utils.Float64ToStr(float64(data.OtherIncome) / 100), utils.Float64ToStr(float64(data.BasicIncome+data.OtherIncome) / 100),
  166. }
  167. // 定义表格列数
  168. col := 4
  169. // 定义单元格位置
  170. cellWidth := 10.0 * 4
  171. cellHeight := 8.0
  172. x := left
  173. y := 140.0
  174. for i := 0; i < len(table); {
  175. pdf.SetXY(x, y)
  176. if i == col {
  177. cellHeight = 13
  178. }
  179. for j := 0; j < col; j++ {
  180. if i < len(table) {
  181. // 循环绘制单元格并输入内容
  182. pdf.CellFormat(cellWidth, cellHeight, table[i], "1", 0, "C", false, 0, "")
  183. }
  184. i++
  185. }
  186. y = y + cellHeight
  187. }
  188. pdf.SetFont("SourceHanSansCN-Light", "", 12)
  189. pdf.Text(100, 170, "实际结算总计(元):")
  190. pdf.Text(160, 170, utils.Float64ToStr(float64(data.BasicIncome+data.OtherIncome)/100))
  191. pdf.Text(210/2-20, 190, "数据确认回执栏")
  192. pdf.Line(left, 193, 180, 194)
  193. pdf.Text(left, 200, "数据确认")
  194. pdf.Text(left, 210, "公司(盖章或手印):")
  195. pdf.Text(left, 220, "授权人代表签字:")
  196. pdf.Text(left, 230, "日期:")
  197. // 保存PDF文件
  198. pdfName := medium.CompanyName + "(" + strings.ReplaceAll(date, "-", "") + ")结算单.pdf"
  199. err := pdf.OutputFileAndClose(path + "/" + pdfName)
  200. if err != nil {
  201. fmt.Println(err)
  202. return
  203. }
  204. c.Header("Content-Type", "application/octet-stream")
  205. c.Header("Content-Disposition", "attachment; filename="+url.QueryEscape(pdfName))
  206. c.Header("Content-Transfer-Encoding", "binary")
  207. c.File(path + "/" + pdfName)
  208. os.Remove(path + "/" + pdfName)
  209. file.Close()
  210. err = os.Remove(path + "/" + num + ".jpg")
  211. fmt.Println(err)
  212. return
  213. }