소스 검색

文章详情

xingzai 2 년 전
부모
커밋
ac489cf0d0

+ 255 - 0
controllers/article.go

@@ -0,0 +1,255 @@
+package controllers
+
+import (
+	"fmt"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/services"
+	"hongze/hongze_clpt/utils"
+	"html"
+	"strconv"
+	"strings"
+)
+
+type ArticleController struct {
+	BaseAuthController
+}
+
+type ArticleCommonController struct {
+	BaseCommonController
+}
+
+// @Title 获取报告详情
+// @Description 获取报告详情接口
+// @Param   ArticleId   query   int  true       "报告ID"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /detail [get]
+func (this *ArticleController) Detail() {
+	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
+	}
+
+	uid := user.UserId
+	articleId, err := this.GetInt("ArticleId")
+	if articleId <= 0 {
+		br.Msg = "文章不存在"
+		br.ErrMsg = "文章不存在,文章ID错误"
+		return
+	}
+	detail := new(models.ArticleDetail)
+	hasPermission := 0
+	hasFree := 0
+	var haveResearch bool
+	//判断是否已经申请过
+	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()
+			return
+		}
+		fmt.Println(detail.Body)
+		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 = html.UnescapeString(detail.Abstract)
+		detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
+		if companyPermission == "" {
+			if applyCount > 0 {
+				hasPermission = 5
+			} else {
+				hasPermission = 2
+			}
+			hasFree = 2
+			goto Loop
+		} else {
+			hasPermission = 1
+			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
+				}
+			}
+			fmt.Println(hasPersion)
+
+			userType, _, err := services.GetUserType(user.CompanyId)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+				return
+			}
+			if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
+				hasPersion = false
+			}
+
+			if detail.IsReport == 1 {
+				fmt.Println("报告权限")
+				detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
+				if err != nil && err.Error() != utils.ErrNoRow() {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
+					return
+				}
+				fmt.Println(detailCategory)
+				permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+					return
+				}
+				if detailCategory != nil {
+					if detailCategory.PermissionType == 1 {
+						if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
+							hasPersion = false
+						}
+					} else if detailCategory.PermissionType == 2 {
+						if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
+							hasPersion = false
+						}
+					}
+				}
+			}
+		}
+		collectCount, err := models.GetArticleCollectCount(uid, articleId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if collectCount > 0 {
+			detail.IsCollect = true
+		}
+		interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
+			detail.IsInterviewApply = true
+			detail.InterviewApplyStatus = interviewApplyItem.Status
+		}
+		//获取销售手机号
+		sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		fmt.Println(sellerItem)
+		if sellerItem != nil {
+			detail.Seller.SellerMobile = sellerItem.Mobile
+			detail.Seller.SellerName = sellerItem.RealName
+		}
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+
+		//作者头像
+		if detail.DepartmentId > 0 {
+			departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
+			if err == nil {
+				detail.DepartmentDetail = departmentDetail
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 5
+		} else {
+			hasPermission = 4
+		}
+	}
+Loop:
+	if hasPermission != 1 {
+		detail.Body = ""
+	} else {
+		articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
+			return
+		}
+		detail.FollowNum = articleFollowdetail.DNum
+		detail.CollectionNum = articleFollowdetail.AcNum
+		if articleFollowdetail.MdNum > 0 {
+			detail.IsFollow = true
+		}
+		haveResearch = true
+	}
+	if hasPermission == 2 || hasPermission == 4 {
+		//获取销售手机号
+		sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if sellerItem != nil {
+			detail.Seller.SellerMobile = sellerItem.Mobile
+			detail.Seller.SellerName = sellerItem.RealName
+		}
+	}
+	if detail.ArticleId < utils.SummaryArticleId {
+		if user.Mobile != "" {
+			chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
+			detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
+		} else {
+			detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
+		}
+		detail.IsNeedJump = true
+	}
+	//hasFree := 0
+	//var haveResearch bool
+	fmt.Println(hasFree)
+	fmt.Println(haveResearch)
+	resp := new(models.ArticleDetailResp)
+	resp.HasPermission = hasPermission
+	resp.Detail = detail
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 0 - 1
controllers/home.go

@@ -45,7 +45,6 @@ func (this *MobileHomeController) List() {
 		br.Ret = 408
 		return
 	}
-	fmt.Println(user)
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	chartPermissionId, _ := this.GetInt("ChartPermissionId")

+ 54 - 0
models/apply_record.go

@@ -0,0 +1,54 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxApplyRecord struct {
+	ApplyRecordId   int       `orm:"column(apply_record_id);pk" description:"申请试用id"`
+	BusinessCardUrl string    `description:"名片地址"`
+	RealName        string    `description:"姓名"`
+	CompanyName     string    `description:"公司名称"`
+	Mobile          string    `description:"手机号"`
+	CreateTime      time.Time `description:"创建时间"`
+	ApplyMethod     int       `description:"1:已付费客户申请试用,2:非客户申请试用"`
+}
+
+func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, companyIdPay, CompanyIdType int) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+
+	sql := `INSERT INTO cygx_apply_record (user_id,business_card_url, real_name,company_name, mobile,create_time, apply_method,company_id_pay,company_name_pay,company_id_type)
+          VALUES(?,?,?,?,?,?,?,?,?,?) `
+	_, err = o.Raw(sql, userId, item.BusinessCardUrl, item.RealName, item.CompanyName, mobile, time.Now(), item.ApplyMethod, companyIdPay, companyNamePay, CompanyIdType).Exec()
+	if err != nil {
+		return
+	}
+	msql := `UPDATE  wx_user
+		SET
+		  note = ?,
+		  is_note = 1,
+		  apply_method = ?,
+          real_name=?,
+		  mobile=?
+		WHERE user_id = ? `
+	_, err = o.Raw(msql, item.CompanyName, item.ApplyMethod, item.RealName, mobile, userId).Exec()
+	return
+}
+
+func GetApplyRecordCount(userId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM cygx_apply_record WHERE user_id=? AND status=0 `
+	err = o.Raw(sql, userId).QueryRow(&count)
+	return
+}

+ 88 - 0
models/article.go

@@ -0,0 +1,88 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type ArticleDetail struct {
+	ArticleId            int             `description:"报告id"`
+	IsReport             int             `description:"是否属于报告,1是,0否"`
+	Title                string          `description:"标题"`
+	CategoryName         string          `description:"一级分类"`
+	CategoryId           int             `description:"分类ID"`
+	CreateDate           string          `description:"创建时间"`
+	PublishDate          string          `description:"发布时间"`
+	Body                 string          `description:"内容"`
+	Abstract             string          `description:"摘要"`
+	Annotation           string          `description:"核心观点"`
+	IsInterviewApply     bool            `description:"是否申请访谈:true,已申请,false:未申请"`
+	InterviewApplyStatus string          `description:"当前访谈申请状态:'待邀请','待访谈','已完成','已取消'"`
+	IsFollow             bool            `description:"是否关注,1是,0否"`
+	FollowNum            int             `description:"关注数量"`
+	IsCollect            bool            `description:"是否收藏:true,已收藏,false:未收藏"`
+	CollectionNum        int             `description:"收藏数量"`
+	DepartmentId         int             `description:"作者ID"`
+	DepartmentImgUrl     string          `description:"作者头像"`
+	NickName             string          `description:"作者昵称"`
+	HttpUrl              string          `description:"文章链接跳转地址"`
+	IsNeedJump           bool            `description:"是否需要跳转链接地址"`
+	Seller               SellerResp      `description:"作者昵称"`
+	DepartmentDetail     *DepartmentResp `description:"作者昵称"`
+}
+
+type SellerResp struct {
+	SellerMobile string `description:"销售手机号"`
+	SellerName   string `description:"销售名称"`
+}
+
+type ArticleDetailResp struct {
+	Detail        *ArticleDetail
+	HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
+}
+
+func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article WHERE article_id = ?  AND publish_status = 1  `
+	err = o.Raw(sql, articleId).QueryRow(&item)
+	return
+}
+
+func GetArticlePermission(companyId int) (item *ChartPermission, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			b.* 
+			FROM
+			cygx_report_mapping AS a
+			INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id 
+			WHERE
+			a.category_id = ?`
+	err = o.Raw(sql, companyId).QueryRow(&item)
+	return
+}
+
+type ArticleFollowDetail struct {
+	DNum   int `description:"作者被关注的数量"`
+	MdNum  int `description:"本人是否关注这个作者"`
+	AcNum  int `description:"文章被收藏的数量"`
+	MacNum int `description:"本人是否收藏这个文章"`
+}
+
+//获取文章被关注被收藏的详情
+func GetArticleFollowDetail(articleId, uid int) (item *ArticleFollowDetail, err error) {
+	//d_num 作者被关注的数量 、 md_num 本人是否关注这个作者 、ac_num 文章被收藏的数量 、 mac_num 本人是否收藏这个文章
+	o := orm.NewOrm()
+	sql := ` SELECT
+	( SELECT count( 1 ) FROM cygx_article_department_follow AS af INNER JOIN wx_user as u ON  u.user_id = af.user_id  WHERE af.department_id = art.department_id AND af.type = 1 ) AS d_num,
+	( SELECT count( 1 ) FROM cygx_article_department_follow AS af WHERE af.department_id = art.department_id AND af.type = 1 AND af.user_id = ? ) AS md_num,
+	( SELECT count( 1 ) FROM cygx_article_collect AS ac INNER JOIN wx_user as u ON  u.user_id = ac.user_id  WHERE ac.article_id = art.article_id  ) AS ac_num,
+	( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = art.article_id  AND ac.user_id = ? ) AS mac_num
+FROM
+	cygx_article AS art
+	LEFT JOIN cygx_article_department_follow AS af ON af.department_id = art.department_id
+	LEFT JOIN cygx_article_collect AS ac ON ac.article_id = art.article_id 
+WHERE
+	art.article_id = ?
+	GROUP BY art.article_id `
+	err = o.Raw(sql, uid, uid, articleId).QueryRow(&item)
+	return
+}

+ 151 - 0
models/article_collect.go

@@ -0,0 +1,151 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_clpt/utils"
+	"time"
+)
+
+type CygxArticleCollect struct {
+	Id          int `orm:"column(id);pk"`
+	ArticleId   int
+	UserId      int
+	CreateTime  time.Time
+	Mobile      string `description:"手机号"`
+	Email       string `description:"邮箱"`
+	CompanyId   int    `description:"公司id"`
+	CompanyName string `description:"公司名称"`
+	RealName    string `description:"用户实际名称"`
+}
+
+//添加收藏信息
+func AddCygxArticleCollect(item *CygxArticleCollect) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type ArticleCollectReq struct {
+	ArticleId int `description:"报告id"`
+}
+
+type ArticleCollectResp struct {
+	Status       int `description:"1:收藏,2:取消收藏"`
+	CollectCount int `description:"收藏总数"`
+}
+
+func RemoveArticleCollect(userId, articleId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_article_collect WHERE user_id=? AND article_id=? `
+	_, err = o.Raw(sql, userId, articleId).Exec()
+	return
+}
+
+func GetArticleCollectUsersCount(articleId int) (count int, err error) {
+	sql := `SELECT COUNT(user_id) AS count FROM cygx_article_collect WHERE article_id=? `
+	err = orm.NewOrm().Raw(sql, articleId).QueryRow(&count)
+	return
+}
+
+func GetArticleCollectCount(userId, articleId int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_article_collect WHERE user_id=? AND article_id=? `
+	err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&count)
+	return
+}
+
+type ArticleCollectList struct {
+	Id              int `orm:"column(id);pk"`
+	ArticleId       int
+	UserId          int
+	CreateTime      time.Time
+	Title           string `description:"标题"`
+	TitleEn         string `description:"英文标题 "`
+	UpdateFrequency string `description:"更新周期"`
+	CreateDate      string `description:"创建时间"`
+	PublishDate     string `description:"发布时间"`
+	Body            string `description:"内容"`
+	Abstract        string `description:"摘要"`
+	CategoryName    string `description:"一级分类"`
+	SubCategoryName string `description:"二级分类"`
+}
+
+func GetCygxArticleCollectList(condition string) (items []*CygxArticleCollect, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_collect  WHERE 1 =1   ` + condition + ` GROUP BY user_id  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改用户收藏文章的相关信息
+func UpdateCygxArticleCollect(wxUser *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	var sql string
+	if wxUser.Mobile != "" {
+		sql = `UPDATE cygx_article_collect SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
+		_, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
+	} else if wxUser.Email != "" {
+		sql = `UPDATE cygx_article_collect SET user_id=?,company_id=?,company_name=?,mobile=?,real_name=? WHERE email=? `
+		_, err = o.Raw(sql, wxUser.UserId, wxUser.CompanyId, wxUser.CompanyName, wxUser.Mobile, wxUser.RealName, wxUser.Email).Exec()
+	}
+	return
+}
+
+type CygxArticleCollectCountRep struct {
+	ArticleId int `description:"文章ID"`
+	Num       int `description:"数量"`
+}
+
+//获取文章被收藏的数量
+func GetUserArticleCollectList() (items []*CygxArticleCollectCountRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			COUNT( 1 ) AS num,
+			f.article_id 
+		FROM
+			cygx_article_collect AS f
+			INNER JOIN wx_user AS u ON u.user_id = f.user_id
+			INNER JOIN cygx_article AS a ON a.article_id = f.article_id 
+		WHERE
+			1 = 1 
+		GROUP BY
+			f.article_id 
+		ORDER BY
+			num DESC 
+			LIMIT 30 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改文章收藏的数量
+func UpdateArticleCollectCountNum(num, articleId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_article SET user_collection_num = ? WHERE article_id = ?`
+	_, err = o.Raw(sql, num, articleId).Exec()
+	return
+}
+
+type CygxArticleNum struct {
+	ArticleId  int  `description:"文章ID"`
+	IsCollect  bool `description:"本人是否收藏"`
+	Pv         int  `description:"PV"`
+	CollectNum int  `description:"收藏人数"`
+}
+
+// GetArticleCollectNum 根据文章ID获取收藏数量的列表
+func GetArticleCollectNum(articleId []string, uid int) (items []*CygxArticleNum, err error) {
+	lenarticleId := len(articleId)
+	if lenarticleId == 0 {
+		return
+	}
+	sql := `SELECT
+			a.article_id,
+			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac  INNER JOIN wx_user as u ON  u.user_id = ac.user_id  WHERE ac.article_id = a.article_id  ) AS collect_num, 
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac  INNER JOIN wx_user as u ON  u.user_id = ac.user_id  WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time )  ) AS collect_num_order, 
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac WHERE ac.article_id = a.article_id  AND user_id = ? ) AS is_collect
+		FROM
+			cygx_article AS a WHERE  1 = 1  AND  article_id IN  (` + utils.GetOrmInReplace(lenarticleId) + `) `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, uid, articleId).QueryRows(&items)
+	return
+}

+ 56 - 0
models/article_department.go

@@ -0,0 +1,56 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxArticleDepartment struct {
+	DepartmentId int       `orm:"column(department_id);pk;主键ID"`
+	CreateTime   time.Time `description:"创建时间"`
+	NickName     string    `description:"昵称"`
+	Remark       string    `description:"备注"`
+	Remarks      string    `description:"备注辅助字段"`
+	Content      string    `description:"初始内容"`
+}
+
+type DepartmentResp struct {
+	DepartmentId int    `description:"作者ID"`
+	CreateTime   string `description:"创建时间"`
+	NickName     string `description:"昵称"`
+	ImgUrl       string `description:"头像链接"`
+	IsFollow     bool   `description:"是否关注"`
+}
+
+type CygxArticleDepartmentId struct {
+	DepartmentId int `description:"作者ID"`
+}
+
+func GetArticleDepartmentDateilById(departmentId int) (item *DepartmentResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_department WHERE department_id = ? `
+	err = o.Raw(sql, departmentId).QueryRow(&item)
+	return
+}
+
+//数量
+func GetArticleDepartmentCount(condition string) (count int, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT COUNT(*) count
+		FROM
+		( SELECT COUNT(1)  FROM cygx_article_department AS d
+		INNER JOIN cygx_article AS a ON a.department_id = d.department_id
+		INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+		INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id WHERE 1= 1  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY d.department_id ) AS num `
+
+	err = o.Raw(sql).QueryRow(&count)
+	return
+}
+
+type IndustrialSubjectList struct {
+	SubjectName string `description:"标的名称"`
+}

+ 80 - 0
models/article_interview_apply.go

@@ -0,0 +1,80 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxInterviewApply struct {
+	InterviewApplyId int       `orm:"column(interview_apply_id);pk"`
+	UserId           int       `description:"用户id"`
+	CompanyId        int       `description:"客户id"`
+	Status           string    `description:"'待邀请','待访谈','已完成','已取消'"`
+	InterviewTime    time.Time `description:"访谈时间"`
+	ArticleId        int       `description:"纪要id"`
+	Sort             int       `description:"排序"`
+	ArticleTitle     string    `description:"纪要标题"`
+	CreateTime       time.Time `description:"创建时间"`
+	ModifyTime       time.Time `description:"修改时间"`
+	ArticleIdMd5     string    `description:"纪要id"`
+}
+
+//添加申请访谈信息
+func AddCygxInterviewApply(item *CygxInterviewApply) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type ArticleInterviewApplyReq struct {
+	ArticleId int `description:"报告id"`
+}
+
+type ArticleInterviewApplyResp struct {
+	Status int `description:"1:申请成功,2:取消申请"`
+}
+
+func RemoveArticleInterviewApply(userId, articleId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_interview_apply WHERE user_id=? AND article_id=? AND status<>'已取消' `
+	_, err = o.Raw(sql, userId, articleId).Exec()
+	return
+}
+
+func GetArticleInterviewApplyUsersCount(articleId int) (count int, err error) {
+	sql := `SELECT COUNT(user_id) AS count FROM cygx_interview_apply WHERE article_id=? `
+	err = orm.NewOrm().Raw(sql, articleId).QueryRow(&count)
+	return
+}
+
+func GetArticleInterviewApply(userId, articleId int) (item *CygxInterviewApply, err error) {
+	sql := `SELECT * FROM cygx_interview_apply WHERE user_id=? AND article_id=? AND status<>'已取消' `
+	err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&item)
+	return
+}
+
+func GetArticleInterviewApplyCount(userId, articleId int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_interview_apply WHERE user_id=? AND article_id=? AND status<>'已取消'  `
+	err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&count)
+	return
+}
+
+type ArticleInterviewApplyList struct {
+	Id               int `orm:"column(id);pk"`
+	ArticleId        int
+	UserId           int
+	CreateTime       string
+	Title            string `description:"标题"`
+	TitleEn          string `description:"英文标题 "`
+	UpdateFrequency  string `description:"更新周期"`
+	CreateDate       string `description:"创建时间"`
+	PublishDate      string `description:"发布时间"`
+	Body             string `description:"内容"`
+	Abstract         string `description:"摘要"`
+	CategoryName     string `description:"一级分类"`
+	SubCategoryName  string `description:"二级分类"`
+	Status           string `description:"'待邀请','待访谈','已完成','已取消'"`
+	InterviewTime    string `description:"访谈时间"`
+	ExpertBackground string `description:"专家背景"`
+	ExpertNumber     string `description:"专家编号"`
+}

+ 41 - 0
models/chart_all.go

@@ -0,0 +1,41 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxChartAll struct {
+	Id            int       `orm:"column(id);pk"`
+	ChartId       int       `description:"图表id"`
+	PtagId        int       `description:"图表父类分类id"`
+	CtagId        int       `description:"图表子类分类id"`
+	PtagIdTwo     int       `description:"图表父类分类id"`
+	CtagIdTwo     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:"图表详情跳转地址"`
+	PtagNameTwo   string    `description:"父类名称"`
+	CtagNameTwo   string    `description:"子类名称"`
+}
+
+//获取所有同步过来的图表
+func GetChartAllListAll() (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT chart_id FROM cygx_chart_all  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//新增图表
+func AddCygxChartAll(item *CygxChartAll) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 40 - 0
models/industrial_management.go

@@ -0,0 +1,40 @@
+package models
+
+type IndustrialManagementRep struct {
+	IndustryName           string `description:"产业名称"`
+	IndustrialManagementId int    `description:"产业id"`
+	ChartPermissionId      int    `description:"权限id"`
+	RecommendedIndex       int    `description:"推荐指数"`
+	LayoutTime             string `description:"布局时间"`
+	ArticleReadNum         int    `description:"文章阅读数量"`
+	IsResearch             bool   `description:"是否属于研选"`
+	IsJump                 bool   `description:"是否跳转"`
+}
+
+type IndustrialManagementCount struct {
+	IndustrialManagementId int `orm:"column(industrial_management_id);pk" description:"产业id"`
+}
+
+type IndustrialManagementIdInt struct {
+	IndustrialManagementId int    `description:"产业Id"`
+	IndustryName           string `description:"产业名称"`
+	SubjectName            string `description:"标的名称"`
+	ArticleId              int    `description:"文章ID"`
+	IsResearch             bool   `description:"是否属于研选"`
+}
+
+type IndustrialManagementIdInts struct {
+	IndustrialManagementId  int    `description:"产业Id"`
+	IndustryName            string `description:"产业名称"`
+	SubjectNames            string `description:"标的名称"`
+	ArticleId               int    `description:"文章ID"`
+	IndustrialAndSubjectIds string `description:"关联标的以及产业ID"`
+}
+
+type IndustrialManagementIdName struct {
+	DepartmentId int    `description:"作者ID"`
+	ArticleId    int    `description:"文章id"`
+	IndustryName string `description:"产业名称"`
+	SubjectName  string `description:"标的名称"`
+	IsReport     string `description:"1观点,0纪要"`
+}

+ 212 - 0
models/report_mapping.go

@@ -0,0 +1,212 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type ReportMapping struct {
+	CategoryId          int    `description:"分类ID"`
+	SubCategoryName     string `description:"主题"`
+	MatchTypeName       string `description:"分类名称"`
+	ChartPermissionName string `description:"行业名称"`
+	ChartPermissionId   int    `description:"行业ID"`
+	IsRed               bool   `description:"是否标红"`
+	PermissionType      int    `description:"1主观,2客观"`
+}
+
+type ReportMappingHome struct {
+	CategoryId      int    `description:"分类ID"`
+	SubCategoryName string `description:"主题名称"`
+	MatchTypeName   string `description:"匹配类型"`
+	IsRed           bool   `description:"是否标红"`
+}
+
+type TradeReportMapping struct {
+	CategoryId      int    `description:"分类ID"`
+	SubCategoryName string `description:"主题名称"`
+	MatchTypeName   string `description:"匹配类型"`
+	IsRed           bool   `description:"是否标红"`
+	UpdateTime      string `description:"更新时间"`
+	Readnum         int    `description:"阅读数量"`
+}
+
+type ReportMappingResp struct {
+	List []*ReportMapping
+}
+
+type ReportMappingHomeResp struct {
+	List []*ReportMappingHome
+}
+
+type TradeReportMappingResp struct {
+	List []*TradeReportMapping
+}
+
+//获取策略下面的所有分类
+func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND chart_permission_id=23 ORDER BY sort ASC `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//获取策略下面的所有分类
+func GetReportMappingStrategyHomeAll() (items []*ReportMappingHome, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	re.category_id,re.sub_category_name,re.match_type_name
+FROM
+	cygx_report_mapping AS re
+	INNER JOIN cygx_article AS art ON art.category_id = re.category_id 
+WHERE
+	re.report_type = 1 
+	AND re.chart_permission_id = 23 
+GROUP  BY
+	re.match_type_name
+ORDER BY
+	sort DESC , art.publish_date DESC`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//行业列表
+func GetTradeAll(ChartPermissionId int) (items []*TradeReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+		MAX( art.publish_date ) AS update_time,
+		re.category_id,
+		re.sub_category_name,
+		re.match_type_name 
+		FROM
+		cygx_report_mapping AS re
+		INNER JOIN cygx_article AS art ON re.category_id = art.category_id 
+		WHERE
+		re.chart_permission_id =? 
+		AND re.report_type = 1 
+		AND art.is_class = 1 
+		AND re.category_id NOT IN (67)
+		GROUP BY
+		art.category_id 
+		ORDER BY
+		update_time DESC`
+	_, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
+	return
+}
+
+type IndustrialToArticleCategoryRep struct {
+	CategoryId    int    `description:"分类ID"`
+	MatchTypeName string `description:"匹配类型"`
+	IsRed         bool   `description:"是否标红"`
+}
+
+type IndustrialToArticleCategoryListRep struct {
+	LayoutTime             string `description:"布局时间"`
+	IndustryName           string `description:"产业名称"`
+	IndustrialManagementId int    `description:"产业D"`
+	List                   []*IndustrialToArticleCategoryRep
+}
+
+//通过分类ID获取详情
+func GetdetailByCategoryId(categoryId int) (item *ReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping WHERE report_type=1 AND category_id=? `
+	err = o.Raw(sql, categoryId).QueryRow(&item)
+	return
+}
+
+//通过分类ID获取详情
+func GetdetailByCategoryIdPush(categoryId int) (item *ReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? `
+	err = o.Raw(sql, categoryId).QueryRow(&item)
+	return
+}
+
+//通过分类ID获取详情主观客观
+func GetdetailByCategoryIdSando(categoryId int) (item *ReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping WHERE permission_type>0 AND category_id=?  LIMIT 1`
+	err = o.Raw(sql, categoryId).QueryRow(&item)
+	return
+}
+
+//通过分类ID获取详情
+func GetdetailByCategoryIdOne(categoryId int) (item *ReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_report_mapping WHERE category_id=? LIMIT 1`
+	err = o.Raw(sql, categoryId).QueryRow(&item)
+	return
+}
+
+//判断该分类下最新的文章用户是否阅读
+func CheckThisCategoryNewArticleIsRead(uid, categoryId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) count
+			FROM cygx_article_history_record 
+			WHERE user_id = ? 
+			AND article_id = ( SELECT article_id FROM	cygx_article WHERE	category_id = ? 	AND is_class = 1 	AND is_report = 1 	AND is_filter = 0 ORDER BY publish_date DESC LIMIT 1)`
+	err = o.Raw(sql, uid, categoryId).QueryRow(&count)
+	return
+}
+
+//获取策略下面的所有分类
+func GetMatchTypeNamenNotNull() (items []*ReportMapping, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT category_id,match_type_name FROM cygx_report_mapping WHERE match_type_name <> ''`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+type ReportMappingStatistical struct {
+	CategoryId      int    `description:"分类ID"`
+	SubCategoryName string `description:"主题名称"`
+	MatchTypeName   string `description:"匹配类型"`
+	IsSummary       string `description:"是否属于纪要,1 是,0否"`
+	IsClass         string `description:"是否归类,1 是,0否"`
+	Pv              int    `description:"Pv"`
+	Uv              int    `description:"Uv"`
+}
+
+//获取报表
+func GetStatisticalReportArtilce(chartPermissionId int) (items []*ReportMappingStatistical, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	m.category_id,
+	m.chart_permission_name,
+	a.article_id,
+	a.title,
+	a.is_summary,
+	a.is_class,
+	(SELECT count( 1 ) FROM cygx_article_history_record AS h  WHERE	h.article_id = a.article_id 	) AS pv,
+	(SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h   WHERE h.article_id = a.article_id ) AS uv
+FROM
+	cygx_report_mapping AS m
+	INNER JOIN cygx_article AS a ON a.category_id = m.category_id 
+WHERE
+	m.chart_permission_id = ?
+	and a.is_class= 1
+	and a.is_report= 1
+	and m.id !=28
+	and a.is_filter= 0
+	GROUP BY a.article_id`
+	_, err = o.Raw(sql, chartPermissionId).QueryRows(&items)
+	return
+}
+
+//获取报表
+func GetStatisticalReportArtilceExpert() (items []*ReportMappingStatistical, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	a.article_id,
+	a.title,
+	a.is_summary,
+	a.is_class,
+	(SELECT count( 1 ) FROM cygx_article_history_record AS h  WHERE	h.article_id = a.article_id ) AS pv,
+	(SELECT COUNT( DISTINCT h.user_id ) FROM cygx_article_history_record AS h   WHERE h.article_id = a.article_id ) AS uv
+	FROM
+		cygx_article AS a
+	WHERE
+		a.category_name LIKE '%研选%'`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 71 - 0
models/seller.go

@@ -0,0 +1,71 @@
+package models
+
+import "github.com/beego/beego/v2/client/orm"
+
+type AdminItem struct {
+	AdminId        int    `description:"系统用户id"`
+	RealName       string `description:"系统用户姓名"`
+	Mobile         string `description:"手机号"`
+	RoleType       int    `description:"角色类型:1需要录入指标,0:不需要"`
+	RoleId         int    `description:"角色id"`
+	RoleName       string `description:"角色名称"`
+	RoleTypeCode   string `description:"角色编码"`
+	DepartmentId   int    `description:"部门id"`
+	DepartmentName string `json:"-" description:"部门名称"`
+	GroupId        int    `description:"分组id"`
+	GroupName      string `json:"-" description:"分组名称"`
+	Authority      int    `description:"管理权限,0:无,1:部门负责人,2:小组负责人"`
+	OpenId         string `description:"openId"`
+	CompanyName    string `description:"客户名称"`
+	UserId         int    `description:"联系人id"`
+}
+
+func GetSellerByCompanyId(companyId int) (item *AdminItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT b.*,c.open_id,c.user_id,a.company_name FROM company_product AS a
+			INNER JOIN admin AS b ON a.seller_id=b.admin_id
+			LEFT JOIN wx_user AS c ON b.mobile=c.mobile
+			WHERE a.company_id=? AND role_type_code LIKE '%rai%'`
+	err = o.Raw(sql, companyId).QueryRow(&item)
+	return
+}
+
+func GetSellerByCompanyIdCheckFicc(companyId, productId int) (item *AdminItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT b.*,c.open_id,c.user_id,a.company_name FROM company_product AS a
+			INNER JOIN admin AS b ON a.seller_id=b.admin_id
+			LEFT JOIN wx_user AS c ON b.mobile=c.mobile
+			WHERE a.company_id=? AND a.product_id=?`
+	err = o.Raw(sql, companyId, productId).QueryRow(&item)
+	return
+}
+
+func GetSellerByName(userName string) (item *AdminItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM admin WHERE real_name=? `
+	err = o.Raw(sql, userName).QueryRow(&item)
+	return
+}
+
+//获取本组的销售ID
+func GetSelleridWhichGroup(companyId, productId int) (adminId string, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT
+			GROUP_CONCAT( DISTINCT admin_id SEPARATOR ',' ) AS adminId
+			FROM
+			admin
+			WHERE
+			group_id IN (
+			SELECT
+			a.group_id
+			FROM
+			company_product AS a
+			INNER JOIN admin AS b ON a.seller_id = b.admin_id
+			INNER JOIN wx_user AS c ON b.mobile = c.mobile
+			WHERE
+			a.company_id = ?
+			AND a.product_id = ?
+)`
+	err = o.Raw(sql, companyId, productId).QueryRow(&adminId)
+	return
+}

+ 9 - 0
routers/commentsRouter.go

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

+ 5 - 0
routers/router.go

@@ -51,6 +51,11 @@ func init() {
 				&controllers.MobileHomeController{},
 			),
 		),
+		web.NSNamespace("/article",
+			web.NSInclude(
+				&controllers.ArticleController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 512 - 0
services/chart.go

@@ -0,0 +1,512 @@
+package services
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/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.SendAlarmMsg("发送邮件:同步用户到策略平台信息失败", 2)
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetArticleListByApi ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+	}()
+	mapChartid := make(map[int]int)
+	chartList, err := models.GetChartListAll()
+	if err != nil {
+		return
+	}
+	for _, v := range chartList {
+		mapChartid[v.ChartId] = v.ChartId
+	}
+
+	mapAllChartid := make(map[int]int)
+	chartAllList, err := models.GetChartAllListAll()
+	if err != nil {
+		return
+	}
+	for _, v := range chartAllList {
+		mapAllChartid[v.ChartId] = v.ChartId
+	}
+
+	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.PtagNameTwo = v.PtagTwo.Name
+		item.CtagNameTwo = v.CtagTwo.Name
+		item.PtagIdTwo = v.PtagTwo.Id
+		item.CtagIdTwo = v.CtagTwo.Id
+		item.Cover = v.Cover
+		item.Iframe = v.Iframe
+
+		//如果没有就新增 有就更新
+		if mapChartid[v.ChartId] == 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["PtagNameTwo"] = v.PtagTwo.Name
+			updateParams["CtagNameTwo"] = v.CtagTwo.Name
+			updateParams["PtagIdTwo"] = v.PtagTwo.Id
+			updateParams["CtagIdTwo"] = v.CtagTwo.Id
+			updateParams["Cover"] = v.Cover
+			updateParams["Iframe"] = v.Iframe
+			whereParam := map[string]interface{}{"chart_id": v.ChartId}
+			err = models.UpdateByExpr(models.CygxChart{}, whereParam, updateParams)
+			if err != nil {
+				return err
+			}
+		}
+	}
+
+	//策略平台图表,记录所有,的显示用户收藏使用
+	url = utils.ApiUrl + "charts?take=100&skip=0" // 获取所有的图表链接
+	body, err = PublicGetDate(url, authorization)
+	if err != nil {
+		return
+	}
+
+	err = json.Unmarshal(body, &chartResult)
+	if err != nil {
+		return err
+	}
+	for _, v := range chartResult.Data {
+		item := new(models.CygxChartAll)
+		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.PtagNameTwo = v.PtagTwo.Name
+		item.CtagNameTwo = v.CtagTwo.Name
+		item.PtagIdTwo = v.PtagTwo.Id
+		item.CtagIdTwo = v.CtagTwo.Id
+		item.Cover = v.Cover
+		item.Iframe = v.Iframe
+
+		//如果没有就新增 有就更新
+		if mapAllChartid[v.ChartId] == 0 {
+			_, err := models.AddCygxChartAll(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["PtagNameTwo"] = v.PtagTwo.Name
+			updateParams["CtagNameTwo"] = v.CtagTwo.Name
+			updateParams["PtagIdTwo"] = v.PtagTwo.Id
+			updateParams["CtagIdTwo"] = v.CtagTwo.Id
+			updateParams["Cover"] = v.Cover
+			updateParams["Iframe"] = v.Iframe
+			whereParam := map[string]interface{}{"chart_id": v.ChartId}
+			err = models.UpdateByExpr(models.CygxChartAll{}, whereParam, updateParams)
+			if err != nil {
+				return err
+			}
+		}
+	}
+	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.CreateDate
+		item.PtagName = v.ChartInfo.Ptag.Name
+		item.CtagName = v.ChartInfo.Ctag.Name
+		item.BodyHtml = v.ChartInfo.Cover
+		item.HttpUrl = utils.CHART_INFO_HTTP_URL + 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
+}
+
+func DoCompany() {
+
+	//listCollect, err := models.GetCygxArticleCollectList()
+	//if err != nil {
+	//	fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
+	//}
+	//for _, v := range listCollect {
+	//	user, err := models.GetWxUserItemByUserId(v.UserId)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//	}
+	//	if user != nil {
+	//		fmt.Println(user.RealName)
+	//		err = models.UpdateCygxArticleCollect(user)
+	//		if err != nil {
+	//			fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+	//		}
+	//	}
+	//}
+
+	//listCollect, err := models.GetCygxSearchKeyWordList()
+	//if err != nil {
+	//	fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
+	//}
+	//for _, v := range listCollect {
+	//	user, err := models.GetWxUserItemByUserId(v.UserId)
+	//	if err != nil && err.Error() != utils.ErrNoRow() {
+	//		fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//	}
+	//	if user != nil {
+	//		fmt.Println(user.RealName)
+	//		err = models.UpdateCygxSearchKeyWord(user)
+	//		if err != nil {
+	//			fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+	//		}
+	//	}
+	//}
+	//var condition string
+	////updateTime := time.Now().Add(-time.Hour * 25).Format(utils.FormatDateTime)
+	//condition = ` AND real_name  = '' `
+	//listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
+	//if err != nil {
+	//	fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
+	//}
+	//fmt.Println("长度", len(listArticlePv))
+	//for k, v := range listArticlePv {
+	//	if v.Mobile != "" {
+	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//		}
+	//		if user != nil {
+	//			fmt.Println(user.RealName, k)
+	//			err = models.UpdateCygxArticleHistoryRecordAll(user)
+	//			if err != nil {
+	//				fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
+	//			}
+	//		}
+	//	}
+	//}
+
+	//listIndustryFllow, err := models.GetCygxIndustryFllowList("")
+	//if err != nil {
+	//	fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
+	//}
+	//fmt.Println("长度", len(listIndustryFllow))
+	//for k, v := range listIndustryFllow {
+	//	if v.Mobile != "" {
+	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//		}
+	//		if user != nil {
+	//			fmt.Println(user.RealName, k)
+	//			err = models.UpdateCygxIndustryFllow(user)
+	//			if err != nil {
+	//				fmt.Println("UpdateCygxIndustryFllow ,Err" + err.Error())
+	//			}
+	//		}
+	//	}
+	//}
+	//
+	//lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList("")
+	//if err != nil {
+	//	fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
+	//}
+	//fmt.Println("长度", len(lisDepartmentF))
+	//for k, v := range lisDepartmentF {
+	//	if v.Mobile != "" {
+	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//		}
+	//		if user != nil {
+	//			fmt.Println(user.RealName, k)
+	//			err = models.UpdateCygxArticleDepartmentFollow(user)
+	//			if err != nil {
+	//				fmt.Println("UpdateCygxArticleDepartmentFollow ,Err" + err.Error())
+	//			}
+	//		}
+	//	}
+	//}
+
+	//listChartCollect, err := models.GetCygxChartCollectByMobileList()
+	//if err != nil {
+	//	fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
+	//}
+	//fmt.Println("长度", len(listChartCollect))
+	//for k, v := range listChartCollect {
+	//	if v.Mobile != "" {
+	//		user, err := models.GetWxUserItemByMobile(v.Mobile)
+	//		if err != nil && err.Error() != utils.ErrNoRow() {
+	//			fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
+	//		}
+	//		if user != nil {
+	//			fmt.Println(user.RealName, k)
+	//			err = models.UpdateCygxChartCollect(user)
+	//			if err != nil {
+	//				fmt.Println("UpdateCygxChartCollect ,Err" + err.Error())
+	//			}
+	//		}
+	//	}
+	//}
+
+	fmt.Println("end")
+}

+ 5 - 2
utils/constants.go

@@ -20,8 +20,11 @@ const (
 )
 
 const (
-	APPNAME          = "弘则-策略平台网页版"
-	EmailSendToUsers = "cxzhang@hzinsights.com"
+	APPNAME             = "弘则-策略平台网页版"
+	EmailSendToUsers    = "cxzhang@hzinsights.com"
+	ApiAuthorization    = "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkiLCJwaG9uZV9udW1iZXIiOiIxMjM0NTY3ODkiLCJuYW1lIjoi5YW25LuWIiwiZW50cmFuY2UiOiJwYXNzd3dvcmQiLCJpYXQiOjE2MzQ4NzA1OTQsImV4cCI6MTYzNDg3NDE5NH0.tho2L9jsbDPn8ltEGUVDve_nHsh0Kzf6ZrSz0RcZ0ag"
+	ApiUrl              = "https://vmp.hzinsights.com/v2api/"
+	CHART_INFO_HTTP_URL = "https://vmp.hzinsights.com/v2/charts/"
 )
 
 //手机号,电子邮箱正则

+ 24 - 0
utils/email.go

@@ -1,7 +1,9 @@
 package utils
 
 import (
+	"encoding/json"
 	"fmt"
+	"github.com/rdlucklib/rdluck_tools/http"
 	"gopkg.in/gomail.v2"
 	"mime"
 	"strings"
@@ -125,3 +127,25 @@ func SendEmailByHongze(title, content string, touser, attachPath, attachName str
 	}
 	return true
 }
+
+var (
+	AlarmMsgUrl = "http://127.0.0.1:8606/api/alarm/send"
+)
+
+//projectName-项目名称
+//runMode-运行模式
+//msgBody-消息内容
+//level:消息基本,1:提示消息,2:警告消息,3:严重错误信息,默认为1 提示消息
+func SendAlarmMsg(msgBody string, level int) {
+	params := make(map[string]interface{})
+	params["ProjectName"] = APPNAME
+	params["RunMode"] = RunMode
+	params["MsgBody"] = msgBody
+	params["Level"] = level
+	param, err := json.Marshal(params)
+	if err != nil {
+		FileLog.Info("SendAlarmMsg json.Marshal Err:" + err.Error())
+		return
+	}
+	http.Post(AlarmMsgUrl, string(param))
+}