home.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/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 * ,(SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = a.article_id ) as pv
  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,article_id DESC LIMIT ?,? `
  26. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  27. return
  28. }
  29. type HomeListResp struct {
  30. HaveResearch bool `description:"是否有研选权限"`
  31. Paging *paging.PagingItem
  32. List []*HomeArticle
  33. }
  34. type HomeArtAndChartListResp struct {
  35. HaveResearch bool `description:"是否有研选权限"`
  36. Paging *paging.PagingItem
  37. List []*HomeArticle `description:"文章列表"`
  38. }