classify.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package models
  2. import (
  3. "eta/eta_mini_crm_ht/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. )
  7. type Classify struct {
  8. Id int `orm:"column(id);pk"`
  9. ClassifyName string `description:"分类名称"`
  10. Sort int `json:"-"`
  11. ParentId int `description:"父级分类id"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"修改时间"`
  14. ClassifyLabel string `description:"分类标签"`
  15. Enabled int `description:"是否可用,1可用,0禁用"`
  16. }
  17. type ClassifyView struct {
  18. Id int `orm:"column(id);pk"`
  19. ClassifyName string `description:"分类名称"`
  20. Sort int `json:"-"`
  21. ParentId int `description:"父级分类id"`
  22. CreateTime time.Time `description:"创建时间"`
  23. ModifyTime time.Time `description:"修改时间"`
  24. ClassifyLabel string `description:"分类标签"`
  25. Enabled int `description:"是否可用,1可用,0禁用"`
  26. Level int `description:"分类层级"`
  27. HasChild int `description:"是否有子分类0:下面没有子分类,1:下面有子分类"`
  28. Child []*ClassifyView `description:"子分类"`
  29. }
  30. func GetClassifyList() (items []*ClassifyView, err error) {
  31. o := orm.NewOrmUsingDB("rddp")
  32. sql := `SELECT * FROM classify WHERE enabled=1`
  33. _, err = o.Raw(sql).QueryRows(&items)
  34. return
  35. }
  36. func GetClassifyById(classifyId int) (item *ClassifyView, err error) {
  37. o := orm.NewOrmUsingDB("rddp")
  38. sql := `SELECT * FROM classify WHERE enabled=1 AND id=?`
  39. err = o.Raw(sql, classifyId).QueryRow(&item)
  40. return
  41. }
  42. func GetClassifyListByIds(ids []string) (items []*ClassifyView, err error) {
  43. if len(ids) == 0 {
  44. return
  45. }
  46. o := orm.NewOrmUsingDB("rddp")
  47. sql := `SELECT * FROM classify WHERE enabled=1 AND id IN (` + utils.GetOrmReplaceHolder(len(ids)) + `)`
  48. _, err = o.Raw(sql, ids).QueryRows(&items)
  49. return
  50. }