company_renewal_record.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // GetUnusualRenewCompanyList 获取销售未续约数据
  21. func GetUnusualRenewCompanyList(startDate, endDate time.Time, productId int) (list []*CompanyRenewalRecord, err error) {
  22. o := orm.NewOrm()
  23. sql := ` SELECT
  24. a.seller_id,a.share_seller_id,
  25. count(
  26. DISTINCT ( a.company_id )) num,
  27. GROUP_CONCAT( DISTINCT a.company_id SEPARATOR ',' ) AS company_ids
  28. FROM
  29. company_renewal_record as a
  30. WHERE
  31. a.modify_time BETWEEN ?
  32. AND ?
  33. AND a.source = 1
  34. AND a.product_id = ?
  35. GROUP BY
  36. a.seller_id;
  37. `
  38. _, err = o.Raw(sql, startDate, endDate, productId).QueryRows(&list)
  39. return
  40. }