home.go 910 B

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