package commonm import ("github.com/astaxie/beego/orm" "wuyebaoxiuapi/models") // 物业公告 type PropertyNotice struct { Id int Title string Content string CreateTime int FCreateTime string } func init() { orm.RegisterModel(new(PropertyNotice)) } func (a *PropertyNotice) TableName() string { return models.TableName("property_notice") } func NewPropertyNotice()(*PropertyNotice) { return new(PropertyNotice) } func (a *PropertyNotice) Add(propertyNotice *PropertyNotice)(int64, error) { return orm.NewOrm().Insert(a) } func (a *PropertyNotice)FindPropertyNotices(page, pageSize int) ([]*PropertyNotice, int64) { offset := (page - 1) * pageSize list := make([]*PropertyNotice, 0) query := orm.NewOrm().QueryTable(models.TableName("property_notice")) total, _ := query.Count() query.OrderBy("-id").Limit(pageSize, offset).All(&list) return list, total } func (a *PropertyNotice)FindPropertyNoticeById(id int) (*PropertyNotice, error) { err := orm.NewOrm().QueryTable(models.TableName("property_notice")).Filter("id", id).One(a) if err != nil { return nil, err } return a, nil } func (a *PropertyNotice) Update(fields ...string) error { if _, err := orm.NewOrm().Update(a, fields...); err != nil { return err } return nil } func (a *PropertyNotice)Delete(id int) (int64, error) { query := orm.NewOrm().QueryTable(models.TableName("property_notice")) return query.Filter("id", id).Delete() }