12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package controllers
- import (
- "encoding/json"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/services"
- )
- // Banner
- type BannerController struct {
- BaseAuthController
- }
- // @Title 列表
- // @Description 列表接口
- // @Success Ret=200 {object} cygx.CygxBannerListResp
- // @router /list [get]
- func (this *BannerController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- resp := new(models.CygxBannerListResp)
- var condition string
- var pars []interface{}
- condition += " AND art.status = 1 ORDER BY art. list_type ASC , art.sort ASC "
- list, err := models.GetCygxBannerList(condition, pars, 0, 99999)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- bannerImgList, err := models.GetCygxBannerImgList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- mapImg := make(map[int]string)
- for _, v := range bannerImgList {
- mapImg[v.ImgId] = v.IndexImg
- }
- for _, v := range list {
- v.IndexImg = mapImg[v.ImgId]
- v.BannerUrlResp = services.GetBannerUrlBody(v.Link)
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 记录点击信息
- // @Description 记录点击信息
- // @Param request body cygx.CygxBannerIdReq true "type json string"
- // @Success 200 Ret=200 发布成功
- // @router /add/history [post]
- func (this *BannerController) History() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var req models.CygxBannerIdReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- bannerId := req.BannerId
- if bannerId == 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,id不可为空"
- return
- }
- go services.AddCygxBannerHistory(user, bannerId)
- br.Ret = 200
- br.Success = true
- br.Msg = "记录成功"
- }
|