property_notice.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package commonm
  2. import ("github.com/astaxie/beego/orm"
  3. "wuyebaoxiuapi/models")
  4. // 物业公告
  5. type PropertyNotice struct {
  6. Id int
  7. Title string
  8. Content string
  9. CreateTime int
  10. FCreateTime string
  11. }
  12. func init() {
  13. orm.RegisterModel(new(PropertyNotice))
  14. }
  15. func (a *PropertyNotice) TableName() string {
  16. return models.TableName("property_notice")
  17. }
  18. func NewPropertyNotice()(*PropertyNotice) {
  19. return new(PropertyNotice)
  20. }
  21. func (a *PropertyNotice) Add(propertyNotice *PropertyNotice)(int64, error) {
  22. return orm.NewOrm().Insert(a)
  23. }
  24. func (a *PropertyNotice)FindPropertyNotices(page, pageSize int) ([]*PropertyNotice, int64) {
  25. offset := (page - 1) * pageSize
  26. list := make([]*PropertyNotice, 0)
  27. query := orm.NewOrm().QueryTable(models.TableName("property_notice"))
  28. total, _ := query.Count()
  29. query.OrderBy("-id").Limit(pageSize, offset).All(&list)
  30. return list, total
  31. }
  32. func (a *PropertyNotice)FindPropertyNoticeById(id int) (*PropertyNotice, error) {
  33. err := orm.NewOrm().QueryTable(models.TableName("property_notice")).Filter("id", id).One(a)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return a, nil
  38. }
  39. func (a *PropertyNotice) Update(fields ...string) error {
  40. if _, err := orm.NewOrm().Update(a, fields...); err != nil {
  41. return err
  42. }
  43. return nil
  44. }
  45. func (a *PropertyNotice)Delete(id int) (int64, error) {
  46. query := orm.NewOrm().QueryTable(models.TableName("property_notice"))
  47. return query.Filter("id", id).Delete()
  48. }