yb_user_collection.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // 研报-用户收藏表
  7. type YbUserCollection struct {
  8. CollectionId uint `orm:"column(collection_id);pk"`
  9. CollectionType uint8 `orm:"column(collection_type)"` //收藏类型:1-研报; 2-视频社区; 3-微路演视频
  10. UserId uint `orm:"column(user_id)"` //用户ID
  11. CompanyId uint `orm:"column(company_id)"` //客户ID
  12. CompanyStatus string `orm:"column(company_status)"` //客户状态
  13. CompanyName string `orm:"column(company_name)"` //客户名称
  14. RealName string `orm:"column(real_name)"` //联系人姓名
  15. PrimaryId uint `orm:"column(primary_id)"` //不同类型的主ID
  16. ExtendId uint `orm:"column(extend_id)"` //扩展ID-如晨周报章节ID
  17. State uint8 `orm:"column(state)"` //状态:1-已收藏;0-取消收藏;
  18. SourceAgent uint8 `orm:"column(source_agent)"` //操作来源:1-小程序 2-小程序 PC 3-弘则研究公众号 4-Web PC
  19. SellerId int `orm:"column(seller_id)"` //客户销售ID
  20. Title string `orm:"column(title)"` //研报/视频标题-冗余
  21. PublishTime time.Time `orm:"column(publish_time)"` //研报/视频发布时间-冗余
  22. CreateTime time.Time `orm:"column(create_time)"` //创建时间
  23. ModifyTime time.Time `orm:"column(modify_time)"` //修改时间
  24. }
  25. // TableName get sql table name.获取数据库表名
  26. func (l *YbUserCollection) TableName() string {
  27. return "yb_user_collection"
  28. }
  29. // 联系人收藏统计
  30. type SellerCollectCount struct {
  31. Num int `json:"num"`
  32. SellerId int `json:"seller_id"`
  33. }
  34. // 收藏统计
  35. type SellerCollectCountListItem struct {
  36. Num int
  37. UserId int
  38. RealName string
  39. CompanyId int
  40. CompanyStatus string
  41. CompanyName string
  42. }
  43. // GetSellerCollectCountByCompanyStatus 获取销售下的联系人收藏次数
  44. func GetSellerCollectCountByCompanyStatus(companyStatus string, startDate, endDate time.Time) (list []*SellerCollectCount, err error) {
  45. o := orm.NewOrm()
  46. pars := make([]interface{}, 0)
  47. sql := `SELECT COUNT(*) AS num, seller_id FROM yb_user_collection WHERE company_status =? AND state=1 and create_time >= ? and create_time <= ? GROUP BY seller_id`
  48. pars = append(pars, companyStatus, startDate, endDate)
  49. _, err = o.Raw(sql, pars).QueryRows(&list)
  50. return
  51. }
  52. type SellerCollectUserLogReq struct {
  53. PageSize int `description:"每页数据条数"`
  54. CurrentIndex int `description:"当前页页码,从1开始"`
  55. SortParam string `description:"排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、'expireDay':到期时间 、 'createTime':创建时间 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间" 、'deadline':距离未完成的任务的截止日期的天数、'ybUserLog': 按照用户的点击量`
  56. SortType string `description:"如何排序,是正序还是倒序,枚举值:asc 正序,desc 倒叙 "`
  57. SellerIds string `description:"销售ID, 用','拼接 "`
  58. CompanyStatus string `description:"客户状态"`
  59. StartDate string `description:"起始时间"`
  60. EndDate string `description:"截止时间"`
  61. }
  62. // 收藏类型
  63. const (
  64. CollectionTypeReport = 1 // 研报
  65. CollectionTypeVideo = 2 // 视频社区
  66. CollectionTypeRoadVideo = 3 // 微路演视频
  67. )
  68. // GetSellerUserCollectCountByCompanyStatus 获取销售下用户收藏记录汇总数
  69. func GetSellerUserCollectCountByCompanyStatus(companyStatus string, startDate, endDate time.Time, sellerIds string, startSize, pageSize int, orderStr string) (list []*SellerCollectCountListItem, total int64, err error) {
  70. o := orm.NewOrm()
  71. pars := make([]interface{}, 0)
  72. sql := `SELECT COUNT(*) AS num, user_id, real_name, company_id, company_status, company_name FROM yb_user_collection WHERE company_status =? AND state=1 and create_time >= ? and create_time <= ? and seller_id in `+sellerIds+` GROUP BY user_id, company_id`
  73. pars = append(pars, companyStatus, startDate, endDate)
  74. totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z `
  75. err = o.Raw(totalSQL, pars).QueryRow(&total)
  76. if err != nil {
  77. return
  78. }
  79. if orderStr != "" {
  80. sql += orderStr
  81. }
  82. sql += ` LIMIT ?,?`
  83. pars = append(pars, startSize, pageSize)
  84. _, err = o.Raw(sql, pars).QueryRows(&list)
  85. return
  86. }
  87. type CollectListReq struct {
  88. PageSize int `description:"每页数据条数"`
  89. CurrentIndex int `description:"当前页页码,从1开始"`
  90. SellerIds string `description:"销售ID, 用','拼接 "`
  91. UserId int `description:"联系人id"`
  92. CompanyStatus string `description:"客户状态"`
  93. StartDate string `description:"起始时间"`
  94. EndDate string `description:"截止时间"`
  95. CollectionType string `description:"收藏类型:1-研报; 2-视频社区; 3-微路演视频"`
  96. }
  97. // GetYbUserCollectionByCondition 获取收藏列表
  98. func GetYbUserCollectionByCondition(condition string, pars []interface{}, startSize, pageSize int) (list []*YbUserCollection, total int64, err error) {
  99. o := orm.NewOrm()
  100. sql := `SELECT * FROM yb_user_collection WHERE state=1 `
  101. if condition != "" {
  102. sql += condition
  103. }
  104. totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z `
  105. err = o.Raw(totalSQL, pars).QueryRow(&total)
  106. if err != nil {
  107. return
  108. }
  109. sql += ` order by create_time desc, collection_id desc LIMIT ?,?`
  110. pars = append(pars, startSize, pageSize)
  111. _, err = o.Raw(sql, pars).QueryRows(&list)
  112. return
  113. }