ziwen 1 年之前
父節點
當前提交
e67f10863b
共有 3 個文件被更改,包括 80 次插入24 次删除
  1. 9 0
      controllers/yanxuan_special.go
  2. 56 24
      models/cygx_yanxuan_special.go
  3. 15 0
      utils/common.go

+ 9 - 0
controllers/yanxuan_special.go

@@ -554,6 +554,15 @@ func (this *YanxuanSpecialController) Center() {
 		return
 	}
 
+	for _, v := range list {
+		hasStyle, err := utils.ArticleHasStyle(v.Content)
+		if err != nil {
+			return
+		}
+		v.ContentHasStyle = hasStyle
+	}
+
+
 	br.Data = list
 	br.Ret = 200
 	br.Success = true

+ 56 - 24
models/cygx_yanxuan_special.go

@@ -6,19 +6,19 @@ import (
 )
 
 type CygxYanxuanSpecial struct {
-	Id          int       `orm:"column(id);pk"`
-	UserId      int       // 用户ID
-	CreateTime  time.Time // 创建时间
-	ModifyTime  time.Time // 修改时间
-	PublishTime time.Time // 提审过审或驳回时间
-	Content     string    // 内容
-	Tags        string    // 标签
-	Status      int       // 1:未发布,2:审核中 3:已发布 4:驳回
-	ImgUrl      string    // 图片链接
-	DocUrl      string    // 文档链接
-	Reason      string    // 理由
-	Title       string    // 标题
-	Type        int       // 类型1:笔记,2:观点
+	Id           int       `orm:"column(id);pk"`
+	UserId       int       // 用户ID
+	CreateTime   time.Time // 创建时间
+	ModifyTime   time.Time // 修改时间
+	PublishTime  time.Time // 提审过审或驳回时间
+	Content      string    // 内容
+	Tags         string    // 标签
+	Status       int       // 1:未发布,2:审核中 3:已发布 4:驳回
+	ImgUrl       string    // 图片链接
+	DocUrl       string    // 文档链接
+	Reason       string    // 理由
+	Title        string    // 标题
+	Type         int       // 类型1:笔记,2:观点
 	CompanyTags  string    // 公司标签
 	IndustryTags string    // 行业标签
 }
@@ -56,11 +56,43 @@ type CygxYanxuanSpecialItem struct {
 
 type CygxYanxuanSpecialResp struct {
 	CygxYanxuanSpecialItem
-	Docs []Doc
+	Docs         []Doc
 	CompanyTags  []string
 	IndustryTags []string
 }
 
+type CygxYanxuanSpecialCenterResp 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            int    // 类型1:笔记,2:观点
+	CollectNum      int
+	MyCollectNum    int
+	IsCollect       int
+	CompanyTags     string
+	IndustryTags    string
+	ContentHasImg   int //正文是否包含图片 1包含 0不包含
+	ContentHasStyle bool //正文是否包含格式
+	Docs            []Doc
+}
+
 type Doc struct {
 	DocName   string
 	DocSuffix string
@@ -68,7 +100,7 @@ type Doc struct {
 	DocIcon   string
 }
 
-func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialItem, err error) {
+func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialCenterResp, err error) {
 	o := orm.NewOrm()
 	sql := ``
 	sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,
@@ -100,7 +132,7 @@ func EnableYanxuanSpecial(id, status int, reason string) (err error) {
 }
 
 type SpecialListResp struct {
-	List     []*CygxYanxuanSpecialItem
+	List     []*CygxYanxuanSpecialCenterResp
 	IsAuthor bool
 }
 
@@ -119,14 +151,14 @@ JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
 }
 
 type CygxYanxuanSpecialReq struct {
-	Id      int    `orm:"column(id);pk"`
-	Content string // 内容
-	Tags    string // 标签
-	DoType  int    // 1保存 2发布
-	ImgUrl  string // 图片链接
-	DocUrl  string // 文档链接
-	Title   string // 标题
-	Type    int    // 类型1:笔记,2:观点
+	Id           int    `orm:"column(id);pk"`
+	Content      string // 内容
+	Tags         string // 标签
+	DoType       int    // 1保存 2发布
+	ImgUrl       string // 图片链接
+	DocUrl       string // 文档链接
+	Title        string // 标题
+	Type         int    // 类型1:笔记,2:观点
 	IndustryTags string // 行业标签
 	CompanyTags  string // 公司标签
 }

+ 15 - 0
utils/common.go

@@ -880,4 +880,19 @@ func ArticleHasImgUrl(body string) (hasImg bool, err error) {
 		hasImg = true
 	})
 	return
+}
+
+func ArticleHasStyle(body string) (hasStyle bool, err error) {
+	r := strings.NewReader(string(body))
+	doc, err := goquery.NewDocumentFromReader(r)
+	if err != nil {
+		fmt.Println(err)
+	}
+	doc.Find("p style").Each(func(i int, s *goquery.Selection) {
+		hasStyle = true
+	})
+	doc.Find("class").Each(func(i int, s *goquery.Selection) {
+		hasStyle = true
+	})
+	return
 }