user_collect_classify.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // @Author gmy 2024/9/21 14:47:00
  2. package models
  3. import "github.com/beego/beego/v2/client/orm"
  4. /**
  5. CREATE TABLE `user_collect_classify` (
  6. `user_collect_classify_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  7. `classify_id` int(9) unsigned NOT NULL DEFAULT '0' COMMENT '分类id',
  8. `sys_user_id` int(9) unsigned DEFAULT '0' COMMENT '收藏人用户id',
  9. `create_time` datetime DEFAULT NULL COMMENT '收藏时间',
  10. PRIMARY KEY (`user_collect_classify_id`)
  11. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户收藏的分类id';
  12. */
  13. type UserCollectClassify struct {
  14. UserCollectClassifyId int `orm:"column(user_collect_classify_id);pk" description:"用户收藏的分类id"`
  15. ClassifyId int `orm:"column(classify_id)" description:"分类id"`
  16. SysUserId int `orm:"column(sys_user_id)" description:"收藏人用户id"`
  17. CreateTime string `orm:"column(create_time)" description:"收藏时间"`
  18. }
  19. // GetUserCollectClassifyList 查询用户收藏的分类列表
  20. func GetUserCollectClassifyList(sysUserId, classifyId int) (list []*UserCollectClassify, err error) {
  21. o := orm.NewOrmUsingDB("rddp")
  22. sql := `SELECT * FROM user_collect_classify WHERE 1=1`
  23. var params []interface{}
  24. // 处理 sysUserId 参数
  25. if sysUserId > 0 {
  26. sql += ` AND sys_user_id=?`
  27. params = append(params, sysUserId)
  28. }
  29. // 处理 classifyId 参数
  30. if classifyId > 0 {
  31. sql += ` AND classify_id=?`
  32. params = append(params, classifyId)
  33. }
  34. _, err = o.Raw(sql, params...).QueryRows(&list)
  35. return
  36. }
  37. // InsertUserCollectClassify 新增用户收藏的分类
  38. func InsertUserCollectClassify(item UserCollectClassify) (err error) {
  39. o := orm.NewOrmUsingDB("rddp")
  40. sql := `INSERT INTO user_collect_classify(classify_id, sys_user_id, create_time) VALUES(?, ?, ?)`
  41. _, err = o.Raw(sql, item.ClassifyId, item.SysUserId, item.CreateTime).Exec()
  42. return
  43. }
  44. // DeleteUserCollectClassify 删除分类
  45. func DeleteUserCollectClassify(sysUserId, classifyId int) (err error) {
  46. o := orm.NewOrmUsingDB("rddp")
  47. sql := `DELETE FROM user_collect_classify WHERE sys_user_id=? AND classify_id=?`
  48. _, err = o.Raw(sql, sysUserId, classifyId).Exec()
  49. return
  50. }
  51. // DeleteUserCollectClassify 删除分类
  52. func DeleteCollectByClassifyId(classifyId int) (err error) {
  53. o := orm.NewOrmUsingDB("rddp")
  54. sql := `DELETE FROM user_collect_classify WHERE classify_id=?`
  55. _, err = o.Raw(sql, classifyId).Exec()
  56. return
  57. }