company_renewal_record.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CompanyRenewalRecord
  7. // @Description: 客户续约状态记录表
  8. type CompanyRenewalRecord struct {
  9. Id int `orm:"column(id);pk"`
  10. CompanyId int `description:"客户id"`
  11. ProductId int `description:"产品id"`
  12. Source int `description:"类型,枚举值,1:续约异常客户;2:续约正常客户;3:超时续约客户"`
  13. SellerId int `description:"销售id"`
  14. SellerName string `description:"销售名称"`
  15. ShareSellerId int `description:"共享销售id"`
  16. ShareSellerName string `description:"共享销售名称"`
  17. CreateTime time.Time `description:"创建时间"`
  18. ModifyTime time.Time `description:"修改时间"`
  19. }
  20. type UnusualRenewCompanyGroup struct {
  21. SellerId int `description:"所属销售id"`
  22. ShareSellerId int `description:"所属共享销售id"`
  23. //AdminName string `description:"所属销售名称"`
  24. Num int `description:"汇总次数"`
  25. CompanyIds string `description:"客户id字符串"`
  26. }
  27. // GetUnusualRenewCompanyList 获取销售未续约数据
  28. func GetUnusualRenewCompanyList(startDate, endDate time.Time, productId int) (list []*CompanyRenewalRecord, err error) {
  29. o := orm.NewOrm()
  30. sql := ` SELECT
  31. *
  32. FROM
  33. company_renewal_record
  34. WHERE
  35. modify_time BETWEEN ?
  36. AND ?
  37. AND source = 1
  38. AND product_id = ?;
  39. `
  40. _, err = o.Raw(sql, startDate, endDate, productId).QueryRows(&list)
  41. return
  42. }
  43. // GetUnusualRenewCompanyByShareSellerList 获取销售未续约数据
  44. func GetUnusualRenewCompanyByShareSellerList(startDate, endDate time.Time, productId, source int) (list []*UnusualRenewCompanyGroup, err error) {
  45. o := orm.NewOrm()
  46. sql := ` SELECT
  47. a.seller_id,a.share_seller_id,
  48. count(
  49. DISTINCT ( a.company_id )) num,
  50. GROUP_CONCAT( DISTINCT a.company_id SEPARATOR ',' ) AS company_ids
  51. FROM
  52. company_renewal_record as a
  53. WHERE
  54. a.modify_time BETWEEN ?
  55. AND ?
  56. AND a.source = ?
  57. AND a.product_id = ?
  58. GROUP BY
  59. a.share_seller_id;
  60. `
  61. _, err = o.Raw(sql, startDate, endDate, source, productId).QueryRows(&list)
  62. return
  63. }
  64. // Add
  65. // @Description: 添加续约用户记录
  66. // @author: Roc
  67. // @datetime 2023-12-07 14:16:37
  68. // @param item *CompanyRenewalRecord
  69. // @return err error
  70. func (item *CompanyRenewalRecord) Add() (err error) {
  71. o := orm.NewOrm()
  72. lastId, err := o.Insert(item)
  73. if err != nil {
  74. return
  75. }
  76. item.Id = int(lastId)
  77. return
  78. }
  79. type GetUnusualRenewListGroupMonth struct {
  80. Date string
  81. CompanyNum int
  82. }
  83. type GetUnusualRenewListGroupMonthResp struct {
  84. List []*GetUnusualRenewListGroupMonth
  85. }
  86. // GetUnusualRenewList 获取未续约公司列表
  87. func GetUnusualRenewList(startDate, endDate time.Time, productId, source int, sellerIds string) (list []*CompanyRenewalRecord, err error) {
  88. o := orm.NewOrm()
  89. sql := `SELECT
  90. *
  91. FROM
  92. company_renewal_record
  93. WHERE
  94. source = ?
  95. AND modify_time BETWEEN ?
  96. AND ?
  97. AND product_id = ?
  98. AND (share_seller_id in (` + sellerIds + `)
  99. OR seller_id in (` + sellerIds + `))
  100. `
  101. _, err = o.Raw(sql, source, startDate, endDate, productId).QueryRows(&list)
  102. return
  103. }
  104. func (item *CompanyRenewalRecord) InsertMulti(items []*CompanyRenewalRecord) (err error) {
  105. o := orm.NewOrm()
  106. _, err = o.InsertMulti(len(items), items)
  107. return
  108. }