面包店
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

92 satır
2.7 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. // GetUserFootMark is 获取商品足迹
  8. func GetUserFootMark(Db *xorm.Engine, uid, itemid interface{}) (*model.UserFootMark, error) {
  9. var m model.UserFootMark
  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 InsertUserFootMarkOne(Db *xorm.Engine, m *model.UserFootMark) (int64, error) {
  17. affected, err := Db.InsertOne(m)
  18. if err != nil {
  19. return 0, err
  20. }
  21. return affected, nil
  22. }
  23. // UpdateUserFootMarkOne is 更新一条足迹记录
  24. func UpdateUserFootMarkOne(Db *xorm.Engine, m *model.UserFootMark) (int64, error) {
  25. row, err := Db.ID(m.Id).AllCols().Update(m)
  26. return row, err
  27. }
  28. //UserFootMarkFindByProvider 根据提供商来筛选足迹的
  29. func UserFootMarkFindByProvider(Db *xorm.Engine, uid interface{}, provider string, limit, start int) ([]*model.UserFootMark, error) {
  30. var m []*model.UserFootMark
  31. var err error
  32. if provider == "all" {
  33. if limit == 0 && start == 0 {
  34. err = Db.Where("uid = ?", uid).Desc("create_at").Find(&m)
  35. } else {
  36. err = Db.Where("uid = ?", uid).Desc("create_at").Limit(limit, start).Find(&m)
  37. }
  38. } else {
  39. if limit == 0 && start == 0 {
  40. err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Find(&m)
  41. } else {
  42. err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Limit(limit, start).Find(&m)
  43. }
  44. }
  45. if err != nil {
  46. return nil, logx.Warn(err)
  47. }
  48. return m, nil
  49. }
  50. //UserFootMarkFindSearchByTitle is 我的足迹搜索
  51. func UserFootMarkFindSearchByTitle(Db *xorm.Engine, uid interface{}, title string, limit, start int) ([]*model.UserFootMark, error) {
  52. var m []*model.UserFootMark
  53. var err error
  54. if limit == 0 && start == 0 {
  55. err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Find(&m)
  56. } else {
  57. err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Limit(limit, start).Find(&m)
  58. }
  59. if err != nil {
  60. return nil, logx.Warn(err)
  61. }
  62. return m, nil
  63. }
  64. // UserFootMarkDelete is 删除足迹夹
  65. func UserFootMarkDelete(Db *xorm.Engine, uid interface{}, itemIds []interface{}) (int64, error) {
  66. var m model.UserFootMark
  67. affect, err := Db.Where("uid = ?", uid).In("item_id", itemIds).Delete(&m)
  68. if err != nil {
  69. return 0, logx.Warn(err)
  70. }
  71. return affect, nil
  72. }
  73. // UserFootMarkDeleteByUserDelete is 删除用户时删除对应的足迹夹
  74. func UserFootMarkDeleteByUserDelete(Db *xorm.Engine, uid interface{}) (int64, error) {
  75. var m model.UserFootMark
  76. affect, err := Db.Where("uid = ?", uid).Delete(&m)
  77. if err != nil {
  78. return 0, logx.Warn(err)
  79. }
  80. return affect, nil
  81. }