zhangchuanxing 6 өдөр өмнө
parent
commit
8fd3993bcb

+ 67 - 0
controllers/chart.go

@@ -0,0 +1,67 @@
+package controllers
+
+import (
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/services"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+)
+
+type ChartController struct {
+	BaseAuthController
+}
+
+// @Title 图表详情
+// @Description 我的收藏接口
+// @Param   ChartId   query   int  true       "图表ID"
+// @Success 200 {object} models.CygxChartDetail
+// @router /detail [get]
+func (this *ChartController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	mobile := user.Mobile
+	if mobile == "" {
+		br.Msg = "请绑定手机号!"
+		return
+	}
+	chartId, _ := this.GetInt("ChartId")
+	if chartId <= 0 {
+		br.Msg = "图表信息不存在!"
+		return
+	}
+	detail, err := models.GetChartDetailById(chartId, user.UserId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	chartUserTokenByMobile, _ := services.GetUserTokenByMobile(mobile)
+	if chartUserTokenByMobile != "" {
+		GetIsCollectionChart, err := services.GetIsCollectionChart(mobile, chartId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取三方关注信息失败,Err:" + err.Error()
+			return
+		}
+		detail.IsCollection = GetIsCollectionChart
+		detail.HttpUrl = utils.CHART_INFO_HTTP_URL + strconv.Itoa(chartId) + "?token=" + chartUserTokenByMobile
+	} else {
+		if detail.CollectionNum > 0 {
+			detail.IsCollection = true
+		}
+	}
+	go services.ServerAddCygxChartRecord(user, chartId) //用户阅读图表,添加浏览记录
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = detail
+}

+ 26 - 0
models/chart_record.go

@@ -0,0 +1,26 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxChartRecord struct {
+	RecordId         int       `orm:"column(record_id);pk"`
+	ChartId          int       `description:"图表ID"`
+	UserId           int       `description:"用户ID"`
+	Mobile           string    `description:"手机号"`
+	Email            string    `description:"邮箱"`
+	CompanyId        int       `description:"公司id"`
+	CompanyName      string    `description:"公司名称"`
+	RealName         string    `description:"用户实际名称"`
+	CreateTime       time.Time `description:"创建时间"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+}
+
+// 添加历史信息
+func AddCygxChartRecord(item *CygxChartRecord) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 1 - 0
models/db.go

@@ -109,6 +109,7 @@ func init() {
 		new(CygxActivitySpecialPermissionPoints),
 		new(time_line.CygxGushouTimeLineHistory),
 		new(CygxXzsChooseCategoryZhouqi),
+		new(CygxChartRecord),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 9 - 0
routers/commentsRouter.go

@@ -376,6 +376,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ChartController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ChartController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ChartPermissionController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ChartPermissionController"],
         beego.ControllerComments{
             Method: "Detail",

+ 5 - 0
routers/router.go

@@ -169,6 +169,11 @@ func init() {
 				&controllers.FiccYbController{},
 			),
 		),
+		web.NSNamespace("/chart",
+			web.NSInclude(
+				&controllers.ChartController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 37 - 133
services/chart.go

@@ -3,6 +3,7 @@ package services
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/utils"
@@ -13,7 +14,7 @@ import (
 	"time"
 )
 
-//get公共请求方法
+// get公共请求方法
 func PublicGetDate(url, authorization string) (body []byte, err error) {
 	defer func() {
 		if err != nil {
@@ -39,7 +40,7 @@ func PublicGetDate(url, authorization string) (body []byte, err error) {
 	return
 }
 
-//同步图表列表
+// 同步图表列表
 func GetChartListByApi(cont context.Context) (err error) {
 	defer func() {
 		if err != nil {
@@ -190,7 +191,7 @@ func GetChartListByApi(cont context.Context) (err error) {
 
 }
 
-//获取图表分类
+// 获取图表分类
 func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
 	defer func() {
 		if err != nil {
@@ -225,7 +226,7 @@ func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
 	return
 }
 
-//获取用户的Token
+// 获取用户的Token
 func GetUserTokenByMobile(mobile string) (token string, err error) {
 	//缓存校验
 	cacheKey := fmt.Sprint("xygx_chart:chart_token:add:", "Mobile", mobile)
@@ -270,7 +271,7 @@ func GetUserTokenByMobile(mobile string) (token string, err error) {
 	return
 }
 
-//获取图表收藏
+// 获取图表收藏
 func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.HomeChartListResp, err error, total int) {
 	defer func() {
 		if err != nil {
@@ -309,7 +310,7 @@ func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.Hom
 	return
 }
 
-//判断策略平台是否已经添加过收藏
+// 判断策略平台是否已经添加过收藏
 func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err error) {
 	//获取所有的收藏列表,进行比对看看是否收藏,调用三方接口详情没有是否收藏的字段
 	list, err, _ := GetChartCollectionByApi(mobile, 9999, 0)
@@ -324,7 +325,7 @@ func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err er
 	return
 }
 
-//添加收藏
+// 添加收藏
 func AddCollectionChart(mobile string, chartId int) (err error) {
 	authorization, err := GetUserTokenByMobile(mobile)
 	if err != nil {
@@ -356,7 +357,7 @@ func AddCollectionChart(mobile string, chartId int) (err error) {
 	return
 }
 
-//移除收藏
+// 移除收藏
 func DeleteCollectionChart(mobile string, chartId int) (err error) {
 	authorization, err := GetUserTokenByMobile(mobile)
 	if err != nil {
@@ -384,129 +385,32 @@ func DeleteCollectionChart(mobile string, chartId int) (err error) {
 	return
 }
 
-func DoCompany() {
-
-	//listCollect, err := models.GetCygxArticleCollectList()
-	//if err != nil {
-	//	fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
-	//}
-	//for _, v := range listCollect {
-	//	user, err := models.GetWxUserItemByUserId(v.UserId)
-	//	if err != nil && err.Error() != utils.ErrNoRow() {
-	//		fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
-	//	}
-	//	if user != nil {
-	//		fmt.Println(user.RealName)
-	//		err = models.UpdateCygxArticleCollect(user)
-	//		if err != nil {
-	//			fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
-	//		}
-	//	}
-	//}
-
-	//listCollect, err := models.GetCygxSearchKeyWordList()
-	//if err != nil {
-	//	fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
-	//}
-	//for _, v := range listCollect {
-	//	user, err := models.GetWxUserItemByUserId(v.UserId)
-	//	if err != nil && err.Error() != utils.ErrNoRow() {
-	//		fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
-	//	}
-	//	if user != nil {
-	//		fmt.Println(user.RealName)
-	//		err = models.UpdateCygxSearchKeyWord(user)
-	//		if err != nil {
-	//			fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
-	//		}
-	//	}
-	//}
-	//var condition string
-	////updateTime := time.Now().Add(-time.Hour * 25).Format(utils.FormatDateTime)
-	//condition = ` AND real_name  = '' `
-	//listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
-	//if err != nil {
-	//	fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
-	//}
-	//fmt.Println("长度", len(listArticlePv))
-	//for k, v := range listArticlePv {
-	//	if v.Mobile != "" {
-	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
-	//		if err != nil && err.Error() != utils.ErrNoRow() {
-	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
-	//		}
-	//		if user != nil {
-	//			fmt.Println(user.RealName, k)
-	//			err = models.UpdateCygxArticleHistoryRecordAll(user)
-	//			if err != nil {
-	//				fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
-	//			}
-	//		}
-	//	}
-	//}
-
-	//listIndustryFllow, err := models.GetCygxIndustryFllowList("")
-	//if err != nil {
-	//	fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
-	//}
-	//fmt.Println("长度", len(listIndustryFllow))
-	//for k, v := range listIndustryFllow {
-	//	if v.Mobile != "" {
-	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
-	//		if err != nil && err.Error() != utils.ErrNoRow() {
-	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
-	//		}
-	//		if user != nil {
-	//			fmt.Println(user.RealName, k)
-	//			err = models.UpdateCygxIndustryFllow(user)
-	//			if err != nil {
-	//				fmt.Println("UpdateCygxIndustryFllow ,Err" + err.Error())
-	//			}
-	//		}
-	//	}
-	//}
-	//
-	//lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList("")
-	//if err != nil {
-	//	fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
-	//}
-	//fmt.Println("长度", len(lisDepartmentF))
-	//for k, v := range lisDepartmentF {
-	//	if v.Mobile != "" {
-	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
-	//		if err != nil && err.Error() != utils.ErrNoRow() {
-	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
-	//		}
-	//		if user != nil {
-	//			fmt.Println(user.RealName, k)
-	//			err = models.UpdateCygxArticleDepartmentFollow(user)
-	//			if err != nil {
-	//				fmt.Println("UpdateCygxArticleDepartmentFollow ,Err" + err.Error())
-	//			}
-	//		}
-	//	}
-	//}
-
-	//listChartCollect, err := models.GetCygxChartCollectByMobileList()
-	//if err != nil {
-	//	fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
-	//}
-	//fmt.Println("长度", len(listChartCollect))
-	//for k, v := range listChartCollect {
-	//	if v.Mobile != "" {
-	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
-	//		if err != nil && err.Error() != utils.ErrNoRow() {
-	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
-	//		}
-	//		if user != nil {
-	//			fmt.Println(user.RealName, k)
-	//			err = models.UpdateCygxChartCollect(user)
-	//			if err != nil {
-	//				fmt.Println("UpdateCygxChartCollect ,Err" + err.Error())
-	//			}
-	//		}
-	//	}
-	//}
-
-	fmt.Println("end")
+// 用户阅读图表,添加浏览记录
+func ServerAddCygxChartRecord(wxUser *models.WxUserItem, ctagId int) {
+	if wxUser.CompanyId < 1 {
+		return
+	}
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("用户阅读图表,添加浏览记录失败 ctagId", ctagId, "userId", wxUser.UserId, err.Error()), 2)
+		}
+	}()
+	item := new(models.CygxChartRecord)
+	item.ChartId = ctagId
+	item.UserId = wxUser.UserId
+	item.RealName = wxUser.RealName
+	item.Mobile = wxUser.Mobile
+	item.Email = wxUser.Email
+	item.CompanyId = wxUser.CompanyId
+	item.CompanyName = wxUser.CompanyName
+	item.CreateTime = time.Now()
+	item.RegisterPlatform = utils.REGISTER_PLATFORM
+	_, e := models.AddCygxChartRecord(item)
+	if e != nil {
+		err = errors.New("AddCygxChartRecord" + e.Error())
+		return
+	}
+	return
 }