image_conf_controller.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. type ImageConfController struct {
  9. BaseAuthController
  10. }
  11. // AddImageMaterial
  12. // @Title 新增图片素材
  13. // @Description 新增图片素材
  14. // @Success 200 操作成功
  15. // @router /add/image/material [post]
  16. func (this *ImageConfController) AddImageMaterial() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. if br.ErrMsg == "" {
  20. br.IsSendEmail = false
  21. }
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. sysUser := this.SysUser
  26. if sysUser == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,SysUser Is Empty"
  29. br.Ret = 408
  30. return
  31. }
  32. var req []*models.ImageConf
  33. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  34. br.Msg = "参数解析异常!"
  35. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  36. return
  37. }
  38. // 校验图片名称是否重复
  39. for _, item := range req {
  40. if item.ImageType <= 0 {
  41. br.Msg = "请选择图片类型!"
  42. br.ErrMsg = "请选择图片类型!"
  43. return
  44. }
  45. if item.Url == "" {
  46. br.Msg = "请上传图片!"
  47. br.ErrMsg = "请上传图片!"
  48. return
  49. }
  50. // 校验名称是否重复
  51. imageConfByName, err := models.GetImageConfByName(item.ImageName)
  52. if err != nil {
  53. return
  54. }
  55. if imageConfByName != nil {
  56. br.Msg = "图片名称已存在,请重新上传!"
  57. br.ErrMsg = "图片名称已存在,请重新上传!"
  58. return
  59. }
  60. }
  61. err := models.BatchAddImageMaterials(req, len(req))
  62. if err != nil {
  63. br.Msg = "操作失败"
  64. br.ErrMsg = "操作失败,Err:" + err.Error()
  65. return
  66. }
  67. br.Msg = "操作成功"
  68. br.Ret = 200
  69. return
  70. }
  71. // AddImageMaterial
  72. // @Title 根据条件查询图片素材
  73. // @Description 根据条件查询图片素材
  74. // @Success
  75. // @router /add/get/image/material [get]
  76. func (this *ImageConfController) getImageMaterialList() {
  77. br := new(models.BaseResponse).Init()
  78. defer func() {
  79. if br.ErrMsg == "" {
  80. br.IsSendEmail = false
  81. }
  82. this.Data["json"] = br
  83. this.ServeJSON()
  84. }()
  85. sysUser := this.SysUser
  86. if sysUser == nil {
  87. br.Msg = "请登录"
  88. br.ErrMsg = "请登录,SysUser Is Empty"
  89. br.Ret = 408
  90. return
  91. }
  92. confType, err := this.GetInt("ConfType")
  93. if err != nil {
  94. return
  95. }
  96. if confType <= 0 {
  97. br.Msg = "请选择配置类型!"
  98. br.ErrMsg = "请选择配置类型!"
  99. return
  100. }
  101. imageType, err := this.GetInt("ImageType")
  102. if err != nil {
  103. return
  104. }
  105. if imageType <= 0 {
  106. br.Msg = "请选择图片类型!"
  107. br.ErrMsg = "请选择图片类型!"
  108. return
  109. }
  110. imageName := this.GetString("ImageName")
  111. pageSize, _ := this.GetInt("PageSize")
  112. currentIndex, _ := this.GetInt("CurrentIndex")
  113. if pageSize <= 0 {
  114. pageSize = utils.PageSize20
  115. }
  116. if currentIndex <= 0 {
  117. currentIndex = 1
  118. }
  119. startSize := paging.StartIndex(currentIndex, pageSize)
  120. var condition string
  121. var pars []interface{}
  122. condition += ` AND conf_type=? `
  123. pars = append(pars, confType)
  124. condition += ` AND image_type=? `
  125. pars = append(pars, imageType)
  126. if imageName != "" {
  127. condition += ` AND image_name LIKE '%` + imageName + `%' `
  128. }
  129. condition += ` ORDER BY modify_time DESC `
  130. condition += ` LIMIT ?, ? `
  131. pars = append(pars, pageSize, startSize)
  132. imageConfList, err := models.GetImageConfByCondition(condition, pars)
  133. br.Msg = "操作成功"
  134. br.Ret = 200
  135. br.Data = imageConfList
  136. return
  137. }