yb_my_chart.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // 研报-用户收藏表
  7. type MyChart struct {
  8. MyChartId int `orm:"column(my_chart_id);pk"`
  9. MyChartClassifyId int `orm:"column(my_chart_classify_id)"` //图表分类ID
  10. ChartInfoId int `orm:"column(chart_info_id)"` //图表ID
  11. ChartName string `orm:"column(chart_name)"` //图表名称
  12. UniqueCode string `orm:"column(unique_code)"` //图表唯一编码
  13. ChartImage string `orm:"column(chart_image)"` //图表图片
  14. ReportId int `orm:"column(report_id)"` //报告ID(从哪个报告收藏的)
  15. ReportChapterId int `orm:"column(report_chapter_id)"` //报告章节ID
  16. Source int `orm:"column(source)"` //操作来源:1-ETA图库;2-ETA表格
  17. UserId uint `orm:"column(user_id)"` //用户ID
  18. CompanyId uint `orm:"column(company_id)"` //客户ID
  19. CompanyStatus string `orm:"column(company_status)"` //客户状态
  20. CompanyName string `orm:"column(company_name)"` //客户名称
  21. RealName string `orm:"column(real_name)"` //联系人姓名
  22. SellerId int `orm:"column(seller_id)"` //客户销售ID
  23. CreateTime time.Time `orm:"column(create_time)"` //创建时间
  24. ModifyTime time.Time `orm:"column(modify_time)"` //修改时间
  25. }
  26. // TableName get sql table name.获取数据库表名
  27. func (l *MyChart) TableName() string {
  28. return "yb_my_chart"
  29. }
  30. // 联系人收藏统计
  31. type SellerChartCollectCount struct {
  32. Num int `json:"num"`
  33. SellerId int `json:"seller_id"`
  34. }
  35. // 收藏统计
  36. type SellerChartCollectCountListItem struct {
  37. Num int
  38. UserId int
  39. RealName string
  40. CompanyId int
  41. CompanyStatus string
  42. CompanyName string
  43. }
  44. // GetSellerChartCollectCountByCompanyStatus 获取销售下的联系人收藏次数
  45. func GetSellerChartCollectCountByCompanyStatus(companyStatus string, startDate, endDate time.Time) (list []*SellerChartCollectCount, err error) {
  46. o := orm.NewOrm()
  47. pars := make([]interface{}, 0)
  48. sql := `SELECT COUNT(*) AS num, seller_id FROM yb_my_chart WHERE company_status =? and create_time >= ? and create_time <= ? GROUP BY seller_id`
  49. pars = append(pars, companyStatus, startDate, endDate)
  50. _, err = o.Raw(sql, pars).QueryRows(&list)
  51. return
  52. }
  53. type SellerChartCollectUserLogReq struct {
  54. PageSize int `description:"每页数据条数"`
  55. CurrentIndex int `description:"当前页页码,从1开始"`
  56. SortParam string `description:"排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、'expireDay':到期时间 、 'createTime':创建时间 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间" 、'deadline':距离未完成的任务的截止日期的天数、'ybUserLog': 按照用户的点击量`
  57. SortType string `description:"如何排序,是正序还是倒序,枚举值:asc 正序,desc 倒叙 "`
  58. SellerIds string `description:"销售ID, 用','拼接 "`
  59. CompanyStatus string `description:"客户状态"`
  60. StartDate string `description:"起始时间"`
  61. EndDate string `description:"截止时间"`
  62. }
  63. // GetSellerUserChartCollectCountByCompanyStatus 获取销售下用户图表收藏记录汇总数
  64. func GetSellerUserChartCollectCountByCompanyStatus(companyStatus string, startDate, endDate time.Time, sellerIds string, startSize, pageSize int, orderStr string) (list []*SellerChartCollectCountListItem, total int64, err error) {
  65. o := orm.NewOrm()
  66. pars := make([]interface{}, 0)
  67. sql := `SELECT COUNT(*) AS num, user_id, real_name, company_id, company_status, company_name FROM yb_my_chart WHERE company_status =? and create_time >= ? and create_time <= ? and seller_id in `+sellerIds+` GROUP BY user_id, company_id`
  68. pars = append(pars, companyStatus, startDate, endDate)
  69. totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z `
  70. err = o.Raw(totalSQL, pars).QueryRow(&total)
  71. if err != nil {
  72. return
  73. }
  74. if orderStr != "" {
  75. sql += orderStr
  76. }
  77. sql += ` LIMIT ?,?`
  78. pars = append(pars, startSize, pageSize)
  79. _, err = o.Raw(sql, pars).QueryRows(&list)
  80. return
  81. }
  82. type ChartCollectListReq struct {
  83. PageSize int `description:"每页数据条数"`
  84. CurrentIndex int `description:"当前页页码,从1开始"`
  85. SellerIds string `description:"销售ID, 用','拼接 "`
  86. UserId int `description:"联系人id"`
  87. CompanyStatus string `description:"客户历史状态"`
  88. CompanyId int `description:"客户Id"`
  89. StartDate string `description:"起始时间"`
  90. EndDate string `description:"截止时间"`
  91. }
  92. // GetYbChartByCondition 获取收藏列表
  93. func GetYbChartByCondition(condition string, pars []interface{}, startSize, pageSize int) (list []*MyChart, total int64, err error) {
  94. o := orm.NewOrm()
  95. sql := `SELECT * FROM yb_my_chart WHERE 1=1 `
  96. if condition != "" {
  97. sql += condition
  98. }
  99. totalSQL := `SELECT COUNT(1) total FROM (` + sql + `) z `
  100. err = o.Raw(totalSQL, pars).QueryRow(&total)
  101. if err != nil {
  102. return
  103. }
  104. sql += ` order by create_time desc, my_chart_id desc LIMIT ?,?`
  105. pars = append(pars, startSize, pageSize)
  106. _, err = o.Raw(sql, pars).QueryRows(&list)
  107. return
  108. }