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