瀏覽代碼

文章

master
huangjiajun 4 天之前
父節點
當前提交
1d15c41503
共有 4 個文件被更改,包括 67 次插入2 次删除
  1. +2
    -0
      src/dao/article_cate_dao.go
  2. +3
    -1
      src/dao/article_dao.go
  3. +27
    -0
      src/implement/article_cate_implement.go
  4. +35
    -1
      src/implement/article_implement.go

+ 2
- 0
src/dao/article_cate_dao.go 查看文件

@@ -7,4 +7,6 @@ import (
type ArticleCateDao interface {
GetArticleCate(id string) (m *model.ArticleCate, err error)
ArticleCateByPid(pid string) (*[]model.ArticleCate, error)
FindArticleCate(page, limit, pid string) (*[]model.ArticleCate, error)
FindArticleCateAndTotal(page, limit, pid string) (*[]model.ArticleCate, int64, error)
}

+ 3
- 1
src/dao/article_dao.go 查看文件

@@ -6,6 +6,8 @@ import (

type ArticleDao interface {
GetArticle(id string) (m *model.Article, err error)
ArticleCateByTypeId(typeId string) (m *model.Article, err error)
ArticleByTypeId(typeId string) (m *model.Article, err error)
ArticleByCid(cid string) (*[]model.Article, error)
FindArticle(page, limit, pid, cateId string) (*[]model.Article, error)
FindArticleAndTotal(page, limit, pid, cateId string) (*[]model.Article, int64, error)
}

+ 27
- 0
src/implement/article_cate_implement.go 查看文件

@@ -3,6 +3,7 @@ package implement
import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx"
"xorm.io/xorm"
)
@@ -33,3 +34,29 @@ func (a ArticleCateDb) ArticleCateByPid(pid string) (*[]model.ArticleCate, error
}
return &m, nil
}
func (a ArticleCateDb) FindArticleCate(page, limit, pid string) (*[]model.ArticleCate, error) {
var m []model.ArticleCate
sess := a.Db.Where("1=1")
start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit)
if pid != "" {
sess.And("pid=?", pid)
}
err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("sort desc,id desc").Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}
func (a ArticleCateDb) FindArticleCateAndTotal(page, limit, pid string) (*[]model.ArticleCate, int64, error) {
var m []model.ArticleCate
sess := a.Db.Where("1=1")
start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit)
if pid != "" {
sess.And("pid=?", pid)
}
count, err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("sort desc,id desc").FindAndCount(&m)
if err != nil {
return nil, count, zhios_order_relate_logx.Error(err)
}
return &m, count, nil
}

+ 35
- 1
src/implement/article_implement.go 查看文件

@@ -3,6 +3,7 @@ package implement
import (
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx"
"xorm.io/xorm"
)
@@ -26,7 +27,7 @@ func (a ArticleDb) GetArticle(id string) (m *model.Article, err error) {
}
return m, nil
}
func (a ArticleDb) ArticleCateByTypeId(typeId string) (m *model.Article, err error) {
func (a ArticleDb) ArticleByTypeId(typeId string) (m *model.Article, err error) {
m = new(model.Article)
has, err := a.Db.Where("is_show=1 and type_id=?", typeId).Get(m)
if err != nil {
@@ -44,3 +45,36 @@ func (a ArticleDb) ArticleByCid(cid string) (*[]model.Article, error) {
}
return &m, nil
}

func (a ArticleDb) FindArticle(page, limit, pid, cateId string) (*[]model.Article, error) {
var m []model.Article
sess := a.Db.Where("1=1")
start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit)
if pid != "" {
sess.And("pid=?", pid)
}
if cateId != "" {
sess.And("cate_id=?", cateId)
}
err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("sort desc,id desc").Find(&m)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &m, nil
}
func (a ArticleDb) FindArticleAndTotal(page, limit, pid, cateId string) (*[]model.Article, int64, error) {
var m []model.Article
sess := a.Db.Where("1=1")
start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit)
if pid != "" {
sess.And("pid=?", pid)
}
if cateId != "" {
sess.And("cate_id=?", cateId)
}
count, err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("sort desc,id desc").FindAndCount(&m)
if err != nil {
return nil, count, zhios_order_relate_logx.Error(err)
}
return &m, count, nil
}

Loading…
取消
儲存