广告平台(站长下代理使用)
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

2 месяцев назад
2 недель назад
2 месяцев назад
2 недель назад
2 месяцев назад
2 недель назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. // SettleCenterMediumList
  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.SettleCenterMediumDataRes "具体看返回内容 这是data里面的数据"
  30. // @Failure 400 {object} md.Response "具体错误"
  31. // @Router /api/settleCenter/medium/list [POST]
  32. func SettleCenterMediumList(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.SettleCenterMediumList(c, req)
  42. e.OutSuc(c, res, nil)
  43. return
  44. }
  45. // SettleCenterList
  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.SettleCenterDataReq true "请求参数"
  53. // @Success 200 {object} md.SettleCenterDataRes "具体看返回内容 这是data里面的数据"
  54. // @Failure 400 {object} md.Response "具体错误"
  55. // @Router /api/settleCenter/agent/list [POST]
  56. func SettleCenterList(c *gin.Context) {
  57. var req md.SettleCenterDataReq
  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.SettleCenterList(c, req)
  66. e.OutSuc(c, res, nil)
  67. return
  68. }
  69. // SettleCenterDetail
  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.CommDetailReq true "请求参数"
  77. // @Success 200 {object} md.SettleCenterDataDetailRes "具体看返回内容 这是data里面的数据"
  78. // @Failure 400 {object} md.Response "具体错误"
  79. // @Router /api/settleCenter/agent/detail [POST]
  80. func SettleCenterDetail(c *gin.Context) {
  81. var req md.CommDetailReq
  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. res := svc.SettleCenterDetail(c, req)
  90. e.OutSuc(c, res, nil)
  91. return
  92. }
  93. // SettleCenterSettleFileSave
  94. // @Summary 渠道个人详情-结算单保存
  95. // @Tags 财务中心------嘉俊
  96. // @Description 财务中心-渠道个人详情-结算单保存
  97. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  98. // @Accept json
  99. // @Produce json
  100. // @Param args body md.SettleFileReq true "请求参数"
  101. // @Success 200 {string} "具体看返回内容 这是data里面的数据"
  102. // @Failure 400 {object} md.Response "具体错误"
  103. // @Router /api/settleCenter/agent/settle/file/save [POST]
  104. func SettleCenterSettleFileSave(c *gin.Context) {
  105. var req md.SettleFileReq
  106. err := c.ShouldBindJSON(&req)
  107. if err != nil {
  108. err = validate.HandleValidateErr(err)
  109. err1 := err.(e.E)
  110. e.OutErr(c, err1.Code, err1.Error())
  111. return
  112. }
  113. svc.SettleCenterSettleFileSave(c, req)
  114. }
  115. // SettleCenterInvoiceSave
  116. // @Summary 渠道个人详情-发票上传
  117. // @Tags 财务中心------嘉俊
  118. // @Description 财务中心-渠道个人详情-发票上传
  119. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  120. // @Accept json
  121. // @Produce json
  122. // @Param args body md.InvoiceReq true "请求参数"
  123. // @Success 200 {string} "具体看返回内容 这是data里面的数据"
  124. // @Failure 400 {object} md.Response "具体错误"
  125. // @Router /api/settleCenter/agent/invoice/save [POST]
  126. func SettleCenterInvoiceSave(c *gin.Context) {
  127. var req md.InvoiceReq
  128. err := c.ShouldBindJSON(&req)
  129. if err != nil {
  130. err = validate.HandleValidateErr(err)
  131. err1 := err.(e.E)
  132. e.OutErr(c, err1.Code, err1.Error())
  133. return
  134. }
  135. svc.SettleCenterInvoiceSave(c, req)
  136. }
  137. func SettleCenterSettleFileDown(c *gin.Context) {
  138. path := "/data/advertisement-pdf"
  139. id := c.Query("id")
  140. engine := db.Db
  141. NewMediumSettlementDb := implement.NewAgentSettlementDb(engine)
  142. data, _ := NewMediumSettlementDb.GetAgentSettlementById(utils.StrToInt(id))
  143. NewMediumListDb := implement.NewAgentListDb(engine)
  144. medium, _ := NewMediumListDb.GetAgentList(data.AgentId)
  145. // 创建一个新的PDF文件
  146. pdf := gofpdf.New("P", "mm", "A4", "")
  147. // 添加一页
  148. pdf.AddPage()
  149. // 设置文本颜色(参数为RGB值)
  150. pdf.SetTextColor(0, 0, 0)
  151. // 换行
  152. pdf.Ln(-1)
  153. // 引入中文字体,需要相应的字体文件
  154. pdf.AddUTF8Font("SourceHanSansCN-Light", "", path+"/_0000000000_2024103011290507244911708.ttf")
  155. // 引入中文字体后设置中文字体和字号
  156. left := 15.0
  157. pdf.Image(path+"/_0000000000_2024103011210157735330925.png", left, 25, 50, 15, false, "PNG", 0, "")
  158. pdf.SetFont("SourceHanSansCN-Light", "", 10)
  159. pdf.Text(130, 40, "杭州激活鸟网络科技有限公司")
  160. //// 生成EAN-13条形码
  161. num := "jihuoniao-Ads-agent-" + time.Now().Format("20060102") + "-" + utils.IntToStr(data.Id)
  162. cs, _ := code128.Encode(num)
  163. // 创建一个要输出数据的文件
  164. file, _ := os.Create(path + "/" + num + ".jpg")
  165. defer file.Close()
  166. // 设置图片像素大小
  167. qrCode, _ := barcode.Scale(cs, 350, 100)
  168. // 将code128的条形码编码为png图片
  169. jpeg.Encode(file, qrCode, nil)
  170. pdf.Image(path+"/"+num+".jpg", left, 50, 170, 30, false, "JPEG", 0, "")
  171. pdf.SetFont("SourceHanSansCN-Light", "", 28)
  172. pdf.Text(left, 95, "激活鸟 · 变现中心结算对账单")
  173. pdf.SetFont("SourceHanSansCN-Light", "", 12)
  174. pdf.Text(left, 105, "结 算 单 号 : "+num)
  175. pdf.Text(left, 115, "制 表 日 期 : "+time.Now().Format("2006/01/02"))
  176. date := ""
  177. if data.StartDate != "0000-00-00" && data.StartDate != "" {
  178. date = strings.ReplaceAll(data.StartDate, "-", ".")
  179. }
  180. if data.EndDate != "0000-00-00" && data.EndDate != "" {
  181. date += " - " + strings.ReplaceAll(data.EndDate, "-", ".")
  182. }
  183. pdf.Text(left, 125, "结 算 日 期 : "+date)
  184. pdf.Text(left, 135, "客 户 名 称 : "+medium.CompanyName)
  185. // 定义表格内容
  186. pdf.SetFont("SourceHanSansCN-Light", "", 12)
  187. table := []string{
  188. "业务类型", "基础收益(元)", "其他调整(元)", "实际结算总计(元)",
  189. "广告合作", utils.Float64ToStr(float64(data.BasicIncome) / 100), utils.Float64ToStr(float64(data.OtherIncome) / 100), utils.Float64ToStr(float64(data.BasicIncome+data.OtherIncome) / 100),
  190. }
  191. // 定义表格列数
  192. col := 4
  193. // 定义单元格位置
  194. cellWidth := 10.0 * 4
  195. cellHeight := 8.0
  196. x := left
  197. y := 140.0
  198. for i := 0; i < len(table); {
  199. pdf.SetXY(x, y)
  200. if i == col {
  201. cellHeight = 13
  202. }
  203. for j := 0; j < col; j++ {
  204. if i < len(table) {
  205. // 循环绘制单元格并输入内容
  206. pdf.CellFormat(cellWidth, cellHeight, table[i], "1", 0, "C", false, 0, "")
  207. }
  208. i++
  209. }
  210. y = y + cellHeight
  211. }
  212. pdf.SetFont("SourceHanSansCN-Light", "", 12)
  213. pdf.Text(100, 170, "实际结算总计(元):")
  214. pdf.Text(160, 170, utils.Float64ToStr(float64(data.BasicIncome+data.OtherIncome)/100))
  215. pdf.Text(210/2-20, 190, "数据确认回执栏")
  216. pdf.Line(left, 193, 180, 194)
  217. pdf.Text(left, 200, "数据确认")
  218. pdf.Text(left, 210, "公司(盖章或手印):")
  219. pdf.Text(left, 220, "授权人代表签字:")
  220. pdf.Text(left, 230, "日期:")
  221. // 保存PDF文件
  222. pdfName := medium.CompanyName + "(" + strings.ReplaceAll(date, " ", "") + ")结算单.pdf"
  223. err := pdf.OutputFileAndClose(path + "/" + pdfName)
  224. if err != nil {
  225. fmt.Println(err)
  226. return
  227. }
  228. c.Header("Content-Type", "application/octet-stream")
  229. c.Header("Content-Disposition", "attachment; filename="+url.QueryEscape(pdfName))
  230. c.Header("Content-Transfer-Encoding", "binary")
  231. c.File(path + "/" + pdfName)
  232. os.Remove(path + "/" + pdfName)
  233. file.Close()
  234. err = os.Remove(path + "/" + num + ".jpg")
  235. fmt.Println(err)
  236. return
  237. }