Bläddra i källkod

Merge branch 'cygx_10.8' into debug

ziwen 1 år sedan
förälder
incheckning
1655990e3e
6 ändrade filer med 294 tillägg och 0 borttagningar
  1. 82 0
      controllers/tag.go
  2. 122 0
      models/cygx_tag.go
  3. 29 0
      models/cygx_tag_history.go
  4. 18 0
      routers/commentsRouter.go
  5. 5 0
      routers/router.go
  6. 38 0
      services/tag.go

+ 82 - 0
controllers/tag.go

@@ -0,0 +1,82 @@
+package controllers
+
+import (
+	"encoding/json"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/services"
+)
+
+type TagController struct {
+	BaseAuthController
+}
+
+
+// @Title 获取标签列表-自定义顺序
+// @Description 获取标签列表-自定义顺序接口
+// @Success 200 {object} cygx.ChartPermissionResp
+// @router /list/custom [get]
+func (this *TagController) TagCustomizeList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.User
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	var condition string
+	list, err := models.GetCygxTagList(condition)
+	if err != nil {
+		br.Msg = "获取标签失败"
+		br.ErrMsg = "获取标签信息失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = list
+}
+
+// @Title 记录点击信息
+// @Description 记录点击信息
+// @Param	request	body cygx.CygxTagIdReq true "type json string"
+// @Success 200 Ret=200 发布成功
+// @router /add/history [post]
+func (this *TagController) 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.CygxTagIdReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	tagId := req.TagId
+	if tagId == 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,id不可为空"
+		return
+	}
+	go services.AddCygxTagHistory(user, tagId)
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "记录成功"
+}

+ 122 - 0
models/cygx_tag.go

@@ -0,0 +1,122 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxTag struct {
+	TagId         int64     `orm:"column(tag_id);pk"`
+	TagName       string    `orm:"column(tag_name);NOT NULL"`       // 标签名
+	ArticleTypes  string    `orm:"column(article_types);NOT NULL"`  // 报告系列
+	ActivityTypes string    `orm:"column(activity_types);NOT NULL"` // 活动类型
+	Industries    string    `orm:"column(industries);NOT NULL"`     // 产业
+	SubjectNames  string    `orm:"column(subject_names);NOT NULL"`  // 标的
+	Sort          int       `orm:"column(sort);"`                   // 优先级
+	ModifyTime    time.Time `orm:"column(modify_time)"`             // 修改时间
+	CreateTime    time.Time `orm:"column(create_time)"`             // 创建时间
+	OnlineTime    time.Time `orm:"column(online_time)"`             // 上线时间
+	OfflineTime   time.Time `orm:"column(offline_time)"`            // 下线时间
+	Status        int       `orm:"column(status);NOT NULL"`         // 状态:0-禁用 1-启用
+}
+
+// 添加标签
+func AddCygxTag(item *CygxTag) (id int64, err error) {
+	o := orm.NewOrm()
+	id, err = o.Insert(item)
+	return
+}
+
+func (m *CygxTag) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}
+
+type CygxTagList struct {
+	TagId         int64  `orm:"column(tag_id);pk"`
+	TagName       string `orm:"column(tag_name);NOT NULL"`       // 标签名
+	ArticleTypes  string `orm:"column(article_types);NOT NULL"`  // 报告系列
+	ActivityTypes string `orm:"column(activity_types);NOT NULL"` // 活动类型
+	Industries    string `orm:"column(industries);NOT NULL"`     // 产业
+	SubjectNames  string `orm:"column(subject_names);NOT NULL"`  // 标的
+	Sort          int    `orm:"column(sort);"`                   // 优先级
+	ModifyTime    string `orm:"column(modify_time)"`             // 修改时间
+	CreateTime    string `orm:"column(create_time)"`             // 创建时间
+	OnlineTime    string `orm:"column(online_time)"`             // 上线时间
+	OfflineTime   string `orm:"column(offline_time)"`            // 下线时间
+	Status        int    `orm:"column(status);NOT NULL"`         // 状态:0-禁用 1-启用
+}
+
+
+// 获取tag列表
+func GetCygxTagList(cond string) (items []*CygxTagList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_tag  WHERE 1=1 AND status = 1 `
+	if cond != "" {
+		sql += cond
+	} else {
+		sql += `  ORDER BY sort ASC `
+	}
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+func UpdateCygxTagStatus(id, status int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	if status == 1 {
+		sql = ` UPDATE  cygx_tag
+			SET
+			  status =1,
+			  online_time = NOW(),
+			  modify_time = NOW() 
+			WHERE tag_id = ?`
+	} else {
+		sql = ` UPDATE  cygx_tag
+			SET
+			  status =0,
+			  offline_time = NOW(),
+			  modify_time = NOW() 
+			WHERE tag_id = ?`
+	}
+
+	_, err = o.Raw(sql, id).Exec()
+	return
+}
+
+// GetCygxTagByTagId 根据指标id获取指标信息
+func GetCygxTagByTagId(tagId int) (item *CygxTag, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_tag WHERE tag_id=? `
+	err = o.Raw(sql, tagId).QueryRow(&item)
+	return
+}
+
+// GetCygxTagMinSort 获取最小不等于0的排序
+func GetCygxTagMinSort() (sort int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT min(sort) FROM cygx_tag WHERE  sort <> 0 `
+	err = o.Raw(sql).QueryRow(&sort)
+	return
+}
+
+// MoveDownCygxTagBySort 往下移动
+func MoveDownCygxTagBySort(prevSort, currentSort int) (err error) {
+	o := orm.NewOrm()
+	sql := `update cygx_tag set sort = sort - 1 where sort <= ? and sort> ? `
+	_, err = o.Raw(sql, prevSort, currentSort).Exec()
+	return
+}
+
+// MoveUpCygxTagBySort 往下移动
+func MoveUpCygxTagBySort(prevSort, currentSort int) (err error) {
+	o := orm.NewOrm()
+	sql := `update cygx_tag set sort = sort + 1 where sort >= ? and sort< ? `
+	_, err = o.Raw(sql, prevSort, currentSort).Exec()
+	return
+}
+
+type CygxTagIdReq struct {
+	TagId int `description:"TagId"`
+}

+ 29 - 0
models/cygx_tag_history.go

@@ -0,0 +1,29 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxTagHistory struct {
+	Id               int `orm:"column(id);pk"`
+	TagId         int `description:"TagId等于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 AddCygxTagHistory(item *CygxTagHistory) (lastId int64, err error) {
+	o := orm.NewOrm()
+	item.ModifyTime = time.Now()
+	lastId, err = o.Insert(item)
+	return
+}

+ 18 - 0
routers/commentsRouter.go

@@ -772,6 +772,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:TagController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:TagController"],
+        beego.ControllerComments{
+            Method: "History",
+            Router: `/add/history`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:TagController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:TagController"],
+        beego.ControllerComments{
+            Method: "TagCustomizeList",
+            Router: `/list/custom`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserCommonController"],
         beego.ControllerComments{
             Method: "Login",

+ 5 - 0
routers/router.go

@@ -143,6 +143,11 @@ func init() {
 				&controllers.BaseBannerController{},
 			),
 		),
+		web.NSNamespace("/tag",
+			web.NSInclude(
+				&controllers.TagController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 38 - 0
services/tag.go

@@ -0,0 +1,38 @@
+package services
+
+import (
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+	"time"
+)
+
+func AddCygxTagHistory(user *models.WxUserItem, tagId int) (err error) {
+	if user.UserId == 0 {
+		return
+	}
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("tag点击信息记录失败"+err.Error()+"tagId"+strconv.Itoa(tagId)+"userId:"+strconv.Itoa(user.UserId), 2)
+		}
+	}()
+	historyRecord := new(models.CygxTagHistory)
+	historyRecord.UserId = user.UserId
+	historyRecord.TagId = tagId
+	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.AddCygxTagHistory(historyRecord)
+	return
+}