home.go 869 B

123456789101112131415161718192021222324252627282930313233343536
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "rdluck_tools/paging"
  5. )
  6. func GetHomeCount(condition string, pars []interface{}) (count int, err error) {
  7. o := orm.NewOrm()
  8. sql := `SELECT COUNT(1) AS count
  9. FROM cygx_article AS a
  10. WHERE a.publish_status=1 `
  11. if condition != "" {
  12. sql += condition
  13. }
  14. err = o.Raw(sql, pars).QueryRow(&count)
  15. return
  16. }
  17. func GetHomeList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeArticle, err error) {
  18. o := orm.NewOrm()
  19. sql := ` SELECT *
  20. FROM cygx_article AS a
  21. WHERE a.publish_status=1 `
  22. if condition != "" {
  23. sql += condition
  24. }
  25. sql += ` ORDER BY publish_date DESC LIMIT ?,? `
  26. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  27. return
  28. }
  29. type HomeListResp struct {
  30. Paging *paging.PagingItem
  31. List []*HomeArticle
  32. }