xingzai 1 год назад
Родитель
Сommit
bfdb4175bb
7 измененных файлов с 301 добавлено и 0 удалено
  1. 97 0
      controllers/banner.go
  2. 80 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. 71 0
      services/banner.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 = "记录成功"
+}

+ 80 - 0
models/banner.go

@@ -0,0 +1,80 @@
+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:关于我们"`
+	Body              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

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

+ 18 - 0
routers/commentsRouter.go

@@ -367,6 +367,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

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

+ 71 - 0
services/banner.go

@@ -0,0 +1,71 @@
+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
+	//3:活动详情  https://web.hzinsights.com/activity/detail/2701
+	//4:产业详情  https://web.hzinsights.com/indepth/info/20/79
+	//5:关于我们  https://clpttest.hzinsights.com/about
+	material := "material/info"
+	activity := "activity/detail"
+	indepth := "indepth/info"
+	about := "/about"
+	item := new(models.BannerUrlResp)
+	item.Body = url
+	urlSlice := strings.Split(url, "/")
+	lenurlSlice := len(urlSlice)
+	sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
+	item.SourceId = sourceId
+	if strings.Contains(url, material) {
+		item.Type = 2
+	} else if strings.Contains(url, activity) {
+		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, about) {
+		item.Type = 5
+	} else {
+		item.Type = 1
+	}
+	itemResp = item
+	return
+}
+
+func AddCygxBannerHistory(user *models.WxUserItem, bannerId int) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("产品内测用户浏览信息记录失败"+err.Error(), 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
+}