model.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }
  35. // GetItemByCondition 条件获取收藏
  36. func GetItemByCondition(condition string, pars []interface{}) (item *YbUserCollection, err error) {
  37. err = global.DEFAULT_MYSQL.Model(YbUserCollection{}).
  38. Where(condition, pars...).
  39. First(&item).Error
  40. return
  41. }
  42. // GetListByCondition 条件获取收藏列表
  43. func GetListByCondition(condition string, pars []interface{}) (list []*YbUserCollection, err error) {
  44. err = global.DEFAULT_MYSQL.Model(YbUserCollection{}).
  45. Where(condition, pars...).
  46. Scan(&list).Error
  47. return
  48. }