image_conf_controller.go 3.2 KB

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