123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type ImageConfController struct {
- BaseAuthController
- }
- // AddImageMaterial
- // @Title 新增图片素材
- // @Description 新增图片素材
- // @Success 200 操作成功
- // @router /add/image/material [post]
- func (this *ImageConfController) AddImageMaterial() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req []*models.ImageConf
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + e.Error()
- return
- }
- // 校验图片名称是否重复
- for _, item := range req {
- if item.ImageType <= 0 {
- br.Msg = "请选择图片类型!"
- br.ErrMsg = "请选择图片类型!"
- return
- }
- if item.Url == "" {
- br.Msg = "请上传图片!"
- br.ErrMsg = "请上传图片!"
- return
- }
- // 校验名称是否重复
- imageConfByName, err := models.GetImageConfByName(item.ImageName)
- if err != nil {
- return
- }
- if imageConfByName != nil {
- br.Msg = "图片名称已存在,请重新上传!"
- br.ErrMsg = "图片名称已存在,请重新上传!"
- return
- }
- }
- err := models.BatchAddImageMaterials(req, len(req))
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- br.Msg = "操作成功"
- br.Ret = 200
- return
- }
- // AddImageMaterial
- // @Title 根据条件查询图片素材
- // @Description 根据条件查询图片素材
- // @Success
- // @router /add/get/image/material [get]
- func (this *ImageConfController) getImageMaterialList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- confType, err := this.GetInt("ConfType")
- if err != nil {
- return
- }
- if confType <= 0 {
- br.Msg = "请选择配置类型!"
- br.ErrMsg = "请选择配置类型!"
- return
- }
- imageType, err := this.GetInt("ImageType")
- if err != nil {
- return
- }
- if imageType <= 0 {
- br.Msg = "请选择图片类型!"
- br.ErrMsg = "请选择图片类型!"
- return
- }
- imageName := this.GetString("ImageName")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize := paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- condition += ` AND conf_type=? `
- pars = append(pars, confType)
- condition += ` AND image_type=? `
- pars = append(pars, imageType)
- if imageName != "" {
- condition += ` AND image_name LIKE '%` + imageName + `%' `
- }
- condition += ` ORDER BY modify_time DESC `
- condition += ` LIMIT ?, ? `
- pars = append(pars, pageSize, startSize)
- imageConfList, err := models.GetImageConfByCondition(condition, pars)
- br.Msg = "操作成功"
- br.Ret = 200
- br.Data = imageConfList
- return
- }
|