ziwen 1 年之前
父节点
当前提交
24cd816f06
共有 3 个文件被更改,包括 48 次插入26 次删除
  1. 9 1
      controllers/yanxuan_special.go
  2. 26 25
      models/cygx_yanxuan_special.go
  3. 13 0
      utils/common.go

+ 9 - 1
controllers/yanxuan_special.go

@@ -58,7 +58,15 @@ func (this *YanxuanSpecialController) List() {
 		br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
 		return
 	}
-
+	for _, v := range list {
+		hasImg, err := utils.ArticleHasImgUrl(v.Content)
+		if err != nil {
+			return
+		}
+		if hasImg{
+			v.ContentHasImg = 1
+		}
+	}
 	resp := new(models.SpecialListResp)
 
 

+ 26 - 25
models/cygx_yanxuan_special.go

@@ -22,30 +22,31 @@ type CygxYanxuanSpecial struct {
 }
 
 type CygxYanxuanSpecialItem struct {
-	Id           int    `orm:"column(id);pk"`
-	UserId       int    // 用户ID
-	CreateTime   string // 创建时间
-	ModifyTime   string // 修改时间
-	PublishTime  string // 提审过审或驳回时间
-	Content      string // 内容
-	Tags         string // 标签
-	Status       int    // 1:未发布,2:审核中 3:已发布 4:驳回
-	ImgUrl       string // 图片链接
-	DocUrl       string // 文档链接
-	SpecialName  string // 专栏名称
-	Introduction string // 介绍
-	Label        string // 标签
-	NickName     string // 昵称
-	RealName     string // 姓名
-	Mobile       string // 手机号
-	HeadImg      string // 头像
-	BgImg        string // 背景图
-	Reason       string // 理由
-	Title        string // 标题
-	Type         string // 类型1:笔记,2:观点
-	CollectNum   int
-	MyCollectNum int
-	IsCollect    int
+	Id            int    `orm:"column(id);pk"`
+	UserId        int    // 用户ID
+	CreateTime    string // 创建时间
+	ModifyTime    string // 修改时间
+	PublishTime   string // 提审过审或驳回时间
+	Content       string // 内容
+	Tags          string // 标签
+	Status        int    // 1:未发布,2:审核中 3:已发布 4:驳回
+	ImgUrl        string // 图片链接
+	DocUrl        string // 文档链接
+	SpecialName   string // 专栏名称
+	Introduction  string // 介绍
+	Label         string // 标签
+	NickName      string // 昵称
+	RealName      string // 姓名
+	Mobile        string // 手机号
+	HeadImg       string // 头像
+	BgImg         string // 背景图
+	Reason        string // 理由
+	Title         string // 标题
+	Type          string // 类型1:笔记,2:观点
+	CollectNum    int
+	MyCollectNum  int
+	IsCollect     int
+	ContentHasImg int //正文是否包含图片 1包含 0不包含
 }
 
 func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialItem, err error) {
@@ -61,7 +62,7 @@ JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
 		sql += condition
 	}
 	sql += `ORDER BY a.publish_time DESC `
-	_, err = o.Raw(sql, userId,pars).QueryRows(&items)
+	_, err = o.Raw(sql, userId, pars).QueryRows(&items)
 	return
 }
 

+ 13 - 0
utils/common.go

@@ -7,6 +7,7 @@ import (
 	"encoding/hex"
 	"encoding/json"
 	"fmt"
+	"github.com/PuerkitoBio/goquery"
 	"image"
 	"image/png"
 	"math"
@@ -868,3 +869,15 @@ func GetTimeDateRemoveYearAndSecond(strTime string) (dataStr string) {
 	dataStr = dataStr[:len(dataStr)-3]
 	return
 }
+
+func ArticleHasImgUrl(body string) (hasImg bool, 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) {
+		hasImg = true
+	})
+	return
+}