浏览代码

首页文章列表首图展示

xingzai 3 年之前
父节点
当前提交
4e20cbcae0

+ 44 - 2
controllers/article.go

@@ -1195,7 +1195,7 @@ func (this *ArticleCommonController) Detaisl() {
 
 	var condition string
 	fmt.Println(condition)
-
+	//
 	//list, err := models.GetOfflineMeetingDetailList()
 	//if err != nil {
 	//	br.Msg = "获取失败"
@@ -1219,13 +1219,14 @@ func (this *ArticleCommonController) Detaisl() {
 	//	}
 	//	fmt.Println(newId)
 	//}
-
+	//
 	//list, err := models.GetActivityMeetDetailLog()
 	//if err != nil {
 	//	br.Msg = "获取失败"
 	//	br.ErrMsg = "获取失败,Err:" + err.Error()
 	//	return
 	//}
+	//fmt.Println(len(list))
 	//for _, v := range list {
 	//	condition = ` AND company_name = '` + v.CompanyName + `' `
 	//	total, err := models.GetActivityMeetDetailLogCount(condition)
@@ -1242,6 +1243,46 @@ func (this *ArticleCommonController) Detaisl() {
 	//		return
 	//	}
 	//}
+	//
+	//list1, err := models.ListActivityMeetDetailLogByUser()
+	//
+	//if err != nil {
+	//	br.Msg = "获取失败"
+	//	br.ErrMsg = "获取失败,Err:" + err.Error()
+	//	return
+	//}
+	//for _, v := range list1 {
+	//	fmt.Println(v.ActivityName, v.ActivityId)
+	//
+	//	list, err := models.GetActivityMeetDetailLogByMobile(v.ActivityId)
+	//	if err != nil {
+	//		br.Msg = "获取失败"
+	//		br.ErrMsg = "获取失败,Err:" + err.Error()
+	//		return
+	//	}
+	//	for _, v := range list {
+	//		//condition = ` AND mobile = '` + v.Mobile + `' `
+	//		//total, err := models.GetActivityMeetDetailLogCount(condition)
+	//		//if err != nil {
+	//		//	br.Msg = "获取失败"
+	//		//	br.ErrMsg = "获取失败,Err:" + err.Error()
+	//		//	return
+	//		//}
+	//		//fmt.Println(v.Mobile, total)
+	//		//err = models.UpdateActivityMeetDetailLogByUser(v.Mobile, total)
+	//		//if err != nil {
+	//		//	br.Msg = "获取失败"
+	//		//	br.ErrMsg = "获取失败,Err:" + err.Error()
+	//		//	return
+	//		//}
+	//		//
+	//		err = models.DeleteActivityMeetDetailLogByUser(v)
+	//		if err != nil {
+	//			fmt.Println(err)
+	//		}
+	//	}
+	//
+	//}
 
 	//list, err := models.GetActivityMeetDetailLogByMobile()
 	//if err != nil {
@@ -1264,6 +1305,7 @@ func (this *ArticleCommonController) Detaisl() {
 	//		br.ErrMsg = "获取失败,Err:" + err.Error()
 	//		return
 	//	}
+	//
 	//}
 
 	resp := new(models.ArticleDetailResp)

+ 22 - 2
controllers/home.go

@@ -1,9 +1,11 @@
 package controllers
 
 import (
+	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
+	"html"
 	"rdluck_tools/paging"
 	"strings"
 )
@@ -108,8 +110,26 @@ func (this *HomeController) ListHome() {
 	lenList := len(list)
 	for i := 0; i < lenList; i++ {
 		item := list[i]
-		list[i].BodyHtml = list[i].Body
-		list[i].Body, _ = services.GetReportContentTextSub(item.Body)
+		//如果文章一开始的内容是图片,优先展示第一张图片
+		imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[i].Body))
+		fmt.Println(list[i].Body)
+		newBody, _ := services.GetReportContentTextSub(item.Body)
+		list[i].Body = newBody
+		if len(newBody) > 0 {
+			strnum := strings.Index((list[i].Body), imgurl)
+			newBody = newBody[0:3]
+
+			strnum2 := strings.Index((list[i].Body), newBody)
+			fmt.Println(imgurl)
+			fmt.Println(newBody)
+			fmt.Println(strnum)
+			fmt.Println(strnum2)
+			if strnum < strnum2 {
+				list[i].BodyHtml = `<p>< img src="` + imgurl + `" class="fr-fic fr-dib"></p>`
+			}
+		} else {
+			list[i].BodyHtml = `<p>< img src="` + imgurl + `" class="fr-fic fr-dib"></p>`
+		}
 		list[i].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
 		if strings.Contains(item.CategoryName, "研选") {
 			list[i].IsResearch = true

+ 19 - 0
controllers/report.go

@@ -99,6 +99,7 @@ func (this *ReportController) IndustryList() {
 	fmt.Println(uid)
 	ChartPermissionId, _ := this.GetInt("ChartPermissionId")
 	orderColumn := this.GetString("OrderColumn")
+	orderColumnNew := this.GetString("OrderColumn")
 	isNewLabel := this.GetString("IsNewLabel")
 	isDeepLabel := this.GetString("IsDeepLabel")
 	keyWord := this.GetString("KeyWord")
@@ -222,6 +223,24 @@ func (this *ReportController) IndustryList() {
 			list[k].IsHot = true
 		}
 	}
+	//记录用户搜索的筛选条件
+	if orderColumnNew != "" {
+		item := new(models.CygxReportIndustrialSeaarchHistory)
+		item.UserId = user.UserId
+		item.Mobile = user.Mobile
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.CreateTime = time.Now()
+		item.IsDeepLabel = isDeepLabel
+		item.IsNewLabel = isNewLabel
+		item.ChartPermissionId = ChartPermissionId
+		if orderColumnNew == "NewTime" {
+			item.OrderColumn = "0"
+		} else {
+			item.OrderColumn = "1"
+		}
+		go models.AddCygxReportIndustrialSeaarchHistory(item)
+	}
 	resp.List = list
 	resp.Paging = page
 	br.Ret = 200

+ 23 - 2
models/activity_meet_detail_log.go

@@ -39,7 +39,7 @@ func GetActivityMeetDetailLog() (item []*CygxActivityMeetDetailLog, err error) {
 
 func GetActivityMeetDetailLogByMobile() (item []*CygxActivityMeetDetailLog, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM  cygx_activity_meet_detail_log WHERE mobile !='' GROUP BY mobile `
+	sql := `SELECT * FROM  cygx_activity_meet_detail_log WHERE mobile !=''  GROUP BY mobile `
 	_, err = o.Raw(sql).QueryRows(&item)
 	return
 }
@@ -57,7 +57,7 @@ func GetActivityMeetDetailLogCount(condition string) (count int, err error) {
 
 //修改公司参会数量
 func UpdateActivityMeetDetailLog(companyName string, num int) (err error) {
-	sql := ` UPDATE cygx_activity_meet_detail_log SET  company_meet_num= ?  WHERE company_name = ?`
+	sql := ` UPDATE cygx_activity_meet_detail_log SET  company_meet_num= ?  WHERE company_name = ? `
 	o := orm.NewOrm()
 	_, err = o.Raw(sql, num, companyName).Exec()
 	return
@@ -70,3 +70,24 @@ func UpdateActivityMeetDetailLogByUser(mobile string, num int) (err error) {
 	_, err = o.Raw(sql, num, mobile).Exec()
 	return
 }
+
+func DeleteActivityMeetDetailLogByUser(item *CygxActivityMeetDetailLog) (err error) {
+	o := orm.NewOrm()
+	sql := ` DELETE FROM cygx_activity_meet_detail_log WHERE mobile=? AND  activity_id = ? AND attendance_id != ? AND company_id =?`
+	_, err = o.Raw(sql, item.Mobile, item.ActivityId, item.AttendanceId, item.CompanyId).Exec()
+	return
+}
+
+func ListActivityMeetDetailLogByUser() (items []*CygxActivityList, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT
+	* 
+FROM
+	cygx_activity 
+WHERE
+	activity_type_id IN ( 4,
+	5,
+	6)`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 0 - 1
models/article.go

@@ -93,7 +93,6 @@ type HomeArticle struct {
 	ExpertBackground string `description:"专家背景"`
 	IsResearch       bool   `description:"是否属于研选"`
 	Pv               int    `description:"PV"`
-	FirstImgUrl      string `description:"第一张图片"`
 }
 
 type ArticleDetail struct {

+ 1 - 0
models/db.go

@@ -65,5 +65,6 @@ func init() {
 		new(CygxActivityMeetDetailLog),
 		new(CygxArticleAuthor),
 		new(CygxUserRecord),
+		new(CygxReportIndustrialSeaarchHistory),
 	)
 }

+ 26 - 0
models/report_industrial_seaarch_history.go

@@ -0,0 +1,26 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type CygxReportIndustrialSeaarchHistory struct {
+	Id                int `orm:"column(id);pk"`
+	UserId            int
+	CreateTime        time.Time
+	Mobile            string `description:"手机号"`
+	CompanyId         int    `description:"公司id"`
+	CompanyName       string `description:"公司名称"`
+	ChartPermissionId int    `description:"表chart_permission中id"`
+	IsNewLabel        string `description:"是否属于新标签,1是,0否"`
+	IsDeepLabel       string `description:"是否属于深标签,1是,0否"`
+	OrderColumn       string `description:"排序字段 ,0 最近更新 ,1弘则推荐"`
+}
+
+//添加
+func AddCygxReportIndustrialSeaarchHistory(item *CygxReportIndustrialSeaarchHistory) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 31 - 0
services/article.go

@@ -253,6 +253,37 @@ func FixArticleContent(articleId int) {
 	}
 }
 
+func FixArticleImgUrl(body string) (contentSub string, err error) {
+	r := strings.NewReader(string(body))
+	doc, err := goquery.NewDocumentFromReader(r)
+	if err != nil {
+		fmt.Println(err)
+	}
+	doc.Find("img").Each(func(i int, s *goquery.Selection) {
+
+		src, _ := s.Attr("src")
+		if i == 0 && src != "" {
+			contentSub = src
+		}
+	})
+	return
+}
+
+//获取标签里的第一个内容
+func FixArticleFirstCount(body string) (contentSub string, err error) {
+
+	doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
+	if err != nil {
+		fmt.Println("create doc err:", err.Error())
+		return
+	}
+	doc.Find("p").Each(func(i int, s *goquery.Selection) {
+		contentTxt := s.Text()
+		fmt.Println(contentTxt)
+	})
+	return
+}
+
 func GetArticleListByApi(cont context.Context) (err error) {
 	url := "https://vmp.hzinsights.com/v2api/articles/mp?take=100&skip=0&publish_status=1"
 	method := "GET"