model.go 986 B

1234567891011121314151617181920212223242526272829303132
  1. package yb_user_collection
  2. import "hongze/hongze_yb/global"
  3. func (item *YbUserCollection) Create() (err error) {
  4. err = global.DEFAULT_MYSQL.Create(item).Error
  5. return
  6. }
  7. func (item *YbUserCollection) Update(updateCols []string) (err error) {
  8. err = global.DEFAULT_MYSQL.Model(item).Select(updateCols).Updates(*item).Error
  9. return
  10. }
  11. // GetPageListByCondition 获取收藏列表-分页
  12. func GetPageListByCondition(condition string, pars []interface{}, pageIndex, pageSize int) (list []*YbUserCollection, err error) {
  13. offset := (pageIndex - 1) * pageSize
  14. err = global.DEFAULT_MYSQL.Model(YbUserCollection{}).
  15. Where(condition, pars...).
  16. Offset(offset).Limit(pageSize).
  17. Order("create_time DESC").
  18. Scan(&list).Error
  19. return
  20. }
  21. // GetItemById 主键获取收藏
  22. func GetItemById(collectionId int) (item *YbUserCollection, err error) {
  23. err = global.DEFAULT_MYSQL.Model(YbUserCollection{}).
  24. Where("collection_id = ? AND state = 1", collectionId).
  25. First(&item).Error
  26. return
  27. }