xingzai преди 1 година
родител
ревизия
9d81e08e0f
променени са 3 файла, в които са добавени 34 реда и са изтрити 20 реда
  1. 15 13
      controllers/yanxuan_special.go
  2. 13 4
      models/cygx_yanxuan_special_user.go
  3. 6 3
      services/cygx_yanxuan_special.go

+ 15 - 13
controllers/yanxuan_special.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hongze_clpt/services"
 	"hongze/hongze_clpt/utils"
 	"path"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -132,9 +133,9 @@ func (this *YanxuanSpecialNoLoginController) List() {
 			v.TagList = []string{}
 		}
 	}
-	isAuthor, isImproveInformation := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
-	resp.IsAuthor = isAuthor
-	resp.IsImproveInformation = isImproveInformation
+	specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
+	resp.IsAuthor = specialAuthorCheck.IsAuthor
+	resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
 	resp.List = list
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp.Paging = page
@@ -925,9 +926,18 @@ func (this *YanxuanSpecialNoLoginController) AuthorList() {
 		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 {
@@ -935,8 +945,8 @@ func (this *YanxuanSpecialNoLoginController) AuthorList() {
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-	condition += `	ORDER BY latest_publish_time DESC`
-	list, tmpErr := models.GetYanxuanSpecialAuthorList(condition, pars, startSize, pageSize)
+	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()
@@ -949,14 +959,6 @@ func (this *YanxuanSpecialNoLoginController) AuthorList() {
 		//userIds = append(userIds, v.UserId)
 	}
 
-	//bestNew := services.GetBestNewYanxuanSpecialByUserId(userIds)
-	//for _, v := range list {
-	//	v.YanxuanSpecialCenter = bestNew[v.UserId]
-	//}
-	resp := new(models.SpecialAuthorListResp)
-	isAuthor, isImproveInformation := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
-	resp.IsAuthor = isAuthor
-	resp.IsImproveInformation = isImproveInformation
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp.List = list
 	resp.Paging = page

+ 13 - 4
models/cygx_yanxuan_special_user.go

@@ -138,11 +138,11 @@ func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
 	return
 }
 
-func GetYanxuanSpecialAuthorList(condition string, pars []interface{}, startSize, pageSize int) (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.*,
+	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
@@ -159,7 +159,16 @@ type SpecialAuthorListResp struct {
 	Paging               *paging.PagingItem `description:"分页数据"`
 	List                 []*CygxYanxuanSpecialAuthorItem
 	IsAuthor             bool
-	IsImproveInformation bool `description:"作者信息是否完善"`
+	IsImproveInformation bool   `description:"作者信息是否完善"`
+	HeadImg              string // 头像
+	SpecialColumnId      int    // 专栏栏目ID
+}
+
+type SpecialAuthorCheckResp struct {
+	IsAuthor             bool
+	IsImproveInformation bool   `description:"作者信息是否完善"`
+	HeadImg              string // 头像
+	SpecialColumnId      int    // 专栏栏目ID
 }
 
 type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {

+ 6 - 3
services/cygx_yanxuan_special.go

@@ -129,13 +129,14 @@ func UpdateYanxuanSpecialResourceData(sourceId int) {
 }
 
 // 获取研选专栏用户信息
-func GetYanxuanSpecialAuthorInfo(user *models.WxUserItem) (isAuthor, isImproveInformation bool) {
+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)
@@ -144,10 +145,12 @@ func GetYanxuanSpecialAuthorInfo(user *models.WxUserItem) (isAuthor, isImproveIn
 		return
 	}
 	if specialUser != nil {
-		isAuthor = true
+		itemResp.IsAuthor = true
+		itemResp.SpecialColumnId = specialUser.Id
+		itemResp.HeadImg = specialUser.HeadImg
 		//如果昵称 、专栏名称、简介 都不为空就表示信息完善
 		if specialUser.SpecialName != "" && specialUser.Introduction != "" && specialUser.NickName != "" {
-			isImproveInformation = true
+			itemResp.IsImproveInformation = true
 		}
 	}
 	return