瀏覽代碼

查研观向6.0

xingzai 3 年之前
父節點
當前提交
10e11d2a6f

+ 22 - 0
controllers/activity.go

@@ -2085,6 +2085,19 @@ func (this *ActivityCoAntroller) AskAdd() {
 		br.ErrMsg = "操作失败,Err:" + errInfo.Error()
 		return
 	}
+	//resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
+	//if activityInfo.ActivityTypeId == 1 && activityInfo.ChartPermissionId != 31 {
+	//	if time.Now().After(resultTime.Add(-time.Minute * 15)) {
+	//		br.Msg = "活动开始前15分钟内无法提交问题"
+	//		return
+	//	}
+	//} else {
+	//	if time.Now().After(resultTime.Add(-time.Minute * 60)) {
+	//		br.Msg = "活动开始前1小时内无法提交问题"
+	//		return
+	//	}
+	//}
+
 	companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
 	if err != nil {
 		br.Msg = "提交失败!"
@@ -3823,6 +3836,15 @@ func (this *ActivityCoAntroller) SpecialDetail() {
 		resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
 	}
 	if hasPermission == 1 {
+		count, err := models.GetCygxUserFollowSpecial(user.UserId)
+		if err != nil {
+			br.Msg = "获取数据失败!"
+			br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+			return
+		}
+		if count == 1 {
+			resp.IsFollow = true
+		}
 		activityInfo.ActivityTypeName = "专项调研"
 		resp.Detail = activityInfo
 	}

+ 427 - 0
controllers/article.go

@@ -989,3 +989,430 @@ func (this *ArticleController) Pdfwatermark() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 获取报告详情(无需token)
+// @Description 获取报告详情接口
+// @Param   ArticleId   query   int  true       "报告ID"
+// @Param   CompanyCode     query string  false       "机构编号"
+// @Param   CompanyName     query string  false       "机构名称"
+// @Param   Email     query string  false       "邮箱"
+// @Param   Sign   query   string  false       "加密签名"
+// @Success 200 {object} models.ArticleDetailHtgjResp
+// @router /detailPublic [get]
+func (this *ArticleCommonController) DetailPublic() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	articleId, _ := this.GetInt("ArticleId")
+	companyCode := this.GetString("CompanyCode")
+	companyNameHt := this.GetString("CompanyName")
+	email := this.GetString("Email")
+	sign := this.GetString("Sign")
+	resp := new(models.ArticleDetailHtgjResp)
+	if companyCode == "" || email == "" {
+		resp.HasPermission = 2
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+	if articleId <= 0 {
+		br.Msg = "文章不存在"
+		br.ErrMsg = "文章不存在,文章ID错误"
+		return
+	}
+
+	errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
+
+	if errMsg != "" {
+		br.Msg = errMsg
+		return
+	}
+	companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
+		return
+	}
+	hasPermission := 0
+
+	detail, err := models.GetArticleDetailById(articleId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	detail.Body = html.UnescapeString(detail.Body)
+	detail.Body = strings.Replace(detail.Body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
+	detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
+	detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
+
+	var articlePermissionPermissionName string
+	if detail.CategoryId > 0 {
+		articlePermission, err := models.GetArticlePermission(detail.CategoryId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if articlePermission == nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		articlePermissionPermissionName = articlePermission.PermissionName
+	} else {
+		articlePermissionPermissionName = detail.CategoryName
+	}
+	var hasPersion bool
+	slice := strings.Split(articlePermissionPermissionName, ",")
+	for _, v := range slice {
+		if strings.Contains(companyPermission, v) {
+			hasPersion = true
+		}
+	}
+	if hasPersion {
+		hasPermission = 1
+	}
+	if strings.Contains(detail.CategoryName, "研选") {
+		detail.IsResearch = true
+	}
+
+	resp.HasPermission = hasPermission
+	if hasPermission == 1 {
+		//获取销售手机号
+		sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if sellerItem != nil {
+			detail.SellerMobile = sellerItem.Mobile
+			detail.SellerName = sellerItem.RealName
+		}
+		sellerList, err := models.GetSellerList(articleId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
+			strnum := strings.Index(detail.SellerAndMobile, "-")
+			detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
+			if strnum > 0 {
+				nickName := detail.SellerAndMobile[0:strnum]
+				sellerAndMobile := &models.SellerRep{
+					SellerMobile: "",
+					SellerName:   nickName,
+				}
+				sellerList = append(sellerList, sellerAndMobile)
+			}
+		}
+		detail.SellerList = sellerList
+		resp.Detail = detail
+		historyRecord := new(models.CygxArticleHistoryRecord)
+		historyRecord.UserId = wxUser.UserId
+		historyRecord.ArticleId = articleId
+		historyRecord.CreateTime = time.Now()
+		historyRecord.Mobile = wxUser.Mobile
+		historyRecord.Email = wxUser.Email
+		historyRecord.CompanyId = wxUser.CompanyId
+		historyRecord.CompanyName = companyName
+		recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
+		if recordCount == 0 {
+			go models.AddCygxArticleHistoryRecord(historyRecord)
+		} else {
+			detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取信息失败,Err:" + err.Error()
+				return
+			}
+			if detailNew.StopTime > 0 {
+				go models.AddCygxArticleHistoryRecord(historyRecord)
+			}
+		}
+		key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
+		if !utils.Rc.IsExist(key) {
+			//新增浏览记录
+			record := new(models.CygxArticleViewRecord)
+			record.UserId = wxUser.UserId
+			record.ArticleId = articleId
+			record.CreateTime = time.Now()
+			record.Mobile = wxUser.Mobile
+			record.Email = wxUser.Email
+			record.CompanyId = wxUser.CompanyId
+			record.CompanyName = companyName
+			go models.AddCygxArticleViewRecord(record)
+			utils.Rc.Put(key, 1, 5*time.Second)
+			models.ModifyReportLastViewTime(wxUser.UserId)
+		}
+	}
+	resp.CompanyName = companyName
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 上传文章阅读时间(无需token)
+// @Description 上传文章阅读时间接口(无需token)
+// @Param  request	body models.AddStopTimeHtgjRep true "type json string"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /addStopTimePublic [post]
+func (this *ArticleCommonController) AddStopTimePublic() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	var req models.AddStopTimeHtgjRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	articleId := req.ArticleId
+	stopTime := req.StopTime
+	outType := req.OutType
+	source := req.Source
+	companyCode := req.CompanyCode
+	companyName := req.CompanyName
+	wxuUserName := req.Email
+	sign := req.Sign
+	if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
+		br.Msg = "上传失败"
+		br.ErrMsg = "必填参数不能为空"
+		return
+	}
+	companyNameHt := companyCode + "_" + companyName
+	errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
+	if errMsg != "" {
+		br.Msg = errMsg
+		return
+	}
+	companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	uid := user.UserId
+	if articleId <= 0 {
+		br.Msg = "文章ID不存在"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	if stopTime == 0 {
+		stopTime = 1
+	}
+	if outType != 2 {
+		outType = 1
+	}
+	if source != "PC" {
+		source = "MOBILE"
+	}
+	detail := new(models.ArticleDetail)
+	hasPermission := 0
+	hasFree := 0
+	//判断是否已经申请过
+	applyCount, err := models.GetApplyRecordCount(uid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+	//`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
+	if user.CompanyId > 1 {
+		companyPermission, err := models.GetCompanyPermission(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		detail, err = models.GetArticleDetailById(articleId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if companyPermission == "" {
+			if applyCount > 0 {
+				hasPermission = 5
+			} else {
+				hasPermission = 2
+			}
+			hasFree = 2
+			goto Loop
+		} else {
+			hasFree = 1
+			var articlePermissionPermissionName string
+			if detail.CategoryId > 0 {
+				articlePermission, err := models.GetArticlePermission(detail.CategoryId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+					return
+				}
+				if articlePermission == nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+					return
+				}
+				articlePermissionPermissionName = articlePermission.PermissionName
+			} else {
+				articlePermissionPermissionName = detail.CategoryName
+			}
+			var hasPersion bool
+			slice := strings.Split(articlePermissionPermissionName, ",")
+			for _, v := range slice {
+				if strings.Contains(companyPermission, v) {
+					hasPersion = true
+				}
+			}
+			if hasPersion {
+				detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
+				if err == nil {
+					hasPermission = 1
+					historyRecord := new(models.AddStopTimeNewRep)
+					historyRecord.StopTime = detailNew.StopTime + stopTime
+					historyRecord.Id = detailNew.Id
+					historyRecord.OutType = outType
+					go models.UpdateArticleStopTime(historyRecord)
+				}
+
+				//不统计本公司的阅读记录、正常退出的不做时间差统计
+				if user.CompanyId != 16 && stopTime > 3 {
+					key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
+					record := new(models.CygxArticleHistoryRecordNewpv)
+					record.UserId = uid
+					record.ArticleId = articleId
+					record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
+					record.ModifyTime = time.Now()
+					record.Mobile = user.Mobile
+					record.Email = user.Email
+					record.CompanyId = user.CompanyId
+					record.CompanyName = companyInfo.CompanyName
+					record.StopTime = stopTime
+					record.OutType = outType
+					record.Source = source
+					if !utils.Rc.IsExist(key) || outType != 2 {
+						//新增浏览记录
+						go models.AddCygxArticleViewRecordNewpv(record)
+						recordRedis := new(services.ReportViewRecord)
+						recordRedis.UserId = user.UserId
+						recordRedis.ReportId = articleId
+						recordRedis.Mobile = user.Mobile
+						recordRedis.Email = user.Email
+						recordRedis.RealName = user.RealName
+						recordRedis.CompanyName = companyName
+						recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
+						go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
+					} else {
+						go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
+					}
+					utils.Rc.Put(key, 1, 10*time.Minute)
+				}
+
+				models.ModifyReportLastViewTime(uid)
+			} else { //无该行业权限
+				hasPermission = 3
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 5
+		} else {
+			hasPermission = 4
+		}
+	}
+Loop:
+	resp := new(models.ArticleDetailAddStopTimeRep)
+	resp.HasPermission = hasPermission
+	resp.HasFree = hasFree
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = resp
+}
+
+// @Title 页面访问统计(无需token)
+// @Description 上传页面访问统计(无需token)
+// @Param	request	body models.CygxPageHistoryRecordHtgjRep true "type json string"
+// @Success Ret=200 新增成功
+// @router /pageHistoryPublic [post]
+func (this *ArticleCommonController) PageHistoryPublic() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	var req models.CygxPageHistoryRecordHtgjRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	companyCode := req.CompanyCode
+	companyName := req.CompanyName
+	wxuUserName := req.Email
+	sign := req.Sign
+	if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
+		br.Msg = "上传失败"
+		br.ErrMsg = "必填参数不能为空"
+		return
+	}
+	companyNameHt := companyCode + "_" + companyName
+	errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
+	if errMsg != "" {
+		br.Msg = errMsg
+		return
+	}
+	companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	item := new(models.CygxPageHistoryRecord)
+	item.UserId = user.UserId
+	item.CreateTime = time.Now()
+	item.Mobile = user.Mobile
+	item.Email = user.Email
+	item.CompanyId = user.CompanyId
+	item.CompanyName = companyName
+	item.DetailId = req.DetailId
+	item.ChartPermissionId = req.ChartPermissionId
+	item.IndustrialManagementId = req.IndustrialManagementId
+	item.PageType = "ArticleCopy"
+	_, err = models.AddCygxPageHistoryRecord(item)
+	if err != nil {
+		br.Msg = "记录信息失败"
+		br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "新增成功"
+}

+ 385 - 0
controllers/chart.go

@@ -0,0 +1,385 @@
+package controllers
+
+import (
+	"encoding/json"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/services"
+	"hongze/hongze_cygx/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type ChartController struct {
+	BaseAuthController
+}
+
+type BaseChartController struct {
+	BaseCommonController
+}
+
+// @Title 图表标签分类
+// @Description 图表标签分类接口
+// @Success 200 {object} models.ChartPtagResp
+// @router /patg [get]
+func (this *BaseChartController) Patg() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	list, err := services.GetChartPtagByApi()
+	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   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} models.HomeChartListItem
+// @router /my/collection [get]
+func (this *ChartController) Collection() {
+	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
+	uid := user.UserId
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	resp := new(models.HomeChartListItem)
+	if mobile == "" {
+		page := paging.GetPaging(currentIndex, pageSize, 0)
+		resp.Paging = page
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		resp.IsBindingMobile = false
+		return
+	} else {
+		resp.IsBindingMobile = true
+	}
+	var listCollection []*models.HomeChartListResp
+	var total int
+	//var err error
+	chartUserTokenByMobile, _ := services.GetUserTokenByMobile(mobile)
+	if chartUserTokenByMobile != "" {
+		list, err, _ := services.GetChartCollectionByApi(mobile, 9999, 0)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取我的收藏失败!"
+			br.ErrMsg = "获取图表分类失败 Err:" + err.Error()
+			return
+		}
+		var chartIds string
+		var condition string
+		var pars []interface{}
+		if len(list) > 0 {
+			for _, v := range list {
+				chartIds += strconv.Itoa(v.ChartId) + ","
+			}
+		}
+		chartIds = strings.TrimRight(chartIds, ",")
+		if chartIds == "" {
+			chartIds = "0"
+		}
+		condition = ` AND a.chart_id IN (` + chartIds + `) `
+		total, err = models.GetChartCount(condition, pars)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取帖子总数失败,Err:" + err.Error()
+			return
+		}
+		listCollection, err = models.GetChartListCollection(chartIds, uid, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取信息失败,GetChartListCollection Err:" + err.Error()
+			return
+		}
+	} else {
+		var err error
+		total, err = models.GetChartCountByUser(uid)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取总数失败,Err:" + err.Error()
+			return
+		}
+		listCollection, err = models.GetChartListCollectionWithCygx(uid, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取信息失败,GetChartListCollection Err:" + err.Error()
+			return
+		}
+	}
+	for k, v := range listCollection {
+		if v.NumTop > 0 {
+			listCollection[k].IsTop = true
+		}
+		listCollection[k].Source = 2
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.List = listCollection
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @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
+		//if !detail.IsCollection {
+		//	err = models.RemoveChartCollect(user.UserId, chartId)
+		//}
+	} else {
+		if detail.CollectionNum > 0 {
+			detail.IsCollection = true
+		}
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = detail
+}
+
+// @Title 收藏、取消收藏
+// @Description 收藏、取消收藏
+// @Param	request	body models.ChartCollectReq true "type json string"
+// @Success 200 {object} models.FontsCollectResp
+// @router /collect [post]
+func (this *ChartController) ChartCollect() {
+	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
+	}
+	uid := user.UserId
+	mobile := user.Mobile
+	var req models.ChartCollectReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.ArticleCollectResp)
+	count, err := models.GetChartCountByUserId(uid, req.ChartId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	chartUserTokenByMobile, _ := services.GetUserTokenByMobile(mobile)
+	if chartUserTokenByMobile != "" {
+		GetIsCollectionChart, err := services.GetIsCollectionChart(mobile, req.ChartId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取三方关注信息失败,Err:" + err.Error()
+			return
+		}
+		if !GetIsCollectionChart {
+			if count <= 0 {
+				item := new(models.CygxChartCollect)
+				item.ChartId = req.ChartId
+				item.UserId = uid
+				item.RealName = user.RealName
+				item.CreateTime = time.Now()
+				item.Mobile = user.Mobile
+				item.Email = user.Email
+				item.CompanyId = user.CompanyId
+				item.CompanyName = user.CompanyName
+				_, err = models.AddCygxChartCollect(item)
+				if err != nil {
+					br.Msg = "收藏失败"
+					br.ErrMsg = "收藏失败,Err:" + err.Error()
+					return
+				}
+			}
+			br.Msg = "收藏成功"
+			resp.Status = 1
+		} else {
+			err = models.RemoveChartCollect(uid, req.ChartId)
+			if err != nil {
+				br.Msg = "取消收藏失败"
+				br.ErrMsg = "取消收藏失败,Err:" + err.Error()
+				return
+			}
+			br.Msg = "已取消收藏"
+			resp.Status = 2
+		}
+		//如果存在就取消收藏、反之添加收藏
+		if GetIsCollectionChart {
+			go services.DeleteCollectionChart(mobile, req.ChartId)
+		} else {
+			go services.AddCollectionChart(mobile, req.ChartId)
+		}
+	} else {
+		if count <= 0 {
+			item := new(models.CygxChartCollect)
+			item.ChartId = req.ChartId
+			item.UserId = uid
+			item.RealName = user.RealName
+			item.CreateTime = time.Now()
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.CompanyId = user.CompanyId
+			item.CompanyName = user.CompanyName
+			_, err = models.AddCygxChartCollect(item)
+			if err != nil {
+				br.Msg = "收藏失败"
+				br.ErrMsg = "收藏失败,Err:" + err.Error()
+				return
+			}
+			br.Msg = "收藏成功"
+			resp.Status = 1
+		} else {
+			err = models.RemoveChartCollect(uid, req.ChartId)
+			if err != nil {
+				br.Msg = "取消收藏失败"
+				br.ErrMsg = "取消收藏失败,Err:" + err.Error()
+				return
+			}
+			br.Msg = "已取消收藏"
+			resp.Status = 2
+		}
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}
+
+// @Title 置顶、取消置顶
+// @Description  置顶、取消置顶
+// @Param	request	body models.ChartCollectReq true "type json string"
+// @Success 200 {object} models.FontsCollectResp
+// @router /top [post]
+func (this *ChartController) ChartTop() {
+	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
+	}
+	uid := user.UserId
+	var req models.ChartCollectReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	count, err := models.GetChartTopCountByUserId(uid, req.ChartId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.ArticleCollectResp)
+	if count <= 0 {
+		item := new(models.CygxChartTop)
+		item.ChartId = req.ChartId
+		item.UserId = uid
+		item.RealName = user.RealName
+		item.CreateTime = time.Now()
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		_, err = models.AddCygxChartTop(item)
+		if err != nil {
+			br.Msg = "置顶失败"
+			br.ErrMsg = "收置顶失败,Err:" + err.Error()
+			return
+		}
+		br.Msg = "置顶成功"
+		resp.Status = 1
+	} else {
+		err = models.RemoveChartTop(uid, req.ChartId)
+		if err != nil {
+			br.Msg = "取消置顶失败"
+			br.ErrMsg = "取消置顶失败,Err:" + err.Error()
+			return
+		}
+		br.Msg = "已取消置顶"
+		resp.Status = 2
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 31 - 0
controllers/chart_permission.go

@@ -198,3 +198,34 @@ func (this *ChartPermissionAuthController) StrategyDetail() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 获取所有品种(无需token)
+// @Description 获取所有品种(无需token)
+// @Success 200 {object} models.ChartPermissionResp
+// @router /allPublic [get]
+func (this *ChartPermissionController) DetailPublic() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var condition string
+	list, err := models.GetChartPermissionAll(condition)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.ChartPermissionResp)
+	for k, v := range list {
+		resp.List = append(resp.List, v)
+		if services.GetShowSustainable() && v.PermissionName == "研选" {
+			resp.List[k].IsShowSustainable = true
+		}
+	}
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 55 - 1
controllers/config.go

@@ -10,6 +10,10 @@ type ConfigController struct {
 	BaseAuthController
 }
 
+type BaseConfigController struct {
+	BaseCommonController
+}
+
 // @Title 获取搜索推荐词
 // @Description 获取搜索推荐词
 // @Success 200 {object} models.ConfigResp
@@ -20,6 +24,7 @@ func (this *ConfigController) BrowseHistoryList() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+	resp := new(models.ConfigResp)
 	detail := new(models.CygxConfig)
 	//configCode := "hot_search"
 	//detail, err := models.GetConfigByCode(configCode)
@@ -29,8 +34,31 @@ func (this *ConfigController) BrowseHistoryList() {
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
+
+	chartList, err := models.GetChartListConfig()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range chartList {
+		item := new(models.KeyWord)
+		item.KeyWord = v.Title
+		resp.List = append(resp.List, item)
+	}
+
+	hotList, err := models.GetSearchKeyWordTop()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range hotList {
+		item := new(models.KeyWord)
+		item.KeyWord = v.KeyWord
+		resp.ListHot = append(resp.ListHot, item)
+	}
 	detail.ConfigValue = hotSearch
-	resp := new(models.ConfigResp)
 	resp.Item = detail
 	br.Msg = "获取成功!"
 	br.Ret = 200
@@ -122,3 +150,29 @@ func (this *ConfigController) DescriptionOfResearch() {
 	br.Success = true
 	br.Data = resp
 }
+
+// @Title 获取搜索推荐词(无需token)
+// @Description 获取搜索推荐词(无需token)
+// @Success 200 {object} models.ConfigResp
+// @router /detailPublic [get]
+func (this *BaseConfigController) HotDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	detail := new(models.CygxConfig)
+	hotSearch, err := models.GetHotSearch()
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	detail.ConfigValue = hotSearch
+	resp := new(models.ConfigResp)
+	resp.Item = detail
+	br.Msg = "获取成功!"
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 368 - 0
controllers/home.go

@@ -14,6 +14,10 @@ type HomeController struct {
 	BaseAuthController
 }
 
+type BaseHomeController struct {
+	BaseCommonController
+}
+
 // @Title 首页列表接口
 // @Description 首页列表接口
 // @Param   PageSize   query   int  true       "每页数据条数"
@@ -168,3 +172,367 @@ func (this *HomeController) ListHome() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 首页列表接口(无需token)
+// @Description 首页列表接口(无需token)
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ChartPermissionId   query   int  true       "品类id,最新传0"
+// @Param   CompanyCode     query string  false       "机构编号"
+// @Param   CompanyName     query string  false       "机构名称"
+// @Param   Email     query string  false       "邮箱"
+// @Param   Sign   query   string  false       "加密签名"
+// @Success 200 {object} models.HomeListResp
+// @router /listPublic [get]
+func (this *BaseHomeController) ListHomePublic() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	companyCode := this.GetString("CompanyCode")
+	companyName := this.GetString("CompanyName")
+	email := this.GetString("Email")
+	sign := this.GetString("Sign")
+	var userType int
+	var err error
+	if companyCode != "" && companyName != "" && email != "" {
+		errMsg, errHt, wxUser, _ := services.CheckHtgj(companyCode, companyName, email, sign)
+		if errHt != nil {
+			br.Msg = "获取"
+			br.ErrMsg = "获取数据失败,Err:" + errHt.Error()
+			return
+		}
+		if errMsg != "" {
+			br.Msg = errMsg
+			return
+		}
+		user := wxUser
+		if user == nil {
+			br.Msg = "请登录"
+			br.ErrMsg = "请登录,用户信息为空"
+			br.Ret = 408
+			return
+		}
+		userType, _, err = services.GetUserType(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	chartPermissionId, _ := this.GetInt("ChartPermissionId")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	var condition string
+	var pars []interface{}
+	var total int
+	resp := new(models.HomeListResp)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.HaveResearch = true
+	condition += ` AND is_summary = 1  `
+	if chartPermissionId > 0 {
+		categoryId, err := models.GetCategoryId(chartPermissionId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
+			return
+		}
+		categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败,Err:" + err.Error()
+			return
+		}
+		if userType == 1 && categoryinfo.PermissionName == "研选" {
+			resp.HaveResearch = false
+			resp.Paging = page
+			br.Ret = 200
+			br.Success = true
+			br.Msg = "获取成功"
+			br.Data = resp
+			return
+		}
+		page = paging.GetPaging(currentIndex, pageSize, total)
+		if categoryId != "" {
+			condition += ` AND category_id IN(` + categoryId + `)`
+			condition += ` OR ( category_name  LIKE '%` + categoryinfo.PermissionName + `%' AND publish_status = 1 AND is_summary = 1 )`
+		} else {
+			condition += ` AND  category_name   LIKE '%` + categoryinfo.PermissionName + `%'`
+		}
+	}
+	//永续客户无法查看研选分类的内容
+	if userType == 1 {
+		condition += ` AND  category_name  NOT LIKE '%研选` + `%'`
+	}
+	total, err = models.GetHomeCount(condition, pars)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.Msg = "获取帖子总数失败,Err:" + err.Error()
+		return
+	}
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	list, err := models.GetHomeList(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.Msg = "获取帖子数据失败,Err:" + err.Error()
+		return
+	}
+	for k, _ := range list {
+		item := list[k]
+		//如果文章一开始的内容是图片,优先展示第一张图片
+		imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[k].Body))
+		newBody, _ := services.GetReportContentTextSub(item.Body)
+		list[k].Body = newBody
+		if imgurl != "" {
+			list[k].BodyHtml = imgurl
+		}
+		list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
+		if strings.Contains(item.CategoryName, "研选") {
+			list[k].IsResearch = true
+		}
+		if item.Pv > 999 {
+			list[k].Pv = 999
+		}
+	}
+	resp.List = list
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 首页列表接口v6版本
+// @Description 首页列表接口v6版本
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ChartPermissionId   query   int  true       "品类id,最新传0"
+// @Param   CtagId   query   int  true       "图表子类ID"
+// @Param   ListType   query   int  true       "列表类型,1最新,2 纪要 ,3图表 默认1"
+// @Success 200 {object} models.HomeArtAndChartListResp
+// @router /artAndChart/list [get]
+func (this *HomeController) ListHomeArtAndChart() {
+	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
+	}
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	chartPermissionId, _ := this.GetInt("ChartPermissionId")
+	ctagId, _ := this.GetInt("CtagId")
+	listType, _ := this.GetInt("ListType")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	if listType <= 0 {
+		listType = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	var condition string
+	var pars []interface{}
+	var total, chartTotal int
+	resp := new(models.HomeArtAndChartListResp)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.HaveResearch = true
+	var chartList []*models.HomeChartListResp
+	var err error
+	if listType == 1 {
+		if currentIndex <= 2 {
+			listCtagId := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+			var chartIds string
+			for _, v := range listCtagId {
+				chartListTwo, err := models.GetChartList(`AND  ctag_id = `+strconv.Itoa(v), pars, 0, 2)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+					return
+				}
+				for _, vChart := range chartListTwo {
+					chartIds += strconv.Itoa(vChart.ChartId) + ","
+				}
+			}
+			chartIds = strings.TrimRight(chartIds, ",")
+			condition += ` AND chart_id IN (` + chartIds + `) `
+			chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+				return
+			}
+		}
+	} else if listType == 3 {
+		if chartPermissionId > 0 {
+			condition += ` AND a.ptag_id =? `
+			pars = append(pars, chartPermissionId)
+		}
+		if ctagId > 0 {
+			condition += ` AND a.ctag_id =? `
+			pars = append(pars, ctagId)
+		}
+		chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+			return
+		}
+		chartTotal, err = models.GetChartCount(condition, pars)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取帖子总数失败,Err:" + err.Error()
+			return
+		}
+	}
+	for k, _ := range chartList {
+		chartList[k].IsNeedJump = true
+		chartList[k].Source = 2
+	}
+	resp.ChartList = chartList
+
+	if listType != 3 {
+		userType, _, err := services.GetUserType(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+			return
+		}
+		condition = ` AND is_summary = 1  `
+		if chartPermissionId > 0 {
+			categoryId, err := models.GetCategoryId(chartPermissionId)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
+				return
+			}
+			categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取信息失败,Err:" + err.Error()
+				return
+			}
+			if userType == 1 && categoryinfo.PermissionName == "研选" {
+				resp.HaveResearch = false
+				resp.Paging = page
+				br.Ret = 200
+				br.Success = true
+				br.Msg = "获取成功"
+				br.Data = resp
+				return
+			}
+			page = paging.GetPaging(currentIndex, pageSize, total)
+			if categoryId != "" {
+				condition += ` AND category_id IN(` + categoryId + `)`
+				condition += ` OR ( category_name  LIKE '%` + categoryinfo.PermissionName + `%' AND publish_status = 1 AND is_summary = 1 )`
+			} else {
+				condition += ` AND  category_name   LIKE '%` + categoryinfo.PermissionName + `%'`
+			}
+		}
+		//永续客户无法查看研选分类的内容
+		if userType == 1 {
+			condition += ` AND  category_name  NOT LIKE '%研选` + `%'`
+		}
+		total, err = models.GetHomeCount(condition, pars)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取帖子总数失败,Err:" + err.Error()
+			return
+		}
+
+		list, err := models.GetHomeList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取帖子数据失败,Err:" + err.Error()
+			return
+		}
+		//研选的五张图片
+		detailResearch, err := models.GetConfigByCode("category_research_img_url")
+		if err != nil {
+			br.Msg = "获取数据失败"
+			br.ErrMsg = "获取数据研选分类图片失败,Err:" + err.Error()
+			return
+		}
+		researchList := strings.Split(detailResearch.ConfigValue, "{|}")
+		//对应分类的所图片
+		detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
+		if err != nil {
+			br.Msg = "获取数据失败"
+			br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
+			return
+		}
+		categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
+		mapCategoryUrl := make(map[string]string)
+		var categoryId string
+		var imgUrlChart string
+		for _, v := range categoryUrlList {
+			vslice := strings.Split(v, "_")
+			categoryId = vslice[0]
+			imgUrlChart = vslice[len(vslice)-1]
+			mapCategoryUrl[categoryId] = imgUrlChart
+		}
+
+		for k, v := range list {
+			item := list[k]
+			//如果文章一开始的内容是图片,优先展示第一张图片
+			imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[k].Body))
+			newBody, _ := services.GetReportContentTextSub(item.Body)
+			list[k].Body = newBody
+			if imgurl != "" {
+				list[k].BodyHtml = imgurl
+			}
+			list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
+			if strings.Contains(item.CategoryName, "研选") {
+				list[k].IsResearch = true
+			}
+			if item.Pv > 999 {
+				list[k].Pv = 999
+			}
+			//如果是研选系列的任意取五张图片的中的一张
+			if v.CategoryId == "0" {
+				knum := v.ArticleId % 5
+				list[k].ImgUrlPc = researchList[knum]
+			} else {
+				list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
+			}
+			if list[k].ArticleId < utils.SummaryArticleId {
+				list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
+				list[k].IsNeedJump = true
+			}
+			list[k].Source = 1
+		}
+		resp.List = list
+	}
+	if chartTotal > total {
+		total = chartTotal
+	}
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 3 - 0
controllers/report.go

@@ -1135,6 +1135,8 @@ func (this *ReportController) IsShow() {
 		return
 	}
 	var resp models.IsShow
+	resp.IsShowChart = true
+	resp.IsShowResearch = true
 	mobile := user.Mobile
 	if mobile == "" {
 		br.Ret = 200
@@ -1146,6 +1148,7 @@ func (this *ReportController) IsShow() {
 	if total > 0 {
 		resp.IsShow = true
 	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Data = resp

+ 275 - 0
controllers/search.go

@@ -13,6 +13,10 @@ type SearchController struct {
 	BaseAuthController
 }
 
+type BaseSearchController struct {
+	BaseCommonController
+}
+
 // @Title 搜索接口
 // @Description 搜索接口
 // @Param   PageSize   query   int  true       "每页数据条数"
@@ -217,3 +221,274 @@ func (this *SearchController) SearchReport() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 搜索接口(无需token)
+// @Description 搜索接口(无需token)
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Param   OrderColumn   query   int  true       "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
+// @Param   CompanyCode     query string  false       "机构编号"
+// @Param   CompanyName     query string  false       "机构名称"
+// @Param   Email     query string  false       "邮箱"
+// @Param   Sign   query   string  false       "加密签名"
+// @Success 200 {object} models.SearchItem
+// @router /listPublic [get]
+func (this *BaseSearchController) SearchListPublic() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	keyWord := this.GetString("KeyWord")
+	orderColumn := this.GetString("OrderColumn")
+	if keyWord == "" {
+		br.Msg = "请输入搜索词"
+		br.ErrMsg = "请输入搜索词"
+		return
+	}
+	companyCode := this.GetString("CompanyCode")
+	companyNameHt := this.GetString("CompanyName")
+	email := this.GetString("Email")
+	sign := this.GetString("Sign")
+
+	if orderColumn == "" {
+		orderColumn = "Matching"
+	}
+	indexName := utils.IndexName
+	pageSize = 20
+	var result []*models.SearchItem
+	var total int64
+	var err error
+	if orderColumn == "PublishDate" {
+		tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, 0)
+		result = tmpResult
+		total = tmpTotal
+		err = tmpErr
+	} else {
+		tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, 0, orderColumn)
+		result = tmpResult
+		total = tmpTotal
+		err = tmpErr
+	}
+	if err != nil {
+		br.Msg = "检索失败"
+		br.ErrMsg = "检索失败,Err:" + err.Error()
+		return
+	}
+	if len(result) == 0 {
+		result = make([]*models.SearchItem, 0)
+	}
+
+	if companyCode != "" && companyNameHt != "" && email != "" {
+		errMsg, errHt, wxUser, _ := services.CheckHtgj(companyCode, companyNameHt, email, sign)
+		if errHt != nil {
+			br.Msg = "获取"
+			br.ErrMsg = "获取数据失败,Err:" + errHt.Error()
+			return
+		}
+		if errMsg != "" {
+			br.Msg = errMsg
+			return
+		}
+		user := wxUser
+		detail, errKey := models.GetNewSearchKeyWordByThisUser(user.UserId, keyWord)
+		if errKey != nil && errKey.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败,Err:" + errKey.Error()
+			return
+		}
+		//同一个用户一分钟之内搜索的词不重复记录
+		if detail == nil || time.Now().After(detail.CreateTime.Add(+time.Minute*1)) {
+			keyWordItem := new(models.CygxSearchKeyWord)
+			keyWordItem.UserId = user.UserId
+			keyWordItem.KeyWord = keyWord
+			keyWordItem.CreateTime = time.Now()
+			go models.AddSearchKeyWord(keyWordItem)
+		}
+	}
+	resp := new(models.SearchResp)
+	page := paging.GetPaging(currentIndex, pageSize, int(total))
+	resp.Paging = page
+	resp.List = result
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 搜索接口
+// @Description 搜索接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Param   OrderColumn   query   int  true       "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
+// @Param   ListType   query   int  true       "列表类型,1最新,2 纪要 ,3图表 默认1"
+// @Success 200 {object} models.SearchItem
+// @router /artAndChart/list [get]
+func (this *SearchController) ListHomeArtAndChart() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	listType, _ := this.GetInt("ListType")
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	keyWord := this.GetString("KeyWord")
+	orderColumn := this.GetString("OrderColumn")
+	if keyWord == "" {
+		br.Msg = "请输入搜索词"
+		br.ErrMsg = "请输入搜索词"
+		return
+	}
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+
+	//研选的五张图片
+	detailResearch, errConfig := models.GetConfigByCode("category_research_img_url")
+	if errConfig != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据研选分类图片失败,Err:" + errConfig.Error()
+		return
+	}
+	researchList := strings.Split(detailResearch.ConfigValue, "{|}")
+	//对应分类的所图片
+	detailCategoryUrl, errConfig := models.GetConfigByCode("category_map_img_url")
+	if errConfig != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "行业配置信息失败,Err:" + errConfig.Error()
+		return
+	}
+	categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
+	mapCategoryUrl := make(map[string]string)
+	var categoryId string
+	var imgUrlChart string
+	for _, v := range categoryUrlList {
+		vslice := strings.Split(v, "_")
+		categoryId = vslice[0]
+		imgUrlChart = vslice[len(vslice)-1]
+		mapCategoryUrl[categoryId] = imgUrlChart
+	}
+	if orderColumn == "" {
+		orderColumn = "Matching"
+	}
+	indexName := utils.IndexName
+
+	var chartTotal int
+	resp := new(models.SearchResp)
+	//page := paging.GetPaging(currentIndex, pageSize, total)
+	var chartList []*models.HomeChartListResp
+	var err error
+	var condition string
+	var pars []interface{}
+	if listType == 1 || listType == 3 {
+		if currentIndex <= 2 {
+			condition = ` AND title LIKE '%` + keyWord + `%'`
+			if listType == 1 {
+				pageSize = 100
+			}
+			chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+				return
+			}
+			chartTotal, err = models.GetChartCount(condition, pars)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.Msg = "获取帖子总数失败,Err:" + err.Error()
+				return
+			}
+		}
+	}
+	for k, _ := range chartList {
+		chartList[k].IsNeedJump = true
+		chartList[k].Source = 2
+	}
+	if len(chartList) == 0 {
+		chartList = make([]*models.HomeChartListResp, 0)
+	}
+	resp.ChartList = chartList
+	var result []*models.SearchItem
+	var total int64
+	if listType == 1 || listType == 2 {
+		if orderColumn == "PublishDate" {
+			tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord, startSize, 100, user.UserId)
+			result = tmpResult
+			total = tmpTotal
+			err = tmpErr
+		} else {
+			tmpResult, tmpTotal, tmpErr := services.EsMultiMatchFunctionScoreQuerySort(indexName, keyWord, startSize, pageSize, user.UserId, orderColumn)
+			result = tmpResult
+			total = tmpTotal
+			err = tmpErr
+		}
+		if err != nil {
+			br.Msg = "检索失败"
+			br.ErrMsg = "检索失败,Err:" + err.Error()
+			return
+		}
+		if len(result) == 0 {
+			result = make([]*models.SearchItem, 0)
+		}
+
+		for k, v := range result {
+			//如果是研选系列的任意取五张图片的中的一张
+			if v.CategoryId == "0" {
+				knum := v.ArticleId % 5
+				result[k].ImgUrlPc = researchList[knum]
+			} else {
+				result[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
+			}
+			result[k].Source = 1
+		}
+	}
+	detail, errKey := models.GetNewSearchKeyWordByThisUser(user.UserId, keyWord)
+	if errKey != nil && errKey.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + errKey.Error()
+		return
+	}
+	//同一个用户一分钟之内搜索的词不重复记录
+	if detail == nil || time.Now().After(detail.CreateTime.Add(+time.Minute*1)) {
+		//fmt.Println("一分钟之内没有搜索")
+		keyWordItem := new(models.CygxSearchKeyWord)
+		keyWordItem.UserId = user.UserId
+		keyWordItem.KeyWord = keyWord
+		keyWordItem.CreateTime = time.Now()
+		go models.AddSearchKeyWord(keyWordItem)
+	}
+	if chartTotal > int(total) {
+		total = int64(chartTotal)
+	}
+	page := paging.GetPaging(currentIndex, pageSize, int(total))
+	resp.Paging = page
+	resp.List = result
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 1 - 0
go.mod

@@ -16,5 +16,6 @@ require (
 	github.com/rdlucklib/rdluck_tools v1.0.3
 	github.com/satori/go.uuid v1.2.0 // indirect
 	github.com/tealeg/xlsx v1.0.5
+	golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
 	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
 )

+ 2 - 1
go.sum

@@ -537,8 +537,9 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
-golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
 golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
+golang.org/x/time v0.0.0-20220411224347-583f2d630306 h1:+gHMid33q6pen7kv9xvT+JRinntgeXO2AeZVd0AWD3w=
+golang.org/x/time v0.0.0-20220411224347-583f2d630306/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

+ 1 - 0
models/activity.go

@@ -625,6 +625,7 @@ type CygxActivitySpecialResp struct {
 	MsgType           string `description:"Type : 类型 , Industry : 行业"`
 	SellerMobile      string `description:"销售电话"`
 	SellerName        string `description:"销售姓名"`
+	IsFollow          bool   `description:"是否关注新调研通知"`
 	Detail            *CygxActivitySpecialDetail
 }
 

+ 7 - 0
models/article.go

@@ -99,6 +99,7 @@ type HomeArticle struct {
 	CategoryId       string `description:"文章分类"`
 	HttpUrl          string `description:"文章链接跳转地址"`
 	IsNeedJump       bool   `description:"是否需要跳转链接地址"`
+	Source           int    `description:"来源  1:文章, 2:图表"`
 }
 
 type ArticleDetail struct {
@@ -227,6 +228,12 @@ type ArticleDetailResp struct {
 	Mobile        string `description:"用户手机号"`
 }
 
+type ArticleDetailHtgjResp struct {
+	HasPermission int    `description:"1:有该行业权限,正常展示,0:试用期已过期"`
+	CompanyName   string `description:"公司名称"`
+	Detail        *ArticleDetail
+}
+
 func ModifyArticleExpert(articleId int, expertNumStr, expertContentStr, interviewDateStr, bodyText string) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE cygx_article SET expert_background=?,expert_number=?,interview_date=?,body_text=? WHERE article_id=? `

+ 11 - 1
models/article_history_record.go

@@ -71,6 +71,17 @@ type AddStopTimeRep struct {
 	Source    string `description:"来源,MOBILE:手机端,PC:电脑端"`
 }
 
+type AddStopTimeHtgjRep struct {
+	ArticleId   int    `description:"文章ID"`
+	StopTime    int    `description:"停留时间"`
+	OutType     int    `description:"退出方式,1正常退出,2强制关闭"`
+	Source      string `description:"来源,MOBILE:手机端,PC:电脑端"`
+	CompanyCode string `description:"机构编码"`
+	CompanyName string `description:"机构名称"`
+	Email       string `description:"机构邮箱"`
+	Sign        string `description:"签名"`
+}
+
 type AddStopTimeNewRep struct {
 	Id        int `description:"ID"`
 	ArticleId int `description:"文章ID"`
@@ -101,7 +112,6 @@ func GetNewArticleHistoryRecord(uid, articleId int) (item *AddStopTimeNewRep, er
 //获取用户阅读记录
 func GetNoAddStoptimeArticleCount(uid, articleId int) (count int, err error) {
 	sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? AND create_time > '` + utils.OnlineTime + `' AND stop_time = 0 `
-	//sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE id = ? AND stop_time = 0 `
 	o := orm.NewOrm()
 	err = o.Raw(sqlCount, uid, articleId).QueryRow(&count)
 	return

+ 258 - 0
models/chart.go

@@ -0,0 +1,258 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"time"
+)
+
+type ChartResultApi struct {
+	Data []ChartResultApidate `json:"data"`
+	Code int                  `json:"code"`
+	Msg  string               `json:"msg"`
+}
+
+type ChartFavoritesResultApi struct {
+	Data       []ChartInfo `json:"data"`
+	Code       int         `json:"code"`
+	Msg        string      `json:"msg"`
+	Pagination Pagination  `json:"pagination"`
+}
+
+type Pagination struct {
+	Total     int `json:"total"`
+	Page      int `json:"id"`
+	PageSize  int `json:"page_size"`
+	PageTotal int `json:"page_total"`
+}
+
+type ChartInfo struct {
+	ChartInfo *ChartResultApidate `json:"chart_info"`
+	ChartId   int                 `json:"chart_id"`
+}
+
+type ChartResultApidate struct {
+	ChartId       int    `json:"id"`
+	PtagId        int    `json:"ptag_id"`
+	CtagId        int    `json:"ctag_id"`
+	Title         string `json:"title"`
+	TitleEn       string `json:"title_en"`
+	CreateDate    string `json:"create_date"`
+	UpdateDate    string `json:"update_date"`
+	PublishStatus int    `json:"publish_status"`
+	Cover         string `json:"cover"`
+	Iframe        string `json:"iframe"`
+	Ptag          Ptag   `json:"ptag"`
+	Ctag          Ptag   `json:"ctag"`
+}
+
+type Ptag struct {
+	Id          int    `json:"id"`
+	Name        string `json:"name"`
+	Description string `json:"description"`
+}
+
+type Ctag struct {
+	Id          int    `json:"id"`
+	Name        string `json:"name"`
+	Description string `json:"description"`
+	PtagId      int    `json:"ptag_id"`
+}
+
+type CygxChart struct {
+	Id            int       `orm:"column(id);pk"`
+	ChartId       int       `description:"图表id"`
+	PtagId        int       `description:"图表父类分类id"`
+	CtagId        int       `description:"图表子类分类id"`
+	Title         string    `description:"标题"`
+	TitleEn       string    `description:"英文标题 "`
+	CreateDate    string    `description:"本地创建时间"`
+	CreateDateApi time.Time `description:"图表创建时间"`
+	PublishStatus int       `description:"发布状态"`
+	PtagName      string    `description:"父类名称"`
+	CtagName      string    `description:"子类名称"`
+	Cover         string    `description:"图表图片"`
+	Iframe        string    `description:"图表详情跳转地址"`
+}
+
+type CygxChartDetail struct {
+	ChartId       int    `description:"图表id"`
+	Title         string `description:"标题"`
+	TitleEn       string `description:"英文标题 "`
+	IsCollection  bool   `description:"是否收藏 "`
+	CollectionNum int    `description:"本人收藏数量 "`
+	HttpUrl       string `orm:"column(iframe)";description:"文章链接跳转地址"`
+}
+
+func GetChartCountById(chartId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM cygx_chart WHERE chart_id = ? `
+	err = o.Raw(sql, chartId).QueryRow(&count)
+	return
+}
+
+//新增图表
+func AddCygxChart(item *CygxChart) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+//标签分类
+type ChartPtagResultApi struct {
+	Data []ChartPtagResultApidate `json:"data"`
+	Code int                      `json:"code"`
+	Msg  string                   `json:"msg"`
+}
+
+type ChartPtagResultApidate struct {
+	ChartPermissionId   int    `json:"id"`
+	ChartPermissionName string `json:"name"`
+	Ctag                []Ctag `json:"ctag"`
+}
+
+type ChartPtagResp struct {
+	ChartPermissionId int         `description:"分类ID"`
+	PermissionName    string      `description:"分类名称"`
+	List              []*CtagResp `description:"子分类"`
+}
+
+type CtagResp struct {
+	CtagId int    `description:"子分类ID"`
+	Name   string `description:"子分类名称"`
+}
+
+type ChartUserTokenResult struct {
+	AccessToken string `json:"access_token"`
+}
+
+type ChartUserTokenResultApi struct {
+	Data ChartUserTokenResult `json:"data"`
+	Code int                  `json:"code"`
+	Msg  string               `json:"msg"`
+}
+
+type HomeChartListResp struct {
+	ChartId    int    `description:"图表ID"`
+	Title      string `description:"标题"`
+	TitleEn    string `description:"英文标题 "`
+	CreateDate string `description:"创建时间"`
+	PtagName   string `description:"父类名称"`
+	CtagName   string `description:"子类名称"`
+	BodyHtml   string `orm:"column(cover)";description:"图片链接"`
+	HttpUrl    string `orm:"column(iframe)";description:"文章链接跳转地址"`
+	IsNeedJump bool   `description:"是否需要跳转链接地址"`
+	IsTop      bool   `description:"是否置顶"`
+	NumTop     int    `description:"置顶数量"`
+	Source     int    `description:"来源  1:文章, 2:图表"`
+}
+
+type HomeChartListItem struct {
+	IsBindingMobile bool `description:"是否绑定过手机号"`
+	Paging          *paging.PagingItem
+	List            []*HomeChartListResp `description:"图表列表"`
+}
+
+type ChartCollectReq struct {
+	ChartId int `description:"图表ID"`
+}
+
+//获取图表列表
+func GetChartList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY create_date DESC LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+////获取图表列表
+//func GetChartCtagIds(ctagId int ) (items []*HomeChartListResp, err error) {
+//	o := orm.NewOrm()
+//	sql := ` SELECT  * FROM cygx_chart AS a WHERE a.publish_status=1 AND  ctag_id = 1 ORDER BY create_date DESC LIMIT 2 `
+//	_, err = o.Raw(sql,ctagId).QueryRows(&items)
+//	return
+//}
+
+//获取图表列表
+func GetChartListCollection(chartIds string, userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT a.*,
+			t.create_time AS t_create_time,
+			c.create_time AS c_create_time,
+			( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
+			( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c 
+		FROM
+			cygx_chart AS a
+			LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
+			LEFT JOIN cygx_chart_collect AS c ON c.chart_id = a.chart_id 
+		WHERE
+			a.publish_status = 1 
+			AND a.chart_id IN (` + chartIds + `) 
+		GROUP BY
+			a.chart_id 
+		ORDER BY
+			t_create_time DESC,
+			c_create_time DESC LIMIT ?,? `
+	_, err = o.Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+//获取图表列表本地
+func GetChartListCollectionWithCygx(userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT
+			a.*,
+			t.create_time AS t_create_time,
+			c.create_time AS c_create_time,
+			( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
+			( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c 
+		FROM
+			cygx_chart_collect AS c
+			INNER JOIN cygx_chart AS a ON c.chart_id = a.chart_id
+			LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id 
+		WHERE
+			a.publish_status = 1 
+			AND c.user_id =? 
+		GROUP BY
+			a.chart_id 
+		ORDER BY
+			t_create_time DESC,
+			c_create_time DESC LIMIT ?,? `
+	_, err = o.Raw(sql, userId, userId, userId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+func GetChartListConfig() (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1    AND  ctag_id IN (7,8,9,10) GROUP BY ctag_id  ORDER BY create_date  DESC LIMIT 4 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//获取图表数量
+func GetChartCount(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count
+                FROM cygx_chart AS a
+                WHERE a.publish_status=1 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func GetChartDetailById(chartId, uid int) (item *CygxChartDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * ,( SELECT COUNT( 1 ) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS collection_num
+		FROM
+			cygx_chart  as a 
+		WHERE
+			a.chart_id =? `
+	err = o.Raw(sql, uid, chartId).QueryRow(&item)
+	return
+}

+ 88 - 0
models/chart_collect.go

@@ -0,0 +1,88 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxChartCollect struct {
+	Id          int       `orm:"column(id);pk"`
+	ChartId     int       `description:"图表ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName  string    `description:"所属销售"`
+}
+
+//添加收藏信息
+func AddCygxChartCollect(item *CygxChartCollect) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type ChartCollectResp struct {
+	Status       int `description:"1:收藏,2:取消收藏"`
+	CollectCount int `description:"收藏总数"`
+}
+
+func RemoveChartCollect(userId, ChartId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_chart_collect WHERE user_id=? AND chart_id=? `
+	_, err = o.Raw(sql, userId, ChartId).Exec()
+	return
+}
+
+func GetChartCountByUserId(userId, chartID int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_chart_collect WHERE user_id=? AND chart_id=? `
+	err = orm.NewOrm().Raw(sql, userId, chartID).QueryRow(&count)
+	return
+}
+
+func GetChartCountByUser(userId int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_chart_collect WHERE user_id=?  `
+	err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
+	return
+}
+
+type CygxChartTop struct {
+	Id          int       `orm:"column(id);pk"`
+	ChartId     int       `description:"图表ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName  string    `description:"所属销售"`
+}
+
+//添加置顶信息
+func AddCygxChartTop(item *CygxChartTop) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type ChartTopresp struct {
+	Status       int `description:"1:收藏,2:取消收藏"`
+	CollectCount int `description:"收藏总数"`
+}
+
+func RemoveChartTop(userId, ChartId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_chart_top WHERE user_id=? AND chart_id=? `
+	_, err = o.Raw(sql, userId, ChartId).Exec()
+	return
+}
+
+func GetChartTopCountByUserId(userId, chartID int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_chart_top WHERE user_id=? AND chart_id=? `
+	err = orm.NewOrm().Raw(sql, userId, chartID).QueryRow(&count)
+	return
+}

+ 10 - 0
models/chart_permission.go

@@ -141,3 +141,13 @@ func AddChartPersion(item *CompanyReportPermission) (newId int64, err error) {
 	newId, err = o.Insert(item)
 	return
 }
+
+//获取海通国际开通的默认权限
+func GetCompanyPermissionIdWithHtgj() (chartpermissionids string, err error) {
+	sql := ` SELECT GROUP_CONCAT(DISTINCT chart_permission_id  ORDER BY b.sort ASC  SEPARATOR ',') AS chartpermissionids
+			FROM chart_permission as  b 
+			WHERE chart_permission_name IN ('医药','消费','科技','智造','研选')`
+	o := orm.NewOrm()
+	err = o.Raw(sql).QueryRow(&chartpermissionids)
+	return
+}

+ 20 - 0
models/company.go

@@ -177,6 +177,10 @@ func GetCompanySellerName(companyId int) (sellerName string, err error) {
 	return
 }
 
+type CompanyProductStatus struct {
+	IsSuspend int `description:"1:暂停,0:启用"`
+}
+
 type CompanyProductDetial struct {
 	IsSuspend int    `description:"1:暂停,0:启用"`
 	Scale     string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
@@ -189,3 +193,19 @@ func GetCompanyProductDetail(companyId, productId int) (item *CompanyProductDeti
 	err = o.Raw(sql, companyId, productId).QueryRow(&item)
 	return
 }
+
+//获取公司详情详情
+func GetCompanyByName(companyName string) (item *Company, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *  FROM company WHERE company_name = ? LIMIT 1`
+	err = o.Raw(sql, companyName).QueryRow(&item)
+	return
+}
+
+//获取公司详情详情
+func GetCompanyByThirdName(tripartiteCompanyCode string) (item *Company, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *  FROM company WHERE tripartite_company_code = ? LIMIT 1`
+	err = o.Raw(sql, tripartiteCompanyCode).QueryRow(&item)
+	return
+}

+ 7 - 1
models/config.go

@@ -13,6 +13,10 @@ type CygxConfig struct {
 	CreateTime  time.Time `json:"-"`
 }
 
+type KeyWord struct {
+	KeyWord string `description:"关键词"`
+}
+
 func GetConfigByCode(configCode string) (item *CygxConfig, err error) {
 	sql := `SELECT * FROM cygx_config WHERE config_code=? `
 	err = orm.NewOrm().Raw(sql, configCode).QueryRow(&item)
@@ -20,7 +24,9 @@ func GetConfigByCode(configCode string) (item *CygxConfig, err error) {
 }
 
 type ConfigResp struct {
-	Item *CygxConfig
+	Item    *CygxConfig
+	List    []*KeyWord `description:"图表搜索推荐"`
+	ListHot []*KeyWord `description:"热搜关键词"`
 }
 
 //获取是否展示限免标签

+ 320 - 0
models/crm_company.go

@@ -0,0 +1,320 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+type Company struct {
+	CompanyId             int       `orm:"column(company_id);pk"`
+	CompanyName           string    `description:"客户名称"`
+	CompanyType           int       `orm:"column(type)"`
+	CreditCode            string    `description:"社会统一信用码"`
+	CompanyCode           string    `description:"客户编码"`
+	Sort                  int       `description:"优先级"`
+	IsFeeCustomer         int       `description:"是否付费用户"`
+	Country               string    `description:"国家编码"`
+	Province              string    `description:"省"`
+	City                  string    `description:"市"`
+	Address               string    `description:"详细地址"`
+	Enabled               int       `description:"用户状态"`
+	CreatedTime           time.Time `description:"创建时间"`
+	LastUpdatedTime       time.Time `description:"最后一次阅读时间"`
+	Seller                string    `description:"销售员"`
+	SellsId               int       `description:"销售员id"`
+	CompanyBelong         string    `description:"客户所属,ficc:ficc客户,public_offering:公募客户,partner:合作伙伴"`
+	StartDate             string    `description:"合同开始日期"`
+	EndDate               string    `description:"合同结束日期"`
+	LastType              int       `description:"原客户标签"`
+	IsVip                 int       `description:"0:普通用户,1:大客户"`
+	FirstStartDate        string    `description:"首次设置为试用客户开始时间"`
+	FirstEndDate          string    `description:"首次设置为试用客户结束时间"`
+	DateType              int       `description:"设置流失类型,1:1个月,2:2个月,3:3个月"`
+	Remark                string    `description:"备注信息"`
+	RegionType            string    `description:"地区类型,国内,国外"`
+	OpenCompanyCode       string    `description:"开放给第三方的客户编码,不让第三方定位我们的客户信息"`
+	TripartiteCompanyCode string    `description:"第三方给过来的客户编码,判断客户是否存在"`
+}
+
+type CompanyLog struct {
+	Id              int       `orm:"column(id);pk"`
+	CompanyId       int       `description:"客户id"`
+	CompanyName     string    `description:"客户名称"`
+	CreditCode      string    `description:"统一社会信用码"`
+	CompanyCode     string    `description:"客户编码"`
+	Sort            int       `description:"优先级"`
+	IsFeeCustomer   int       `description:"是否付费用户"`
+	Country         string    `description:"国家编码"`
+	ProvinceId      int       `description:"省id"`
+	CityId          int       `description:"市id"`
+	Address         string    `description:"详细地址"`
+	Ctype           int       `orm:"column(type)" description:"客户标签,1:付费客户,2:试用客户,3:流失客户,4:潜在客户" `
+	Enabled         int       `description:"用户状态"`
+	CreatedTime     time.Time `description:"创建时间"`
+	LastUpdatedTime time.Time `description:"最后修改时间"`
+	Seller          string    `description:"销售员"`
+	SellsId         int       `description:"销售员ID"`
+	CompanyBelong   string    `description:"客户所属,ficc:ficc客户,public_offering:公募客户,partner:合作伙伴"`
+	StartDate       string    `description:"合同开始日期"`
+	EndDate         string    `description:"合同结束日期"`
+	LoseReason      string    `description:"流失原因"`
+	LastType        int       `description:"原客户标签"`
+	FirstStartDate  string    `description:"首次设置为试用客户开始时间"`
+	FirstEndDate    string    `description:"首次设置为试用客户结束时间"`
+	DateType        int       `description:"日期类型"`
+	AdminId         int       `description:"操作人id"`
+	LogType         string    `description:"日志类型"`
+	LogCreateTime   time.Time `description:"日志创建时间"`
+	Province        string    `description:"省"`
+	City            string    `description:"市"`
+}
+
+type CompanyOperationRecord struct {
+	Id              int       `orm:"column(id);pk"`
+	CompanyId       int       `description:"客户id"`
+	CompanyName     string    `description:"客户名称"`
+	SellerId        int       `description:"销售员id"`
+	SysUserId       int       `description:"操作者id"`
+	SysRealName     string    `description:"操作者名称"`
+	Remark          string    `description:"备注"`
+	Operation       string    `description:"操作"`
+	CreateTime      time.Time `description:"操作时间"`
+	ProductId       int       `description:"产品id"`
+	ProductName     string    `description:"产品名称"`
+	ApproveUserId   int       `description:"审批人id"`
+	ApproveRealName string    `description:"审批人姓名"`
+	ApproveContent  string    `description:"审批人内容"`
+	ApproveRemark   string    `description:"审批人内容"`
+	Status          string    `description:"状态"`
+}
+
+type CompanyPermissionLog struct {
+	Id                int `orm:"column(id);pk"`
+	CompanyId         int
+	ChartPermissionId int
+	CreateTime        time.Time
+	SysUserId         int
+	SysUserName       string
+	StartDate         string
+	EndDate           string
+	ProductId         int
+	ProductName       string
+}
+
+type CompanyProduct struct {
+	CompanyProductId    int       `orm:"column(company_product_id);pk" description:"客户产品id"`
+	CompanyId           int       `description:"客户id"`
+	ProductId           int       `description:"产品id"`
+	ProductName         string    `description:"产品名称"`
+	CompanyName         string    `description:"客户名称"`
+	Source              string    `description:"来源"`
+	Reasons             string    `description:"新增理由"`
+	Status              string    `description:"客户状态"`
+	IndustryId          int       `description:"行业id"`
+	IndustryName        string    `description:"行业名称"`
+	SellerId            int       `description:"销售id"`
+	SellerName          string    `description:"销售名称"`
+	GroupId             int       `description:"销售分组id"`
+	DepartmentId        int       `description:"销售部门id"`
+	IsSuspend           int       `description:"1:暂停,0:启用"`
+	SuspendTime         time.Time `description:"暂停启用时间"`
+	TryOutTime          time.Time `description:"正式转试用时间"`
+	RenewalReason       string    `description:"正式转试用后的续约情况说明"`
+	LastDescriptionTime time.Time `description:"上次添加说明时间"`
+	RenewalIntention    int       `description:"是否勾选无续约意向,1:确认,0:未确认"`
+	ApproveStatus       string    `description:"审批状态:'审批中','通过','驳回'"`
+	FreezeTime          time.Time `description:"冻结时间"`
+	FreezeReason        time.Time `description:"冻结理由"`
+	Remark              string    `description:"备注信息"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"修改时间"`
+	StartDate           string    `description:"开始日期"`
+	EndDate             string    `description:"结束日期"`
+	ContractEndDate     time.Time `description:"合同结束日期"`
+	LoseReason          string    `description:"流失原因"`
+	LossTime            time.Time `description:"流失时间"`
+	CompanyType         string    `description:"客户类型"`
+	OpenCode            string    `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
+}
+
+type CompanyProductLog struct {
+	Id               int       `orm:"column(id);pk"`
+	CompanyProductId int       `description:"产品id"`
+	CompanyId        int       `description:"客户id"`
+	ProductId        int       `description:"产品id"`
+	ProductName      string    `description:"产品名称"`
+	CompanyName      string    `description:"客户名称"`
+	Source           string    `description:"来源"`
+	Reasons          string    `description:"新增理由"`
+	Status           string    `description:"客户状态"`
+	IndustryId       int       `description:"行业id"`
+	IndustryName     string    `description:"行业名称"`
+	SellerId         int       `description:"所属销售id"`
+	SellerName       string    `description:"所属销售名称"`
+	GroupId          int       `description:"所属销售分组id"`
+	DepartmentId     int       `description:"所属销售部门id"`
+	IsSuspend        int       `description:"1:暂停,0:启用"`
+	SuspendTime      time.Time `description:"暂停时间"`
+	FreezeTime       time.Time `description:"冻结时间"`
+	Remark           string    `description:"备注信息"`
+	StartDate        string    `description:"开始日期"`
+	EndDate          string    `description:"结束日期"`
+	CreateTime       time.Time `description:"创建时间"`
+	ModifyTime       time.Time `description:"修改时间"`
+	LoseReason       string    `description:"流失原因"`
+	LossTime         time.Time `description:"流失时间"`
+	LogType          string    `description:"日志类型"`
+	LogCreateTime    time.Time `description:"日志创建时间"`
+	AdminId          int       `description:"操作人id"`
+	ApproveStatus    string    `description:"审批状态:'审批中','通过','驳回'"`
+	FreezeStartDate  string    `description:"冻结开始日期"`
+	FreezeEndDate    string    `description:"冻结结束日期"`
+}
+
+//type CompanyReportPermission struct {
+//之前的结构体已存在
+//}
+
+type CompanySource struct {
+	SourceId   int    `orm:"column(source_id);pk"`
+	SourceName string `description:"来源名称"`
+}
+
+//判断公司名称是否存在
+func GetCompanyCountByName(companyName string) (count int, err error) {
+	sql := `SELECT  COUNT(1) AS count FROM company WHERE company_name = ?`
+	err = orm.NewOrm().Raw(sql, companyName).QueryRow(&count)
+	return
+}
+
+//判断三方公司公司名称是否存在
+func GetCompanyCountByThirdName(tripartiteCompanyCode string) (count int, err error) {
+	sql := `SELECT  COUNT(1) AS count FROM company WHERE tripartite_company_code = ?`
+	err = orm.NewOrm().Raw(sql, tripartiteCompanyCode).QueryRow(&count)
+	return
+}
+
+//获取来源详情
+func GetCompanySourceByName(companyName string) (item *CompanySource, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *  FROM company_source WHERE source_name = ?`
+	err = o.Raw(sql, companyName).QueryRow(&item)
+	return
+}
+
+func GetCompanyCode() (companyCode string, err error) {
+	var num int
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS num FROM company WHERE created_time >=? `
+	err = o.Raw(sql, time.Now().Format(utils.FormatDate)).QueryRow(&num)
+	if err != nil {
+		return
+	}
+	companyCode = "KH" + time.Now().Format("20060102") + fmt.Sprintf("%03d", num)
+	return
+}
+
+//新增客户
+func AddCompany(item *Company) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+//更新客户基础信息
+func (company *Company) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(company, cols...)
+	fmt.Println(company)
+	fmt.Println(err)
+	return
+}
+
+//新增客户产品
+func AddCompanyProduct(item *CompanyProduct) (newId int64, err error) {
+	o := orm.NewOrm()
+	newId, err = o.Insert(item)
+	return
+}
+
+//新增客户产品
+func AddCompanyProductLog(item *CompanyProductLog) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+func GetCompanyReportPermissionCount(companyId, productId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM company_report_permission WHERE company_id=? AND product_id=? `
+	err = o.Raw(sql, companyId, productId).QueryRow(&count)
+	return
+}
+
+func DeleteCompanyReportPermission(companyId, productId int) (err error) {
+	o := orm.NewOrm()
+	sql := ` DELETE FROM company_report_permission WHERE company_id=? AND product_id=? `
+	_, err = o.Raw(sql, companyId, productId).Exec()
+	return
+}
+
+//新增客户权限
+func AddCompanyReportPermission(item *CompanyReportPermission) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+//新增客户权限日志
+func AddCompanyPermissionLog(item *CompanyPermissionLog) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+//新增客户操作记录
+func AddCompanyOperationRecord(item *CompanyOperationRecord) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+//新增客户产品
+func AddCompanyLog(item *CompanyLog) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+type UserSellerRelation struct {
+	RelationId int64     `orm:"column(relation_id);pk"`
+	UserId     int       `description:"用户id"`
+	CompanyId  int       `description:"企业用户id"`
+	SellerId   int       `description:"销售id"`
+	Seller     string    `description:"销售员名称"`
+	ProductId  int       `description:"产品id"`
+	Mobile     string    `description:"手机号"`
+	Email      string    `description:"邮箱"`
+	ModifyTime time.Time `description:"修改时间"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+//添加销售员与员工的关系
+func AddUserSellerRelation(userId int64, companyId, sellerId, productId int, seller, mobile, email string) (lastId int64, err error) {
+	o := orm.NewOrm()
+	relation := UserSellerRelation{
+		UserId:     int(userId),
+		SellerId:   sellerId,
+		CompanyId:  companyId,
+		Seller:     seller,
+		ProductId:  productId,
+		Mobile:     mobile,
+		Email:      email,
+		CreateTime: time.Now(),
+		ModifyTime: time.Now(),
+	}
+	lastId, err = o.Insert(&relation)
+	return
+}

+ 10 - 0
models/db.go

@@ -86,12 +86,22 @@ func init() {
 		new(CygxActivityMeetDetailLog),
 		new(CygxUserSearchKeyWord),
 		new(CompanyReportPermission),
+		new(Company),
+		new(CompanyLog),
+		new(CompanyOperationRecord),
+		new(CompanyPermissionLog),
+		new(CompanyProduct),
+		new(CompanyProductLog),
+		new(UserSellerRelation),
 		new(CygxShanghaiCompanyLog),
 		new(CygxShanghaiErrLog),
 		new(CygxUserFreeeButton),
 		new(UserInvitee),
 		new(CygxActivitySpecialSignup),
 		new(CygxUserFollowSpecial),
+		new(CygxChart),
+		new(CygxChartCollect),
+		new(CygxChartTop),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 7 - 0
models/home.go

@@ -35,3 +35,10 @@ type HomeListResp struct {
 	Paging       *paging.PagingItem
 	List         []*HomeArticle
 }
+
+type HomeArtAndChartListResp struct {
+	HaveResearch bool `description:"是否有研选权限"`
+	Paging       *paging.PagingItem
+	List         []*HomeArticle       `description:"文章列表"`
+	ChartList    []*HomeChartListResp `description:"图表列表"`
+}

+ 10 - 0
models/page_history_record.go

@@ -26,6 +26,16 @@ type CygxPageHistoryRecordRep struct {
 	PageType               string `description:"页面类型,纪要:Summary,纪要搜索:SummarySearch,报告:Report,报告搜索:ReportSearch,产业列表:IndustryList,活动:Activit,活动搜索:ActivitSearch,活动详情:ActivitParticulars,报告详情:ReportParticulars , 我的日程:MySchedule, 更多标签:LabelMore , 文章复制:ArticleCopy"`
 }
 
+type CygxPageHistoryRecordHtgjRep struct {
+	DetailId               string `description:"详情ID"`
+	ChartPermissionId      int    `description:"行业ID"`
+	IndustrialManagementId string `description:"产业ID"`
+	CompanyCode            string `description:"机构编码"`
+	CompanyName            string `description:"机构名称"`
+	Email                  string `description:"机构邮箱"`
+	Sign                   string `description:"签名"`
+}
+
 //添加
 func AddCygxPageHistoryRecord(item *CygxPageHistoryRecord) (lastId int64, err error) {
 	o := orm.NewOrm()

+ 3 - 1
models/report.go

@@ -217,7 +217,9 @@ func GetWhichDepartmentCount(condition string) (count int, err error) {
 }
 
 type IsShow struct {
-	IsShow bool `description:"是否展示"`
+	IsShow         bool `description:"是否展示"`
+	IsShowResearch bool `description:"研选是否展示限免"`
+	IsShowChart    bool `description:"图表是否展示限免"`
 }
 
 //获取用户是否有查看权限

+ 4 - 2
models/search.go

@@ -13,6 +13,7 @@ type SearchItem struct {
 	ExpertBackground string   `description:"专家背景"`
 	ImgUrlPc         string   `description:"图片链接"`
 	CategoryId       string   `description:"文章分类"`
+	Source           int      `description:"来源  1:文章, 2:图表"`
 }
 
 type CategoryItem struct {
@@ -31,6 +32,7 @@ func GetCategoryByCompanyId(companyId int) (items []*CategoryItem, err error) {
 }
 
 type SearchResp struct {
-	Paging *paging.PagingItem
-	List   []*SearchItem
+	Paging    *paging.PagingItem
+	List      []*SearchItem
+	ChartList []*HomeChartListResp `description:"图表列表"`
 }

+ 8 - 0
models/search_key_word.go

@@ -26,3 +26,11 @@ func GetNewSearchKeyWordByThisUser(uid int, keyWord string) (item *CygxSearchKey
 	err = o.Raw(sql, uid, keyWord).QueryRow(&item)
 	return
 }
+
+//获取用户搜索词汇频率较高的词
+func GetSearchKeyWordTop() (items []*CygxSearchKeyWord, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT key_word, COUNT(*) AS num FROM cygx_search_key_word GROUP BY key_word ORDER BY num DESC LIMIT 8 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 1 - 1
models/seller.go

@@ -42,7 +42,7 @@ func GetSellerByCompanyIdCheckFicc(companyId, productId int) (item *AdminItem, e
 
 func GetSellerByName(userName string) (item *AdminItem, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM admin WHERE admin_name=? `
+	sql := ` SELECT * FROM admin WHERE real_name=? `
 	err = o.Raw(sql, userName).QueryRow(&item)
 	return
 }

+ 38 - 0
models/wx_user.go

@@ -48,6 +48,7 @@ type WxUser struct {
 	CountryCode         string    `description:"区号"`
 	OutboundMobile      string    `description:"外呼手机号"`
 	OutboundCountryCode string    `description:"外呼手机号区号"`
+	TripartiteCode      string    `description:"第三方给过来的用户编码,判断用户是否存在"`
 }
 
 //添加用户信息
@@ -250,3 +251,40 @@ func UPdateUserCountryCode(item *WxUserItem) (err error) {
 
 	return
 }
+
+//判断公司下用户名称是否存在
+func GetUserCountByName(companyId int, name string) (count int, err error) {
+	sql := `SELECT  COUNT(1) AS count FROM wx_user WHERE company_id = ? AND real_name = ?`
+	err = orm.NewOrm().Raw(sql, companyId, name).QueryRow(&count)
+	return
+}
+
+//判断公司下用户名称是否存在
+func GetUserCountByThirdName(companyId int, name string) (count int, err error) {
+	sql := `SELECT  COUNT(1) AS count FROM wx_user WHERE company_id = ? AND tripartite_code = ?`
+	err = orm.NewOrm().Raw(sql, companyId, name).QueryRow(&count)
+	return
+}
+
+func UpdateUserMobile(uid int, mobile string) (err error) {
+	sql := ` UPDATE wx_user SET mobile=?
+			WHERE user_id=? `
+	_, err = orm.NewOrm().Raw(sql, mobile, uid).Exec()
+	return
+}
+
+//获取公司下用户详情详情详情
+func GetUserByName(companyId int, name string) (item *WxUser, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *  FROM wx_user WHERE company_id = ? AND real_name = ? `
+	err = o.Raw(sql, companyId, name).QueryRow(&item)
+	return
+}
+
+//获取公司下用户详情详情详情
+func GetUserByThirdName(companyId int, name string) (item *WxUser, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *  FROM wx_user WHERE company_id = ? AND tripartite_code = ? `
+	err = o.Raw(sql, companyId, name).QueryRow(&item)
+	return
+}

+ 126 - 0
routers/commentsRouter_controllers.go

@@ -214,6 +214,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleCommonController"],
+        beego.ControllerComments{
+            Method: "AddStopTimePublic",
+            Router: "/addStopTimePublic",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleCommonController"],
+        beego.ControllerComments{
+            Method: "DetailPublic",
+            Router: "/detailPublic",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleCommonController"],
         beego.ControllerComments{
             Method: "Detail",
@@ -223,6 +241,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleCommonController"],
+        beego.ControllerComments{
+            Method: "PageHistoryPublic",
+            Router: "/pageHistoryPublic",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ArticleController"],
         beego.ControllerComments{
             Method: "AddStopTime",
@@ -277,6 +304,78 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseChartController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseChartController"],
+        beego.ControllerComments{
+            Method: "Patg",
+            Router: "/patg",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseConfigController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseConfigController"],
+        beego.ControllerComments{
+            Method: "HotDetail",
+            Router: "/detailPublic",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseHomeController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseHomeController"],
+        beego.ControllerComments{
+            Method: "ListHomePublic",
+            Router: "/listPublic",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseSearchController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:BaseSearchController"],
+        beego.ControllerComments{
+            Method: "SearchListPublic",
+            Router: "/listPublic",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartController"],
+        beego.ControllerComments{
+            Method: "ChartCollect",
+            Router: "/collect",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: "/detail",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartController"],
+        beego.ControllerComments{
+            Method: "Collection",
+            Router: "/my/collection",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartController"],
+        beego.ControllerComments{
+            Method: "ChartTop",
+            Router: "/top",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartPermissionAuthController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartPermissionAuthController"],
         beego.ControllerComments{
             Method: "Detail",
@@ -304,6 +403,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartPermissionController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ChartPermissionController"],
+        beego.ControllerComments{
+            Method: "DetailPublic",
+            Router: "/allPublic",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ConfigController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ConfigController"],
         beego.ControllerComments{
             Method: "DescriptionOfResearch",
@@ -331,6 +439,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:HomeController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:HomeController"],
+        beego.ControllerComments{
+            Method: "ListHomeArtAndChart",
+            Router: "/artAndChart/list",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:HomeController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:HomeController"],
         beego.ControllerComments{
             Method: "ListHome",
@@ -619,6 +736,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:SearchController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:SearchController"],
+        beego.ControllerComments{
+            Method: "ListHomeArtAndChart",
+            Router: "/artAndChart/list",
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:SearchController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:SearchController"],
         beego.ControllerComments{
             Method: "SearchList",

+ 15 - 0
routers/router.go

@@ -27,6 +27,9 @@ func init() {
 			web.NSInclude(
 				&controllers.HomeController{},
 			),
+			web.NSInclude(
+				&controllers.BaseHomeController{},
+			),
 		),
 		web.NSNamespace("/wechat",
 			web.NSInclude(
@@ -55,11 +58,17 @@ func init() {
 			web.NSInclude(
 				&controllers.ConfigController{},
 			),
+			web.NSInclude(
+				&controllers.BaseConfigController{},
+			),
 		),
 		web.NSNamespace("/search",
 			web.NSInclude(
 				&controllers.SearchController{},
 			),
+			web.NSInclude(
+				&controllers.BaseSearchController{},
+			),
 		),
 		web.NSNamespace("/resource",
 			web.NSInclude(
@@ -92,6 +101,12 @@ func init() {
 				&controllers.ResearchController{},
 			),
 		),
+		web.NSNamespace("/chart",
+			web.NSInclude(
+				&controllers.BaseChartController{},
+				&controllers.ChartController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 295 - 0
services/chart.go

@@ -0,0 +1,295 @@
+package services
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"io/ioutil"
+	nhttp "net/http"
+	"strconv"
+	"strings"
+	"time"
+)
+
+//get公共请求方法
+func PublicGetDate(url, authorization string) (body []byte, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", url+"Get ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+	}()
+	method := "GET"
+	client := &nhttp.Client{}
+	req, err := nhttp.NewRequest(method, url, nil)
+	if err != nil {
+		return
+	}
+	req.Header.Add("Authorization", authorization)
+	res, err := client.Do(req)
+	if err != nil {
+		return
+	}
+	defer res.Body.Close()
+	body, err = ioutil.ReadAll(res.Body)
+	if err != nil {
+		return
+	}
+	return
+}
+
+//获取列表
+func GetChartListByApi(cont context.Context) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+	}()
+	url := utils.ApiUrl + "charts/mp?take=100&skip=0"
+	authorization := utils.ApiAuthorization
+	body, err := PublicGetDate(url, authorization)
+	if err != nil {
+		return
+	}
+	var chartResult models.ChartResultApi
+	err = json.Unmarshal(body, &chartResult)
+	if err != nil {
+		return err
+	}
+	for _, v := range chartResult.Data {
+		item := new(models.CygxChart)
+		item.ChartId = v.ChartId
+		item.PtagId = v.PtagId
+		item.CtagId = v.CtagId
+		item.Title = v.Title
+		item.TitleEn = v.TitleEn
+		item.CreateDateApi = time.Now()
+		item.CreateDate = v.CreateDate
+		item.PublishStatus = v.PublishStatus
+		item.PtagName = v.Ptag.Name
+		item.CtagName = v.Ctag.Name
+		item.Cover = v.Cover
+		item.Iframe = v.Iframe
+		count, err := models.GetChartCountById(v.ChartId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			return err
+		}
+		if count == 0 {
+			_, err := models.AddCygxChart(item)
+			if err != nil {
+				return err
+			}
+		} else {
+			updateParams := make(map[string]interface{})
+			updateParams["Title"] = v.Title
+			updateParams["PtagId"] = v.PtagId
+			updateParams["CtagId"] = v.CtagId
+			updateParams["TitleEn"] = v.TitleEn
+			updateParams["CreateDate"] = v.CreateDate
+			updateParams["PublishStatus"] = v.PublishStatus
+			updateParams["PtagName"] = v.Ptag.Name
+			updateParams["CtagName"] = v.Ctag.Name
+			updateParams["Cover"] = v.Cover
+			updateParams["Iframe"] = v.Iframe
+			whereParam := map[string]interface{}{"chart_id": v.ChartId}
+			err = models.UpdateByExpr(models.CygxChart{}, whereParam, updateParams)
+		}
+	}
+	return
+
+}
+
+//获取图表分类
+func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetChartPtagByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+	}()
+	url := utils.ApiUrl + "charts/ptag"
+	authorization := utils.ApiAuthorization
+	body, err := PublicGetDate(url, authorization)
+	if err != nil {
+		return
+	}
+	var chartResult models.ChartPtagResultApi
+	err = json.Unmarshal(body, &chartResult)
+	if err != nil {
+		return
+	}
+	for _, v := range chartResult.Data {
+		item := new(models.ChartPtagResp)
+		item.PermissionName = v.ChartPermissionName
+		item.ChartPermissionId = v.ChartPermissionId
+		if len(v.Ctag) > 0 {
+			for _, v2 := range v.Ctag {
+				itemCtag := new(models.CtagResp)
+				itemCtag.CtagId = v2.Id
+				itemCtag.Name = v2.Name
+				item.List = append(item.List, itemCtag)
+			}
+		}
+		items = append(items, item)
+	}
+	return
+}
+
+//获取用户的Token
+func GetUserTokenByMobile(mobile string) (token string, err error) {
+	//缓存校验
+	cacheKey := fmt.Sprint("xygx_chart:chart_token:add:", "Mobile", mobile)
+	ttlTime := utils.Rc.GetRedisTTL(cacheKey)
+	if ttlTime > 0 {
+		token, _ = utils.Rc.RedisString(cacheKey)
+	}
+	if token == "" {
+		url := utils.ApiUrl + "auth/login"
+		method := "POST"
+		payload := strings.NewReader(`{
+    "phone_number":"` + mobile + `",
+    "password":"hz123456"}`)
+		client := &nhttp.Client{}
+		req, errReq := nhttp.NewRequest(method, url, payload)
+		if errReq != nil {
+			err = errReq
+			return
+		}
+		req.Header.Add("Content-Type", "application/json")
+		req.Header.Add("Cookie", "sessionid=naj5j5kl1jjynh7og1rsaxkl1vrsl829")
+		res, errReq := client.Do(req)
+		if errReq != nil {
+			err = errReq
+			return
+		}
+		defer res.Body.Close()
+		body, errReq := ioutil.ReadAll(res.Body)
+		if errReq != nil {
+			err = errReq
+			return
+		}
+		var chartResult models.ChartUserTokenResultApi
+		errReq = json.Unmarshal(body, &chartResult)
+		if errReq != nil {
+			err = errReq
+			return
+		}
+		token = chartResult.Data.AccessToken
+		utils.Rc.Put(cacheKey, token, time.Hour*24)
+	}
+	return
+}
+
+//获取图表收藏
+func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.HomeChartListResp, err error, total int) {
+	defer func() {
+		if err != nil {
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetChartPtagByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+	}()
+	url := utils.ApiUrl + "charts/favorites?take=" + strconv.Itoa(take) + "&skip=" + strconv.Itoa(skip)
+	authorization, err := GetUserTokenByMobile(mobile)
+	if err != nil {
+		return
+	}
+	authorization = "bearer " + authorization
+	body, err := PublicGetDate(url, authorization)
+	if err != nil {
+		return
+	}
+	var chartResult models.ChartFavoritesResultApi
+	err = json.Unmarshal(body, &chartResult)
+	if err != nil {
+		return
+	}
+	for _, v := range chartResult.Data {
+		item := new(models.HomeChartListResp)
+		item.ChartId = v.ChartId
+		item.Title = v.ChartInfo.Title
+		item.TitleEn = v.ChartInfo.TitleEn
+		item.CreateDate = v.ChartInfo.CreateDate
+		item.PtagName = v.ChartInfo.Ptag.Name
+		item.CtagName = v.ChartInfo.Ctag.Name
+		item.BodyHtml = v.ChartInfo.Cover
+		item.HttpUrl = "https://vmp.hzinsights.com/v2/charts/" + strconv.Itoa(v.ChartId)
+		item.IsNeedJump = true
+		items = append(items, item)
+	}
+	total = chartResult.Pagination.Total
+	return
+}
+
+//判断策略平台是否已经添加过收藏
+func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err error) {
+	//获取所有的收藏列表,进行比对看看是否收藏,调用三方接口详情没有是否收藏的字段
+	list, err, _ := GetChartCollectionByApi(mobile, 9999, 0)
+	if err != nil {
+		return
+	}
+	for _, v := range list {
+		if v.ChartId == chartId {
+			isCollection = true
+		}
+	}
+	return
+}
+
+//添加收藏
+func AddCollectionChart(mobile string, chartId int) (err error) {
+	authorization, err := GetUserTokenByMobile(mobile)
+	if err != nil {
+		return
+	}
+	authorization = "bearer " + authorization
+	url := utils.ApiUrl + "charts/favorites"
+	method := "POST"
+	payload := strings.NewReader(`{
+    "chart_id":` + strconv.Itoa(chartId) + `
+}`)
+	client := &nhttp.Client{}
+	req, err := nhttp.NewRequest(method, url, payload)
+	if err != nil {
+		return
+	}
+	req.Header.Add("Authorization", authorization)
+	req.Header.Add("Content-Type", "application/json")
+	req.Header.Add("Cookie", "sessionid=naj5j5kl1jjynh7og1rsaxkl1vrsl829")
+	res, err := client.Do(req)
+	if err != nil {
+		return
+	}
+	defer res.Body.Close()
+	_, err = ioutil.ReadAll(res.Body)
+	if err != nil {
+		return
+	}
+	return
+}
+
+//移除收藏
+func DeleteCollectionChart(mobile string, chartId int) (err error) {
+	authorization, err := GetUserTokenByMobile(mobile)
+	if err != nil {
+		return
+	}
+	authorization = "bearer " + authorization
+	url := utils.ApiUrl + "charts/favorites/" + strconv.Itoa(chartId)
+	method := "DELETE"
+	client := &nhttp.Client{}
+	req, err := nhttp.NewRequest(method, url, nil)
+	if err != nil {
+		return
+	}
+	req.Header.Add("Authorization", authorization)
+	req.Header.Add("Cookie", "sessionid=naj5j5kl1jjynh7og1rsaxkl1vrsl829")
+	res, err := client.Do(req)
+	if err != nil {
+		return
+	}
+	defer res.Body.Close()
+	_, err = ioutil.ReadAll(res.Body)
+	if err != nil {
+		return
+	}
+	return
+}

+ 0 - 4
services/elastic.go

@@ -707,9 +707,6 @@ func EsMultiMatchFunctionScoreQuerySort(indexName, keyWord string, startSize, pa
 		keyWordArr = append(keyWordArr, keyWord)
 		keyWordLen = len(keyWordArr)
 	}
-	for _, v := range keyWordArr {
-		fmt.Println(v)
-	}
 
 	// @Param   OrderColumn   query   int  true       "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
 	utils.FileLog.Info("SearchKeyWord:%s, userId:%s", keyWordArr, strconv.Itoa(userId))
@@ -823,7 +820,6 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
 		keyWordArr = append(keyWordArr, keyWord)
 		keyWordLen = len(keyWordArr)
 	}
-	fmt.Println(keyWordArr)
 	utils.FileLog.Info("SearchKeyWord:%s, userId:%s", keyWordArr, strconv.Itoa(userId))
 	for _, v := range keyWordArr {
 		if v != "" {

+ 310 - 0
services/htgj.go

@@ -0,0 +1,310 @@
+package services
+
+import (
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+func CheckHtgj(companyCodeHt, companyNameHt, email, sign string) (errMsg string, errHt error, user *models.WxUser, companyName string) {
+	errMsg = CheckSign(companyCodeHt+companyNameHt+email, sign)
+	if errMsg != "" {
+		errMsg = "签名方式错误!"
+		return
+	}
+	var wxuUserName, tripartiteCompanyCode string
+	var startDate, endDate string
+	var companyId int64
+
+	companyName = companyCodeHt[0:4] + "_" + companyNameHt
+	tripartiteCompanyCode = companyCodeHt + "_" + companyNameHt
+	wxUser := new(models.WxUser)
+	productId := 2
+	productName := "权益"
+	itemCompany := new(models.Company)
+	sellerInfo, err := models.GetSellerByName(utils.HtgjDefaultSaleName)
+	if err != nil {
+		errHt = err
+		return
+	}
+	wxuUserName = email
+	countCompay, err := models.GetCompanyCountByThirdName(tripartiteCompanyCode)
+	if err != nil {
+		errHt = err
+		return
+	}
+	if countCompay == 0 {
+		defaultPermissionIds, err := models.GetCompanyPermissionIdWithHtgj()
+		if err != nil {
+			errHt = err
+			return
+		}
+		companySourceInfo, err := models.GetCompanySourceByName(utils.HtgjName)
+		if err != nil {
+			errHt = err
+			return
+		}
+
+		companyCode, err := models.GetCompanyCode()
+		if err != nil {
+			errHt = err
+			return
+		}
+		startDate = time.Now().Format(utils.FormatDate)
+		endDate = time.Now().AddDate(0, 2, 0).Format(utils.FormatDate)
+		itemCompany.TripartiteCompanyCode = tripartiteCompanyCode
+		itemCompany.CompanyName = companyName
+		itemCompany.CreditCode = "HZ" + strconv.FormatInt(time.Now().UnixNano()/1e6, 10)
+		itemCompany.CompanyCode = companyCode
+		itemCompany.StartDate = startDate
+		itemCompany.EndDate = endDate
+		itemCompany.CreatedTime = time.Now()
+		itemCompany.LastUpdatedTime = time.Now()
+		itemCompany.Enabled = 1
+		itemCompany.CompanyType = 2
+		itemCompany.RegionType = "海外"
+		companyId, err = models.AddCompany(itemCompany)
+		if err != nil {
+			errHt = err
+			return
+		}
+		//更新三方Code
+		itemCompany.OpenCompanyCode = GenerateOpenCompanyCode(int(companyId))
+		itemCompany.CompanyId = int(companyId)
+		itemCompany.Update([]string{"OpenCompanyCode"})
+
+		companyProduct := new(models.CompanyProduct)
+		companyProduct.CompanyId = int(companyId)
+		companyProduct.ProductId = productId
+		companyProduct.ProductName = productName
+		companyProduct.CompanyName = companyName
+		companyProduct.Source = companySourceInfo.SourceName
+		companyProduct.Reasons = ""
+		companyProduct.Status = "试用"
+		companyProduct.StartDate = startDate
+		companyProduct.EndDate = endDate
+		companyProduct.IndustryId = 11 //11是海通国际的ID
+		companyProduct.IndustryName = "其他类型"
+		companyProduct.SellerId = sellerInfo.AdminId
+		companyProduct.SellerName = sellerInfo.RealName
+		companyProduct.GroupId = sellerInfo.GroupId
+		companyProduct.DepartmentId = sellerInfo.DepartmentId
+		companyProduct.IsSuspend = 0
+		companyProduct.CreateTime = time.Now()
+		companyProduct.ModifyTime = time.Now()
+		companyProduct.CompanyType = "权益"
+		companyProduct.OpenCode = GenerateOpenCompanyProductCode(int(companyId), productId)
+		companyProductId, err := models.AddCompanyProduct(companyProduct)
+		if err != nil {
+			errHt = err
+			return
+		}
+		err = AddCompanyPermission(int(companyId), sellerInfo.AdminId, productId, productName, sellerInfo.RealName, defaultPermissionIds, startDate, endDate)
+		if err != nil {
+			errHt = err
+			return
+		}
+
+		{
+			record := new(models.CompanyOperationRecord)
+			record.CompanyId = int(companyId)
+			record.CompanyName = companyName
+			record.SellerId = sellerInfo.AdminId
+			record.SysUserId = sellerInfo.AdminId
+			record.SysRealName = sellerInfo.RealName
+			record.Remark = "新增客户"
+			record.Operation = "add"
+			record.CreateTime = time.Now()
+			record.ProductId = productId
+			record.ProductName = productName
+			record.Status = "试用"
+			_, err = models.AddCompanyOperationRecord(record)
+			if err != nil {
+				errHt = err
+				go utils.SendEmail(utils.APPNAME+"失败提醒"+utils.RunMode, "海通国际添加客户失败"+err.Error(), utils.EmailSendToUsers)
+			}
+		}
+		//新增客户日志
+		{
+			companyLog := new(models.CompanyLog)
+			companyLog.CompanyId = int(companyId)
+			companyLog.CompanyName = companyName
+			companyLog.CreditCode = ""
+			companyLog.CompanyCode = companyCode
+			companyLog.Sort = itemCompany.Sort
+			companyLog.IsFeeCustomer = itemCompany.IsFeeCustomer
+			companyLog.Country = itemCompany.Country
+			companyLog.Address = itemCompany.Address
+			companyLog.City = itemCompany.City
+			companyLog.Province = itemCompany.Province
+			companyLog.Enabled = itemCompany.Enabled
+			companyLog.CreatedTime = itemCompany.CreatedTime
+			companyLog.LastUpdatedTime = itemCompany.LastUpdatedTime
+			companyLog.Seller = itemCompany.Seller
+			companyLog.SellsId = itemCompany.SellsId
+			companyLog.CompanyBelong = itemCompany.CompanyBelong
+			companyLog.StartDate = itemCompany.StartDate
+			companyLog.EndDate = itemCompany.EndDate
+			companyLog.FirstStartDate = itemCompany.FirstStartDate
+			companyLog.FirstEndDate = itemCompany.FirstEndDate
+			companyLog.DateType = itemCompany.DateType
+			companyLog.AdminId = sellerInfo.AdminId
+			companyLog.LogType = "add"
+			companyLog.LogCreateTime = time.Now()
+			go models.AddCompanyLog(companyLog)
+		}
+
+		//新增客户产品日志
+		{
+			productLog := new(models.CompanyProductLog)
+			productLog.CompanyProductId = int(companyProductId)
+			productLog.CompanyId = companyProduct.CompanyId
+			productLog.ProductId = companyProduct.ProductId
+			productLog.ProductName = companyProduct.ProductName
+			productLog.CompanyName = companyProduct.CompanyName
+			productLog.CompanyName = companyProduct.CompanyName
+			productLog.Source = companyProduct.Source
+			productLog.Reasons = companyProduct.Reasons
+			productLog.Status = companyProduct.Status
+			productLog.IndustryId = companyProduct.IndustryId
+			productLog.IndustryName = companyProduct.IndustryName
+			productLog.SellerId = companyProduct.SellerId
+			productLog.SellerName = companyProduct.SellerName
+			productLog.GroupId = companyProduct.GroupId
+			productLog.DepartmentId = companyProduct.DepartmentId
+			productLog.IsSuspend = companyProduct.IsSuspend
+			productLog.SuspendTime = companyProduct.SuspendTime
+			productLog.ApproveStatus = companyProduct.ApproveStatus
+			productLog.FreezeTime = companyProduct.FreezeTime
+			productLog.Remark = companyProduct.Remark
+			productLog.StartDate = companyProduct.StartDate
+			productLog.EndDate = companyProduct.EndDate
+			productLog.CreateTime = companyProduct.CreateTime
+			productLog.ModifyTime = companyProduct.ModifyTime
+			productLog.LoseReason = companyProduct.LoseReason
+			productLog.LossTime = companyProduct.LossTime
+			productLog.LogType = "add"
+			productLog.LogCreateTime = time.Now()
+			productLog.AdminId = sellerInfo.AdminId
+			go models.AddCompanyProductLog(productLog)
+		}
+
+	} else {
+		companyInfo, err := models.GetCompanyByThirdName(tripartiteCompanyCode)
+		if err != nil {
+			errHt = err
+			return
+		}
+		companyId = int64(companyInfo.CompanyId)
+	}
+	countUser, err := models.GetUserCountByThirdName(int(companyId), wxuUserName)
+	if countUser == 0 {
+		wxUser.CompanyId = int(companyId)
+		wxUser.RealName = wxuUserName
+		wxUser.Email = wxuUserName
+		wxUser.TripartiteCode = wxuUserName
+		wxUser.Source = 7
+		wxUser.CreatedTime = time.Now()
+		newUserId, err := models.AddWxUser(wxUser)
+		if err != nil {
+			errHt = err
+			return
+		}
+		md5Mobile := utils.Get16MD5Encode(strconv.Itoa(int(newUserId)))
+		wxUser.Mobile = md5Mobile
+		wxUser.UserId = int(newUserId)
+		err = models.UpdateUserMobile(int(newUserId), md5Mobile)
+		if err != nil {
+			errHt = err
+			return
+		}
+		models.AddUserSellerRelation(newUserId, int(companyId), sellerInfo.AdminId, productId, sellerInfo.RealName, wxUser.Mobile, wxuUserName)
+	} else {
+		wxUser, err = models.GetUserByThirdName(int(companyId), wxuUserName)
+		if err != nil {
+			errHt = err
+			return
+		}
+	}
+	user = wxUser
+	return
+}
+
+// GenerateOpenCompanyCode 生成第三方code编号
+func GenerateOpenCompanyCode(companyId int) (openCode string) {
+	openCode = utils.MD5(fmt.Sprint(companyId, "hzyj20210902"))
+	return
+}
+
+// GenerateOpenCompanyProductCode 生成客户产品第三方code编号
+func GenerateOpenCompanyProductCode(companyId, productId int) (openCode string) {
+	openCode = utils.MD5(fmt.Sprint(companyId, "_", productId, "hzyj20210902"))
+	return
+}
+
+//新增客户权限
+func AddCompanyPermission(companyId, sysUserId, productId int, productName, sysUserName, permissionStr, startDate, endDate string) (err error) {
+	if permissionStr == "" {
+		return
+	}
+	permissionArr := strings.Split(permissionStr, ",")
+	count, _ := models.GetCompanyReportPermissionCount(companyId, productId)
+
+	//删除权限
+	if count > 0 {
+		err = models.DeleteCompanyReportPermission(companyId, productId)
+		if err != nil {
+			return
+		}
+	}
+	for _, pv := range permissionArr {
+		permissionId, err := strconv.Atoi(pv)
+		if err != nil {
+			return err
+		}
+		permission := new(models.CompanyReportPermission)
+		permission.CompanyId = companyId
+		permission.ReportPermissionId = permissionId
+		permission.CreatedTime = time.Now()
+		permission.LastUpdatedTime = time.Now()
+		permission.ChartPermissionId = permissionId
+		permission.StartDate = startDate
+		permission.EndDate = endDate
+		permission.ProductId = productId
+		permission.ProductName = productName
+		permission.ModifyTime = time.Now().Format(utils.FormatDateTime)
+		permission.Status = "试用"
+		err = models.AddCompanyReportPermission(permission)
+		if err != nil {
+			return err
+		}
+
+		cpLog := new(models.CompanyPermissionLog)
+		cpLog.CompanyId = companyId
+		cpLog.ChartPermissionId = permissionId
+		cpLog.CreateTime = time.Now()
+		cpLog.SysUserId = sysUserId
+		cpLog.SysUserName = sysUserName
+		cpLog.StartDate = startDate
+		cpLog.EndDate = endDate
+		cpLog.ProductId = productId
+		cpLog.ProductName = productName
+		go models.AddCompanyPermissionLog(cpLog)
+	}
+	return
+}
+
+func CheckSign(userName, sign string) (errMsg string) {
+	var pwdSign string
+	pwdSign = userName + utils.HtgjSalt
+	fmt.Println("pwdSign", pwdSign)
+	pwdSign = strings.ToUpper(utils.MD5(pwdSign))
+	fmt.Println(pwdSign)
+	if sign != pwdSign {
+		errMsg = "签名错误"
+	}
+	return
+}

+ 4 - 0
services/task.go

@@ -39,6 +39,9 @@ func Task() {
 
 		dotongbuShangHaiSendEmail := task.NewTask("dotongbuShangHaiSendEmail", "0 00 4 * * *", DotongbuShangHaiSendEmail) //发送上海策略品台同步结果名单的邮件附件
 		task.AddTask("发送上海策略品台同步结果名单的邮件附件", dotongbuShangHaiSendEmail)
+
+		getChartListByApi := task.NewTask("getChartListByApi", "0 */30 * * * *", GetChartListByApi) //同步图表
+		task.AddTask("getChartListByApi", getChartListByApi)
 	}
 
 	if utils.IsTask {
@@ -61,6 +64,7 @@ func Task() {
 
 		sendEmailFileForAskMsg := task.NewTask("sendEmailFileForAskMsg", "0 */5 8-22 * * *", SendEmailFileForAskMsg) //非研选系列专家电话会,根据主持人姓名,会前15分钟将问题列表发送给至该主持人对应邮箱
 		task.AddTask("sendEmailFileForAskMsg", sendEmailFileForAskMsg)
+
 	}
 
 	//ActivityAttendanceDetail()

+ 1 - 1
services/user.go

@@ -222,7 +222,7 @@ func BindWxUser(openid, mobile, email, countryCode string) (wxUser *models.WxUse
 			OutboundCountryCode: countryCode,
 		}
 		tmpUserId, addUserErr := models.AddWxUser(user)
-		if err != nil {
+		if addUserErr != nil {
 			err = addUserErr
 			return
 		}

+ 7 - 0
utils/common.go

@@ -68,6 +68,13 @@ func MD5(data string) string {
 	return hex.EncodeToString(m[:])
 }
 
+//md5加密
+func Get16MD5Encode(data string) string {
+	m := md5.Sum([]byte(data))
+	encodehex := hex.EncodeToString(m[:])
+	return encodehex[8:24]
+}
+
 // 获取数字随机字符
 func GetRandDigit(n int) string {
 	return fmt.Sprintf("%0"+strconv.Itoa(n)+"d", rnd.Intn(int(math.Pow10(n))))

+ 6 - 0
utils/config.go

@@ -63,6 +63,9 @@ var (
 	EmailExpert               string //研选行业专家邮箱
 	EmaiWhiteUserList         string //白名单邮箱
 	IsTask                    bool   //是否执行定时任务
+	HtgjDefaultSaleName       string //海通默认销售名称
+	HtgjSalt                  string //海通加密使用的盐
+	HtgjName                  string //海通国际名称
 	ActSendMsgMobile          string //活动带问发送模板消息接收者的手机号
 	StrategyPlatform          string //策略品台跳转链接地址
 )
@@ -110,6 +113,9 @@ func init() {
 	YanxSummaryPermissionId = 1001     //研选纪要分类ID
 	YanxViewpointPermissionId = 1002   //研选观点分类ID
 	WxMsgTemplateIdAskMsgMobileAll = "15557270714,18767183922,18621268829"
+	HtgjDefaultSaleName = "王芳"
+	HtgjSalt = "HTGJ&HZ"
+	HtgjName = "海通国际"
 	StrategyPlatform = "https://vmp.hzinsights.com/v2/articles/"
 	if RunMode == "release" {
 		WxAppId = "wxcc32b61f96720d2f"

+ 2 - 0
utils/constants.go

@@ -24,6 +24,8 @@ const (
 	EmailSendToUsers  = "glji@hzinsights.com;pyan@hzinsights.com;cxzhang@hzinsights.com"
 	EmailSendToExpert = "cxzhang@hzinsights.com"
 	DefaultHeadimgurl = "https://hzstatic.hzinsights.com/static/temp/20220426202204/20220426/P5qLR2zzfBdKItp3eX2Du1tvq9Ba.jpg"
+	ApiAuthorization  = "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag"
+	ApiUrl            = "https://vmp.hzinsights.com/v2api/"
 )
 
 //手机号,电子邮箱正则