瀏覽代碼

查研观向10.0banner

xingzai 1 年之前
父節點
當前提交
996d23c0e8
共有 8 個文件被更改,包括 388 次插入2 次删除
  1. 97 0
      controllers/banner.go
  2. 81 0
      models/banner.go
  3. 29 0
      models/banner_history.go
  4. 1 0
      models/db.go
  5. 18 0
      routers/commentsRouter.go
  6. 5 0
      routers/router.go
  7. 135 0
      services/banner.go
  8. 22 2
      utils/constants.go

+ 97 - 0
controllers/banner.go

@@ -0,0 +1,97 @@
+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 = "记录成功"
+}

+ 81 - 0
models/banner.go

@@ -0,0 +1,81 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type CygxBannerResp struct {
+	BannerId       int            `description:"BannerId等于0新增,大于零修改"`
+	ImgId          int            `description:"cygx_banner_img主键ID"`
+	IndexImg       string         `description:"小程序封面图"`
+	ListType       string         `description:"ABC哪一列"`
+	BannerTypeName string         `description:"添加类型名称"`
+	Title          string         `description:"标题"`
+	Link           string         `description:"链接地址"`
+	Subtitle       string         `description:"副标题"`
+	BannerUrlResp  *BannerUrlResp `description:"跳转地址"`
+}
+
+type CygxBannerIdReq struct {
+	BannerId int `description:"BannerId"`
+}
+
+type GetCygxBannerImgRespDetailResp struct {
+	Detail *CygxBannerResp
+}
+
+// 通过ID获取详情
+func GetCygxBannerDetail(banneId int) (item *CygxBannerResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_banner  WHERE banner_id=? `
+	err = o.Raw(sql, banneId).QueryRow(&item)
+	return
+}
+
+// 获取数量
+func GetCygxBannerCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_banner as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 列表
+func GetCygxBannerList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxBannerResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_banner as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+type CygxBannerListResp struct {
+	List []*CygxBannerResp
+}
+
+type CygxBannerImgResp struct {
+	ImgId    int    `description:"图片ID"`
+	IndexImg string `description:"小程序封面图"`
+}
+
+type BannerUrlResp struct {
+	ChartPermissionId int    `description:"行业id"`
+	SourceId          int    `description:"资源ID"`
+	Type              int    `description:"类型:1普通文本,2:文章、3:活动、4:产业、5:关于我们、6:产品内测"`
+	Body              string `description:"内容"`
+	Path              string `description:"小程序路径"`
+}
+
+// 列表
+func GetCygxBannerImgList() (items []*CygxBannerImgResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_banner_img as art WHERE 1= 1 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 29 - 0
models/banner_history.go

@@ -0,0 +1,29 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxBannerHistory struct {
+	Id               int `orm:"column(id);pk"`
+	BannerId         int `description:"BannerId等于0新增,大于零修改"`
+	UserId           int
+	CreateTime       time.Time
+	Mobile           string    `description:"手机号"`
+	Email            string    `description:"邮箱"`
+	CompanyId        int       `description:"公司id"`
+	CompanyName      string    `description:"公司名称"`
+	ModifyTime       time.Time `description:"修改时间"`
+	RealName         string    `description:"用户实际名称"`
+	SellerName       string    `description:"所属销售"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+}
+
+// 添加历史信息
+func AddCygxBannerHistory(item *CygxBannerHistory) (lastId int64, err error) {
+	o := orm.NewOrm()
+	item.ModifyTime = time.Now()
+	lastId, err = o.Insert(item)
+	return
+}

+ 1 - 0
models/db.go

@@ -145,6 +145,7 @@ func init() {
 		new(CygxReportMappingGroup),
 		new(CygxAboutUsVideoHistory),
 		new(CygxActivitySignupBreak),
+		new(CygxBannerHistory),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 18 - 0
routers/commentsRouter.go

@@ -385,6 +385,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BannerController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BannerController"],
+        beego.ControllerComments{
+            Method: "History",
+            Router: `/add/history`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BannerController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BannerController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseChartController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseChartController"],
         beego.ControllerComments{
             Method: "Patg",

+ 5 - 0
routers/router.go

@@ -154,6 +154,11 @@ func init() {
 				&controllers.MorningMeetingController{},
 			),
 		),
+		web.NSNamespace("/banner",
+			web.NSInclude(
+				&controllers.BannerController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 135 - 0
services/banner.go

@@ -0,0 +1,135 @@
+package services
+
+import (
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+// GetBannerUrlBody 处理banner的连接并做跳转处理
+func GetBannerUrlBody(url string) (itemResp *models.BannerUrlResp) {
+	//2:文章详情  https://web.hzinsights.com/material/info/8436  小程序路径:/pageMy/reportDetail/reportDetail?id=
+	//3:活动详情  https://web.hzinsights.com/activity/detail/2701  小程序路径:/activityPages/activityDetail/activityDetail?id=
+	//4:产业详情  https://web.hzinsights.com/indepth/info/20/79  小程序路径:/reportPages/IndustryReport/IndustryReport?id=
+	//5:关于我们  https://clpttest.hzinsights.com/about
+	//6:产品内测 https://clpttest.hzinsights.com/internal/article/29  小程序路径:/reportPages/internalDetials/internalDetials?id=
+	//7:本周研究汇总 https://clpttest.hzinsights.com/summary/2/152  小程序路径:/reportPages/reportSecretDetail/reportSecretDetail?type=2&id=
+	//8:上周研究汇总 https://clpttest.hzinsights.com/summary/3/112 小程序路径:/reportPages/reportSecretDetail/reportSecretDetail?type=3&id=
+	//9:专项调研活动 https://clpttest.hzinsights.com/activity/info/70  小程序路径:/activityPages/specialDetail/specialDetail?id=
+	//10: 重点公司 https://clpttest.hzinsights.com/recent/67  小程序路径:/reportPages/keyCompany/keyCompany
+	//11: 主题详情 https://clpttest.hzinsights.com/community/theme/117  小程序路径:/reportPages/researchTheme/researchTheme?id=
+	//12: 作者详情 https://clpttest.hzinsights.com/community/author/78 小程序路径:/reportPages/authorPages/authorPages?id=
+
+	mapPath := make(map[int]string)
+	mapPath[2] = utils.WX_MSG_PATH_ARTICLE_DETAIL          //文章详情
+	mapPath[3] = utils.WX_MSG_PATH_ACTIVITY_DETAIL         //活动详情
+	mapPath[4] = utils.WX_MSG_PATH_INDUSTRY_DETAIL         //产业详情
+	mapPath[6] = utils.WX_MSG_PATH_PRODUCTINTERIOR_DETAIL  //产品内测
+	mapPath[7] = utils.WX_MSG_PATH_THIS_WEEK_DETAIL        //本周研究汇总
+	mapPath[8] = utils.WX_MSG_PATH_LAST_WEEK_DETAIL        //上周研究汇总
+	mapPath[9] = utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL //专项调研活动
+	mapPath[10] = utils.WX_MSG_PATH_KEY_COMPANY_DETAIL     //重点公司
+	mapPath[11] = utils.WX_MSG_PATH_RESEARCHTHEME_DETAIL   //主题详情
+	mapPath[12] = utils.WX_MSG_PATH_AUTHOR_DETAIL          //作者详情
+
+	material := "material/info"             //2:文章详情
+	activity := "activity/detail"           //3:活动详情
+	activityVideo := "activity/video"       //3:活动视频页,调活动详情
+	indepth := "indepth/info"               //4:产业详情
+	indepthVideo := "indepth/video"         //4:产业视频页,调详情
+	about := "/about"                       //5:关于我们
+	internal := "internal/article"          //6:产品内测
+	thisWeek := "summary/2/"                //7:本周研究汇总
+	lastWeek := "summary/3/"                //8:上周研究汇总
+	activitySpecial := "activity/info"      //9:专项调研活动
+	recent := "/recent/"                    //10:重点公司
+	communityTheme := "/community/theme/"   //11:主题详情
+	communityAuthor := "/community/author/" //12:作者详情
+	item := new(models.BannerUrlResp)
+	item.Body = url
+	urlSlice := strings.Split(url, "/")
+	lenurlSlice := len(urlSlice)
+	sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
+
+	if strings.Contains(url, material) {
+		item.Type = 2
+	} else if strings.Contains(url, activity) {
+		item.Type = 3
+	} else if strings.Contains(url, activityVideo) {
+		activityVideo, err := models.GetCygxActivityVideoById(sourceId)
+		if err != nil {
+			go utils.SendAlarmMsg("banner链接解析失败"+err.Error()+url, 2)
+		}
+		if activityVideo != nil {
+			sourceId = activityVideo.ActivityId
+			item.Type = 3
+		}
+	} else if strings.Contains(url, indepth) {
+		if lenurlSlice >= 2 {
+			chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
+			item.ChartPermissionId = chartPermissionId
+		}
+		item.Type = 4
+	} else if strings.Contains(url, indepthVideo) {
+		if lenurlSlice >= 2 {
+			sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
+		}
+		item.Type = 4
+	} else if strings.Contains(url, about) {
+		item.Type = 5
+	} else if strings.Contains(url, internal) {
+		item.Type = 6
+	} else if strings.Contains(url, thisWeek) {
+		item.Type = 7
+	} else if strings.Contains(url, lastWeek) {
+		item.Type = 8
+	} else if strings.Contains(url, activitySpecial) {
+		item.Type = 9
+	} else if strings.Contains(url, recent) {
+		item.Type = 10
+	} else if strings.Contains(url, communityTheme) {
+		item.Type = 11
+	} else if strings.Contains(url, communityAuthor) {
+		item.Type = 12
+	} else {
+		item.Type = 1
+	}
+	if mapPath[item.Type] != "" {
+		item.Path = "/" + mapPath[item.Type]
+	}
+	item.SourceId = sourceId
+	itemResp = item
+	return
+}
+
+func AddCygxBannerHistory(user *models.WxUserItem, bannerId int) (err error) {
+	if user.UserId == 0 {
+		return
+	}
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("banner点击信息记录失败"+err.Error()+"bannerId"+strconv.Itoa(bannerId)+"userId:"+strconv.Itoa(user.UserId), 2)
+		}
+	}()
+	historyRecord := new(models.CygxBannerHistory)
+	historyRecord.UserId = user.UserId
+	historyRecord.BannerId = bannerId
+	historyRecord.CreateTime = time.Now()
+	historyRecord.Mobile = user.Mobile
+	historyRecord.Email = user.Email
+	historyRecord.CompanyId = user.CompanyId
+	historyRecord.CompanyName = user.CompanyName
+	historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
+	sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	historyRecord.RealName = user.RealName
+	if sellerItem != nil {
+		historyRecord.SellerName = sellerItem.RealName
+	}
+	_, err = models.AddCygxBannerHistory(historyRecord)
+	return
+}

+ 22 - 2
utils/constants.go

@@ -158,10 +158,30 @@ const (
 // 模板消息地址路由
 const (
 	WX_MSG_PATH_ARTICLE_DETAIL           = "pageMy/reportDetail/reportDetail?id="            //文章详情模板消息地址
+	WX_MSG_PATH_ACTIVITY_DETAIL          = "activityPages/activityDetail/activityDetail?id=" //活动模板消息地址
 	WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL  = "activityPages/specialDetail/specialDetail?id="   //专项调研活动模板消息地址
 	WX_MSG_PATH_ACTIVITY_INDUSTRYR_EPORT = "reportPages/IndustryReport/IndustryReport?id="   //产业文章列表模板消息地址
-	WX_MSG_PATH_ACTIVITY_DETAIL          = "activityPages/activityDetail/activityDetail?id=" //活动模板消息地址
-)
+
+	WX_MSG_PATH_AUTHOR_DETAIL          = "reportPages/authorPages/authorPages?id="                      //作者详情模板消息地址
+	WX_MSG_PATH_INDUSTRY_DETAIL        = "reportPages/IndustryReport/IndustryReport?id="                //产业详情模板消息地址
+	WX_MSG_PATH_PRODUCTINTERIOR_DETAIL = "reportPages/internalDetials/internalDetials?id="              //产品内测详情模板消息地址
+	WX_MSG_PATH_THIS_WEEK_DETAIL       = "reportPages/reportSecretDetail/reportSecretDetail?type=2&id=" //本周研究汇总详情模板消息地址
+	WX_MSG_PATH_LAST_WEEK_DETAIL       = "reportPages/reportSecretDetail/reportSecretDetail?type=3&id=" //上周纪要汇总详情模板消息地址
+	WX_MSG_PATH_KEY_COMPANY_DETAIL     = "reportPages/keyCompany/keyCompany"                            //重点公司详情模板消息地址
+	WX_MSG_PATH_RESEARCHTHEME_DETAIL   = "reportPages/researchTheme/researchTheme?id="                  //主题详情模板消息地址
+)
+
+//2:文章详情  https://web.hzinsights.com/material/info/8436  小程序路径:/pageMy/reportDetail/reportDetail?id=
+//3:活动详情  https://web.hzinsights.com/activity/detail/2701  小程序路径:/activityPages/activityDetail/activityDetail?id=
+//4:产业详情  https://web.hzinsights.com/indepth/info/20/79  小程序路径:/reportPages/IndustryReport/IndustryReport?id=
+//5:关于我们  https://clpttest.hzinsights.com/about
+//6:产品内测 https://clpttest.hzinsights.com/internal/article/29  小程序路径:/reportPages/internalDetials/internalDetials?id=
+//7:本周研究汇总 https://clpttest.hzinsights.com/summary/2/152  小程序路径:/reportPages/reportSecretDetail/reportSecretDetail?type=2&id=
+//8:上周研究汇总 https://clpttest.hzinsights.com/summary/3/112 小程序路径:/reportPages/reportSecretDetail/reportSecretDetail?type=3&id=
+//9:专项调研活动 https://clpttest.hzinsights.com/activity/info/70  小程序路径:/activityPages/specialDetail/specialDetail?id=
+//10: 重点公司 https://clpttest.hzinsights.com/recent/67  小程序路径:/reportPages/keyCompany/keyCompany
+//11: 主题详情 https://clpttest.hzinsights.com/community/theme/117  小程序路径:/reportPages/researchTheme/researchTheme?id=
+//12: 作者详情 https://clpttest.hzinsights.com/community/author/78 小程序路径:/reportPages/authorPages/authorPages?id=
 
 // 模板消息地址路由
 const (