chart_collect.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. type CygxChartCollectByCygx struct {
  19. Id int `orm:"column(id);pk"`
  20. ChartId int `description:"图表ID"`
  21. UserId int `description:"用户ID"`
  22. CreateTime time.Time `description:"创建时间"`
  23. Mobile string `description:"手机号"`
  24. Email string `description:"邮箱"`
  25. CompanyId int `description:"公司id"`
  26. CompanyName string `description:"公司名称"`
  27. RealName string `description:"用户实际名称"`
  28. SellerName string `description:"所属销售"`
  29. }
  30. //添加收藏信息
  31. func AddCygxChartCollect(item *CygxChartCollect) (lastId int64, err error) {
  32. o, err := orm.NewOrm().Begin()
  33. if err != nil {
  34. return
  35. }
  36. defer func() {
  37. if err == nil {
  38. o.Commit()
  39. } else {
  40. o.Rollback()
  41. }
  42. }()
  43. lastId, err = o.Insert(item)
  44. if err != nil {
  45. return
  46. }
  47. //添加查研观向来源的记录
  48. itemCygx := new(CygxChartCollectByCygx)
  49. itemCygx.ChartId = item.ChartId
  50. itemCygx.UserId = item.UserId
  51. itemCygx.RealName = item.RealName
  52. itemCygx.CreateTime = time.Now()
  53. itemCygx.Mobile = item.Mobile
  54. itemCygx.Email = item.Email
  55. itemCygx.CompanyId = item.CompanyId
  56. itemCygx.CompanyName = item.CompanyName
  57. lastId, err = o.Insert(itemCygx)
  58. if err != nil {
  59. return
  60. }
  61. return
  62. }
  63. type ChartCollectResp struct {
  64. Status int `description:"1:收藏,2:取消收藏"`
  65. CollectCount int `description:"收藏总数"`
  66. }
  67. //移除
  68. func RemoveChartCollect(userId, ChartId int) (err error) {
  69. o, err := orm.NewOrm().Begin()
  70. if err != nil {
  71. return
  72. }
  73. defer func() {
  74. if err == nil {
  75. o.Commit()
  76. } else {
  77. o.Rollback()
  78. }
  79. }()
  80. sql := `DELETE FROM cygx_chart_collect WHERE user_id=? AND chart_id=? `
  81. _, err = o.Raw(sql, userId, ChartId).Exec()
  82. if err != nil {
  83. return
  84. }
  85. sql = `DELETE FROM cygx_chart_collect_by_cygx WHERE user_id=? AND chart_id=? `
  86. _, err = o.Raw(sql, userId, ChartId).Exec()
  87. return
  88. }
  89. func GetChartCountByUserId(userId, chartID int) (count int, err error) {
  90. sql := `SELECT COUNT(1) AS count FROM cygx_chart_collect WHERE user_id=? AND chart_id=? `
  91. err = orm.NewOrm().Raw(sql, userId, chartID).QueryRow(&count)
  92. return
  93. }
  94. func GetChartCountByUser(userId int) (count int, err error) {
  95. sql := `SELECT COUNT(1) AS count FROM cygx_chart_collect WHERE user_id=? `
  96. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  97. return
  98. }
  99. type CygxChartTop struct {
  100. Id int `orm:"column(id);pk"`
  101. ChartId int `description:"图表ID"`
  102. UserId int `description:"用户ID"`
  103. CreateTime time.Time `description:"创建时间"`
  104. Mobile string `description:"手机号"`
  105. Email string `description:"邮箱"`
  106. CompanyId int `description:"公司id"`
  107. CompanyName string `description:"公司名称"`
  108. RealName string `description:"用户实际名称"`
  109. SellerName string `description:"所属销售"`
  110. }
  111. //添加置顶信息
  112. func AddCygxChartTop(item *CygxChartTop) (lastId int64, err error) {
  113. o := orm.NewOrm()
  114. lastId, err = o.Insert(item)
  115. return
  116. }
  117. type ChartTopresp struct {
  118. Status int `description:"1:收藏,2:取消收藏"`
  119. CollectCount int `description:"收藏总数"`
  120. }
  121. func RemoveChartTop(userId, ChartId int) (err error) {
  122. o := orm.NewOrm()
  123. sql := `DELETE FROM cygx_chart_top WHERE user_id=? AND chart_id=? `
  124. _, err = o.Raw(sql, userId, ChartId).Exec()
  125. return
  126. }
  127. func GetChartTopCountByUserId(userId, chartID int) (count int, err error) {
  128. sql := `SELECT COUNT(1) AS count FROM cygx_chart_top WHERE user_id=? AND chart_id=? `
  129. err = orm.NewOrm().Raw(sql, userId, chartID).QueryRow(&count)
  130. return
  131. }
  132. func RemoveChartCollectByMobile(mobile string) (err error) {
  133. o := orm.NewOrm()
  134. sql := `DELETE FROM cygx_chart_collect WHERE mobile IN (` + mobile + `)`
  135. _, err = o.Raw(sql).Exec()
  136. return
  137. }
  138. //批量添加收藏信息
  139. func AddCygxChartCollectList(items []*CygxChartCollect) (lastId int64, err error) {
  140. o := orm.NewOrm()
  141. _, err = o.InsertMulti(1, items)
  142. return
  143. }
  144. //获取列表信息根据手机号分组
  145. func GetCygxChartCollectByMobileList() (items []*CygxChartCollect, err error) {
  146. o := orm.NewOrm()
  147. sql := `SELECT * FROM cygx_chart_collect GROUP BY mobile `
  148. _, err = o.Raw(sql).QueryRows(&items)
  149. return
  150. }
  151. //修改用户收藏文章的相关信息
  152. func UpdateCygxChartCollect(wxUser *WxUserItem) (err error) {
  153. o := orm.NewOrm()
  154. sql := `UPDATE cygx_chart_collect SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  155. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  156. return
  157. }
  158. //获取列表
  159. func GetCygxChartCollectList() (items []*CygxChartCollect, err error) {
  160. o := orm.NewOrm()
  161. sql := `SELECT * FROM cygx_chart_collect `
  162. _, err = o.Raw(sql).QueryRows(&items)
  163. return
  164. }