image_conf_controller.go 3.0 KB

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