package controllers import ( "encoding/json" "hongze/hongze_clpt/models" "hongze/hongze_clpt/services" "hongze/hongze_clpt/utils" "time" ) // 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.show_type IN (0,2) 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].Img4 } } 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 = "记录成功" } // @Title 研选banner列表 // @Description 研选banner列表接口 // @Success Ret=200 {object} cygx.CygxBannerListResp // @router /listYx [get] func (this *BaseBannerController) ListYx() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() resp := new(models.BannerUrlYxListResp) var listA []*models.BannerUrlYxResp var listB []*models.BannerUrlYxResp var listC []*models.BannerUrlYxResp listA = []*models.BannerUrlYxResp{ &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_5.png", Path: "/index/"}, &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_6.png", Path: ""}, } listB = []*models.BannerUrlYxResp{ &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_3.png", Path: "/index/"}, } listC = []*models.BannerUrlYxResp{ &models.BannerUrlYxResp{IndexImg: "https://hzstatic.hzinsights.com/banner/yx/web_4.png", Path: ""}, } 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/yxSurvey [post] func (this *BannerController) YxSurvey() { 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.CygxBannerYxSurveyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } content := req.Content if content == "" { br.Msg = "内容不能为空" br.ErrMsg = "内容不能为空" return } item := new(models.CygxBannerYxSurvey) item.UserId = user.UserId item.CreateTime = time.Now() item.ModifyTime = time.Now() item.Mobile = user.Mobile item.Email = user.Email item.CompanyId = user.CompanyId item.CompanyName = user.CompanyName item.Content = content item.RegisterPlatform = utils.REGISTER_PLATFORM sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2) if err != nil && err.Error() != utils.ErrNoRow() { return } item.RealName = user.RealName if sellerItem != nil { item.SellerName = sellerItem.RealName } newId, err := models.AddCygxBannerYxSurvey(item) if err != nil { br.Msg = "申请失败" br.ErrMsg = "申请失败,Err:" + err.Error() return } go services.SendCygxBannerYxSurveyTemplateMsg(user, content, int(newId)) br.Ret = 200 br.Success = true br.Msg = "记录成功" }