chart_collect.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxChartCollect struct {
  7. Id int `orm:"column(id);pk"`
  8. ChartId int `description:"图表ID"`
  9. UserId int `description:"用户ID"`
  10. CreateTime time.Time `description:"创建时间"`
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. RealName string `description:"用户实际名称"`
  16. SellerName string `description:"所属销售"`
  17. }
  18. //添加收藏信息
  19. func AddCygxChartCollect(item *CygxChartCollect) (lastId int64, err error) {
  20. o := orm.NewOrm()
  21. lastId, err = o.Insert(item)
  22. return
  23. }
  24. type ChartCollectResp struct {
  25. Status int `description:"1:收藏,2:取消收藏"`
  26. CollectCount int `description:"收藏总数"`
  27. }
  28. func RemoveChartCollect(userId, ChartId int) (err error) {
  29. o := orm.NewOrm()
  30. sql := `DELETE FROM cygx_chart_collect WHERE user_id=? AND chart_id=? `
  31. _, err = o.Raw(sql, userId, ChartId).Exec()
  32. return
  33. }
  34. func GetChartCountByUserId(userId, chartID int) (count int, err error) {
  35. sql := `SELECT COUNT(1) AS count FROM cygx_chart_collect WHERE user_id=? AND chart_id=? `
  36. err = orm.NewOrm().Raw(sql, userId, chartID).QueryRow(&count)
  37. return
  38. }
  39. func GetChartCountByUser(userId int) (count int, err error) {
  40. sql := `SELECT COUNT(1) AS count FROM cygx_chart_collect WHERE user_id=? `
  41. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  42. return
  43. }
  44. type CygxChartTop struct {
  45. Id int `orm:"column(id);pk"`
  46. ChartId int `description:"图表ID"`
  47. UserId int `description:"用户ID"`
  48. CreateTime time.Time `description:"创建时间"`
  49. Mobile string `description:"手机号"`
  50. Email string `description:"邮箱"`
  51. CompanyId int `description:"公司id"`
  52. CompanyName string `description:"公司名称"`
  53. RealName string `description:"用户实际名称"`
  54. SellerName string `description:"所属销售"`
  55. }
  56. //添加置顶信息
  57. func AddCygxChartTop(item *CygxChartTop) (lastId int64, err error) {
  58. o := orm.NewOrm()
  59. lastId, err = o.Insert(item)
  60. return
  61. }
  62. type ChartTopresp struct {
  63. Status int `description:"1:收藏,2:取消收藏"`
  64. CollectCount int `description:"收藏总数"`
  65. }
  66. func RemoveChartTop(userId, ChartId int) (err error) {
  67. o := orm.NewOrm()
  68. sql := `DELETE FROM cygx_chart_top WHERE user_id=? AND chart_id=? `
  69. _, err = o.Raw(sql, userId, ChartId).Exec()
  70. return
  71. }
  72. func GetChartTopCountByUserId(userId, chartID int) (count int, err error) {
  73. sql := `SELECT COUNT(1) AS count FROM cygx_chart_top WHERE user_id=? AND chart_id=? `
  74. err = orm.NewOrm().Raw(sql, userId, chartID).QueryRow(&count)
  75. return
  76. }
  77. func RemoveChartCollectByMobile(mobile string) (err error) {
  78. o := orm.NewOrm()
  79. sql := `DELETE FROM cygx_chart_collect WHERE mobile IN (` + mobile + `)`
  80. _, err = o.Raw(sql).Exec()
  81. return
  82. }
  83. //批量添加收藏信息
  84. func AddCygxChartCollectList(items []*CygxChartCollect) (lastId int64, err error) {
  85. o := orm.NewOrm()
  86. _, err = o.InsertMulti(1, items)
  87. return
  88. }
  89. //获取列表信息根据手机号分组
  90. func GetCygxChartCollectByMobileList() (items []*CygxChartCollect, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT * FROM cygx_chart_collect GROUP BY mobile `
  93. _, err = o.Raw(sql).QueryRows(&items)
  94. return
  95. }
  96. //修改用户收藏文章的相关信息
  97. func UpdateCygxChartCollect(wxUser *WxUserItem) (err error) {
  98. o := orm.NewOrm()
  99. sql := `UPDATE cygx_chart_collect SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  100. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  101. return
  102. }