@@ -7,4 +7,6 @@ import ( | |||||
type ArticleCateDao interface { | type ArticleCateDao interface { | ||||
GetArticleCate(id string) (m *model.ArticleCate, err error) | GetArticleCate(id string) (m *model.ArticleCate, err error) | ||||
ArticleCateByPid(pid string) (*[]model.ArticleCate, error) | ArticleCateByPid(pid string) (*[]model.ArticleCate, error) | ||||
FindArticleCate(page, limit, pid string) (*[]model.ArticleCate, error) | |||||
FindArticleCateAndTotal(page, limit, pid string) (*[]model.ArticleCate, int64, error) | |||||
} | } |
@@ -6,6 +6,8 @@ import ( | |||||
type ArticleDao interface { | type ArticleDao interface { | ||||
GetArticle(id string) (m *model.Article, err error) | 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) | 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) | |||||
} | } |
@@ -3,6 +3,7 @@ package implement | |||||
import ( | import ( | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "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" | zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | ||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -33,3 +34,29 @@ func (a ArticleCateDb) ArticleCateByPid(pid string) (*[]model.ArticleCate, error | |||||
} | } | ||||
return &m, nil | 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 | |||||
} |
@@ -3,6 +3,7 @@ package implement | |||||
import ( | import ( | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "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" | zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | ||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -26,7 +27,7 @@ func (a ArticleDb) GetArticle(id string) (m *model.Article, err error) { | |||||
} | } | ||||
return m, nil | 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) | m = new(model.Article) | ||||
has, err := a.Db.Where("is_show=1 and type_id=?", typeId).Get(m) | has, err := a.Db.Where("is_show=1 and type_id=?", typeId).Get(m) | ||||
if err != nil { | if err != nil { | ||||
@@ -44,3 +45,36 @@ func (a ArticleDb) ArticleByCid(cid string) (*[]model.Article, error) { | |||||
} | } | ||||
return &m, nil | 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 | |||||
} |