mirror of
https://github.com/tiger1103/gfast.git
synced 2026-09-21 10:12:59 +00:00
cms前端页面
This commit is contained in:
@@ -3,6 +3,7 @@ package cms_category_news
|
||||
import (
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Fill with you ideas below.
|
||||
@@ -16,3 +17,16 @@ func GetCategoriesByNewsId(newsId uint64) (cateNews []*Entity, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//通过文章id获取关联的栏目id
|
||||
func GetCheckedCategoryIdByNewsId(newsId uint64) (catIds []int, err error) {
|
||||
categories, err := GetCategoriesByNewsId(newsId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
catIds = make([]int, len(categories))
|
||||
for k, v := range categories {
|
||||
catIds[k] = gconv.Int(v.CategoryId)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"gfast/app/model/admin/user"
|
||||
"gfast/library/service"
|
||||
"gfast/library/utils"
|
||||
"github.com/gogf/gf/container/gvar"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/errors/gerror"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
@@ -16,21 +17,26 @@ import (
|
||||
"github.com/gogf/gf/util/gconv"
|
||||
)
|
||||
|
||||
// Fill with you ideas below.
|
||||
//文章列表
|
||||
type NewsList struct {
|
||||
Entity
|
||||
UserNickname string `json:"user_nickname"`
|
||||
CateList *gvar.Var `json:"cateList"`
|
||||
}
|
||||
|
||||
//添加文章参数
|
||||
type ReqAddParams struct {
|
||||
NewsStatus uint `p:"status" v:"in:0,1#状态只能为0或1"` // 状态;1:已发布;0:未发布;
|
||||
Attr []int `p:attr` //文章标记 置顶 推荐
|
||||
PublishedTime string `p:"published_time"` // 发布时间
|
||||
NewsTitle string `p:"title" v:"required#标题不能为空"` // post标题
|
||||
NewsKeywords string `p:"keywords"` // seo keywords
|
||||
NewsExcerpt string `p:"excerpt"` // post摘要
|
||||
NewsSource string `p:"source" ` // 转载文章的来源
|
||||
Thumbnail string `p:"thumbnail" ` // 缩略图
|
||||
IsJump uint `p:"IsJump" v:"in:0,1#跳转类型只能为0或1"` // 是否跳转地址
|
||||
JumpUrl string `p:"JumpUrl" v:"required-if:IsJump,1|url#跳转地址不能为空|跳转地址格式不正确"` // 跳转地址
|
||||
ModelForm map[string]interface{} `p:"modelForm"`
|
||||
NewsStatus uint `p:"status" v:"in:0,1#状态只能为0或1"` // 状态;1:已发布;0:未发布;
|
||||
Attr []int `p:"attr"` //文章标记 置顶 推荐
|
||||
PublishedTime string `p:"published_time"` // 发布时间
|
||||
NewsTitle string `p:"title" v:"required#标题不能为空"` // post标题
|
||||
NewsKeywords string `p:"keywords"` // seo keywords
|
||||
NewsExcerpt string `p:"excerpt"` // post摘要
|
||||
NewsSource string `p:"source" ` // 转载文章的来源
|
||||
Thumbnail string `p:"thumbnail" ` // 缩略图
|
||||
IsJump uint `p:"IsJump" v:"in:0,1#跳转类型只能为0或1"` // 是否跳转地址
|
||||
JumpUrl string `p:"JumpUrl" v:"required-if:IsJump,1|url#跳转地址不能为空|跳转地址格式不正确"` // 跳转地址
|
||||
ModelForm g.Map `p:"modelForm"`
|
||||
}
|
||||
|
||||
//文章搜索参数
|
||||
@@ -39,8 +45,13 @@ type ReqListSearchParams struct {
|
||||
PublishedTimeStart string `p:"pubTimeStart"`
|
||||
PublishedTimeEnd string `p:"pubTimeEnd"`
|
||||
KeyWords string `p:"keyWords"`
|
||||
IsSlide string `p:"isSlide"`
|
||||
IsTop string `p:"IsTop"`
|
||||
Recommended string `p:"Recommended"`
|
||||
NewsStatus string `p:"NewsStatus"`
|
||||
PageNum int `p:"page"` //当前页码
|
||||
PageSize int `p:"pageSize"` //每页数
|
||||
OrderBy string //排序字段
|
||||
}
|
||||
|
||||
type ReqEditParams struct {
|
||||
@@ -75,6 +86,8 @@ func AddNews(req *ReqAddParams, cateIds []int, userId uint64, tx *gdb.TX) (insId
|
||||
entity.IsTop = 1
|
||||
} else if v == 2 {
|
||||
entity.Recommended = 1
|
||||
} else if v == 3 {
|
||||
entity.IsSlide = 1
|
||||
}
|
||||
}
|
||||
res, e := Model.TX(tx).Insert(entity)
|
||||
@@ -128,11 +141,16 @@ func EditNews(req *ReqEditParams, cateIds []int, tx *gdb.TX) (err error) {
|
||||
entity.Thumbnail = req.Thumbnail
|
||||
entity.IsJump = req.IsJump
|
||||
entity.JumpUrl = req.JumpUrl
|
||||
entity.IsTop = 0
|
||||
entity.Recommended = 0
|
||||
entity.IsSlide = 0
|
||||
for _, v := range req.Attr {
|
||||
if v == 1 {
|
||||
entity.IsTop = 1
|
||||
} else if v == 2 {
|
||||
entity.Recommended = 1
|
||||
} else if v == 3 {
|
||||
entity.IsSlide = 1
|
||||
}
|
||||
}
|
||||
_, err = Model.TX(tx).Replace(entity)
|
||||
@@ -170,7 +188,7 @@ func EditNews(req *ReqEditParams, cateIds []int, tx *gdb.TX) (err error) {
|
||||
}
|
||||
|
||||
//文章列表查询
|
||||
func ListByPage(req *ReqListSearchParams) (total, page int, list gdb.Result, err error) {
|
||||
func ListByPage(req *ReqListSearchParams) (total, page int, list []*NewsList, err error) {
|
||||
model := g.DB().Table(Table + " news")
|
||||
if req != nil {
|
||||
if len(req.CateId) > 0 {
|
||||
@@ -186,6 +204,18 @@ func ListByPage(req *ReqListSearchParams) (total, page int, list gdb.Result, err
|
||||
if req.PublishedTimeEnd != "" {
|
||||
model = model.Where("news.published_time <=?", utils.StrToTimestamp(req.PublishedTimeEnd))
|
||||
}
|
||||
if req.IsSlide != "" {
|
||||
model = model.Where("news.is_slide", gconv.Int(req.IsSlide))
|
||||
}
|
||||
if req.IsTop != "" {
|
||||
model = model.Where("news.is_top", gconv.Int(req.IsTop))
|
||||
}
|
||||
if req.Recommended != "" {
|
||||
model = model.Where("news.recommended", gconv.Int(req.Recommended))
|
||||
}
|
||||
if req.NewsStatus != "" {
|
||||
model = model.Where("news.news_status", gconv.Int(req.NewsStatus))
|
||||
}
|
||||
}
|
||||
model = model.LeftJoin(user.Table+" user", "news.user_id=user.id")
|
||||
total, err = model.Count()
|
||||
@@ -201,13 +231,20 @@ func ListByPage(req *ReqListSearchParams) (total, page int, list gdb.Result, err
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = service.AdminPageNum
|
||||
}
|
||||
|
||||
list, err = model.Page(page, req.PageSize).Fields("news.*,user.user_nickname").Order("published_time desc,news.id desc").All()
|
||||
var datas gdb.Result
|
||||
order := "published_time desc,news.id desc"
|
||||
if req.OrderBy != "" {
|
||||
order = req.OrderBy
|
||||
}
|
||||
datas, err = model.Page(page, req.PageSize).Fields("news.*,user.user_nickname").
|
||||
Order(order).All()
|
||||
if err != nil {
|
||||
g.Log().Error(err)
|
||||
err = gerror.New("获取数据失败")
|
||||
return
|
||||
}
|
||||
list = make([]*NewsList, len(datas))
|
||||
err = datas.Structs(&list)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ type Entity struct {
|
||||
NewsStatus uint `orm:"news_status" json:"news_status"` // 状态;1:已发布;0:未发布;
|
||||
IsTop uint `orm:"is_top" json:"is_top"` // 是否置顶;1:置顶;0:不置顶
|
||||
Recommended uint `orm:"recommended" json:"recommended"` // 是否推荐;1:推荐;0:不推荐
|
||||
IsSlide uint `orm:"is_slide" json:"is_slide"` // 是否幻灯;1:是;0:否
|
||||
NewsHits uint64 `orm:"news_hits" json:"news_hits"` // 查看数
|
||||
NewsLike uint64 `orm:"news_like" json:"news_like"` // 点赞数
|
||||
CreateTime uint `orm:"create_time" json:"create_time"` // 创建时间
|
||||
|
||||
@@ -29,6 +29,7 @@ var (
|
||||
NewsStatus string // 状态;1:已发布;0:未发布;
|
||||
IsTop string // 是否置顶;1:置顶;0:不置顶
|
||||
Recommended string // 是否推荐;1:推荐;0:不推荐
|
||||
IsSlide string //是否幻灯 1是 0 否
|
||||
NewsHits string // 查看数
|
||||
NewsLike string // 点赞数
|
||||
CreateTime string // 创建时间
|
||||
@@ -48,6 +49,7 @@ var (
|
||||
NewsStatus: "news_status",
|
||||
IsTop: "is_top",
|
||||
Recommended: "recommended",
|
||||
IsSlide: "is_slide",
|
||||
NewsHits: "news_hits",
|
||||
NewsLike: "news_like",
|
||||
CreateTime: "create_time",
|
||||
|
||||
Reference in New Issue
Block a user