123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- package controllers
- import (
- "encoding/json"
- "hongze/hongze_web_mfyx/models"
- "hongze/hongze_web_mfyx/services"
- "hongze/hongze_web_mfyx/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 研选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 = "记录成功"
- }
- // @Title 首页banner图片
- // @Description 研选banner列表接口
- // @Success Ret=200 {object} cygx.BannerUrHomeListResp
- // @router /listhome [get]
- func (this *BaseBannerController) ListHome() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- resp := new(models.BannerUrHomeListResp)
- key := "web_mfyx_banner_list"
- conf, e := models.GetConfigByCode(key)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
- return
- }
- if conf.ConfigValue == "" {
- br.Msg = "获取失败"
- br.ErrMsg = "首页头部导航配置值有误"
- return
- }
- if e = json.Unmarshal([]byte(conf.ConfigValue), &resp); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|