cygx_yanxuan_special_collect.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxYanxuanSpecialCollect struct {
  7. CygxYanxuanSpecialCollectId int `orm:"column(cygx_yanxuan_special_collect_id);pk"`
  8. UserId int // 用户ID
  9. Mobile string // 手机号
  10. Email string // 邮箱
  11. CompanyId int // 公司ID
  12. CompanyName string // 公司名称
  13. RealName string // 用户实际名称
  14. SellerName string // 所属销售
  15. CreateTime time.Time // 创建时间
  16. ModifyTime time.Time // 修改时间
  17. RegisterPlatform int // 来源 1小程序,2:网页
  18. YanxuanSpecialId int // cygx_yanxuan_special 表主键ID
  19. }
  20. func AddCygxYanxuanSpecialCollect(item *CygxYanxuanSpecialCollect) (lastId int64, err error) {
  21. o := orm.NewOrm()
  22. lastId, err = o.Insert(item)
  23. return
  24. }
  25. type CollectCygxYanxuanSpecialReq struct {
  26. Id int // 文章id
  27. Status int // 1收藏2取消收藏
  28. }
  29. func DelCygxYanxuanSpecialCollect(userId, articleId int) (err error) {
  30. o := orm.NewOrm()
  31. sql := `DELETE FROM cygx_yanxuan_special_collect WHERE user_id=? AND yanxuan_special_id=? `
  32. _, err = o.Raw(sql, userId, articleId).Exec()
  33. return
  34. }
  35. // 获取数量
  36. func GetCygxYanxuanSpecialCollectCount(condition string, pars []interface{}) (count int, err error) {
  37. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_collect as a WHERE 1= 1 `
  38. if condition != "" {
  39. sqlCount += condition
  40. }
  41. o := orm.NewOrm()
  42. err = o.Raw(sqlCount, pars).QueryRow(&count)
  43. return
  44. }
  45. // GetCygxYanxuanSpecialCollectByUser 根据用户ID获取所有文章收藏
  46. func GetCygxYanxuanSpecialCollectByUser(userId int) (items []*CygxYanxuanSpecialCollect, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT * FROM cygx_yanxuan_special_collect WHERE 1 =1 AND user_id =? `
  49. _, err = o.Raw(sql, userId).QueryRows(&items)
  50. return
  51. }