Kaynağa Gözat

Merge branch 'cygx_12.0.1' of http://8.136.199.33:3000/cxzhang/hongze_clpt

xingzai 1 yıl önce
ebeveyn
işleme
bc835581b1

+ 87 - 53
controllers/yanxuan_special.go

@@ -2,10 +2,12 @@ package controllers
 
 import (
 	"encoding/json"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/services"
 	"hongze/hongze_clpt/utils"
 	"path"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -20,7 +22,9 @@ type YanxuanSpecialNoLoginController struct {
 
 // @Title 专栏列表
 // @Description 专栏列表
-// @Param	request	body help_doc.AddHelpDocReq true "type json string"
+// @Param   SpecialColumnId   query   int  true       "作者专栏ID"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Success 200 {object} models.AddEnglishReportResp
 // @router /list [get]
 func (this *YanxuanSpecialNoLoginController) List() {
@@ -38,29 +42,44 @@ func (this *YanxuanSpecialNoLoginController) List() {
 	}
 
 	specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
+	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)
+	resp := new(models.SpecialListResp)
 	var condition string
 	var pars []interface{}
 
-	var specialUser *models.CygxYanxuanSpecialAuthorItem
-	var err error
 	if specialColumnId > 0 {
-		condition += ` AND b.id = ? `
-		pars = append(pars, specialColumnId)
+		authorItem, err := models.GetYanxuanSpecialAuthorById(specialColumnId)
+		if err != nil {
+			br.Msg = "查询栏目详情失败!"
+			br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
+			return
+		}
+		condition += ` AND a.user_id = ? `
+		pars = append(pars, authorItem.UserId)
 	}
 
-	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId, sysUser.UserId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
+	condition += ` AND a.status = 3 `
+	total, err := models.GetCygxYanxuanSpecialCount(condition, pars)
+	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败, Err:" + err.Error()
 		return
 	}
 
-	condition += ` AND a.status = 3 `
-
-	list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars)
-	if tmpErr != nil {
+	list, err := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, startSize, pageSize)
+	if err != nil {
 		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
+		br.ErrMsg = "获取失败, Err:" + err.Error()
 		return
 	}
 	for _, v := range list {
@@ -114,13 +133,12 @@ func (this *YanxuanSpecialNoLoginController) List() {
 			v.TagList = []string{}
 		}
 	}
-	resp := new(models.SpecialListResp)
-
-	if specialUser != nil {
-		resp.IsAuthor = true
-	}
+	specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
+	resp.IsAuthor = specialAuthorCheck.IsAuthor
+	resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
 	resp.List = list
-
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.Paging = page
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true
@@ -164,18 +182,8 @@ func (this *YanxuanSpecialController) Detail() {
 		item.IsCollect = 1
 	}
 
-	//industryTagList, tmpErr := models.GetYanxuanSpecialIndustry("")
-	//if tmpErr != nil {
-	//	br.Msg = "获取失败"
-	//	br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
-	//	return
-	//}
-	//industryTagMap := make(map[string]int, 0)
-	//for _, v := range industryTagList {
-	//	industryTagMap[v] = 1
-	//}
-
 	var resp models.CygxYanxuanSpecialResp
+	resp.HasPermission = 1
 	resp.CygxYanxuanSpecialItem = *item
 	if item.DocUrl != "" {
 		var docs []models.Doc
@@ -212,6 +220,20 @@ func (this *YanxuanSpecialController) Detail() {
 		resp.IndustryTags = []string{}
 	}
 
+	var configCode string
+	//如果是研选的就推送给汪洋跟王芳,否则就推送给王芳
+	configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
+	cnf, err := models.GetConfigByCode(configCode)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+	if item.UserId != sysUser.UserId && item.Status != 3 && !strings.Contains(cnf.ConfigValue, sysUser.Mobile) {
+		resp.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
+		resp.HasPermission = 2
+	}
+
 	go services.AddSpecialRecord(this.User, specialId)
 
 	br.Data = resp
@@ -603,7 +625,7 @@ func (this *YanxuanSpecialController) Center() {
 	condition += ` AND a.status = ? `
 	pars = append(pars, status)
 
-	list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars)
+	list, tmpErr := models.GetYanxuanSpecialList(sysUser.UserId, condition, pars, 0, 0)
 	if tmpErr != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
@@ -877,7 +899,8 @@ func (this *YanxuanSpecialController) Cancel() {
 
 // @Title 作者列表
 // @Description 作者列表
-// @Param	request	body help_doc.AddHelpDocReq true "type json string"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Success 200 {object} models.AddEnglishReportResp
 // @router /author/list [get]
 func (this *YanxuanSpecialNoLoginController) AuthorList() {
@@ -893,42 +916,53 @@ func (this *YanxuanSpecialNoLoginController) AuthorList() {
 		br.Ret = 408
 		return
 	}
-	var specialUser *models.CygxYanxuanSpecialAuthorItem
-	var err error
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
 
-	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId, sysUser.UserId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+	resp := new(models.SpecialAuthorListResp)
+	specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
+	resp.IsAuthor = specialAuthorCheck.IsAuthor
+	resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
+	resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
+	resp.HeadImg = specialAuthorCheck.HeadImg
+
+	var condition string
+	var conditionUserSort string
+	var pars []interface{}
+	condition += ` AND  a.nick_name <> '' `
+	conditionUserSort += ` ( IF ( a.user_id = ` + strconv.Itoa(sysUser.UserId) + `, 1 = 1, user_id = 1 ) ) AS user_sort , ` // 用户本人如果开通了专栏,就放在最前面
+
+	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 user_sort DESC, latest_publish_time DESC`
+	list, tmpErr := models.GetYanxuanSpecialAuthorList(conditionUserSort, condition, pars, startSize, pageSize)
 	if tmpErr != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
 		return
 	}
 
-	resp := new(models.SpecialAuthorListResp)
-
+	//var userIds []int
 	for _, v := range list {
 		v.LatestPublishDate = v.LatestPublishTime.Format(utils.FormatDate) + "更新"
-		if v.UserId == sysUser.UserId {
-			resp.List = append(resp.List, v)
-		}
-	}
-
-	for _, v := range list {
-		if v.UserId != sysUser.UserId {
-			resp.List = append(resp.List, v)
-		}
-	}
-
-	if specialUser != nil {
-		resp.IsAuthor = true
+		//userIds = append(userIds, v.UserId)
 	}
 
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.List = list
+	resp.Paging = page
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true

+ 32 - 8
models/cygx_yanxuan_special.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"time"
 )
 
@@ -60,9 +61,10 @@ type CygxYanxuanSpecialItem struct {
 
 type CygxYanxuanSpecialResp struct {
 	CygxYanxuanSpecialItem
-	Docs         []Doc
-	CompanyTags  []string
-	IndustryTags []string
+	Docs          []Doc
+	CompanyTags   []string
+	IndustryTags  []string
+	HasPermission int `description:"1:正常展示,2:不展示"`
 }
 
 type Doc struct {
@@ -78,7 +80,7 @@ type DocReq struct {
 	DocUrl    string
 }
 
-func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialItem, err error) {
+func GetYanxuanSpecialList(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialItem, err error) {
 	o := orm.NewOrm()
 	sql := ``
 	sql = `SELECT a.*,b.id AS special_column_id,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,b.status AS author_status,
@@ -91,7 +93,12 @@ 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)
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,? `
+		_, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql, userId, pars).QueryRows(&items)
+	}
 	return
 }
 
@@ -110,8 +117,10 @@ func EnableYanxuanSpecial(id, status int, reason string) (err error) {
 }
 
 type SpecialListResp struct {
-	List     []*CygxYanxuanSpecialItem
-	IsAuthor bool
+	IsAuthor             bool               `description:"是否开通了研选专栏"`
+	IsImproveInformation bool               `description:"作者信息是否完善"`
+	Paging               *paging.PagingItem `description:"分页数据"`
+	List                 []*CygxYanxuanSpecialItem
 }
 
 func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
@@ -128,6 +137,21 @@ JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
 	return
 }
 
+func GetYanxuanSpecialListBycondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialItem, 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
+}
+
 type CygxYanxuanSpecialReq struct {
 	Id           int      `orm:"column(id);pk"`
 	Content      string   // 内容
@@ -221,7 +245,7 @@ JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
 
 // 获取数量
 func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int, err error) {
-	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special WHERE 1= 1  `
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special  as a WHERE 1= 1  `
 	if condition != "" {
 		sqlCount += condition
 	}

+ 50 - 14
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"
 )
 
@@ -43,6 +44,14 @@ type CygxYanxuanSpecialAuthorItem struct {
 	LatestPublishTime time.Time // 最近更新时间
 	LatestPublishDate string    // 最近更新时间
 	IsFollow          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) {
@@ -65,7 +74,7 @@ func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
 	return
 }
 
-func GetYanxuanSpecialAuthor(reqUserId, sysUserId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
+func GetYanxuanSpecialAuthor(reqUserId, sysUserId int, cond string) (item *CygxYanxuanSpecialAuthorItem, err error) {
 	o := orm.NewOrm()
 	sql := ``
 	sql = `SELECT
@@ -76,6 +85,9 @@ func GetYanxuanSpecialAuthor(reqUserId, sysUserId int) (item *CygxYanxuanSpecial
 	( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf  WHERE cf.follow_user_id =? AND cf.user_id = ?  ) AS is_follow 
 FROM
 	cygx_yanxuan_special_author as a WHERE a.user_id=? `
+	if cond != "" {
+		sql += cond
+	}
 	err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
 	return
 }
@@ -97,6 +109,17 @@ FROM
 	return
 }
 
+// 获取数量
+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
+}
+
 type SaveCygxYanxuanSpecialAuthorReq struct {
 	SpecialColumnId int    // 专栏栏目ID
 	SpecialName     string // 专栏名称
@@ -115,30 +138,43 @@ func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
 	return
 }
 
-func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err error) {
+func GetYanxuanSpecialAuthorList(conditionUserSort, condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialAuthorItem, err error) {
 	o := orm.NewOrm()
 	sql := ``
-	sql = `SELECT
-	a.*,
-	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 
+	sql = `SELECT ` + conditionUserSort +
+		` a.*,
+	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 {
-	List     []*CygxYanxuanSpecialAuthorItem
-	IsAuthor bool
+	Paging               *paging.PagingItem `description:"分页数据"`
+	List                 []*CygxYanxuanSpecialAuthorItem
+	IsAuthor             bool
+	IsImproveInformation bool   `description:"作者信息是否完善"`
+	HeadImg              string // 头像
+	SpecialColumnId      int    // 专栏栏目ID
+}
+
+type SpecialAuthorCheckResp struct {
+	IsAuthor             bool
+	IsImproveInformation bool   `description:"作者信息是否完善"`
+	HeadImg              string // 头像
+	SpecialColumnId      int    // 专栏栏目ID
 }
 
 type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
-	SpecialColumnId int    // 专栏栏目ID
-	HeadImg         string // 头像
+	Paging          *paging.PagingItem `description:"分页数据"`
+	SpecialColumnId int                // 专栏栏目ID
+	HeadImg         string             // 头像
 }
 
 func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {

+ 62 - 0
services/cygx_yanxuan_special.go

@@ -127,3 +127,65 @@ func UpdateYanxuanSpecialResourceData(sourceId int) {
 	}
 	return
 }
+
+// 获取研选专栏用户信息
+func GetYanxuanSpecialAuthorInfo(user *models.WxUserItem) (itemResp *models.SpecialAuthorCheckResp) {
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetYanxuanSpecialAuthorInfo Err ", err, "userId", user.UserId), 2)
+		}
+	}()
+	itemResp = new(models.SpecialAuthorCheckResp)
+	var condition string
+	condition += ` AND a.status = 1 `
+	specialUser, e := models.GetYanxuanSpecialAuthor(user.UserId, user.UserId, condition)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetYanxuanSpecialAuthor, Err: " + e.Error())
+		return
+	}
+	if specialUser != nil {
+		itemResp.IsAuthor = true
+		itemResp.SpecialColumnId = specialUser.Id
+		itemResp.HeadImg = specialUser.HeadImg
+		//如果昵称 、专栏名称、简介 都不为空就表示信息完善
+		if specialUser.SpecialName != "" && specialUser.Introduction != "" && specialUser.NickName != "" {
+			itemResp.IsImproveInformation = true
+		}
+	}
+	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
+}

+ 1 - 1
services/es_comprehensive.go

@@ -784,7 +784,7 @@ func GetResourceDataEsList(list []*SearchComprehensiveItem, user *models.WxUserI
 		pars = make([]interface{}, 0)
 		condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
 		pars = append(pars, yanxuanSpecialIds)
-		listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars)
+		listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
 		if e != nil {
 			err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
 			return

+ 1 - 1
services/resource_data.go

@@ -456,7 +456,7 @@ func GetResourceDataList(condition string, pars []interface{}, startSize, pageSi
 		pars = make([]interface{}, 0)
 		condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
 		pars = append(pars, yanxuanSpecialIds)
-		listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars)
+		listyanxuanSpecial, e := models.GetYanxuanSpecialList(user.UserId, condition, pars, 0, 0)
 		if e != nil {
 			err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
 			return