|
@@ -0,0 +1,203 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "hongze/hongze_clpt/models"
|
|
|
+ "hongze/hongze_clpt/services"
|
|
|
+)
|
|
|
+
|
|
|
+// Banner
|
|
|
+type BannerController struct {
|
|
|
+ BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+type BaseBannerController struct {
|
|
|
+ BaseCommonController
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 列表
|
|
|
+// @Description 列表接口
|
|
|
+// @Success Ret=200 {object} cygx.CygxBannerListResp
|
|
|
+// @router /list [get]
|
|
|
+func (this *BaseBannerController) List() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ 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]*models.CygxBannerImgResp)
|
|
|
+ for _, v := range bannerImgList {
|
|
|
+ mapImg[v.ImgId] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ var listA []*models.CygxBannerResp
|
|
|
+ var listB []*models.CygxBannerResp
|
|
|
+ var listC []*models.CygxBannerResp
|
|
|
+ for _, v := range list {
|
|
|
+ v.BannerUrlResp = services.GetBannerUrlBody(v.Link)
|
|
|
+ if v.ListType == "A" {
|
|
|
+ listA = append(listA, v)
|
|
|
+ } else if v.ListType == "B" {
|
|
|
+ listB = append(listB, v)
|
|
|
+ } else if v.ListType == "C" {
|
|
|
+ listC = append(listC, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var listCount int
|
|
|
+ if len(listA) == 0 {
|
|
|
+ listA = make([]*models.CygxBannerResp, 0)
|
|
|
+ } else {
|
|
|
+ listCount++
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(listB) == 0 {
|
|
|
+ listB = make([]*models.CygxBannerResp, 0)
|
|
|
+ } else {
|
|
|
+ listCount++
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(listC) == 0 {
|
|
|
+ listC = make([]*models.CygxBannerResp, 0)
|
|
|
+ } else {
|
|
|
+ listCount++
|
|
|
+ }
|
|
|
+ //当有一列的时候过滤图片
|
|
|
+ if listCount == 1 {
|
|
|
+ if len(listA) > 0 {
|
|
|
+ for _, v := range listA {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(listB) > 0 {
|
|
|
+ for _, v := range listB {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(listC) > 0 {
|
|
|
+ for _, v := range listC {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //当有两列的时候过滤图片
|
|
|
+ if listCount == 2 {
|
|
|
+ if len(listA) > 0 {
|
|
|
+ for _, v := range listA {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img2
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(listB) > 0 {
|
|
|
+ for _, v := range listB {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img3
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if len(listB) > 0 {
|
|
|
+ for _, v := range listB {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img2
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(listC) > 0 {
|
|
|
+ for _, v := range listC {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img3
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //当有三列的时候过滤图片
|
|
|
+ if listCount == 3 {
|
|
|
+ for _, v := range listA {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img2
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range listB {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img3
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range listC {
|
|
|
+ if mapImg[v.ImgId] != nil {
|
|
|
+ v.IndexImg = mapImg[v.ImgId].Img4
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.ListA = listA
|
|
|
+ resp.ListB = listB
|
|
|
+ resp.ListC = listC
|
|
|
+ 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 = "记录成功"
|
|
|
+}
|