report.go 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package statistic_report
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyReportRecord struct {
  7. CompanyReportRecordId int `orm:"column(company_report_record_id);pk"`
  8. CompanyId int `description:"客户id"`
  9. CompanyProductId int
  10. CompanyName string `description:"客户名称"`
  11. Status string `description:"客户状态,枚举值:试用,永续,冻结,流失,正式,潜在"`
  12. StartDate string `description:"开始日期"`
  13. EndDate string `description:"结束日期"`
  14. CompanyBelong string `description:"客户所属,ficc:ficc客户,public_offering:公募客户,partner:合作伙伴"`
  15. SellerId int `description:"所属销售id"`
  16. SellerName string `description:"所属销售名称"`
  17. CreditCode string `description:"社会统一信用码"`
  18. CreateDate time.Time `description:"创建日期"`
  19. CreateTime time.Time `description:"创建时间"`
  20. ModifyTime time.Time `description:"修改时间"`
  21. }
  22. type CompanyReportRecordGroup struct {
  23. AdminId int `description:"所属销售id"`
  24. AdminName string `description:"所属销售名称"`
  25. Num int `description:"汇总次数"`
  26. CompanyIds string `description:"客户id字符串"`
  27. TryStage int `description:"试用客户标签:1未分类、2 推进、3 跟踪、4 预备"`
  28. }
  29. // GetGroupCompanyReportRecordGroupList 获取销售分组数据
  30. func GetGroupCompanyReportRecordGroupList(condition string, pars []interface{}) (list []*CompanyReportRecordGroup, err error) {
  31. o := orm.NewOrm()
  32. sql := ` SELECT seller_id as admin_id,seller_name admin_name,count(1) num, GROUP_CONCAT(DISTINCT company_id SEPARATOR ',') AS company_ids
  33. FROM company_report_record
  34. WHERE 1=1
  35. `
  36. if condition != "" {
  37. sql += condition
  38. }
  39. sql += ` GROUP BY seller_id`
  40. _, err = o.Raw(sql, pars).QueryRows(&list)
  41. return
  42. }
  43. // GetTryGroupCompanyReportRecordGroupList 获取销售试用分组数据
  44. func GetTryGroupCompanyReportRecordGroupList(date time.Time, productId int) (list []*CompanyReportRecordGroup, err error) {
  45. o := orm.NewOrm()
  46. sql := ` SELECT c.seller_id as admin_id,c.seller_name as admin_name,count(1) num, b.try_stage, GROUP_CONCAT(DISTINCT c.company_id SEPARATOR ',') AS company_ids
  47. FROM company_report_record c
  48. left JOIN (select * from company_product where product_id=? AND status = "试用") b on b.company_id= c.company_id
  49. WHERE 1=1
  50. and c.create_date = ? and c.status = "试用" and c.product_id = ? GROUP BY c.seller_id, b.try_stage`
  51. _, err = o.Raw(sql, productId, date, productId).QueryRows(&list)
  52. return
  53. }
  54. type IncrementalCompanyListReq struct {
  55. PageSize int `description:"每页数据条数"`
  56. CurrentIndex int `description:"当前页页码,从1开始"`
  57. SortParam string `description:"排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、
  58. 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、'expireDay':到期时间 、 'createTime':创建时间 、
  59. 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间 、
  60. 'deadline':距离未完成的任务的截止日期的天数、sellerName:所属销售、shareSellerName:分配销售、status:客户状态"`
  61. SortType string `description:"如何排序,是正序还是倒序,枚举值:asc 正序,desc 倒叙 "`
  62. CompanyIds string `description:"标签,多个标签用、隔开;长度255"`
  63. }
  64. type UpdateLogDate struct {
  65. CompanyId int `description:"客户id"`
  66. CreateTime string `description:"创建时间"`
  67. }
  68. // GetLatestDateFromUpdateLog 获取试用和活跃用户的转试用时间
  69. func GetLatestDateFromUpdateLog(condition string) (list []*UpdateLogDate, err error) {
  70. o := orm.NewOrm()
  71. sql := ` SELECT company_id,MAX(create_time) create_time FROM company_product_update_log WHERE source IN ('thaw','receive','apply_receive','add') `
  72. if condition != "" {
  73. sql += condition
  74. }
  75. sql += ` GROUP BY company_id`
  76. _, err = o.Raw(sql).QueryRows(&list)
  77. return
  78. }