Переглянути джерело

策略报告详情页,通过模板消息打开,也增加取关功能的提示栏

xingzai 2 роки тому
батько
коміт
e3ca2bb3f0

+ 25 - 17
controllers/article.go

@@ -82,32 +82,39 @@ func (this *ArticleController) Detail() {
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
-	if isSendWx == 1 {
+	if isSendWx == 0 {
 		var condition string
 		var pars []interface{}
 		pars = make([]interface{}, 0)
 		condition = ` AND article_id  = ? `
-		pars = append(pars, articleId)
-		industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
-		if err != nil && err.Error() != utils.ErrNoRow() {
-			br.Msg = "获取信息失败"
-			br.ErrMsg = "获取信息失败,Err:" + err.Error()
-			return
-		}
-		if len(industrialList) > 0 {
-			industryUserFollowMap, err := services.GetIndustryUserFollowMap(user)
-			if err != nil {
+		reportMappingMap, _ := services.GetReportMappingMap()
+
+		if reportMappingMap[detail.CategoryId] {
+			chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
+			detail.IsShowFollowButton = true
+			detail.IsFollowButton = chooseCategoryMap[detail.CategoryId]
+		} else {
+			pars = append(pars, articleId)
+			industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
+			if err != nil && err.Error() != utils.ErrNoRow() {
 				br.Msg = "获取信息失败"
-				br.ErrMsg = "GetActivitySignupResp,Err:" + err.Error()
+				br.ErrMsg = "获取信息失败,Err:" + err.Error()
 				return
 			}
-			for _, v := range industrialList {
-				fmt.Println(v.IndustrialManagementId)
-				if industryUserFollowMap[v.IndustrialManagementId] {
-					detail.IsFollowButton = true
+			if len(industrialList) > 0 {
+				industryUserFollowMap, err := services.GetIndustryUserFollowMap(user)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "GetActivitySignupResp,Err:" + err.Error()
+					return
+				}
+				for _, v := range industrialList {
+					if industryUserFollowMap[v.IndustrialManagementId] {
+						detail.IsFollowButton = true
+					}
 				}
+				detail.IsShowFollowButton = true
 			}
-			detail.IsShowFollowButton = true
 		}
 	}
 	//是否属于专项调研报告
@@ -428,6 +435,7 @@ Loop:
 			detail.ReportLink += "?token=" + chartUserTokenByMobile
 		}
 	}
+	detail.Body = ""
 	resp.HasPermission = hasPermission
 	resp.HaveResearch = haveResearch
 	resp.Detail = detail

+ 54 - 8
controllers/industry.go

@@ -3,6 +3,7 @@ package controllers
 import (
 	"encoding/json"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
 	"strconv"
 	"time"
@@ -47,18 +48,63 @@ func (this *IndustryController) Fllow() {
 	var pars []interface{}
 	var industrialIds []int
 	if source == "article" {
-		pars = make([]interface{}, 0)
-		condition = ` AND article_id  = ? `
-		pars = append(pars, sourceId)
-		industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
-		if err != nil && err.Error() != utils.ErrNoRow() {
+		articleDetail, err := models.GetArticleDetailById(sourceId)
+		if err != nil {
 			br.Msg = "获取信息失败"
 			br.ErrMsg = "获取信息失败,Err:" + err.Error()
 			return
 		}
-		if len(industrialList) > 0 {
-			for _, v := range industrialList {
-				industrialIds = append(industrialIds, v.IndustrialManagementId)
+		//判读是否属于策略的文章类型
+		reportMappingMap, _ := services.GetReportMappingMap()
+		if reportMappingMap[articleDetail.CategoryId] {
+			chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
+			//判断用户是否关注策略对应分类
+			if !chooseCategoryMap[articleDetail.CategoryId] {
+				item := new(models.CygxXzsChooseCategory)
+				item.CategoryId = articleDetail.CategoryId
+				item.UserId = uid
+				item.Email = user.Email
+				item.Mobile = user.Mobile
+				item.RealName = user.RealName
+				item.CompanyId = user.CompanyId
+				item.CompanyName = user.CompanyName
+				item.CreateTime = time.Now()
+				item.ModifyTime = time.Now()
+				_, err = models.AddCygxCategoryFllow(item)
+				if err != nil {
+					br.Msg = "操作失败"
+					br.ErrMsg = "操作失败,Err:" + err.Error()
+					return
+				}
+				resp.Status = 1
+			} else {
+				err = models.RemoveCygxCategoryFllow(user.Mobile, articleDetail.CategoryId)
+				if err != nil {
+					br.Msg = "操作失败"
+					br.ErrMsg = "取消关注失败,Err:" + err.Error()
+					return
+				}
+				resp.Status = 2
+			}
+			br.Msg = "操作成功"
+			br.Ret = 200
+			br.Success = true
+			br.Data = resp
+			return
+		} else {
+			pars = make([]interface{}, 0)
+			condition = ` AND article_id  = ? `
+			pars = append(pars, sourceId)
+			industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取信息失败,Err:" + err.Error()
+				return
+			}
+			if len(industrialList) > 0 {
+				for _, v := range industrialList {
+					industrialIds = append(industrialIds, v.IndustrialManagementId)
+				}
 			}
 		}
 	} else if source == "activity" {

+ 1 - 0
models/db.go

@@ -131,6 +131,7 @@ func init() {
 		new(CygxResearchSummaryVoiceHistory),
 		new(CygxMinutesSummaryVoiceHistory),
 		new(CygxReportSelectionVoiceHistory),
+		new(CygxXzsChooseCategory),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 14 - 0
models/report_mapping.go

@@ -252,3 +252,17 @@ WHERE
 	err = o.Raw(sql, categoryId).QueryRow(&item)
 	return
 }
+
+// 获取所有的报告分类
+func GetReportMappingByPermissionName(chartPermissionName string) (items []*ReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+				* 
+			FROM
+				cygx_report_mapping
+			WHERE
+				1 = 1 
+				AND chart_permission_name = ? `
+	_, err = o.Raw(sql, chartPermissionName).QueryRows(&items)
+	return
+}

+ 42 - 0
models/xzs_choose_category.go

@@ -0,0 +1,42 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxXzsChooseCategory struct {
+	Id          int       `orm:"column(id);pk"`
+	UserId      int       `description:"用户ID"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	CategoryId  int       `description:"权益文章对应分类,cygx_article"`
+	CreateTime  time.Time `description:"创建时间"`
+	ModifyTime  time.Time `description:"更新时间"`
+}
+
+// 根据手机号获取用户关注的产业
+func GetCygxXzsChooseCategoryList(mobile string) (items []*CygxXzsChooseCategory, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_xzs_choose_category WHERE mobile = ?`
+	_, err = o.Raw(sql, mobile).QueryRows(&items)
+	return
+}
+
+// 添加
+func AddCygxCategoryFllow(item *CygxXzsChooseCategory) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 删除
+func RemoveCygxCategoryFllow(mobile string, CategoryId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? `
+	_, err = o.Raw(sql, mobile, CategoryId).Exec()
+	return
+}

+ 26 - 0
services/report_mapping.go

@@ -0,0 +1,26 @@
+package services
+
+import (
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+)
+
+func GetReportMappingMap() (mapResp map[int]bool, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("GetReportMappingMap, ErrMsg: "+err.Error(), 3)
+		}
+	}()
+	mapResp = make(map[int]bool, 0)
+	list, err := models.GetReportMappingByPermissionName(utils.CE_LUE_NAME)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	if len(list) > 0 {
+		for _, v := range list {
+			mapResp[v.CategoryId] = true
+		}
+	}
+	return
+
+}

+ 29 - 0
services/xzs_choose_category.go

@@ -0,0 +1,29 @@
+package services
+
+import (
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+)
+
+func GetChooseCategoryMap(wxUser *models.WxUserItem) (mapResp map[int]bool, err error) {
+	if wxUser.Mobile == "" {
+		return
+	}
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("GetChooseCategoryMap, ErrMsg: "+err.Error(), 3)
+		}
+	}()
+	mapResp = make(map[int]bool, 0)
+	list, err := models.GetCygxXzsChooseCategoryList(wxUser.Mobile)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	if len(list) > 0 {
+		for _, v := range list {
+			mapResp[v.CategoryId] = true
+		}
+	}
+	return
+
+}