Sfoglia il codice sorgente

Merge branch 'banner_mark' into debug

zwxi 1 anno fa
parent
commit
86bc414c28

+ 79 - 0
controller/public.go

@@ -2,6 +2,7 @@ package controller
 
 import (
 	"encoding/json"
+	"errors"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"hongze/hongze_yb/controller/response"
@@ -9,6 +10,9 @@ import (
 	"hongze/hongze_yb/logic"
 	"hongze/hongze_yb/models/request"
 	respond "hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/tables/banner_view_history"
+	"hongze/hongze_yb/models/tables/company"
+	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/models/tables/yb_config"
 	"hongze/hongze_yb/models/tables/yb_resource"
 	"hongze/hongze_yb/models/tables/yb_suncode_pars"
@@ -348,3 +352,78 @@ func GetTelAreaList(c *gin.Context) {
 	}
 	response.OkData("获取成功", respList, c)
 }
+
+
+// BannerMark banner图埋点
+// @Tags 公共模块
+// @Summary  banner图埋点
+// @Description banner图埋点
+// @Security ApiKeyAuth
+// @securityDefinitions.basic BasicAuth
+// @Param email	query string true "电子邮箱账号"
+// @Accept  json
+// @Product json
+// @Success 200 {string} string 获取验证码成功
+// @Failure 400 {string} string 请输入邮箱地址
+// @Router /banner/mark [post]
+func BannerMark(c *gin.Context) {
+	userInfo := user.GetInfoByClaims(c)
+	var req request.BannerMarkReq
+	if err := c.Bind(&req); err != nil {
+		response.Fail("参数有误:"+err.Error(), c)
+		return
+	}
+
+	if req.BannerUrl == "" {
+		response.FailMsg("参数有误", "BannerUrl不能为空", c)
+		return
+	}
+
+	if req.FirstSource <= 0 {
+		response.FailMsg("参数有误", "FirstSource不能为空", c)
+		return
+	}
+
+	if req.SecondSource <= 0 {
+		response.FailMsg("参数有误", "SecondSource", c)
+	}
+
+
+	// 联系人信息
+	strInt64 := strconv.FormatUint(userInfo.UserID, 10)
+	id, _ := strconv.Atoi(strInt64)
+	wxUserInfo, err := wx_user.GetByUserId(id)
+	if err != nil {
+		fmt.Println("GetByUserId:", err.Error())
+		return
+	}
+	companyInfo, tmpErr := company.GetByCompanyId(wxUserInfo.CompanyID)
+	if tmpErr != nil {
+		err = tmpErr
+		if tmpErr == utils.ErrNoRow {
+			err = errors.New("找不到该客户")
+			return
+		}
+		return
+	}
+
+	//新增userViewHistory记录
+	banner_view_history := &banner_view_history.BannerViewHistory{
+		UserID:          userInfo.UserID,
+		Mobile:          wxUserInfo.Mobile,
+		Email:           wxUserInfo.Email,
+		RealName:        wxUserInfo.RealName,
+		CompanyName:     companyInfo.CompanyName,
+		CreatedTime:     time.Now(),
+		LastUpdatedTime: time.Now(),
+		FirstSource:     req.FirstSource,
+		SecondSource:    req.SecondSource,
+		BannerUrl:       req.BannerUrl,
+	}
+	err = banner_view_history.AddBannerViewHistory()
+	if err != nil {
+		fmt.Println("AddUserViewHistory err", err.Error())
+	}
+
+	response.Ok("成功", c)
+}

+ 6 - 0
models/request/public.go

@@ -20,3 +20,9 @@ type ReportChapterSetReq struct {
 	TypeId  uint64 `json:"type_id"`
 	IsClose uint64 `json:"is_close" description:"是否关闭:1,关闭,0:不关闭"`
 }
+
+type BannerMarkReq struct {
+	BannerUrl    string `json:"banner_url"`
+	FirstSource  int    `json:"first_source" description:"一级来源 1小程序移动 2小程序pc 3研报官网"`
+	SecondSource int    `json:"second_source" description:"二级来源 1首页 2研报详情页"`
+}

+ 23 - 0
models/tables/banner_view_history/banner_view_history.go

@@ -0,0 +1,23 @@
+package banner_view_history
+
+import "time"
+
+// BannerViewHistory banner访问历史
+type BannerViewHistory struct {
+	ViewHistoryID   uint64    `gorm:"primaryKey;column:view_history_id" json:"-"` // id
+	UserID          uint64    `gorm:"column:user_id" json:"userId"`               // 用户id
+	Mobile          string    `gorm:"column:mobile" json:"mobile"`                // 手机号
+	Email           string    `gorm:"column:email" json:"email"`                  // 邮箱
+	RealName        string    `gorm:"column:real_name" json:"realName"`           // 用户实际名称
+	CompanyName     string    `gorm:"column:company_name" json:"companyName"`     // 公司名称
+	CreatedTime     time.Time `gorm:"column:created_time" json:"createdTime"`     // 创建时间
+	LastUpdatedTime time.Time `gorm:"column:last_updated_time" json:"lastUpdatedTime"`
+	FirstSource     int       `gorm:"column:first_source" json:"firstSource"`   // 一级来源 1小程序移动 2小程序pc 3研报官网
+	SecondSource    int       `gorm:"column:second_source" json:"secondSource"` // 二级来源 1首页 2研报详情页
+	BannerUrl       string    `gorm:"column:banner_url" json:"bannerUrl"`
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *BannerViewHistory) TableName() string {
+	return "banner_view_history"
+}

+ 9 - 0
models/tables/banner_view_history/create.go

@@ -0,0 +1,9 @@
+package banner_view_history
+
+import "hongze/hongze_yb/global"
+
+// AddBannerViewHistory 新增记录
+func (bannerViewHistory *BannerViewHistory) AddBannerViewHistory() (err error) {
+	err = global.DEFAULT_MYSQL.Create(bannerViewHistory).Error
+	return
+}

+ 1 - 0
routers/public.go

@@ -12,6 +12,7 @@ func InitPublic(r *gin.Engine) {
 	{
 		rGroup.GET("/get_apply_variety_list", controller.GetApplyVarietyList)
 		rGroup.POST("/upload", controller.Upload)
+		rGroup.POST("/banner/mark", controller.BannerMark)
 	}
 
 	initPublic(r)