面包店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 9 месеца
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. // GetUserFav is 获取商品收藏
  8. func GetUserFav(Db *xorm.Engine, uid, itemid interface{}) (*model.UserFavorite, error) {
  9. var m model.UserFavorite
  10. if has, err := Db.Where("uid = ? AND item_id = ?", uid, itemid).Get(&m); err != nil || !has {
  11. return nil, logx.Warn(err)
  12. }
  13. return &m, nil
  14. }
  15. //InsertUserFavOne is 插入一条收藏记录
  16. func InsertUserFavOne(Db *xorm.Engine, m *model.UserFavorite) (int64, error) {
  17. affected, err := Db.InsertOne(m)
  18. if err != nil {
  19. return 0, err
  20. }
  21. return affected, nil
  22. }
  23. //UserFavFindByProvider 根据提供商来筛选收藏的
  24. func UserFavFindByProvider(Db *xorm.Engine, uid interface{}, provider string, limit, start int) ([]*model.UserFavorite, error) {
  25. var m []*model.UserFavorite
  26. var err error
  27. if provider == "all" {
  28. if limit == 0 && start == 0 {
  29. err = Db.Where("uid = ?", uid).Desc("create_at").Find(&m)
  30. } else {
  31. err = Db.Where("uid = ?", uid).Desc("create_at").Limit(limit, start).Find(&m)
  32. }
  33. } else {
  34. if limit == 0 && start == 0 {
  35. err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Find(&m)
  36. } else {
  37. err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Limit(limit, start).Find(&m)
  38. }
  39. }
  40. if err != nil {
  41. return nil, logx.Warn(err)
  42. }
  43. return m, nil
  44. }
  45. //UserFavFindSearchByTitle is 我的收藏搜索
  46. func UserFavFindSearchByTitle(Db *xorm.Engine, uid interface{}, title string, limit, start int) ([]*model.UserFavorite, error) {
  47. var m []*model.UserFavorite
  48. var err error
  49. if limit == 0 && start == 0 {
  50. err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Find(&m)
  51. } else {
  52. err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Limit(limit, start).Find(&m)
  53. }
  54. if err != nil {
  55. return nil, logx.Warn(err)
  56. }
  57. return m, nil
  58. }
  59. // UserFavDelete is 删除收藏夹
  60. func UserFavDelete(Db *xorm.Engine, uid interface{}, itemIds []interface{}) (int64, error) {
  61. var m model.UserFavorite
  62. affect, err := Db.Where("uid = ?", uid).In("item_id", itemIds).Delete(&m)
  63. if err != nil {
  64. return 0, logx.Warn(err)
  65. }
  66. return affect, nil
  67. }
  68. // UserFavDeleteByUserDelete is 删除用户时删除对应的收藏夹
  69. func UserFavDeleteByUserDelete(Db *xorm.Engine, uid interface{}) (int64, error) {
  70. var m model.UserFavorite
  71. affect, err := Db.Where("uid = ?", uid).Delete(&m)
  72. if err != nil {
  73. return 0, logx.Warn(err)
  74. }
  75. return affect, nil
  76. }