model.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // GetPageListTotalByCondition 获取收藏列表总数-分页
  22. func GetPageListTotalByCondition(condition string, pars []interface{}) (total int64, err error) {
  23. err = global.DEFAULT_MYSQL.Model(YbUserCollection{}).
  24. Where(condition, pars...).
  25. Count(&total).Error
  26. return
  27. }
  28. // GetItemById 主键获取收藏
  29. func GetItemById(collectionId int) (item *YbUserCollection, err error) {
  30. err = global.DEFAULT_MYSQL.Model(YbUserCollection{}).
  31. Where("collection_id = ? AND state = 1", collectionId).
  32. First(&item).Error
  33. return
  34. }