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

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

xingzai 1 жил өмнө
parent
commit
33fa491d04

+ 41 - 22
controllers/yanxuan_special.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"encoding/json"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
@@ -14,8 +15,10 @@ type YanxuanSpecialController struct {
 
 // @Title 专栏列表
 // @Description 专栏列表
-// @Param	request	body help_doc.AddHelpDocReq true "type json string"
-// @Success 200 {object} models.AddEnglishReportResp
+// @Param   UserId   query   int  true       "用户ID"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} models.SpecialListResp
 // @router /list [get]
 func (this *YanxuanSpecialController) List() {
 	br := new(models.BaseResponse).Init()
@@ -30,33 +33,38 @@ func (this *YanxuanSpecialController) List() {
 		br.Ret = 408
 		return
 	}
-
 	userId, _ := this.GetInt("UserId", 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 userId > 0 {
 		condition += ` AND a.user_id = ? `
 		pars = append(pars, userId)
 	}
-
-	cond := ``
-	cond += ` AND a.status = 1 `
-	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId, sysUser.UserId, cond)
-	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 {
@@ -98,12 +106,13 @@ func (this *YanxuanSpecialController) List() {
 			v.Tags += v.IndustryTags
 		}
 	}
-	resp := new(models.SpecialListResp)
 
-	if specialUser != nil {
-		resp.IsAuthor = true
-	}
+	isAuthor, isImproveInformation := services.GetYanxuanSpecialAuthorInfo(sysUser) //用户是否没开通研选专栏以及,专栏信息是否完善
+	resp.IsAuthor = isAuthor
+	resp.IsImproveInformation = isImproveInformation
 	resp.List = list
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.Paging = page
 
 	br.Data = resp
 	br.Ret = 200
@@ -113,7 +122,8 @@ func (this *YanxuanSpecialController) List() {
 
 // @Title 专栏详情
 // @Description 专栏详情
-// @Param	request	body help_doc.AddHelpDocReq true "type json string"
+// @Param   IsSendWx   query   int  false       "是否是通过微信模版进来的 1是,其它否"
+// @Param   Id   query   int  true       "详情ID"
 // @Success 200 {object} models.AddEnglishReportResp
 // @router /detail [get]
 func (this *YanxuanSpecialController) Detail() {
@@ -131,6 +141,7 @@ func (this *YanxuanSpecialController) Detail() {
 	}
 
 	specialId, _ := this.GetInt("Id", 0)
+	isSendWx, _ := this.GetInt("IsSendWx", 0)
 
 	if specialId <= 0 {
 		br.Msg = "参数错误"
@@ -172,6 +183,13 @@ func (this *YanxuanSpecialController) Detail() {
 		resp.IndustryTags = append(resp.IndustryTags, item.IndustryTags)
 	}
 
+	if isSendWx == 1 {
+		if item.UserId == sysUser.UserId {
+			resp.IsShowExamine = true
+		}
+		resp.ExamineStatus = item.Status
+	}
+
 	go services.AddSpecialRecord(this.User, specialId)
 
 	br.Data = resp
@@ -551,7 +569,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()
@@ -833,7 +851,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 *YanxuanSpecialController) AuthorList() {

+ 20 - 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"
 )
 
@@ -56,9 +57,12 @@ type CygxYanxuanSpecialItem struct {
 
 type CygxYanxuanSpecialResp struct {
 	CygxYanxuanSpecialItem
-	Docs         []Doc
-	CompanyTags  []string
-	IndustryTags []string
+	Docs          []Doc
+	CompanyTags   []string
+	IndustryTags  []string
+	HasPermission int  `description:"1:正常展示,2:不展示"`
+	ExamineStatus int  `description:"1:审核通过,2:审核未通过"`
+	IsShowExamine bool `description:"是否展示审核状态按钮"`
 }
 
 type CygxYanxuanSpecialCenterResp struct {
@@ -103,7 +107,7 @@ type Doc struct {
 	DocIcon   string
 }
 
-func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialCenterResp, err error) {
+func GetYanxuanSpecialList(userId int, condition string, pars []interface{}, startSize, pageSize int) (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,
@@ -116,7 +120,13 @@ 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
 }
 
@@ -135,8 +145,10 @@ func EnableYanxuanSpecial(id, status int, reason string) (err error) {
 }
 
 type SpecialListResp struct {
-	List     []*CygxYanxuanSpecialCenterResp
-	IsAuthor bool
+	IsAuthor             bool               `description:"是否开通了研选专栏"`
+	IsImproveInformation bool               `description:"作者信息是否完善"`
+	Paging               *paging.PagingItem `description:"分页数据"`
+	List                 []*CygxYanxuanSpecialCenterResp
 }
 
 func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
@@ -257,7 +269,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
 	}

+ 1 - 1
services/es_comprehensive.go

@@ -1464,7 +1464,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

+ 33 - 0
services/yanxuan_special.go

@@ -0,0 +1,33 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+)
+
+// 获取研选专栏用户信息
+func GetYanxuanSpecialAuthorInfo(user *models.WxUserItem) (isAuthor, isImproveInformation bool) {
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetYanxuanSpecialAuthorInfo Err ", err, "userId", user.UserId), 2)
+		}
+	}()
+	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 {
+		isAuthor = true
+		//如果昵称 、专栏名称、简介 都不为空就表示信息完善
+		if specialUser.SpecialName != "" && specialUser.Introduction != "" && specialUser.NickName != "" {
+			isImproveInformation = true
+		}
+	}
+	return
+}