package db import ( "applet/app/db/model" "applet/app/utils/logx" "xorm.io/xorm" ) // GetUserFootMark is 获取商品足迹 func GetUserFootMark(Db *xorm.Engine, uid, itemid interface{}) (*model.UserFootMark, error) { var m model.UserFootMark if has, err := Db.Where("uid = ? AND item_id = ?", uid, itemid).Get(&m); err != nil || !has { return nil, logx.Warn(err) } return &m, nil } //InsertUserFavOne is 插入一条足迹记录 func InsertUserFootMarkOne(Db *xorm.Engine, m *model.UserFootMark) (int64, error) { affected, err := Db.InsertOne(m) if err != nil { return 0, err } return affected, nil } // UpdateUserFootMarkOne is 更新一条足迹记录 func UpdateUserFootMarkOne(Db *xorm.Engine, m *model.UserFootMark) (int64, error) { row, err := Db.ID(m.Id).AllCols().Update(m) return row, err } //UserFootMarkFindByProvider 根据提供商来筛选足迹的 func UserFootMarkFindByProvider(Db *xorm.Engine, uid interface{}, provider string, limit, start int) ([]*model.UserFootMark, error) { var m []*model.UserFootMark var err error if provider == "all" { if limit == 0 && start == 0 { err = Db.Where("uid = ?", uid).Desc("create_at").Find(&m) } else { err = Db.Where("uid = ?", uid).Desc("create_at").Limit(limit, start).Find(&m) } } else { if limit == 0 && start == 0 { err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Find(&m) } else { err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Limit(limit, start).Find(&m) } } if err != nil { return nil, logx.Warn(err) } return m, nil } //UserFootMarkFindSearchByTitle is 我的足迹搜索 func UserFootMarkFindSearchByTitle(Db *xorm.Engine, uid interface{}, title string, limit, start int) ([]*model.UserFootMark, error) { var m []*model.UserFootMark var err error if limit == 0 && start == 0 { err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Find(&m) } else { err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Limit(limit, start).Find(&m) } if err != nil { return nil, logx.Warn(err) } return m, nil } // UserFootMarkDelete is 删除足迹夹 func UserFootMarkDelete(Db *xorm.Engine, uid interface{}, itemIds []interface{}) (int64, error) { var m model.UserFootMark affect, err := Db.Where("uid = ?", uid).In("item_id", itemIds).Delete(&m) if err != nil { return 0, logx.Warn(err) } return affect, nil } // UserFootMarkDeleteByUserDelete is 删除用户时删除对应的足迹夹 func UserFootMarkDeleteByUserDelete(Db *xorm.Engine, uid interface{}) (int64, error) { var m model.UserFootMark affect, err := Db.Where("uid = ?", uid).Delete(&m) if err != nil { return 0, logx.Warn(err) } return affect, nil }