Эх сурвалжийг харах

Merge branch 'cygx_12.0.1' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 1 жил өмнө
parent
commit
857ef06013

+ 28 - 13
controllers/yanxuan_special.go

@@ -885,35 +885,50 @@ func (this *YanxuanSpecialController) AuthorList() {
 		br.Ret = 408
 		return
 	}
-	var specialUser *models.CygxYanxuanSpecialAuthorItem
-	var err error
 
-	cond := ``
-	cond += ` AND a.status = 1 `
-	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId, sysUser.UserId, cond)
-	if err != nil && err.Error() != utils.ErrNoRow() {
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+	var condition string
+	var pars []interface{}
+	condition += ` AND  a.nick_name <> '' `
+
+	total, err := models.GetCygxYanxuanSpecialAuthorCount(condition, pars)
+	if err != nil {
 		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败, Err:" + err.Error()
+		br.ErrMsg = "获取失败Err:" + err.Error()
 		return
 	}
-
-	list, tmpErr := models.GetYanxuanSpecialAuthorList()
+	condition += `	ORDER BY latest_publish_time DESC`
+	list, tmpErr := models.GetYanxuanSpecialAuthorList(condition, pars, startSize, pageSize)
 	if tmpErr != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
 		return
 	}
 
+	var userIds []int
 	for _, v := range list {
 		v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate) + "更新"
+		userIds = append(userIds, v.UserId)
 	}
-	resp := new(models.SpecialAuthorListResp)
 
-	if specialUser != nil {
-		resp.IsAuthor = true
+	bestNew := services.GetBestNewYanxuanSpecialByUserId(userIds)
+	for _, v := range list {
+		v.YanxuanSpecialCenter = bestNew[v.UserId]
 	}
+	resp := new(models.SpecialAuthorListResp)
+	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp.List = list
-
+	resp.Paging = page
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true

+ 15 - 1
models/cygx_yanxuan_special.go

@@ -121,12 +121,26 @@ JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
 	}
 	sql += `ORDER BY a.publish_time DESC `
 	if startSize+pageSize > 0 {
-		sql += `LIMIT ?,? `
+		sql += ` LIMIT ?,? `
 		_, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
 	} else {
 		_, err = o.Raw(sql, userId, pars).QueryRows(&items)
 	}
+	return
+}
 
+func GetYanxuanSpecialListBycondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialCenterResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT a.* FROM cygx_yanxuan_special AS a WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,? `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql, pars).QueryRows(&items)
+	}
 	return
 }
 

+ 50 - 28
models/cygx_yanxuan_special_user.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"time"
 )
 
@@ -23,28 +24,36 @@ type CygxYanxuanSpecialAuthor struct {
 }
 
 type CygxYanxuanSpecialAuthorItem struct {
-	Id                int       `orm:"column(id);pk"`
-	UserId            int       // 用户ID
-	SpecialName       string    // 专栏名称
-	Introduction      string    // 介绍
-	Label             string    // 标签
-	NickName          string    // 昵称
-	RealName          string    // 姓名
-	CompanyName       string    // 公司名
-	Mobile            string    // 手机号
-	CreateTime        string    // 创建时间
-	ModifyTime        time.Time // 修改时间
-	HeadImg           string    // 头像
-	BgImg             string    // 背景图
-	BgImgDown         string    // 背景图下半部分
-	Status            int       // 1启用2禁用
-	CollectNum        int       // 被收藏数
-	FollowNum         int       // 被关注数
-	SpecialArticleNum int       // 文章数
-	LatestPublishTime time.Time // 最近更新时间
-	LatestPublishDate string    // 最近更新时间
-	IsFollow          int       // 是否已关注 1已关注 0 未关注
-	HasChangeHeadImg  int       // 是否更换过默认头像 1是,0否
+	Id                   int                                 `orm:"column(id);pk"`
+	UserId               int                                 // 用户ID
+	SpecialName          string                              // 专栏名称
+	Introduction         string                              // 介绍
+	Label                string                              // 标签
+	NickName             string                              // 昵称
+	RealName             string                              // 姓名
+	CompanyName          string                              // 公司名
+	Mobile               string                              // 手机号
+	CreateTime           string                              // 创建时间
+	ModifyTime           time.Time                           // 修改时间
+	HeadImg              string                              // 头像
+	BgImg                string                              // 背景图
+	BgImgDown            string                              // 背景图下半部分
+	Status               int                                 // 1启用2禁用
+	CollectNum           int                                 // 被收藏数
+	FollowNum            int                                 // 被关注数
+	SpecialArticleNum    int                                 // 文章数
+	LatestPublishTime    time.Time                           // 最近更新时间
+	LatestPublishDate    string                              // 最近更新时间
+	IsFollow             int                                 // 是否已关注 1已关注 0 未关注
+	HasChangeHeadImg     int                                 // 是否更换过默认头像 1是,0否
+	YanxuanSpecialCenter *CygxYanxuanSpecialCenterAuthorResp // 研选专栏文章内容
+}
+
+type CygxYanxuanSpecialCenterAuthorResp struct {
+	Id          int    //研选专栏ID
+	UserId      int    // 用户ID
+	PublishTime string // 提审过审或驳回时间
+	Title       string // 标题
 }
 
 func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
@@ -103,7 +112,18 @@ func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
 	return
 }
 
-func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err error) {
+// 获取数量
+func GetCygxYanxuanSpecialAuthorCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_author as  a  WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+func GetYanxuanSpecialAuthorList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialAuthorItem, err error) {
 	o := orm.NewOrm()
 	sql := ``
 	sql = `SELECT
@@ -111,15 +131,17 @@ func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err e
 	IFNULL(( SELECT publish_time FROM cygx_yanxuan_special WHERE user_id = a.user_id AND STATUS = 3 ORDER BY publish_time DESC LIMIT 1 ), a.modify_time) AS latest_publish_time
 FROM
 	cygx_yanxuan_special_author AS a
-WHERE
-	a.nick_name <> ''
-ORDER BY
-	latest_publish_time DESC `
-	_, err = o.Raw(sql).QueryRows(&items)
+WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
 
 type SpecialAuthorListResp struct {
+	Paging   *paging.PagingItem `description:"分页数据"`
 	List     []*CygxYanxuanSpecialAuthorItem
 	IsAuthor bool
 }

+ 34 - 0
services/cygx_yanxuan_special.go

@@ -327,3 +327,37 @@ func GetYanxuanSpecialAuthorInfo(user *models.WxUserItem) (isAuthor, isImproveIn
 	}
 	return
 }
+
+// 获取专栏用户最新的一篇文章信息
+func GetBestNewYanxuanSpecialByUserId(userIds []int) (mapResp map[int]*models.CygxYanxuanSpecialCenterAuthorResp) {
+	lenArr := len(userIds)
+	if lenArr == 0 {
+		return
+	}
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetBestNewYanxuanSpecialByUserId Err ", err, "userIds", userIds), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition += ` AND user_id  IN (` + utils.GetOrmInReplace(lenArr) + `) AND status = 3  GROUP BY user_id ORDER BY publish_time DESC`
+	pars = append(pars, userIds)
+	list, e := models.GetYanxuanSpecialListBycondition(condition, pars, 0, lenArr)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetYanxuanSpecialListBycondition, Err: " + e.Error())
+		return
+	}
+	mapResp = make(map[int]*models.CygxYanxuanSpecialCenterAuthorResp, 0)
+	for _, v := range list {
+		item := new(models.CygxYanxuanSpecialCenterAuthorResp)
+		item.UserId = v.UserId
+		item.Id = v.Id
+		item.Title = v.Title
+		item.PublishTime = v.PublishTime
+		mapResp[v.UserId] = item
+	}
+	return
+}